Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 
 
 

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