// 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, p { \ font-family: inherit; \ font-size: inherit; \ }\ .page-settings {\ font-family: Arial, Helvetica Neue, Sans;\ 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 dialog = new wn.ui.Dialog({ title: "Print Formats", fields: [ {fieldtype:"Select", label:"Print Format", fieldname:"print_format", reqd:1}, {fieldtype:"Check", label:"No Letter Head", fieldname:"no_letterhead"}, {fieldtype:"HTML", options: '
\ \ \
'}, ] }) dialog.$wrapper.find(".btn-print").click(function() { var args = dialog.get_values(); _p.build( args.print_format, // fmtname _p.go, // onload args.no_letterhead // no_letterhead ); }); dialog.$wrapper.find(".btn-preview").click(function() { var args = dialog.get_values(); _p.build( args.print_format, // fmtname _p.preview, // onload args.no_letterhead // no_letterhead ); }); dialog.onshow = function() { var $print = dialog.fields_dict.print_format.$input; $print.add_options(cur_frm.print_formats); if(cur_frm.$print_view_select && cur_frm.$print_view_select.val()) $print.val(cur_frm.$print_view_select.val()); } _p.dialog = dialog; }, // 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, no_heading) { 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, no_heading), style: _p.print_style, doc: doc, title: doc.name, no_letterhead: args.no_letterhead, no_heading: no_heading, 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, no_heading: no_heading, only_body: args.only_body })); } }, render: function(args) { var container = document.createElement('div'); var stat = ''; if(!args.no_heading) { // 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 "\