From 03c1a053ead72cfb9b51c932b4e201519a526bc5 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Mon, 25 Nov 2013 14:38:55 +0530 Subject: [PATCH] [print preview] brought back inside form --- public/js/legacy/form.js | 163 +++++++++++++++++++++---------- public/js/legacy/print_format.js | 2 +- 2 files changed, 110 insertions(+), 55 deletions(-) diff --git a/public/js/legacy/form.js b/public/js/legacy/form.js index a977833105..ba2a1e367f 100644 --- a/public/js/legacy/form.js +++ b/public/js/legacy/form.js @@ -7,7 +7,6 @@ + this.wrapper + this.toolbar + this.form_wrapper - + this.main + this.head + this.body + this.layout @@ -98,6 +97,9 @@ _f.Frm.prototype.setup = function() { }); this.frm_head = this.toolbar; + // print layout + this.setup_print_layout(); + // 2 column layout this.setup_std_layout(); @@ -117,6 +119,77 @@ _f.Frm.prototype.setup = function() { this.setup_done = true; } +_f.Frm.prototype.setup_print_layout = function() { + this.print_wrapper = $('
\ + \ + \ +
') + .appendTo(this.layout_main) + .toggle(false); + + var me = this; + this.print_wrapper.find(".close").click(function() { + me.hide_print(); + }); + + this.print_formats = wn.meta.get_print_formats(this.meta.name); + this.print_letterhead = this.print_wrapper + .find(".print-letterhead") + .on("change", function() { me.print_sel.trigger("change"); }); + this.print_sel = this.print_wrapper + .find(".print-preview-select") + .on("change", function() { + _p.build(me.print_sel.val(), function(html) { + me.print_wrapper.find(".print-preview").html(html); + }, !me.print_letterhead.is(":checked"), true, true); + }) + + this.print_wrapper.find(".print-print").click(function() { + _p.build( + me.print_sel.val(), // fmtname + _p.go, // onload + !me.print_letterhead.is(":checked") // no_letterhead + ); + }) +} + +_f.Frm.prototype.print_doc = function() { + if(this.print_wrapper.is(":visible")) { + this.hide_print(); + return; + } + if(this.doc.docstatus==2) { + msgprint("Cannot Print Cancelled Documents."); + return; + } + this.print_wrapper.toggle(true); + this.print_sel + .empty().add_options(this.print_formats) + .trigger("change"); + + this.form_wrapper.toggle(false); +} + +_f.Frm.prototype.hide_print = function() { + if(this.setup_done) { + this.print_wrapper.toggle(false); + this.form_wrapper.toggle(true); + } +} + _f.Frm.prototype.watch_model_updates = function() { // watch model updates var me = this; @@ -151,11 +224,9 @@ _f.Frm.prototype.onhide = function() { } _f.Frm.prototype.setup_std_layout = function() { - this.form_wrapper = $('
').appendTo(this.layout_main).get(0); - $parent = $(this.form_wrapper); - this.main = this.form_wrapper; - this.body_header = $a(this.main, 'div'); - this.body = $a(this.main, 'div'); + this.form_wrapper = $('
').appendTo(this.layout_main); + this.body_header = $("
").appendTo(this.form_wrapper); + this.body = $("
").appendTo(this.form_wrapper); // only tray this.meta.section_style='Simple'; // always simple! @@ -181,22 +252,6 @@ _f.Frm.prototype.setup_std_layout = function() { }); } -_f.Frm.prototype.setup_print = function() { - this.print_formats = wn.meta.get_print_formats(this.meta.name); - this.print_sel = $("