From 7e7640bb8bfe1ccb277883fa35d834ca0838038f Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Tue, 19 Aug 2014 17:34:21 +0530 Subject: [PATCH] [fix] Remove button in Attach field --- frappe/public/js/frappe/form/attachments.js | 19 +++++++++++++++++-- frappe/public/js/frappe/form/control.js | 6 ++++-- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/frappe/public/js/frappe/form/attachments.js b/frappe/public/js/frappe/form/attachments.js index 8cd9dffc1e..b0b1fe5739 100644 --- a/frappe/public/js/frappe/form/attachments.js +++ b/frappe/public/js/frappe/form/attachments.js @@ -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(); } }); }, diff --git a/frappe/public/js/frappe/form/control.js b/frappe/public/js/frappe/form/control.js index 538246667d..dc615ffbe3 100644 --- a/frappe/public/js/frappe/form/control.js +++ b/frappe/public/js/frappe/form/control.js @@ -559,8 +559,10 @@ frappe.ui.form.ControlAttach = frappe.ui.form.ControlData.extend({ me.onclick(); }); this.$value = $('
\ - \ - \ +
\ + \ + \ +
\ ×
') .prependTo(me.input_area) .toggle(false);