wn.widgets.form.sidebar.Attachments = function(parent, sidebar, doctype, docname) { var me = this; this.frm = sidebar.form; this.make = function() { if(this.wrapper) this.wrapper.innerHTML = ''; else this.wrapper = $a(parent, 'div', 'sidebar-comment-wrapper'); // attachment this.attach_wrapper = $a(this.wrapper, 'div'); // no attachments if file is unsaved if(this.frm.doc.__islocal) { this.attach_wrapper.innerHTML = 'Attachments can be uploaded after saving' return; } // no of attachments var n = this.frm.doc.file_list ? this.frm.doc.file_list.split('\n').length : 0; // button if the number of attachments is less than max if(n < this.frm.meta.max_attachments || !this.frm.meta.max_attachments) { this.btn = $btn($a(this.wrapper, 'div', 'sidebar-comment-message'), 'Add', function() { me.add_attachment() }); } // render this.render(); } // create Attachment objects from // the file_list this.render = function() { // clear exisitng this.attach_wrapper.innerHTML = '' var doc = locals[me.frm.doctype][me.frm.docname]; var fl = doc.file_list ? doc.file_list.split('\n') : []; // add attachment objects for(var i=0; i