From 0611104a0423c85a9d869f6f95836096d0aba2ec Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Tue, 4 Dec 2012 19:57:42 +0530 Subject: [PATCH 1/5] refactored print_table --- public/build.json | 1 + public/js/legacy/widgets/form/form.js | 9 +- public/js/legacy/widgets/form/print_format.js | 402 +++++++++--------- public/js/wn/form/formatters.js | 2 +- public/js/wn/print/print_table.js | 206 +++++++++ 5 files changed, 416 insertions(+), 204 deletions(-) create mode 100644 public/js/wn/print/print_table.js diff --git a/public/build.json b/public/build.json index 5e8c32c5cf..00eab1c0bc 100644 --- a/public/build.json +++ b/public/build.json @@ -145,6 +145,7 @@ "lib/public/js/legacy/wn/widgets/form/attachments.js", "lib/public/js/legacy/wn/widgets/form/assign_to.js", "lib/public/js/wn/form/linked_with.js", + "lib/public/js/wn/print/print_table.js", 'lib/public/js/lib/jquery/jquery.ui.interactions.min.js', diff --git a/public/js/legacy/widgets/form/form.js b/public/js/legacy/widgets/form/form.js index 82d3192cc2..e9c907b138 100644 --- a/public/js/legacy/widgets/form/form.js +++ b/public/js/legacy/widgets/form/form.js @@ -132,6 +132,13 @@ _f.Frm.prototype.setup_print_layout = function() { 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); @@ -421,7 +428,7 @@ _f.Frm.prototype.refresh_print_layout = function() { } // create print format here - _p.build(this.print_formats[0], print_callback, null, 1); + _p.build(this.$print_view_select.val(), print_callback, null, 1); } diff --git a/public/js/legacy/widgets/form/print_format.js b/public/js/legacy/widgets/form/print_format.js index 913728aea8..017a934db3 100644 --- a/public/js/legacy/widgets/form/print_format.js +++ b/public/js/legacy/widgets/form/print_format.js @@ -289,21 +289,19 @@ $.extend(_p, { // This is used to calculate and substitude values in the HTML run_embedded_js: function(container, doc) { - var jslist = container.getElementsByTagName('script'); - while(jslist && jslist.length > 0) { - for(i in jslist) { - if(jslist[i] && jslist[i].innerHTML) { - var code = jslist[i].innerHTML; - var parent = jslist[i].parentNode; - var span = $a(parent, 'span'); - parent.replaceChild(span, jslist[i]); - var val = code ? eval(code) : ''; - if(!val || typeof(val)=='object') { val = ''; } - span.innerHTML = val; - } - } - jslist = container.getElementsByTagName('script'); - } + $(container).find("script").each(function(element) { + var code = this.innerHTML; + var new_html = code ? (eval(code) || "") : ""; + if(typeof new_html=="string") + $(this).replaceWith(new_html); + + // var parent = jslist[i].parentNode; + // var span = $a(parent, 'span'); + // parent.replaceChild(span, jslist[i]); + // var val = code ? eval(code) : ''; + // if(!val || typeof(val)=='object') { val = ''; } + // span.innerHTML = val; + }) }, @@ -645,190 +643,190 @@ $.extend(_p, { }); -print_table = function(dt, dn, fieldname, tabletype, cols, head_labels, widths, condition, cssClass, modifier, hide_empty) { - var me = this; - $.extend(this, { - flist: (function() { - var f_list = []; - var fl = wn.meta.docfield_list[tabletype]; - if(fl) { - for(var i=0; i