// 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. // // default print style _p.def_print_style_body = "html, body, div, span, td { \ font-family: Arial, Helvetica; \ font-size: 9pt; \ }\ pre { margin:0; padding:0;}"; _p.def_print_style_other = "\n.simpletable, .noborder { \ border-collapse: collapse;\ margin-bottom: 10px;\ }\ .simpletable td {\ border: 1pt solid #777;\ vertical-align: top;\ padding: 4px;\ }\ .noborder td {\ vertical-align: top;\ }"; _p.go = function(html) { var d = document.createElement('div') d.innerHTML = html $(d).printElement(); } _p.preview = function(html) { var w = window.open(''); if(!w) return; w.document.write(html) w.document.close(); } // _p can be referenced as this inside $.extend $.extend(_p, { show_dialog: function() { if(!_p.dialog) { _p.make_dialog(); } _p.dialog.show(); }, make_dialog: function() { // Prepare Dialog Box Layout var d = new Dialog( 360, // w 140, // h 'Print Formats', // title [ // content ['HTML', 'Select'], ['Check', 'No Letterhead'], ['HTML', 'Buttons'] ]); //d.widgets['No Letterhead'].checked = 1; // Print Button $btn(d.widgets.Buttons, 'Print', function() { _p.build( sel_val(cur_frm.print_sel), // fmtname _p.go, // onload d.widgets['No Letterhead'].checked // no_letterhead ); }, { cssFloat: 'right', marginBottom: '16px', marginLeft: '7px' }, 'green'); // Print Preview $btn(d.widgets.Buttons, 'Preview', function() { _p.build( sel_val(cur_frm.print_sel), // fmtname _p.preview, // onload d.widgets['No Letterhead'].checked // no_letterhead ); }, { cssFloat: 'right', marginBottom: '16px' }, ''); // Delete previous print format select list and Reload print format list from current form d.onshow = function() { var c = _p.dialog.widgets['Select']; if(c.cur_sel && c.cur_sel.parentNode == c) { c.removeChild(c.cur_sel); } c.appendChild(cur_frm.print_sel); c.cur_sel = cur_frm.print_sel; } _p.dialog = d; }, // Define formats dict formats: {}, /* args dict can contain: + fmtname --> print format name + onload + no_letterhead + only_body */ build: function(fmtname, onload, no_letterhead, only_body) { if(!fmtname) { fmtname= "Standard"; } args = { fmtname: fmtname, onload: onload, no_letterhead: no_letterhead, only_body: only_body }; if(!cur_frm) { alert('No Document Selected'); return; } // Get current doc (record) var doc = locals[cur_frm.doctype][cur_frm.docname]; if(args.fmtname == 'Standard') { args.onload(_p.render({ body: _p.print_std(args.no_letterhead), style: _p.print_style, doc: doc, title: doc.name, no_letterhead: args.no_letterhead, only_body: args.only_body })); } else { var print_format_doc = locals["Print Format"][args.fmtname]; if(!print_format_doc) { msgprint("Unknown Print Format: " + args.fmtname); return; } args.onload(_p.render({ body: print_format_doc.html, style: '', doc: doc, title: doc.name, no_letterhead: args.no_letterhead, only_body: args.only_body })); } }, render: function(args) { var container = document.createElement('div'); var stat = ''; // if draft/archived, show draft/archived banner stat += _p.show_draft(args); stat += _p.show_archived(args); stat += _p.show_cancelled(args); // Append args.body's content as a child of container container.innerHTML = args.body; // Show letterhead? _p.show_letterhead(container, args); _p.run_embedded_js(container, args.doc); var style = _p.consolidate_css(container, args); _p.render_header_on_break(container, args); return _p.render_final(style, stat, container, args); }, head_banner_format: function() { return "\