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 = $("