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.
 
 
 
 
 
 

189 lines
5.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. // 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, 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. cur_frm.doc = wn.model.get_doc(cur_frm.doc.doctype, cur_frm.doc.name);
  80. var labinfo = {
  81. 0: ['Saved', 'label-success'],
  82. 1: ['Submitted', 'label-info'],
  83. 2: ['Cancelled', 'label-important']
  84. }[cint(cur_frm.doc.docstatus)];
  85. if(labinfo[0]=='Saved' && cur_frm.meta.is_submittable) {
  86. labinfo[0]='Saved, to Submit';
  87. }
  88. if(cur_frm.doc.__unsaved || cur_frm.doc.__islocal) {
  89. labinfo[0] = 'Not Saved';
  90. labinfo[1] = 'label-warning'
  91. }
  92. this.set_label(labinfo);
  93. // show update button if unsaved
  94. if(cur_frm.doc.__unsaved && cint(cur_frm.doc.docstatus)==1 && this.appframe.buttons['Update']) {
  95. this.appframe.buttons['Update'].toggle(true);
  96. }
  97. },
  98. set_label: function(labinfo) {
  99. this.$w.find('.label').remove();
  100. $(repl('<span class="label %(lab_class)s">\
  101. %(lab_status)s</span>', {
  102. lab_status: labinfo[0],
  103. lab_class: labinfo[1]
  104. })).appendTo(this.$w.find('.appframe-subject'))
  105. },
  106. refresh_toolbar: function() {
  107. // clear
  108. if(cur_frm.meta.hide_toolbar) {
  109. $('.appframe-toolbar').toggle(false);
  110. return;
  111. }
  112. this.appframe.clear_buttons();
  113. var p = cur_frm.perm[0];
  114. // Edit
  115. if(cur_frm.meta.read_only_onload && !cur_frm.doc.__islocal) {
  116. if(!cur_frm.editable)
  117. this.appframe.add_button('Edit', function() {
  118. cur_frm.edit_doc();
  119. },'icon-pencil');
  120. else
  121. this.appframe.add_button('Print View', function() {
  122. cur_frm.is_editable[cur_frm.docname] = 0;
  123. cur_frm.refresh(); }, 'icon-print' );
  124. }
  125. var docstatus = cint(cur_frm.doc.docstatus);
  126. // Save
  127. if(docstatus==0 && p[WRITE]) {
  128. this.appframe.add_button('Save', function() {
  129. cur_frm.save('Save', null, this);}, 'icon-save');
  130. this.appframe.buttons['Save'].addClass('btn-info')
  131. .html("<i class='icon-save'></i> Save (Ctrl+S)");
  132. }
  133. // Submit
  134. if(docstatus==0 && p[SUBMIT] && (!cur_frm.doc.__islocal))
  135. this.appframe.add_button('Submit', function() {
  136. cur_frm.savesubmit(this);}, 'icon-lock');
  137. // Update after sumit
  138. if(docstatus==1 && p[SUBMIT]) {
  139. this.appframe.add_button('Update', function() {
  140. cur_frm.save('Update', null, this);
  141. }, '').toggle(false);
  142. }
  143. // Cancel
  144. if(docstatus==1 && p[CANCEL])
  145. this.appframe.add_button('Cancel', function() {
  146. cur_frm.savecancel(this) }, 'icon-remove');
  147. // Amend
  148. if(docstatus==2 && p[AMEND])
  149. this.appframe.add_button('Amend', function() {
  150. cur_frm.amend_doc() }, 'icon-pencil');
  151. // Help
  152. // if(cur_frm.meta.description) {
  153. // this.appframe.add_help_button(wn.markdown('#### ' + cur_frm.doctype + '\n\n'
  154. // + cur_frm.meta.description));
  155. // }
  156. },
  157. show: function() {
  158. },
  159. hide: function() {
  160. },
  161. hide_close: function() {
  162. this.$w.find('.close').toggle(false);
  163. }
  164. })