diff --git a/js/legacy/app.js b/js/legacy/app.js index 0e5e0046e5..ca0a3bfe88 100644 --- a/js/legacy/app.js +++ b/js/legacy/app.js @@ -134,8 +134,7 @@ function redirect_to_login() { } // default print style -_p.def_print_style_body = "html, body, div, span, td { font-family: Arial, Helvetica; font-size: 12px; }" - +"\npre { margin:0; padding:0;}" +_p.def_print_style_body = "html, body, div, span, td { font-family: Arial, Helvetica; font-size: 12px; }" + "\npre { margin:0; padding:0;}" _p.def_print_style_other = "\n.simpletable, .noborder { border-collapse: collapse; margin-bottom: 10px;}" +"\n.simpletable td {border: 1pt solid #000; vertical-align: top; padding: 2px; }" diff --git a/js/legacy/form.compressed.js b/js/legacy/form.compressed.js index 3a78902891..e19b8ce61c 100644 --- a/js/legacy/form.compressed.js +++ b/js/legacy/form.compressed.js @@ -340,74 +340,81 @@ _f.FormGrid.prototype.move_row=function(up){if(!this.check_selected())return;var len=len-1;if(r.rowIndex<(len-1)) var swap_row=this.tab.rows[r.rowIndex+1];} if(swap_row){var cidx=_f.cur_grid_cell.cellIndex;this.cell_deselect();var aidx=locals[this.doctype][r.docname].idx;locals[this.doctype][r.docname].idx=locals[this.doctype][swap_row.docname].idx;locals[this.doctype][swap_row.docname].idx=aidx;var adocname=swap_row.docname;this.refresh_row(swap_row.rowIndex,r.docname);this.refresh_row(r.rowIndex,adocname);this.cell_select(this.tab.rows[swap_row.rowIndex].cells[cidx]);this.set_unsaved();}} -_p.show_dialog=function(){if(!_p.dialog){_p.make_dialog();} -_p.dialog.show();} -_p.make_dialog=function(){var d=new Dialog(360,140,"Print Formats");d.make_body([['HTML','Select'],['Check','No Letterhead','Will ignore letterhead if it can be set. May not work for all formats'],['HTML','Buttons']]);d.widgets['No Letterhead'].checked=1;$btn(d.widgets.Buttons,'Print',function(){_p.build(sel_val(cur_frm.print_sel),_p.go,d.widgets['No Letterhead'].checked);},{cssFloat:'right',marginBottom:'16px',marginLeft:'7px'},'green');$btn(d.widgets.Buttons,'Preview',function(){_p.build(sel_val(cur_frm.print_sel),_p.preview,d.widgets['No Letterhead'].checked);},{cssFloat:'right',marginBottom:'16px'},'');_p.dialog=d;d.onshow=function(){var c=d.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.field_tab=function(layout_cell){var t=$a(layout_cell,'table','',{width:'100%'});var r=t.insertRow(0);this.r=r;r.insertCell(0);r.insertCell(1);r.cells[0].className='datalabelcell';r.cells[1].className='datainputcell';return r} -_p.print_std_add_table=function(t,layout,pf_list,dt,no_letterhead){if(t.appendChild){layout.cur_cell.appendChild(t);}else{for(var ti=0;ti';layout=_p.add_layout(dt,no_letterhead);pf_list[pf_list.length]=layout;layout.addrow();layout.addcell();var div=$a(layout.cur_cell,'div');div.innerHTML='Continued from previous page...';div.style.padding='4px';} +$.extend(_p,{show_dialog:function(){if(!_p.dialog){_p.make_dialog();} +_p.dialog.show();},make_dialog:function(){var d=new Dialog(360,140,'Print Formats',[['HTML','Select'],['Check','No Letterhead'],['HTML','Buttons']]);$btn(d.widgets.Buttons,'Print',function(){_p.build(sel_val(cur_frm.print_sel),_p.go,d.widgets['No Letterhead'].checked);},{cssFloat:'right',marginBottom:'16px',marginLeft:'7px'},'green');$btn(d.widgets.Buttons,'Preview',function(){_p.build(sel_val(cur_frm.print_sel),_p.preview,d.widgets['No Letterhead'].checked);},{cssFloat:'right',marginBottom:'16px'},'');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;},formats:{},build:function(fmtname,onload,no_letterhead,only_body){args={fmtname:fmtname,onload:onload,no_letterhead:no_letterhead,only_body:only_body};if(!cur_frm){alert('No Document Selected');return;} +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{if(!_p.formats[args.fmtname]){var build_args=args;$c(command='webnotes.widgets.form.get_print_format',args={'name':build_args.fmtname},fn=function(r,rt){_p.formats[build_args.fmtname]=r.message;build_args.onload(_p.render({body:_p.formats[build_args.fmtname],style:'',doc:doc,title:doc.name,no_letterhead:build_args.no_letterhead,only_body:build_args.only_body}));});}else{args.onload(_p.render({body:_p.formats[args.fmtname],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='';stat+=_p.show_draft(args);stat+=_p.show_archived(args);container.innerHTML=args.body;_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"\ +
\ +
\ + {{HEAD}}\ +
\ + {{DESCRIPTION}}\ +
"},show_draft:function(args){if(args.doc&&cint(args.doc.docstatus)==0&&cur_frm.perm[0][SUBMIT]){draft=_p.head_banner_format();draft=draft.replace("{{HEAD}}","DRAFT");draft=draft.replace("{{DESCRIPTION}}","This box will go away after the document is submitted.");return draft;}else{return"";}},show_archived:function(args){if(args.doc&&args.doc.__archived){archived=_p.head_banner_format();archived=archived.replace("{{HEAD}}","ARCHIVED");archived=archived.replace("{{DESCRIPTION}}","You must restore this document to make it editable.");}else{return"";}},consolidate_css:function(container,args){var body_style='';var style_list=container.getElementsByTagName('style');while(style_list&&style_list.length>0){for(i in style_list){if(style_list[i]&&style_list[i].innerHTML){body_style+=style_list[i].innerHTML;var parent=style_list[i].parentNode;if(parent){parent.removeChild(style_list[i]);}else{container.removeChild(style_list[i]);}}} +style_list=container.getElementsByTagName('style');} +style_concat=(args.only_body?'':_p.def_print_style_body) ++_p.def_print_style_other+args.style+body_style;return style_concat;},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');}},show_letterhead:function(container,args){if(!(args.no_letterhead||args.only_body)){container.innerHTML='
'+_p.get_letter_head()+'
' ++container.innerHTML;}},render_header_on_break:function(container,args){var page_set=container.getElementsByClassName('page-settings');if(page_set.length){for(var i=0;i\ + \ + \ + \n'+header;footer=footer+'\n\n\ + ';} +var finished=header ++stat ++container.innerHTML.replace(/
'+field.label+':
'+(val?val:'')+'
';break;case'Text Editor':var div=$a(me.layout.cur_cell,'div');var val=_f.get_value(doctype,docname,field.fieldname);div.innerHTML=val?val:'';break;default:_p.print_std_add_field(doctype,docname,field,me.layout);break;}}});for(var i=0;i'+f.label+': '+'
'+(v?v:'')+'
';break;case'Text Editor':var tmp=$a(layout.cur_cell,'div');var v=_f.get_value(dt,dn,f.fieldname);tmp.innerHTML=v?v:'';break;default:_p.print_std_add_field(dt,dn,f,layout);}}}} -layout.close_borders();var html='';for(var i=0;i0){for(var i=0;i'+block.innerHTML;} -if(only_body){return tmp_html+block.innerHTML.replace(/\n' -+'' -+''+title+'' -+'' -+'' -+tmp_html -+block.innerHTML.replace(/';}} -print_table=function(dt,dn,fieldname,tabletype,cols,head_labels,widths,condition,cssClass){var fl=fields_list[tabletype];var ds=getchildren(tabletype,dn,fieldname,dt);var tl=[];var cell_style={border:'1px solid #000',padding:'2px',verticalAlign:'top'};var head_cell_style={border:'1px solid #000',padding:'2px',verticalAlign:'top',backgroundColor:'#ddd'};var make_table=function(fl){var w=document.createElement('div');var t=$a(w,'table','',{width:'100%',borderCollapse:'collapse',marginBottom:'10px'});t.wrapper=w;t.insertRow(0);var c_start=0;if(fl[0]=='SR'){var cell=t.rows[0].insertCell(0) -cell.innerHTML=head_labels?head_labels[0]:'Sr';$y(cell,{width:'30px'});$y(cell,head_cell_style) -c_start=1;} -for(var c=c_start;c1)return tl;else return tl[0];} +return layout;},print_std_add_field:function(dt,dn,f,layout){var val=_f.get_value(dt,dn,f.fieldname);if(f.fieldtype!='Button'){if(val||in_list(['Float','Int','Currency'],f.fieldtype)){row=_p.field_tab(layout.cur_cell);row.cells[0].innerHTML=f.label?f.label:f.fieldname;$s(row.cells[1],val,f.fieldtype);if(f.fieldtype=='Currency'){$y(row.cells[1],{textAlign:'left'});}}}},field_tab:function(layout_cell){var tab=$a(layout_cell,'table','',{width:'100%'});var row=tab.insertRow(0);_p.row=row;row.insertCell(0);row.insertCell(1);row.cells[0].className='datalabelcell';row.cells[1].className='datainputcell';return row;}});print_table=function(dt,dn,fieldname,tabletype,cols,head_labels,widths,condition,cssClass,modifier){var me=this;$.extend(this,{flist:fields_list[tabletype],data:getchildren(tabletype,dn,fieldname,dt),cell_style:{border:'1px solid #000',padding:'2px',verticalAlign:'top'},head_cell_style:{border:'1px solid #000',padding:'2px',verticalAlign:'top',backgroundColor:'#ddd',fontWeight:'bold'},table_style:{width:'100%',borderCollapse:'collapse',marginBottom:'10px'},prepare_col_heads:function(flist){var new_flist=[];if(cols&&cols.length){if(cols[0]=='SR'){new_flist.push('SR')} +for(var i=0;iSR';$y(cell,{width:'30px'});$y(cell,me.head_cell_style);col_start++;} +for(var c=col_start;c1)?me.table_list:me.table_list[0];} _e.email_as_field='email_id';_e.email_as_dt='Contact';_e.email_as_in='email_id,contact_name';sendmail=function(emailto,emailfrom,cc,subject,message,fmt,with_attachments){var fn=function(html){$c('webnotes.utils.email_lib.send_form',{'sendto':emailto,'sendfrom':emailfrom?emailfrom:'','cc':cc?cc:'','subject':subject,'message':replace_newlines(message),'body':html,'full_domain':wn.urllib.get_base_url(),'with_attachments':with_attachments?1:0,'dt':cur_frm.doctype,'dn':cur_frm.docname},function(r,rtxt){});} _p.build(fmt,fn);} _e.make=function(){var d=new Dialog(440,440,"Send Email");var email_go=function(){var emailfrom=d.widgets['From'].value;var emailto=d.widgets['To'].value;if(!emailfrom) diff --git a/js/legacy/widgets/form/print_format.js b/js/legacy/widgets/form/print_format.js index 3d519417cf..f7e0c74ce0 100644 --- a/js/legacy/widgets/form/print_format.js +++ b/js/legacy/widgets/form/print_format.js @@ -1,416 +1,725 @@ -_p.show_dialog = function() { - if(!_p.dialog) { - _p.make_dialog(); - } - _p.dialog.show(); -} - -_p.make_dialog = function() { - var d = new Dialog(360, 140, "Print Formats"); - d.make_body( - [['HTML','Select'] - ,['Check','No Letterhead','Will ignore letterhead if it can be set. May not work for all formats'] - ,['HTML', 'Buttons'] - ]); - - d.widgets['No Letterhead'].checked = 1; - - // prints - $btn(d.widgets.Buttons, 'Print', - function() { _p.build(sel_val(cur_frm.print_sel), _p.go, d.widgets['No Letterhead'].checked); }, - {cssFloat:'right', marginBottom:'16px', marginLeft:'7px'}, 'green'); - - // preview - $btn(d.widgets.Buttons, 'Preview', - function() { _p.build(sel_val(cur_frm.print_sel), _p.preview, d.widgets['No Letterhead'].checked); }, - {cssFloat:'right', marginBottom:'16px'}, ''); - - _p.dialog = d; - d.onshow = function() { - var c = d.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.field_tab = function(layout_cell) { - var t = $a(layout_cell, 'table', '', {width:'100%'}); - var r = t.insertRow(0); this.r = r; - r.insertCell(0); r.insertCell(1); - r.cells[0].className='datalabelcell'; - r.cells[1].className='datainputcell'; - return r -} - - -// standard layout -// ========================================================================== - -_p.print_std_add_table = function(t, layout, pf_list, dt, no_letterhead) { - if(t.appendChild) { - // one table only - layout.cur_cell.appendChild(t); - } else { - // multiple tables - for(var ti=0;ti print format name + + onload + + no_letterhead + + only_body + */ + build: function(fmtname, onload, no_letterhead, only_body) { + args = { + fmtname: fmtname, + onload: onload, + no_letterhead: no_letterhead, + only_body: only_body + }; - var fl = getchildren('DocField', dt, 'fields', 'DocType'); - - if(fl[0]&&fl[0].fieldtype!="Section Break") { - layout.addrow(); // default section break - if(fl[0].fieldtype!="Column Break") // without column too - layout.addcell(); - } - - // build each field - for(var i=0;i'; - break; - case 'Column Break': - layout.addcell(f.width, f.label); - //if(f.label) layout.cur_cell.header.innerHTML = '
'+f.label+'
'; - break; - case 'Table': - var t = print_table(dt, dn,f.fieldname,f.options,null,null,null,null); - layout = _p.print_std_add_table(t, layout, pf_list, dt, no_letterhead); - break; - case 'HTML': - var tmp = $a(layout.cur_cell, 'div'); - tmp.innerHTML = f.options; - break; - case 'Code': - var tmp = $a(layout.cur_cell, 'div'); - var v= _f.get_value(dt,dn,f.fieldname); - tmp.innerHTML = '
'+ f.label + ':
' + '
'+(v?v:'')+'
'; - break; - case 'Text Editor': - var tmp = $a(layout.cur_cell, 'div'); - var v= _f.get_value(dt,dn,f.fieldname); - tmp.innerHTML = v?v:''; - break; - default: - // add cell data - _p.print_std_add_field(dt, dn, f, layout); - - } - } + // If print format is already loaded, go ahead with args onload function call + args.onload(_p.render({ + body: _p.formats[args.fmtname], + style: '', + doc: doc, + title: doc.name, + no_letterhead: args.no_letterhead, + only_body: args.only_body + })); + } } - } - - layout.close_borders(); + }, - // build html for each page - var html = ''; - for(var i=0;i \ +
\ + {{HEAD}}\ +
\ + {{DESCRIPTION}}\ + " + }, + + /* + Check if doc's status is not submitted (docstatus == 0) + and submission is pending + + Display draft in header if true + */ + show_draft: function(args) { + if(args.doc && cint(args.doc.docstatus)==0 && cur_frm.perm[0][SUBMIT]) { + draft = _p.head_banner_format(); + draft = draft.replace("{{HEAD}}", "DRAFT"); + draft = draft.replace("{{DESCRIPTION}}", "This box will go away after the document is submitted."); + return draft; } else { - html += pf_list[i]; + return ""; } - } - - pf_list = []; // cleanup - return html; -} - -_p.print_style = ".datalabelcell {padding: 2px 0px; width: 38%;vertical-align:top; }" - +".datainputcell { padding: 2px 0px; width: 62%; text-align:left; }" - +".sectionHeading { font-size: 16px; font-weight: bold; margin: 8px 0px }" - +".columnHeading { font-size: 14px; font-weight: bold; margin: 8px 0px; }" - -_p.formats = {} - -_p.build = function(fmtname, onload, no_letterhead, only_body) { - if(!cur_frm) { alert('No Document Selected'); return; } - var doc = locals[cur_frm.doctype][cur_frm.docname]; - if(fmtname=='Standard') { - onload(_p.render(_p.print_std(no_letterhead), _p.print_style, doc, doc.name, no_letterhead, only_body)); - } else { - if(!_p.formats[fmtname]) // not loaded, get data - $c('webnotes.widgets.form.get_print_format', {'name':fmtname }, - function(r,rt) { - _p.formats[fmtname] = r.message; - onload(_p.render(_p.formats[fmtname], '', doc, doc.name, no_letterhead, only_body)); - } - ); - else // loaded - onload(_p.render(_p.formats[fmtname], '', doc, doc.name, no_letterhead, only_body)); - } -} - -_p.render = function(body, style, doc, title, no_letterhead, only_body) { - var block = document.createElement('div'); - var tmp_html = ''; + }, - if(doc && cint(doc.docstatus)==0 && cur_frm.perm[0][SUBMIT]) { - var tmp_html = '
DRAFT
This box will go away after the document is submitted.
'; - } - if(doc && doc.__archived) { - var tmp_html = '
ARCHIVED
You must restore this document to make it editable.
'; - } - - style = (only_body ? '' : _p.def_print_style_body) + _p.def_print_style_other + style; - block.innerHTML = body; + /* + Check if doc is archived + Display archived in header if true + */ + show_archived: function(args) { + if(args.doc && args.doc.__archived) { + archived = _p.head_banner_format(); + archived = archived.replace("{{HEAD}}", "ARCHIVED"); + archived = archived.replace("{{DESCRIPTION}}", "You must restore this document to make it editable."); + } else { + return ""; + } + }, - // run embedded javascript - var jslist = block.getElementsByTagName('script'); - while(jslist.length>0) { - for(var i=0; i' + block.innerHTML; - } - if(only_body) { - return tmp_html + block.innerHTML.replace(/\n' - + '' - + ''+title+'' - + '' - + '' - + tmp_html - + block.innerHTML.replace(/'; - } -} - -print_table = function(dt, dn, fieldname, tabletype, cols, head_labels, widths, condition, cssClass) { - var fl = fields_list[tabletype]; - var ds = getchildren(tabletype, dn, fieldname, dt); - var tl = []; - var cell_style = {border:'1px solid #000', padding:'2px', verticalAlign:'top'}; - var head_cell_style = {border:'1px solid #000', padding:'2px', verticalAlign:'top', backgroundColor:'#ddd'}; - - var make_table = function(fl) { - var w = document.createElement('div'); - var t = $a(w, 'table', '', {width:'100%', borderCollapse:'collapse', marginBottom:'10px'}); - t.wrapper = w; - - // head row - t.insertRow(0); - var c_start = 0; - if(fl[0]=='SR') { - var cell = t.rows[0].insertCell(0) - cell.innerHTML = head_labels?head_labels[0]:'Sr'; - $y(cell, {width:'30px'}); - $y(cell, head_cell_style) - - c_start = 1; - } - - for(var c=c_start;c content from container + var body_style = ''; + var style_list = container.getElementsByTagName('style'); + while(style_list && style_list.length>0) { + for(i in style_list) { + if(style_list[i] && style_list[i].innerHTML) { + body_style += style_list[i].innerHTML; + var parent = style_list[i].parentNode; + if(parent) { + parent.removeChild(style_list[i]); + } else { + container.removeChild(style_list[i]); + } } } + style_list = container.getElementsByTagName('style'); } - } else { // remove hidden cols - newfl = ['SR'] - for(var j=0;j 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'); + } + }, + + + // Attach letterhead at top of container + show_letterhead: function(container, args) { + if(!(args.no_letterhead || args.only_body)) { + container.innerHTML = '
' + _p.get_letter_head() + '
' + + container.innerHTML; + } + }, + + + render_header_on_break: function(container, args) { + var page_set = container.getElementsByClassName('page-settings'); + if(page_set.length) { + for(var i = 0; i < page_set.length; i++) { + var tmp = ''; + // if draft/archived, show draft/archived banner + tmp += _p.show_draft(args); + tmp += _p.show_archived(args); + _p.show_letterhead(page_set[i], args); + page_set[i].innerHTML = tmp + page_set[i].innerHTML; } } - } - fl = newfl; + }, - var t = make_table(fl); - tl.push(t.wrapper); + + // called by _p.render for final render of print + render_final: function(style, stat, container, args) { + var header = '
\n'; + var footer = '\n
'; + if(!args.only_body) { + header = '\n\ + \ + \ + ' + args.title + '\ + \ + \ + \n' + header; + + footer = footer + '\n\n\ + '; + } + var finished = header + + stat + + container.innerHTML.replace(/
SR - var c_start = 0; - if(fl[0]=='SR') { c_start = 1; } + $.extend(this, { + build_head: function(doctype, docname) { + // Heading + var h1_style = { + fontSize: '22px', + marginBottom: '8px' + } + var h1 = $a(me.layout.cur_row.header, 'h1', '', h1_style); + h1.innerHTML = cur_frm.pformat[docname] ? cur_frm.pformat[docname] : + get_doctype_label(doctype); + + var h2_style = { + fontSize: '16px', + color: '#888', + marginBottom: '8px', + paddingBottom: '8px', + borderBottom: (me.layout.with_border ? '0px' : + '1px solid #000') + } + var h2 = $a(me.layout.cur_row.header, 'div', '', h2_style); + h2.innerHTML = docname; + }, + + build_data: function(data, doctype, docname) { + // Start with a row and a cell in that row + if(data[0] && data[0].fieldtype != "Section Break") { + me.layout.addrow(); + if(data[0].fieldtype != "Column Break") { + me.layout.addcell(); + } + } + + $.extend(this, { + generate_custom_html: function(field, doctype, docname) { + var container = $a(me.layout.cur_cell, 'div'); + container.innerHTML = cur_frm.pformat[field.fieldname](locals[doctype][docname]); + }, + + render_normal: function(field) { + switch(field.fieldtype) { + case 'Section Break': + me.layout.addrow(); + + // Add column if no column break after this field + if(field[i+1] && field[i+1].fieldtype != + 'Column Break') { + me.layout.addcell(); + } + break; + + case 'Column Break': + me.layout.addcell(field.width, field.label); + break; + + case 'Table': + var table = print_table( + doctype, // dt + docname, // dn + field.fieldname, + field.options, // tabletype + null, // cols + null, // head_labels + null, // widths + null); // condition + me.layout = _p.print_std_add_table(table, me.layout, me.pf_list, doctype, no_letterhead); + break; + + case 'HTML': + var div = $a(me.layout.cur_cell, 'div'); + div.innerHTML = field.options; + break; + + case 'Code': + var div = $a(me.layout.cur_cell, 'div'); + var val = _f.get_value(doctype, docname, + field.fieldname); + div.innerHTML = '
' + field.label + + ':
' + (val ? val : '') +
+									'
'; + break; + + case 'Text Editor': + var div = $a(me.layout.cur_cell, 'div'); + var val = _f.get_value(doctype, docname, + field.fieldname); + div.innerHTML = val ? val : ''; + break; + + default: + // Add Cell Data + _p.print_std_add_field(doctype, docname, field, me.layout); + break; + } + } + }); + + // Then build each field + for(var i = 0; i < data.length; i++) { + var fieldname = data[i].fieldname ? data[i].fieldname : + data[i].label; + var field = fieldname ? + get_field(doctype, fieldname, docname) : data[i]; + if(!field.print_hide) { + if(cur_frm.pformat[field.fieldname]) { + // If there is a custom method to generate the HTML, then use it + this.generate_custom_html(field, doctype, docname); + } else { + // Do the normal rendering + this.render_normal(field); + } + } + } + me.layout.close_borders(); + }, + + build_html: function() { + var html = ''; + for(var i = 0; i < me.pf_list.length; i++) { + if(me.pf_list[i].wrapper) { + html += me.pf_list[i].wrapper.innerHTML; + } else if(me.pf_list[i].innerHTML) { + html += me.pf_list[i].innerHTML; + } else { + html += me.pf_list[i]; + } + } + this.pf_list = []; + return html; + } + }); - // data - var sr = 0; - for(var r=0;r1) return tl; // multiple tables with page breakes - else return tl[0]; + }, + + field_tab: function(layout_cell) { + var tab = $a(layout_cell, 'table', '', {width:'100%'}); + var row = tab.insertRow(0); + _p.row = row; // Don't know this line's purpose + row.insertCell(0); + row.insertCell(1); + row.cells[0].className = 'datalabelcell'; + row.cells[1].className = 'datainputcell'; + return row; + } +}); + + +print_table = function(dt, dn, fieldname, tabletype, cols, head_labels, widths, condition, cssClass, modifier) { + var me = this; + $.extend(this, { + flist: fields_list[tabletype], + + data: getchildren( + tabletype, // child_dt + dn, // parent + fieldname, // parentfield + dt // parenttype + ), + + cell_style: { + border: '1px solid #000', + padding: '2px', + verticalAlign: 'top' + }, + + head_cell_style: { + border: '1px solid #000', + padding: '2px', + verticalAlign: 'top', + backgroundColor: '#ddd', + fontWeight: 'bold' + }, + + table_style: { + width: '100%', + borderCollapse: 'collapse', + marginBottom: '10px' + }, + + /* + This function prepares a list of columns to be displayed and calls make_print_table to create a table with these columns + */ + prepare_col_heads: function(flist) { + var new_flist = []; + + // Make a list of column headings + if(cols && cols.length) { + // If cols to be displayed are passed in print_table + if(cols[0] == 'SR') { new_flist.push('SR') } + for(var i = 0; i < cols.length; i++) { + for(var j = 0; j < flist.length; j++) { + if(flist[j].fieldname == cols[i]) { + new_flist.push(flist[j]); + break; + } + } + } + } else { + // Default action: remove hidden cols + new_flist.push('SR'); + for(var i = 0; i < flist.length; i++) { + if(!flist[i].print_hide) { + new_flist.push(flist[i]); + } + } + } + + // Changing me.flist so that it could be used to hide data + me.flist = new_flist; + }, + + // This function makes a new table with its heading rows + make_print_table: function(flist) { + // Make a table + var wrapper = document.createElement('div'); + var table = $a(wrapper, 'table', '', me.table_style); + table.wrapper = wrapper; + + // Make Head Row + table.insertRow(0); + var col_start = 0; + + // If 'SR' exists in flist, then create its heading column cell + if(flist[0]=='SR') { + var cell = table.rows[0].insertCell(0); + cell.innerHTML = head_labels?head_labels[0]:'SR'; + $y(cell, { width: '30px' }); + $y(cell, me.head_cell_style); + col_start++; + } + + for(var c = col_start; c < flist.length; c++) { + var cell = table.rows[0].insertCell(c); + $y(cell, me.head_cell_style); + cell.innerHTML = head_labels?head_labels[c]:flist[c].label; + if(flist[c].width) { $y(cell, {width: flist[c].width}); } + if(widths) { $y(cell, {width: widths[c]}); } + if(in_list(['Currency', 'Float'], flist[c].fieldtype)) { + $y(cell, { textAlign: 'right' }); + } + } + return table; + }, + + // Populate table with data + populate_table: function(table, data) { + for(var r = 0; r < data.length; r++) { + if((!condition) || (condition(data[r]))) { + // Check for page break + if(data[r].page_break) { + table = me.make_print_table(me.flist); + me.table_list.push(table.wrapper); + } + + var row = table.insertRow(table.rows.length); + + // Add serial number if required + if(me.flist[0] == 'SR') { + var cell = row.insertCell(0); + cell.innerHTML = r + 1; + $y(cell, me.cell_style); + } + + for(var c=me.flist.indexOf('SR')+1; c 1) ? me.table_list : me.table_list[0]; } diff --git a/js/legacy/wnf.compressed.js b/js/legacy/wnf.compressed.js index 997f89695f..eb79295b56 100644 --- a/js/legacy/wnf.compressed.js +++ b/js/legacy/wnf.compressed.js @@ -909,8 +909,7 @@ redirect_to_login();});} function redirect_to_login(){if(login_file) window.location.href=login_file;else window.location.href='index.html';} -_p.def_print_style_body="html, body, div, span, td { font-family: Arial, Helvetica; font-size: 12px; }" -+"\npre { margin:0; padding:0;}" +_p.def_print_style_body="html, body, div, span, td { font-family: Arial, Helvetica; font-size: 12px; }"+"\npre { margin:0; padding:0;}" _p.def_print_style_other="\n.simpletable, .noborder { border-collapse: collapse; margin-bottom: 10px;}" +"\n.simpletable td {border: 1pt solid #000; vertical-align: top; padding: 2px; }" +"\n.noborder td { vertical-align: top; }" diff --git a/py/core/doctype/print_format/print_format.py b/py/core/doctype/print_format/print_format.py new file mode 100644 index 0000000000..7f932d6231 --- /dev/null +++ b/py/core/doctype/print_format/print_format.py @@ -0,0 +1,35 @@ +import webnotes + +class DocType: + def __init__(self, d, dl): + self.doc, self.doclist = d,dl + + def on_update(self): + """ + On update, create/update a DocFormat record corresponding to DocType and Print Format Name + """ + if self.doc.doc_type: + from webnotes.model.doc import Document + res = webnotes.conn.sql(""" + SELECT * FROM `tabDocFormat` + WHERE format=%s""", self.doc.name) + if res and res[0]: + d = Document('DocFormat', res[0][0]) + d.parent = self.doc.doc_type + d.parenttype = 'DocType' + d.parentfield = 'formats' + d.format = self.doc.name + d.save() + else: + max_idx = webnotes.conn.sql(""" + SELECT MAX(idx) FROM `tabDocFormat` + WHERE parent=%s + AND parenttype='DocType' + AND parentfield='formats'""", self.doc.doc_type)[0][0] + d = Document('DocFormat') + d.parent = self.doc.doc_type + d.parenttype = 'DocType' + d.parentfield = 'formats' + d.format = self.doc.name + d.idx = max_idx + 1 + d.save(1) diff --git a/py/core/doctype/print_format/print_format.txt b/py/core/doctype/print_format/print_format.txt index 4e6cb8999e..95b7aff239 100644 --- a/py/core/doctype/print_format/print_format.txt +++ b/py/core/doctype/print_format/print_format.txt @@ -5,14 +5,14 @@ { 'creation': '2009-05-12 11:19:11', 'docstatus': 0, - 'modified': '2010-12-20 22:42:13', - 'modified_by': 'yogesh@webnotestech.com', + 'modified': '2011-11-14 16:51:20', + 'modified_by': 'Administrator', 'owner': 'Administrator' }, # These values are common for all DocType { - '_last_update': '1307624201', + '_last_update': '1321269659', 'allow_copy': 0, 'allow_email': 0, 'allow_print': 0, @@ -21,7 +21,6 @@ 'doctype': 'DocType', 'hide_heading': 0, 'hide_toolbar': 0, - 'idx': 0, 'issingle': 0, 'istable': 0, 'module': 'Core', @@ -30,7 +29,7 @@ 'section_style': 'Simple', 'server_code_error': ' ', 'show_in_menu': 0, - 'version': 3 + 'version': 8 }, # These values are common for all DocField @@ -45,18 +44,18 @@ # These values are common for all DocPerm { + 'amend': 0, 'cancel': 0, 'create': 1, 'doctype': 'DocPerm', 'execute': 0, - 'idx': 1, 'name': '__common__', 'parent': 'Print Format', 'parentfield': 'permissions', 'parenttype': 'DocType', 'permlevel': 0, 'read': 1, - 'role': 'Administrator', + 'role': 'System Manager', 'submit': 0, 'write': 1 }, @@ -77,7 +76,6 @@ 'doctype': 'DocField', 'fieldname': 'module', 'fieldtype': 'Select', - 'idx': 1, 'label': 'Module', 'oldfieldname': 'module', 'oldfieldtype': 'Select', @@ -88,15 +86,11 @@ # DocField { 'doctype': 'DocField', - 'fieldname': 'html', - 'fieldtype': 'Code', - 'hidden': 0, - 'idx': 2, - 'label': 'HTML', - 'oldfieldname': 'html', - 'oldfieldtype': 'Text Editor', - 'reqd': 0, - 'search_index': 0 + 'fieldname': 'doc_type', + 'fieldtype': 'Select', + 'label': 'DocType', + 'options': 'link:DocType', + 'reqd': 0 }, # DocField @@ -104,12 +98,24 @@ 'doctype': 'DocField', 'fieldname': 'standard', 'fieldtype': 'Select', - 'idx': 3, 'label': 'Standard', 'oldfieldname': 'standard', 'oldfieldtype': 'Select', 'options': '\nYes\nNo', 'reqd': 1, 'search_index': 1 + }, + + # DocField + { + 'doctype': 'DocField', + 'fieldname': 'html', + 'fieldtype': 'Code', + 'hidden': 0, + 'label': 'HTML', + 'oldfieldname': 'html', + 'oldfieldtype': 'Text Editor', + 'reqd': 0, + 'search_index': 0 } ] \ No newline at end of file diff --git a/py/webnotes/utils/__init__.py b/py/webnotes/utils/__init__.py index b3d044d7dd..39c36cca29 100644 --- a/py/webnotes/utils/__init__.py +++ b/py/webnotes/utils/__init__.py @@ -389,7 +389,7 @@ def money_in_words(number, main_currency = None, fraction_currency=None): if not fraction_currency: fraction_currency = d.get('fraction_currency', 'paise') - n = str(flt(number)) + n = "%.2f" % flt(number) main, fraction = n.split('.') if len(fraction)==1: fraction += '0'