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.
 
 
 
 
 
 

146 lines
4.5 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.ui.AppFrame(parent)
  32. this.$w = this.appframe.$w;
  33. },
  34. refresh: function() {
  35. // refresh breadcrumbs
  36. if(cur_frm.cscript.set_breadcrumbs) {
  37. this.appframe.clear_breadcrumbs();
  38. cur_frm.cscript.set_breadcrumbs();
  39. } else {
  40. wn.views.breadcrumbs(this.appframe,
  41. cur_frm.meta.module, cur_frm.meta.name, cur_frm.docname);
  42. }
  43. this.refresh_labels();
  44. this.refresh_toolbar();
  45. },
  46. refresh_labels: function() {
  47. cur_frm.doc = get_local(cur_frm.doc.doctype, cur_frm.doc.name);
  48. var labinfo = {
  49. 0: ['Saved', 'label-success'],
  50. 1: ['Submitted', 'label-info'],
  51. 2: ['Cancelled', 'label-important']
  52. }[cint(cur_frm.doc.docstatus)];
  53. if(labinfo[0]=='Saved' && cur_frm.meta.is_submittable) {
  54. labinfo[0]='Saved, to Submit';
  55. }
  56. if(cur_frm.doc.__unsaved || cur_frm.doc.__islocal) {
  57. labinfo[0] = 'Not Saved';
  58. labinfo[1] = 'label-warning'
  59. }
  60. this.set_label(labinfo);
  61. // show update button if unsaved
  62. if(cur_frm.doc.__unsaved && cint(cur_frm.doc.docstatus)==1 && this.appframe.buttons['Update']) {
  63. this.appframe.buttons['Update'].toggle(true);
  64. }
  65. },
  66. set_label: function(labinfo) {
  67. this.$w.find('.label').remove();
  68. $(repl('<span class="label %(lab_class)s">\
  69. %(lab_status)s</span>', {
  70. lab_status: labinfo[0],
  71. lab_class: labinfo[1]
  72. })).insertBefore(this.$w.find('.breadcrumb-area'))
  73. },
  74. refresh_toolbar: function() {
  75. // clear
  76. if(cur_frm.meta.hide_toolbar) {
  77. $('.appframe-toolbar').toggle(false);
  78. return;
  79. }
  80. this.appframe.clear_buttons();
  81. var p = cur_frm.get_doc_perms();
  82. // Edit
  83. if(cur_frm.meta.read_only_onload && !cur_frm.doc.__islocal) {
  84. if(!cur_frm.editable)
  85. this.appframe.add_button('Edit', function() {
  86. cur_frm.edit_doc();
  87. },'icon-pencil');
  88. else
  89. this.appframe.add_button('Print View', function() {
  90. cur_frm.is_editable[cur_frm.docname] = 0;
  91. cur_frm.refresh(); }, 'icon-print' );
  92. }
  93. var docstatus = cint(cur_frm.doc.docstatus);
  94. // Save
  95. if(docstatus==0 && p[WRITE]) {
  96. this.appframe.add_button('Save', function() { cur_frm.save('Save');}, '');
  97. this.appframe.buttons['Save'].addClass('btn-info').text("Save (Ctrl+S)");
  98. }
  99. // Submit
  100. if(docstatus==0 && p[SUBMIT] && (!cur_frm.doc.__islocal))
  101. this.appframe.add_button('Submit', function() { cur_frm.savesubmit();}, 'icon-lock');
  102. // Update after sumit
  103. if(docstatus==1 && p[SUBMIT]) {
  104. this.appframe.add_button('Update', function() { cur_frm.saveupdate();}, '');
  105. if(!cur_frm.doc.__unsaved) this.appframe.buttons['Update'].toggle(false);
  106. }
  107. // Cancel
  108. if(docstatus==1 && p[CANCEL])
  109. this.appframe.add_button('Cancel', function() { cur_frm.savecancel() }, 'icon-remove');
  110. // Amend
  111. if(docstatus==2 && p[AMEND])
  112. this.appframe.add_button('Amend', function() { cur_frm.amend_doc() }, 'icon-pencil');
  113. // Help
  114. if(cur_frm.meta.description) {
  115. this.appframe.add_help_button(wn.markdown('## ' + cur_frm.doctype + '\n\n'
  116. + cur_frm.meta.description));
  117. }
  118. },
  119. show: function() {
  120. },
  121. hide: function() {
  122. },
  123. hide_close: function() {
  124. this.$w.find('.close').toggle(false);
  125. }
  126. })