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.
 
 
 
 
 
 

327 lines
9.6 KiB

  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. // features
  23. // --------
  24. // toolbar - standard and custom
  25. // label - saved, submitted etc
  26. // breadcrumbs
  27. // save / submit button toggle based on "saved" or not
  28. // highlight and fade name based on refresh
  29. _f.FrmHeader = Class.extend({
  30. init: function(parent, frm) {
  31. this.appframe = new wn.views.AppFrame(parent)
  32. this.appframe.$titlebar.append('<span class="label-area"></span>\
  33. <span class="breadcrumb-area"></span>');
  34. this.$w = this.appframe.$w;
  35. },
  36. refresh: function() {
  37. // refresh breadcrumbs
  38. wn.views.breadcrumbs($(this.$w.find('.breadcrumb-area')),
  39. cur_frm.meta.module, cur_frm.meta.name, cur_frm.docname);
  40. this.refresh_labels();
  41. this.refresh_toolbar();
  42. },
  43. refresh_labels: function() {
  44. var labinfo = {
  45. 0: ['Draft', ''],
  46. 1: ['Submitted', 'label-info'],
  47. 2: ['Cancelled', 'label-important']
  48. }[cint(cur_frm.doc.docstatus)];
  49. if(cur_frm.doc.__unsaved) {
  50. labinfo[1] = 'label-warning'
  51. }
  52. this.$w.find('.label-area').html(repl('<span class="label %(lab_class)s">\
  53. %(lab_status)s</span>', {
  54. lab_status: labinfo[0],
  55. lab_class: labinfo[1]
  56. }));
  57. },
  58. refresh_toolbar: function() {
  59. // clear
  60. this.appframe.clear_buttons();
  61. var p = cur_frm.get_doc_perms();
  62. // Edit
  63. if(cur_frm.meta.read_only_onload && !cur_frm.doc.__islocal) {
  64. if(!cur_frm.editable)
  65. this.appframe.add_button('Edit', function() {
  66. cur_frm.edit_doc();
  67. },'icon-pencil');
  68. else
  69. this.appframe.add_button('Print View', function() {
  70. cur_frm.is_editable[cur_frm.docname] = 0;
  71. cur_frm.refresh(); }, 'icon-print' );
  72. }
  73. var docstatus = cint(cur_frm.doc.docstatus);
  74. // Save
  75. if(docstatus==0 && p[WRITE]) {
  76. this.appframe.add_button('Save', function() { cur_frm.save('Save');}, '');
  77. this.appframe.buttons['Save'].addClass('btn-info');
  78. }
  79. // Submit
  80. if(docstatus==0 && p[SUBMIT] && (!cur_frm.doc.__islocal))
  81. this.appframe.add_button('Submit', function() { cur_frm.savesubmit();}, 'icon-lock');
  82. // Update after sumit
  83. if(docstatus==1 && p[SUBMIT]) {
  84. this.appframe.add_button('Update', function() { cur_frm.savesubmit();}, '');
  85. if(!cur_frm.doc.__unsaved) this.appframe.buttons['Update'].toggle(false);
  86. }
  87. // Cancel
  88. if(docstatus==1 && p[CANCEL])
  89. this.appframe.add_button('Cancel', function() { cur_frm.savecancel() }, 'icon-remove');
  90. // Amend
  91. if(docstatus==2 && p[AMEND])
  92. this.appframe.add_button('Amend', function() { cur_frm.amend_doc() }, 'icon-pencil');
  93. },
  94. show: function() {
  95. },
  96. hide: function() {
  97. },
  98. hide_close: function() {
  99. this.$w.find('.close').toggle(false);
  100. }
  101. })
  102. /*
  103. _f.FrmHeader = function(parent, frm) {
  104. var me = this;
  105. this.wrapper = $a(parent, 'div');
  106. if(frm.meta.in_dialog) $y(this.wrapper, {marginLeft:'8px', marginRight:'8px'});
  107. this.page_head = new PageHeader(this.wrapper);
  108. wn.views.breadcrumbs(this.page_head.breadcrumbs, frm.meta.module, frm.meta.name);
  109. // doctype
  110. this.dt_area = $a(this.page_head.main_head, 'span', '', {marginRight:'8px', display:'inline'})
  111. // name
  112. var div = $a(null, 'div', '', {marginBottom:'4px'});
  113. this.page_head.wrapper.insertBefore(div, this.page_head.sub_head);
  114. this.dn_area = $a(div, 'span', '', {fontSize:'14px', fontWeight:'normal', marginRight:'8px', padding: '2px'})
  115. // status
  116. this.status_area = $a(div, 'span', '', {marginRight:'8px', marginBottom:'2px', cursor:'pointer', textShadow:'none'})
  117. }
  118. _f.FrmHeader.prototype.show = function() { $ds(this.wrapper); }
  119. _f.FrmHeader.prototype.hide = function() { $dh(this.wrapper); }
  120. // toolbar buttons
  121. // =======================================================================
  122. _f.FrmHeader.prototype.refresh= function() {
  123. var me = this;
  124. var p = cur_frm.get_doc_perms();
  125. this.page_head.clear_toolbar();
  126. // Edit
  127. if(cur_frm.meta.read_only_onload && !cur_frm.doc.__islocal) {
  128. if(!cur_frm.editable)
  129. this.page_head.add_button('Edit', function() {
  130. cur_frm.edit_doc();
  131. }, 1, 'icon-pencil', 1
  132. );
  133. else
  134. this.page_head.add_button('Print View', function() {
  135. cur_frm.is_editable[cur_frm.docname] = 0;
  136. cur_frm.refresh(); }, 1, 'icon-print' );
  137. }
  138. // Save
  139. if(cur_frm.editable && cint(cur_frm.doc.docstatus)==0 && p[WRITE])
  140. this.page_head.add_button('Save', function() { cur_frm.save('Save');}, 1, '',1);
  141. // Submit
  142. if(cint(cur_frm.doc.docstatus)==0 && p[SUBMIT] && (!cur_frm.doc.__islocal))
  143. this.page_head.add_button('Submit', function() { cur_frm.savesubmit(); }, 0, 'icon-lock');
  144. // Update after sumit
  145. if(cint(cur_frm.doc.docstatus)==1 && p[SUBMIT]) {
  146. this.update_btn = this.page_head.add_button('Update', function() { cur_frm.saveupdate(); }, 1, 'icon-ok', 1);
  147. if(!cur_frm.doc.__unsaved) $dh(this.update_btn);
  148. }
  149. // Cancel
  150. if(cint(cur_frm.doc.docstatus)==1 && p[CANCEL])
  151. this.page_head.add_button('Cancel', function() { cur_frm.savecancel() }, 0, 'icon-remove');
  152. // Amend
  153. if(cint(cur_frm.doc.docstatus)==2 && p[AMEND])
  154. this.page_head.add_button('Amend', function() { cur_frm.amend_doc() }, 0, 'icon-pencil');
  155. }
  156. _f.FrmHeader.prototype.show_toolbar = function() { $ds(this.wrapper); this.refresh(); }
  157. _f.FrmHeader.prototype.hide_toolbar = function() { $dh(this.wrapper); }
  158. // refresh toolbar
  159. // -------------------------------------------------------------------
  160. _f.FrmHeader.prototype.refresh_toolbar = function() {
  161. var m = cur_frm.meta;
  162. if(m.hide_heading || cur_frm.in_dialog) {
  163. // no heading... poof
  164. this.hide();
  165. } else {
  166. this.show();
  167. // with or without toolbar?
  168. if(m.hide_toolbar) {
  169. this.hide_toolbar();
  170. } else {
  171. this.show_toolbar();
  172. }
  173. }
  174. //this.refresh_comments();
  175. }
  176. // make the status tag
  177. // -------------------------------------------------------------------
  178. _f.FrmHeader.prototype.get_status_tags = function(doc, f) {
  179. var make_tag = function(label, col) {
  180. var s= $a(null, 'span', '', {padding: '2px', backgroundColor:col, color:'#FFF', fontWeight:'bold', marginLeft:(f.meta.issingle ? '0px' : '8px'), fontSize:'11px'});
  181. $(s).css('-moz-border-radius','3px').css('-webkit-border-radius','3px')
  182. s.innerHTML = label;
  183. return s;
  184. }
  185. var sp1 = null; var sp2 = null;
  186. if(doc.__islocal) {
  187. label = 'Unsaved Draft'; col = '#F81';
  188. } else if(cint(doc.__unsaved)) {
  189. label = 'Not Saved'; col = '#F81';
  190. if(doc.docstatus==1 && this.update_btn) $ds(this.update_btn);
  191. } else if(cint(doc.docstatus)==0) {
  192. label = 'Saved'; col = '#0A1';
  193. // if submittable, show it
  194. if(f.get_doc_perms()[SUBMIT]) {
  195. sp2 = make_tag('To Be Submitted', '#888');
  196. }
  197. } else if(cint(doc.docstatus)==1) {
  198. label = 'Submitted'; col = '#44F';
  199. } else if(cint(doc.docstatus)==2) {
  200. label = 'Cancelled'; col = '#F44';
  201. }
  202. sp1 = make_tag(label, col);
  203. this.set_in_recent(doc, col);
  204. return [sp1, sp2];
  205. }
  206. // refresh "recent" tag colour
  207. // -------------------------------------------------------------------
  208. _f.FrmHeader.prototype.set_in_recent = function(doc, col) {
  209. var tn = $i('rec_'+doc.doctype+'-'+doc.name);
  210. if(tn)
  211. $y(tn,{backgroundColor:col});
  212. }
  213. // set the button color of save / submit
  214. _f.FrmHeader.prototype.set_save_submit_color = function(doc) {
  215. var save_btn = this.page_head.buttons['Save'];
  216. var submit_btn = this.page_head.buttons['Submit'];
  217. if(cint(doc.docstatus)==0 && submit_btn && save_btn) {
  218. if(cint(doc.__unsaved)) {
  219. $(save_btn).addClass('btn-info');
  220. $(save_btn).find('i').addClass('icon-white');
  221. $(submit_btn).removeClass('btn-info');
  222. $(submit_btn).find('i').removeClass('icon-white');
  223. } else {
  224. $(submit_btn).addClass('btn-info');
  225. $(submit_btn).find('i').addClass('icon-white');
  226. $(save_btn).removeClass('btn-info');
  227. $(save_btn).find('i').removeClass('icon-white');
  228. }
  229. }
  230. }
  231. // refresh the labels!
  232. // -------------------------------------------------------------------
  233. _f.FrmHeader.prototype.refresh_labels = function(f) {
  234. var ph = this.page_head;
  235. var me = this;
  236. // main title
  237. this.dt_area.innerHTML = get_doctype_label(f.doctype);
  238. if(f.meta.issingle) $(this.dn_area).toggle(false);
  239. // sub title
  240. this.dn_area.innerHTML = '';
  241. if(!f.meta.issingle)
  242. this.dn_area.innerHTML = f.docname;
  243. $(this.dn_area)
  244. .removeClass('background-fade-in')
  245. .css('background-color', '#ff8')
  246. // get the doc
  247. var doc = locals[f.doctype][f.docname];
  248. // get the tags
  249. var sl = this.get_status_tags(doc, f);
  250. // set save, submit color
  251. this.set_save_submit_color(doc);
  252. // add the tags
  253. var t = this.status_area;
  254. t.innerHTML = '';
  255. t.appendChild(sl[0]);
  256. if(sl[1])t.appendChild(sl[1]);
  257. setTimeout('$(cur_frm.frm_head.dn_area).addClass("background-fade-in")\
  258. .css("background-color", "white")', 1500)
  259. }
  260. */