diff --git a/core/doctype/letter_head/letter_head.js b/core/doctype/letter_head/letter_head.js index 60086ee016..b65bf92e36 100644 --- a/core/doctype/letter_head/letter_head.js +++ b/core/doctype/letter_head/letter_head.js @@ -23,19 +23,21 @@ cur_frm.cscript.refresh = function(doc) { if (doc.docstatus) hide_field('steps'); + var has_attachments = !$.isEmptyObject(cur_frm.attachments.get_attachments()); + cur_frm.set_intro(""); if(doc.__islocal) { cur_frm.set_intro("Step 1: Set the name and save."); } else { - if(!doc.file_list) { + if(has_attachments) { cur_frm.set_intro("Step 2: Upload your letter head image / set html content directly"); cur_frm.add_custom_button("Upload", function() { cur_frm.attachments.add_attachment(); - }, 'icon-upload'); + }, 'icon-upload'); } } - if(doc.file_list && !doc.content) { + if(has_attachments && !doc.content) { cur_frm.cscript['set_from_image'](doc); } @@ -49,7 +51,7 @@ cur_frm.cscript.content = function(doc) { } cur_frm.cscript['set_from_image'] = function(doc, dt, dn) { - if(!doc.file_list) { + if(!cur_frm.get_files().length) { msgprint('Please attach an image file first'); return; } diff --git a/public/js/legacy/widgets/form/clientscriptAPI.js b/public/js/legacy/widgets/form/clientscriptAPI.js index b8c97e603d..dfcec586b1 100644 --- a/public/js/legacy/widgets/form/clientscriptAPI.js +++ b/public/js/legacy/widgets/form/clientscriptAPI.js @@ -210,7 +210,7 @@ _f.Frm.prototype.call_server = function(method, args, callback) { _f.Frm.prototype.get_files = function() { return cur_frm.attachments - ? keys(cur_frm.attachments.get_file_list()).sort() + ? keys(cur_frm.attachments.get_attachments()).sort() : [] ; } diff --git a/public/js/legacy/widgets/form/form.js b/public/js/legacy/widgets/form/form.js index 81165b256b..2d98e0e14c 100644 --- a/public/js/legacy/widgets/form/form.js +++ b/public/js/legacy/widgets/form/form.js @@ -655,10 +655,6 @@ _f.Frm.prototype.copy_doc = function(onload, from_amend) { var dn = this.docname; // copy parent var newdoc = wn.model.copy_doc(this.doctype, dn, from_amend); - - // do not copy attachments - if(this.meta.allow_attach && newdoc.file_list && !from_amend) - newdoc.file_list = null; // copy chidren var dl = make_doclist(this.doctype, dn); @@ -830,5 +826,8 @@ _f.Frm.prototype.set_value_in_locals = function(dt, dn, fn, v) { _f.Frm.prototype.dirty = function() { this.doc.__unsaved = 1; $(this.wrapper).trigger('dirty') - +} + +_f.Frm.prototype.get_docinfo = function() { + return wn.model.docinfo[this.doctype][this.docname]; } \ No newline at end of file diff --git a/public/js/wn/form/assign_to.js b/public/js/wn/form/assign_to.js index 6161fec5fa..68a07723e7 100644 --- a/public/js/wn/form/assign_to.js +++ b/public/js/wn/form/assign_to.js @@ -48,11 +48,11 @@ wn.ui.form.AssignTo = Class.extend({ return; } this.parent.toggle(true); - this.render(JSON.parse(this.frm.doc.__assign_to || "[]")); + this.render(this.frm.get_docinfo().assignments); }, render: function(d) { var me = this; - this.frm.doc.__assign_to = JSON.stringify(d); + this.frm.get_docinfo().assignments = d; this.$list.empty(); if(this.dialog) { this.dialog.hide(); diff --git a/public/js/wn/form/attachments.js b/public/js/wn/form/attachments.js index a9ea6653f2..dc9efd830f 100644 --- a/public/js/wn/form/attachments.js +++ b/public/js/wn/form/attachments.js @@ -40,7 +40,7 @@ wn.ui.form.Attachments = Class.extend({ }, max_reached: function() { // no of attachments - var n = keys(this.get_file_list()).length; + var n = keys(this.get_attachments()).length; // button if the number of attachments is less than max if(n < this.frm.meta.max_attachments || !this.frm.meta.max_attachments) { @@ -59,22 +59,22 @@ wn.ui.form.Attachments = Class.extend({ this.$list.empty(); - var file_list = this.get_file_list(); - var file_names = keys(file_list).sort(); + var attachments = this.get_attachments(); + var file_names = keys(attachments).sort(); // add attachment objects for(var i=0; i\ @@ -143,7 +143,7 @@ wn.ui.form.Attachments = Class.extend({ update_attachment: function(fileid, filename, fieldname, r) { this.dialog && this.dialog.hide(); if(fileid) { - this.add_to_file_list(fileid, filename); + this.add_to_attachments(fileid, filename); this.refresh(); if(fieldname) { this.frm.set_value(fieldname, "files/"+filename); @@ -151,20 +151,17 @@ wn.ui.form.Attachments = Class.extend({ } } }, - add_to_file_list: function(fileid, filename) { - var doc = this.frm.doc; - var file_list = doc.file_list ? this.get_file_list() : {}; - file_list[filename] = fileid; - doc.file_list = JSON.stringify(file_list); + add_to_attachments: function(fileid, filename) { + this.get_attachments()[filename] = fileid; }, remove_fileid: function(fileid) { - var file_list = this.get_file_list(); - var new_file_list = {}; - $.each(file_list, function(key, value) { + var attachments = this.get_attachments(); + var new_attachments = {}; + $.each(attachments, function(key, value) { if(value!=fileid) - new_file_list[key] = value; + new_attachments[key] = value; }); - this.frm.doc.file_list = JSON.stringify(new_file_list); + this.frm.get_docinfo().attachments = new_attachments; this.refresh(); }, refresh_attachment_select_fields: function() { diff --git a/public/js/wn/form/comments.js b/public/js/wn/form/comments.js index c171f9ceee..196860a1b5 100644 --- a/public/js/wn/form/comments.js +++ b/public/js/wn/form/comments.js @@ -23,6 +23,9 @@ wn.ui.form.Comments = Class.extend({ this.list = $('
') .appendTo(this.parent); }, + get_comments: function() { + return this.frm.get_docinfo().comments; + }, refresh: function() { var me = this; if(this.frm.doc.__islocal) { @@ -31,7 +34,7 @@ wn.ui.form.Comments = Class.extend({ } this.wrapper.toggle(true); this.list.empty(); - var comments = JSON.parse(this.frm.doc.__comments || "[]"); + var comments = this.get_comments(); $.each(comments, function(i, c) { if(wn.model.can_delete("Comment")) { c["delete"] = '×'; @@ -82,8 +85,8 @@ wn.ui.form.Comments = Class.extend({ }, callback: function(r) { if(!r.exc) { - var comments = JSON.parse(me.frm.doc.__comments || "[]"); - me.frm.doc.__comments = JSON.stringify(r.message.concat(comments)); + me.frm.get_docinfo().comments = + r.message.concat(me.get_comments()); me.frm.toolbar.show_infobar(); me.input.val(""); me.refresh(); @@ -102,14 +105,13 @@ wn.ui.form.Comments = Class.extend({ }, callback: function(r) { if(!r.exc) { - me.frm.doc.__comments = JSON.stringify( - $.map(JSON.parse(me.frm.doc.__comments || "[]"), + me.frm.get_docinfo().comments = + $.map(me.frm.get_docinfo().comments, function(v) { if(v.name==name) return null; else return v; } - ) - ); + ); me.refresh(); me.frm.toolbar.show_infobar(); } diff --git a/public/js/wn/form/control.js b/public/js/wn/form/control.js index de5a64b11a..f99f887f7f 100644 --- a/public/js/wn/form/control.js +++ b/public/js/wn/form/control.js @@ -54,6 +54,7 @@ wn.ui.form.Control = Class.extend({ var set = function(value) { me.set_model_value(value); me.inside_change_event = false; + me.set_mandatory && me.set_mandatory(value); } this.validate ? this.validate(value, set) : set(value); @@ -129,7 +130,7 @@ wn.ui.form.ControlInput = wn.ui.form.Control.extend({ this.$wrapper = $("").appendTo(this.parent); } else { this.$wrapper = $('
\ - \ + \
\ \

 

\ @@ -183,7 +184,7 @@ wn.ui.form.ControlInput = wn.ui.form.Control.extend({ me.set_description(); me.set_label(); - me.set_mandatory(); + me.set_mandatory(me.value); return false; } @@ -208,9 +209,9 @@ wn.ui.form.ControlInput = wn.ui.form.Control.extend({ set_empty_description: function() { this.$wrapper.find(".help-box").html(" "); }, - set_mandatory: function() { + set_mandatory: function(value) { this.$wrapper.toggleClass("has-error", (this.df.reqd - && (this.value==null || this.value==="")) ? true : false); + && (value==null || value==="")) ? true : false); }, }); @@ -220,7 +221,7 @@ wn.ui.form.ControlData = wn.ui.form.ControlInput.extend({ make_input: function() { this.$input = $("<"+ this.html_element +">") .attr("type", this.input_type) - .addClass("col col-lg-12") + .addClass("col col-lg-12 input-with-feedback") .prependTo(this.input_area) this.set_input_attributes(); @@ -245,9 +246,10 @@ wn.ui.form.ControlData = wn.ui.form.ControlInput.extend({ set_input: function(val) { this.$input.val(this.format_for_input(val)); this.last_value = val; + this.set_mandatory && this.set_mandatory(val); }, get_value: function() { - return this.$input.val(); + return this.$input ? this.$input.val() : undefined; }, format_for_input: function(val) { return val==null ? "" : val; @@ -516,11 +518,10 @@ wn.ui.form.ControlSelect = wn.ui.form.ControlData.extend({ }, get_file_attachment_list: function() { if(!this.frm) return; - var fl = this.frm.doc.file_list; + var fl = wn.model.docinfo[this.frm.doctype][this.frm.docname]; if(fl) { this.set_description(""); - var fl = JSON.parse(fl), - options = [""]; + var options = [""]; for(var fname in fl) { if(fname.substr(0,4)!="http") fname = "files/" + fname; @@ -543,7 +544,7 @@ wn.ui.form.ControlSelect = wn.ui.form.ControlData.extend({ wn.ui.form.ControlLink = wn.ui.form.ControlData.extend({ make_input: function() { $('