您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 
 

184 行
5.8 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. // save / submit button toggle based on "saved" or not
  27. // highlight and fade name based on refresh
  28. _f.FrmHeader = Class.extend({
  29. init: function(parent, frm) {
  30. this.appframe = new wn.ui.AppFrame(parent, null, frm.meta.module)
  31. this.$w = this.appframe.$w;
  32. this.frm = frm;
  33. if(!frm.meta.issingle) {
  34. this.appframe.add_tab(frm.doctype + " List", 0.5, function() {
  35. wn.set_route("List", frm.doctype);
  36. });
  37. }
  38. this.appframe.add_module_tab(frm.meta.module);
  39. },
  40. refresh: function() {
  41. this.appframe.set_title(this.frm.docname);
  42. this.refresh_labels();
  43. this.refresh_toolbar();
  44. this.refresh_timestamps();
  45. },
  46. refresh_timestamps: function() {
  47. this.$w.find(".avatar").remove();
  48. var doc = this.frm.doc;
  49. if(doc.__islocal || !doc.owner || !doc.modified_by)
  50. return;
  51. $(repl('<span class="avatar avatar avatar-small">\
  52. <img title="%(created_by)s" src="%(avatar_created)s"/></span>\
  53. <span class="avatar avatar avatar-small">\
  54. <img title="%(modified_by)s" src="%(avatar_modified)s"/></span>', {
  55. created_by: wn.user_info(doc.owner).fullname,
  56. avatar_created: wn.utils.get_file_link(wn.user_info(doc.owner).image),
  57. modified_by: wn.user_info(doc.modified_by).fullname,
  58. avatar_modified: wn.utils.get_file_link(wn.user_info(doc.modified_by).image),
  59. })).insertAfter(this.$w.find(".appframe-title"));
  60. this.$w.find(".avatar:eq(0)").popover({
  61. trigger:"hover",
  62. title: wn._("Created By"),
  63. content: wn.user_info(this.frm.doc.owner).fullname.bold()
  64. +" on "+ dateutil.str_to_user(this.frm.doc.creation)
  65. });
  66. this.$w.find(".avatar:eq(1)").popover({
  67. trigger:"hover",
  68. title: wn._("Modified By"),
  69. content: wn.user_info(this.frm.doc.modified_by).fullname.bold()
  70. +" on "+ dateutil.str_to_user(this.frm.doc.modified)
  71. });
  72. this.$w.find('.avatar img').centerImage();
  73. },
  74. refresh_labels: function() {
  75. cur_frm.doc = wn.model.get_doc(cur_frm.doc.doctype, cur_frm.doc.name);
  76. var labinfo = {
  77. 0: ['Saved', 'label-success'],
  78. 1: ['Submitted', 'label-info'],
  79. 2: ['Cancelled', 'label-important']
  80. }[cint(cur_frm.doc.docstatus)];
  81. if(labinfo[0]=='Saved' && cur_frm.meta.is_submittable) {
  82. labinfo[0]='Saved, to Submit';
  83. }
  84. if(cur_frm.doc.__unsaved || cur_frm.doc.__islocal) {
  85. labinfo[0] = 'Not Saved';
  86. labinfo[1] = 'label-warning'
  87. }
  88. this.set_label(labinfo);
  89. // show update button if unsaved
  90. if(cur_frm.doc.__unsaved && cint(cur_frm.doc.docstatus)==1 && this.appframe.buttons['Update']) {
  91. this.appframe.buttons['Update'].toggle(true);
  92. }
  93. },
  94. set_label: function(labinfo) {
  95. this.$w.find('.label').remove();
  96. $(repl('<span class="label %(lab_class)s">\
  97. %(lab_status)s</span>', {
  98. lab_status: labinfo[0],
  99. lab_class: labinfo[1]
  100. })).insertBefore(this.$w.find('.appframe-title'))
  101. },
  102. refresh_toolbar: function() {
  103. // clear
  104. if(cur_frm.meta.hide_toolbar) {
  105. $('.appframe-toolbar').toggle(false);
  106. return;
  107. }
  108. this.appframe.clear_buttons();
  109. var p = cur_frm.perm[0];
  110. // Edit
  111. if(cur_frm.meta.read_only_onload && !cur_frm.doc.__islocal) {
  112. if(!cur_frm.editable)
  113. this.appframe.add_button('Edit', function() {
  114. cur_frm.edit_doc();
  115. },'icon-pencil');
  116. else
  117. this.appframe.add_button('Print View', function() {
  118. cur_frm.is_editable[cur_frm.docname] = 0;
  119. cur_frm.refresh(); }, 'icon-print' );
  120. }
  121. var docstatus = cint(cur_frm.doc.docstatus);
  122. // Save
  123. if(docstatus==0 && p[WRITE]) {
  124. this.appframe.add_button('Save', function() {
  125. cur_frm.save('Save', null, this);}, '');
  126. this.appframe.buttons['Save'].addClass('btn-info').text("Save (Ctrl+S)");
  127. }
  128. // Submit
  129. if(docstatus==0 && p[SUBMIT] && (!cur_frm.doc.__islocal))
  130. this.appframe.add_button('Submit', function() {
  131. cur_frm.savesubmit(this);}, 'icon-lock');
  132. // Update after sumit
  133. if(docstatus==1 && p[SUBMIT]) {
  134. this.appframe.add_button('Update', function() {
  135. cur_frm.save('Update', null, this);
  136. }, '');
  137. if(!cur_frm.doc.__unsaved) this.appframe.buttons['Update'].toggle(false);
  138. }
  139. // Cancel
  140. if(docstatus==1 && p[CANCEL])
  141. this.appframe.add_button('Cancel', function() {
  142. cur_frm.savecancel(this) }, 'icon-remove');
  143. // Amend
  144. if(docstatus==2 && p[AMEND])
  145. this.appframe.add_button('Amend', function() {
  146. cur_frm.amend_doc() }, 'icon-pencil');
  147. // Help
  148. if(cur_frm.meta.description) {
  149. this.appframe.add_help_button(wn.markdown('#### ' + cur_frm.doctype + '\n\n'
  150. + cur_frm.meta.description));
  151. }
  152. },
  153. show: function() {
  154. },
  155. hide: function() {
  156. },
  157. hide_close: function() {
  158. this.$w.find('.close').toggle(false);
  159. }
  160. })