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.
 
 
 
 
 
 

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