Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 
 
 

200 rader
6.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. // 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. this.appframe.add_home_breadcrumb();
  34. this.appframe.add_module_breadcrumb(frm.meta.module)
  35. if(!frm.meta.issingle) {
  36. this.appframe.add_list_breadcrumb(frm.meta.name)
  37. }
  38. this.appframe.add_breadcrumb("icon-file");
  39. },
  40. refresh: function() {
  41. var title = this.frm.docname;
  42. if(title.length > 30) {
  43. title = title.substr(0,30) + "...";
  44. }
  45. this.appframe.set_title(title, wn._(this.frm.docname));
  46. this.refresh_labels();
  47. this.refresh_toolbar();
  48. this.refresh_timestamps();
  49. },
  50. refresh_timestamps: function() {
  51. this.$w.find(".avatar").remove();
  52. var doc = this.frm.doc;
  53. if(doc.__islocal || !doc.owner || !doc.modified_by)
  54. return;
  55. $(repl('<span class="avatar avatar avatar-small">\
  56. <img title="%(created_by)s" src="%(avatar_created)s"/></span>\
  57. <span class="avatar avatar avatar-small">\
  58. <img title="%(modified_by)s" src="%(avatar_modified)s"/></span>', {
  59. created_by: wn.user_info(doc.owner).fullname,
  60. avatar_created: wn.utils.get_file_link(wn.user_info(doc.owner).image),
  61. modified_by: wn.user_info(doc.modified_by).fullname,
  62. avatar_modified: wn.utils.get_file_link(wn.user_info(doc.modified_by).image),
  63. })).insertAfter(this.$w.find(".appframe-title"));
  64. this.$w.find(".avatar:eq(0)").popover({
  65. trigger:"hover",
  66. title: wn._("Created By"),
  67. content: wn.user_info(this.frm.doc.owner).fullname
  68. +" on "+ dateutil.str_to_user(this.frm.doc.creation)
  69. });
  70. this.$w.find(".avatar:eq(1)").popover({
  71. trigger:"hover",
  72. title: wn._("Modified By"),
  73. content: wn.user_info(this.frm.doc.modified_by).fullname
  74. +" on "+ dateutil.str_to_user(this.frm.doc.modified)
  75. });
  76. this.$w.find('.avatar img').centerImage();
  77. },
  78. refresh_labels: function() {
  79. var me = this;
  80. this.frm.doc = wn.model.get_doc(this.frm.doc.doctype, this.frm.doc.name);
  81. var labinfo = {
  82. 0: [wn._('Saved'), 'label-success'],
  83. 1: [wn._('Submitted'), 'label-info'],
  84. 2: [wn._('Cancelled'), 'label-important']
  85. }[cint(this.frm.doc.docstatus)];
  86. if(labinfo[0]==wn._('Saved') && this.frm.meta.is_submittable) {
  87. labinfo[0]=wn._('Saved, to Submit');
  88. }
  89. if(this.frm.doc.__unsaved || this.frm.doc.__islocal) {
  90. labinfo[0] = wn._('Not Saved');
  91. labinfo[1] = 'label-warning'
  92. }
  93. this.set_label(labinfo);
  94. // show update button if unsaved
  95. if(this.frm.doc.__unsaved && cint(this.frm.doc.docstatus)==1 && this.frm.perm[0][SUBMIT]) {
  96. this.appframe.add_button('Update', function() {
  97. me.frm.save('Update', null, this);
  98. }, '').html(wn._('Update'))
  99. }
  100. this.set_primary_button();
  101. },
  102. set_label: function(labinfo) {
  103. this.$w.find('.label').remove();
  104. if(this.frm.meta.hide_toolbar || this.frm.save_disabled)
  105. return;
  106. console.log(labinfo)
  107. $(repl('<span class="label %(lab_class)s">\
  108. %(lab_status)s</span>', {
  109. lab_status: labinfo[0],
  110. lab_class: labinfo[1]
  111. })).appendTo(this.$w.find('.appframe-subject'))
  112. },
  113. refresh_toolbar: function() {
  114. // clear
  115. var me = this;
  116. if(this.frm.meta.hide_toolbar) {
  117. this.appframe.$w.find('.appframe-toolbar').toggle(false);
  118. this.frm.save_disabled = true;
  119. return;
  120. }
  121. this.appframe.clear_buttons();
  122. var p = this.frm.perm[0];
  123. // Edit
  124. if(this.frm.meta.read_only_onload && !this.frm.doc.__islocal) {
  125. this.appframe.add_button('Print View', function() {
  126. me.frm.last_view_is_edit[me.frm.docname] = 0;
  127. me.frm.refresh(); }, 'icon-print' ).html(wn._('Print View'));
  128. }
  129. var docstatus = cint(this.frm.doc.docstatus);
  130. // Save
  131. if(docstatus==0 && p[WRITE] && !this.read_only) {
  132. this.appframe.add_button('Save', function() {
  133. me.frm.save('Save', null, this);}, 'icon-save');
  134. this.appframe.buttons['Save'].addClass("btn-save")
  135. .html("<i class='icon-save'></i> "+wn._("Save"));
  136. }
  137. // Submit
  138. if(!wn.model.get("Workflow", {document_type: me.frm.doctype}).length) {
  139. if(docstatus==0 && p[SUBMIT] && (!me.frm.doc.__islocal))
  140. this.appframe.add_button('Submit', function() {
  141. me.frm.savesubmit(this);}, 'icon-lock').html(wn._('Submit'));
  142. // Cancel
  143. if(docstatus==1 && p[CANCEL])
  144. this.appframe.add_button('Cancel', function() {
  145. me.frm.savecancel(this) }, 'icon-remove').html(wn._('Cancel'));
  146. // Amend
  147. if(docstatus==2 && p[AMEND])
  148. this.appframe.add_button('Amend', function() {
  149. me.frm.amend_doc() }, 'icon-pencil').html(wn._('Amend'));
  150. }
  151. this.set_primary_button();
  152. },
  153. set_primary_button: function() {
  154. if(!this.appframe.toolbar)
  155. return;
  156. var buttons = this.appframe.buttons;
  157. // highlight save
  158. this.appframe.toolbar.find("button").removeClass("btn-info");
  159. if(buttons["Save"]) {
  160. buttons["Save"].addClass("btn-info");
  161. }
  162. // highlight submit button
  163. if(buttons["Submit"] && !this.frm.doc.__unsaved) {
  164. this.appframe.toolbar.find("button").removeClass("btn-info");
  165. buttons["Submit"].addClass("btn-info");
  166. // highlight update button
  167. } else if(buttons["Update"] && this.frm.doc.__unsaved) {
  168. this.appframe.toolbar.find("button").removeClass("btn-info");
  169. buttons["Update"].addClass("btn-info");
  170. }
  171. },
  172. hide_close: function() {
  173. this.$w.find('.close').toggle(false);
  174. }
  175. })