// Copyright (c) 2012 Web Notes Technologies Pvt Ltd (http://erpnext.com) // // MIT License (MIT) // // Permission is hereby granted, free of charge, to any person obtaining a // copy of this software and associated documentation files (the "Software"), // to deal in the Software without restriction, including without limitation // the rights to use, copy, modify, merge, publish, distribute, sublicense, // and/or sell copies of the Software, and to permit persons to whom the // Software is furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A // PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF // CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE // OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // /* Form page structure + this.parent (either FormContainer or Dialog) + this.wrapper + this.content + wn.PageLayout (this.page_layout) + this.wrapper + this.wtab (table) + this.main + this.head + this.body + this.layout + this.footer + this.sidebar + this.print_wrapper + this.head */ wn.provide('_f'); wn.provide('wn.ui.form'); wn.ui.form.Controller = Class.extend({ init: function(opts) { $.extend(this, opts); } }); _f.frms = {}; _f.Frm = function(doctype, parent, in_form) { this.docname = ''; this.doctype = doctype; this.display = 0; this.refresh_if_stale_for = 600; var me = this; this.is_editable = {}; this.opendocs = {}; this.sections = []; this.grids = []; this.cscript = new wn.ui.form.Controller({frm:this}); this.pformat = {}; this.fetch_dict = {}; this.parent = parent; this.tinymce_id_list = []; this.setup_meta(doctype); // show in form instead of in dialog, when called using url (router.js) this.in_form = in_form ? true : false; // notify on rename var me = this; $(document).bind('rename', function(event, dt, old_name, new_name) { if(dt==me.doctype) me.rename_notify(dt, old_name, new_name) }); } // ====================================================================================== _f.Frm.prototype.check_doctype_conflict = function(docname) { var me = this; if(this.doctype=='DocType' && docname=='DocType') { msgprint('Allowing DocType, DocType. Be careful!') } else if(this.doctype=='DocType') { if (wn.views.formview[docname] || wn.pages['List/'+docname]) { msgprint("Cannot open DocType when its instance is open") throw 'doctype open conflict' } } else { if (wn.views.formview.DocType && wn.views.formview.DocType.frm.opendocs[this.doctype]) { msgprint("Cannot open instance when its DocType is open") throw 'doctype open conflict' } } } _f.Frm.prototype.setup = function() { var me = this; this.fields = []; this.fields_dict = {}; // wrapper this.wrapper = this.parent; // create area for print fomrat this.setup_print_layout(); // 2 column layout this.setup_std_layout(); // client script must be called after "setup" - there are no fields_dict attached to the frm otherwise this.setup_client_script(); this.setup_done = true; } // ====================================================================================== _f.Frm.prototype.setup_print_layout = function() { var me = this; this.print_wrapper = $a(this.wrapper, 'div'); wn.ui.make_app_page({ parent: this.print_wrapper, single_column: true, set_document_title: false, title: me.doctype + ": Print View", module: me.meta.module }); var appframe = this.print_wrapper.appframe; appframe.add_button("View Details", function() { me.edit_doc(); }).addClass("btn-success"); appframe.add_button("Print", function() { me.print_doc(); }, 'icon-print'); this.$print_view_select = appframe.add_select("Select Preview", this.print_formats) .css({"float":"right"}) .val(this.print_formats[0]) .change(function() { me.refresh_print_layout(); }) appframe.add_ripped_paper_effect(this.print_wrapper); var layout_main = $(this.print_wrapper).find(".layout-main"); this.print_body = $("
/)==-1) txt = '
' + txt + '
'; this.intro_area.html(txt); } else { this.intro_area.remove(); this.intro_area = null; } } _f.Frm.prototype.set_footnote = function(txt) { if(!this.footnote_area) { this.footnote_area = $('/)==-1) txt = '
' + txt + '
'; this.footnote_area.html(txt); } else { this.footnote_area.remove(); this.footnote_area = null; } } _f.Frm.prototype.setup_fields_std = function() { var fl = wn.meta.docfield_list[this.doctype]; fl.sort(function(a,b) { return a.idx - b.idx}); if(fl[0]&&fl[0].fieldtype!="Section Break" || get_url_arg('embed')) { this.layout.addrow(); // default section break if(fl[0].fieldtype!="Column Break") {// without column too var c = this.layout.addcell(); $y(c.wrapper, {padding: '8px'}); } } var sec; for(var i=0;i