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.

form_header.js 5.7 KiB

13 jaren geleden
13 jaren geleden
13 jaren geleden
12 jaren geleden
12 jaren geleden
13 jaren geleden
13 jaren geleden
13 jaren geleden
13 jaren geleden
13 jaren geleden
13 jaren geleden
13 jaren geleden
13 jaren geleden
13 jaren geleden
13 jaren geleden
13 jaren geleden
13 jaren geleden
13 jaren geleden
13 jaren geleden
13 jaren geleden
13 jaren geleden
13 jaren geleden
13 jaren geleden
13 jaren geleden
13 jaren geleden
13 jaren geleden
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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 && cur_frm.perm[0][SUBMIT]) {
  95. this.appframe.add_button('Update', function() {
  96. cur_frm.save('Update', null, this);
  97. }, '')
  98. }
  99. },
  100. set_label: function(labinfo) {
  101. this.$w.find('.label').remove();
  102. $(repl('<span class="label %(lab_class)s">\
  103. %(lab_status)s</span>', {
  104. lab_status: labinfo[0],
  105. lab_class: labinfo[1]
  106. })).appendTo(this.$w.find('.appframe-subject'))
  107. },
  108. refresh_toolbar: function() {
  109. // clear
  110. if(cur_frm.meta.hide_toolbar) {
  111. $('.appframe-toolbar').toggle(false);
  112. return;
  113. }
  114. this.appframe.clear_buttons();
  115. var p = cur_frm.perm[0];
  116. // Edit
  117. if(cur_frm.meta.read_only_onload && !cur_frm.doc.__islocal) {
  118. if(!cur_frm.editable)
  119. this.appframe.add_button('Edit', function() {
  120. cur_frm.edit_doc();
  121. },'icon-pencil');
  122. else
  123. this.appframe.add_button('Print View', function() {
  124. cur_frm.is_editable[cur_frm.docname] = 0;
  125. cur_frm.refresh(); }, 'icon-print' );
  126. }
  127. var docstatus = cint(cur_frm.doc.docstatus);
  128. // Save
  129. if(docstatus==0 && p[WRITE]) {
  130. this.appframe.add_button('Save', function() {
  131. cur_frm.save('Save', null, this);}, 'icon-save');
  132. this.appframe.buttons['Save'].addClass('btn-info')
  133. .html("<i class='icon-save'></i> Save (Ctrl+S)");
  134. }
  135. // Submit
  136. if(!wn.model.get("Workflow", {document_type: cur_frm.doctype}).length) {
  137. if(docstatus==0 && p[SUBMIT] && (!cur_frm.doc.__islocal))
  138. this.appframe.add_button('Submit', function() {
  139. cur_frm.savesubmit(this);}, 'icon-lock');
  140. // Cancel
  141. if(docstatus==1 && p[CANCEL])
  142. this.appframe.add_button('Cancel', function() {
  143. cur_frm.savecancel(this) }, 'icon-remove');
  144. // Amend
  145. if(docstatus==2 && p[AMEND])
  146. this.appframe.add_button('Amend', function() {
  147. cur_frm.amend_doc() }, 'icon-pencil');
  148. }
  149. },
  150. show: function() {
  151. },
  152. hide: function() {
  153. },
  154. hide_close: function() {
  155. this.$w.find('.close').toggle(false);
  156. }
  157. })