You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

form_header.js 7.4 KiB

13 years ago
13 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. // Copyright (c) 2012 Web Notes Technologies Pvt Ltd (http://erpnext.com)
  2. //
  3. // MIT License (MIT)
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a
  6. // copy of this software and associated documentation files (the "Software"),
  7. // to deal in the Software without restriction, including without limitation
  8. // the rights to use, copy, modify, merge, publish, distribute, sublicense,
  9. // and/or sell copies of the Software, and to permit persons to whom the
  10. // Software is furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  16. // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  17. // PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  18. // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
  19. // CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
  20. // OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  21. //
  22. _f.FrmHeader = function(parent, frm) {
  23. var me = this;
  24. this.wrapper = $a(parent, 'div');
  25. if(frm.meta.in_dialog) $y(this.wrapper, {marginLeft:'8px', marginRight:'8px'});
  26. this.page_head = new PageHeader(this.wrapper);
  27. // doctype
  28. this.dt_area = $a(this.page_head.main_head, 'h1', '', {marginRight:'8px', display:'inline'})
  29. // name
  30. var div = $a(null, 'div', '', {marginBottom:'4px'});
  31. this.page_head.lhs.insertBefore(div, this.page_head.sub_head);
  32. this.dn_area = $a(div, 'span', '', {fontSize:'14px', fontWeight:'normal', marginRight:'8px'})
  33. // status
  34. this.status_area = $a(div, 'span', '', {marginRight:'8px', marginBottom:'2px', cursor:'pointer', textShadow:'none'})
  35. // timestamp
  36. this.timestamp_area = $a($a(div,'div','',{marginTop:'3px'}), 'span', 'field_description', {fontSize:'11px'});
  37. }
  38. _f.FrmHeader.prototype.show = function() { $ds(this.wrapper); }
  39. _f.FrmHeader.prototype.hide = function() { $dh(this.wrapper); }
  40. // toolbar buttons
  41. // =======================================================================
  42. _f.FrmHeader.prototype.refresh= function() {
  43. var me = this;
  44. var p = cur_frm.get_doc_perms();
  45. this.page_head.clear_toolbar();
  46. // Edit
  47. if(cur_frm.meta.read_only_onload && !cur_frm.doc.__islocal) {
  48. if(!cur_frm.editable)
  49. this.page_head.add_button('Edit', function() {
  50. cur_frm.edit_doc();
  51. }, 1, 'ui-icon-document', 1
  52. );
  53. else
  54. this.page_head.add_button('Print View', function() {
  55. cur_frm.is_editable[cur_frm.docname] = 0;
  56. cur_frm.refresh(); }, 1, 'ui-icon-document' );
  57. }
  58. // Save
  59. if(cur_frm.editable && cint(cur_frm.doc.docstatus)==0 && p[WRITE])
  60. this.page_head.add_button('Save', function() { cur_frm.save('Save');}, 1, 'ui-icon-disk',1);
  61. // Submit
  62. if(cint(cur_frm.doc.docstatus)==0 && p[SUBMIT] && (!cur_frm.doc.__islocal))
  63. this.page_head.add_button('Submit', function() { cur_frm.savesubmit(); }, 0, 'ui-icon-locked');
  64. // Update after sumit
  65. if(cint(cur_frm.doc.docstatus)==1 && p[SUBMIT]) {
  66. this.update_btn = this.page_head.add_button('Update', function() { cur_frm.saveupdate(); }, 1, 'ui-icon-disk', 1);
  67. if(!cur_frm.doc.__unsaved) $dh(this.update_btn);
  68. }
  69. // Cancel
  70. if(cint(cur_frm.doc.docstatus)==1 && p[CANCEL])
  71. this.page_head.add_button('Cancel', function() { cur_frm.savecancel() }, 0, 'ui-icon-closethick');
  72. // Amend
  73. if(cint(cur_frm.doc.docstatus)==2 && p[AMEND])
  74. this.page_head.add_button('Amend', function() { cur_frm.amend_doc() }, 0, 'ui-icon-scissors');
  75. }
  76. _f.FrmHeader.prototype.show_toolbar = function() { $ds(this.wrapper); this.refresh(); }
  77. _f.FrmHeader.prototype.hide_toolbar = function() { $dh(this.wrapper); }
  78. // refresh toolbar
  79. // -------------------------------------------------------------------
  80. _f.FrmHeader.prototype.refresh_toolbar = function() {
  81. var m = cur_frm.meta;
  82. if(m.hide_heading || cur_frm.in_dialog) {
  83. // no heading... poof
  84. this.hide();
  85. } else {
  86. this.show();
  87. // with or without toolbar?
  88. if(m.hide_toolbar) {
  89. this.hide_toolbar();
  90. } else {
  91. this.show_toolbar();
  92. }
  93. }
  94. //this.refresh_comments();
  95. }
  96. /*_f.FrmHeader.prototype.refresh_comments = function() {
  97. var n = cint(cur_frm.n_comments[cur_frm.doc.name]);
  98. if(this.comment_btn && !cur_frm.doc.__islocal)
  99. this.comment_btn.innerHTML = 'Comments ('+n+')';
  100. }*/
  101. // refresh heading and labels
  102. // -------------------------------------------------------------------
  103. _f.FrmHeader.prototype.get_timestamp = function(doc) {
  104. var scrub_date = function(d) {
  105. if(d)t=d.split(' ');else return '';
  106. return dateutil.str_to_user(t[0]) + ' ' + t[1];
  107. }
  108. return repl("Created: %(c_by)s %(c_on)s %(m_by)s %(m_on)s",
  109. {c_by:doc.owner
  110. ,c_on:scrub_date(doc.creation ? doc.creation:'')
  111. ,m_by:doc.modified_by?(' | Modified: '+doc.modified_by):''
  112. ,m_on:doc.modified ? ('on '+scrub_date(doc.modified)) : ''} );
  113. }
  114. // make the status tag
  115. // -------------------------------------------------------------------
  116. _f.FrmHeader.prototype.get_status_tags = function(doc, f) {
  117. var make_tag = function(label, col) {
  118. var s= $a(null, 'span', '', {padding: '2px', backgroundColor:col, color:'#FFF', fontWeight:'bold', marginLeft:(f.meta.issingle ? '0px' : '8px'), fontSize:'11px'});
  119. $(s).css('-moz-border-radius','3px').css('-webkit-border-radius','3px')
  120. s.innerHTML = label;
  121. return s;
  122. }
  123. var sp1 = null; var sp2 = null;
  124. if(doc.__islocal) {
  125. label = 'Unsaved Draft'; col = '#F81';
  126. } else if(cint(doc.__unsaved)) {
  127. label = 'Not Saved'; col = '#F81';
  128. if(doc.docstatus==1 && this.update_btn) $ds(this.update_btn);
  129. } else if(cint(doc.docstatus)==0) {
  130. label = 'Saved'; col = '#0A1';
  131. // if submittable, show it
  132. if(f.get_doc_perms()[SUBMIT]) {
  133. sp2 = make_tag('To Be Submitted', '#888');
  134. }
  135. } else if(cint(doc.docstatus)==1) {
  136. label = 'Submitted'; col = '#44F';
  137. } else if(cint(doc.docstatus)==2) {
  138. label = 'Cancelled'; col = '#F44';
  139. }
  140. sp1 = make_tag(label, col);
  141. this.set_in_recent(doc, col);
  142. return [sp1, sp2];
  143. }
  144. // refresh "recent" tag colour
  145. // -------------------------------------------------------------------
  146. _f.FrmHeader.prototype.set_in_recent = function(doc, col) {
  147. var tn = $i('rec_'+doc.doctype+'-'+doc.name);
  148. if(tn)
  149. $y(tn,{backgroundColor:col});
  150. }
  151. // set the button color of save / submit
  152. _f.FrmHeader.prototype.set_save_submit_color = function(doc) {
  153. var save_btn = this.page_head.buttons['Save'];
  154. var submit_btn = this.page_head.buttons['Submit'];
  155. if(cint(doc.docstatus)==0 && submit_btn && save_btn) {
  156. if(cint(doc.__unsaved)) {
  157. $(save_btn).addClass('btn-info');
  158. $(submit_btn).removeClass('btn-info');
  159. } else {
  160. $(submit_btn).addClass('btn-info');
  161. $(save_btn).removeClass('btn-info');
  162. }
  163. }
  164. }
  165. // refresh the labels!
  166. // -------------------------------------------------------------------
  167. _f.FrmHeader.prototype.refresh_labels = function(f) {
  168. var ph = this.page_head;
  169. var me = this;
  170. // main title
  171. this.dt_area.innerHTML = get_doctype_label(f.doctype);
  172. // sub title
  173. this.dn_area.innerHTML = '';
  174. if(!f.meta.issingle)
  175. this.dn_area.innerHTML = f.docname;
  176. // get the doc
  177. var doc = locals[f.doctype][f.docname];
  178. // get the tags
  179. var sl = this.get_status_tags(doc, f);
  180. // set save, submit color
  181. this.set_save_submit_color(doc);
  182. // add the tags
  183. var t = this.status_area;
  184. t.innerHTML = '';
  185. t.appendChild(sl[0]);
  186. if(sl[1])t.appendChild(sl[1]);
  187. // timestamp
  188. this.timestamp_area.innerHTML = me.get_timestamp(doc);
  189. }