[fix] Remove button in Attach field

This commit is contained in:
Anand Doshi 2014-08-19 17:34:21 +05:30
parent 2be8f347bf
commit 7e7640bb8b
2 changed files with 21 additions and 4 deletions

View file

@ -109,10 +109,25 @@ frappe.ui.form.Attachments = Class.extend({
// hash is not escaped, https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURI
return encodeURI(file_url).replace(/#/g, '%23');
},
get_file_id_from_file_url: function(file_url) {
var fid;
$.each(this.get_attachments(), function(i, attachment) {
if (attachment.file_url === file_url) {
fid = attachment.name;
return false;
}
});
return fid;
},
remove_attachment_by_filename: function(filename, callback) {
this.remove_attachment(this.get_attachments()[filename], callback);
this.remove_attachment(this.get_file_id_from_file_url(filename), callback);
},
remove_attachment: function(fileid, callback) {
if (!fileid) {
if (callback) callback();
return;
}
var me = this;
return frappe.call({
method: 'frappe.widgets.form.utils.remove_attach',
@ -131,7 +146,7 @@ frappe.ui.form.Attachments = Class.extend({
me.frm.toolbar.show_infobar();
me.frm.get_docinfo().comments.push(r.message);
me.frm.comments.refresh();
if(callback) callback();
if (callback) callback();
}
});
},

View file

@ -559,8 +559,10 @@ frappe.ui.form.ControlAttach = frappe.ui.form.ControlData.extend({
me.onclick();
});
this.$value = $('<div style="margin-top: 5px;">\
<i class="icon-paper-clip" style="overflow: hidden; display: inline-block"></i> \
<a class="attached-file text-ellipsis" style="width: 80%" target="_blank"></a>\
<div class="text-ellipsis" style="display: inline-block; width: 90%;">\
<i class="icon-paper-clip"></i> \
<a class="attached-file" target="_blank"></a>\
</div>\
<a class="close">&times;</a></div>')
.prependTo(me.input_area)
.toggle(false);