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 4.3 KiB

13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. // breadcrumbs
  27. // save / submit button toggle based on "saved" or not
  28. // highlight and fade name based on refresh
  29. _f.FrmHeader = Class.extend({
  30. init: function(parent, frm) {
  31. this.appframe = new wn.ui.AppFrame(parent)
  32. this.$w = this.appframe.$w;
  33. },
  34. refresh: function() {
  35. // refresh breadcrumbs
  36. if(cur_frm.cscript.set_breadcrumbs) {
  37. this.appframe.clear_breadcrumbs();
  38. cur_frm.cscript.set_breadcrumbs();
  39. } else {
  40. wn.views.breadcrumbs(this.appframe,
  41. cur_frm.meta.module, cur_frm.meta.name, cur_frm.docname);
  42. }
  43. this.refresh_labels();
  44. this.refresh_toolbar();
  45. },
  46. refresh_labels: function() {
  47. var labinfo = {
  48. 0: ['Saved', 'label-success'],
  49. 1: ['Submitted', 'label-info'],
  50. 2: ['Cancelled', 'label-important']
  51. }[cint(cur_frm.doc.docstatus)];
  52. if(labinfo[0]=='Saved' && cur_frm.meta.is_submittable) {
  53. labinfo[0]='Saved, to Submit';
  54. }
  55. if(cur_frm.doc.__unsaved || cur_frm.doc.__islocal) {
  56. labinfo[0] = 'Not Saved';
  57. labinfo[1] = 'label-warning'
  58. }
  59. this.set_label(labinfo);
  60. // show update button if unsaved
  61. if(cur_frm.doc.__unsaved && cint(cur_frm.doc.docstatus)==1 && this.appframe.buttons['Update']) {
  62. this.appframe.buttons['Update'].toggle(true);
  63. }
  64. },
  65. set_label: function(labinfo) {
  66. this.$w.find('.label').remove();
  67. $(repl('<span class="label %(lab_class)s">\
  68. %(lab_status)s</span>', {
  69. lab_status: labinfo[0],
  70. lab_class: labinfo[1]
  71. })).insertBefore(this.$w.find('.breadcrumb-area'))
  72. },
  73. refresh_toolbar: function() {
  74. // clear
  75. this.appframe.clear_buttons();
  76. var p = cur_frm.get_doc_perms();
  77. // Edit
  78. if(cur_frm.meta.read_only_onload && !cur_frm.doc.__islocal) {
  79. if(!cur_frm.editable)
  80. this.appframe.add_button('Edit', function() {
  81. cur_frm.edit_doc();
  82. },'icon-pencil');
  83. else
  84. this.appframe.add_button('Print View', function() {
  85. cur_frm.is_editable[cur_frm.docname] = 0;
  86. cur_frm.refresh(); }, 'icon-print' );
  87. }
  88. var docstatus = cint(cur_frm.doc.docstatus);
  89. // Save
  90. if(docstatus==0 && p[WRITE]) {
  91. this.appframe.add_button('Save', function() { cur_frm.save('Save');}, '');
  92. this.appframe.buttons['Save'].addClass('btn-info');
  93. }
  94. // Submit
  95. if(docstatus==0 && p[SUBMIT] && (!cur_frm.doc.__islocal))
  96. this.appframe.add_button('Submit', function() { cur_frm.savesubmit();}, 'icon-lock');
  97. // Update after sumit
  98. if(docstatus==1 && p[SUBMIT]) {
  99. this.appframe.add_button('Update', function() { cur_frm.saveupdate();}, '');
  100. if(!cur_frm.doc.__unsaved) this.appframe.buttons['Update'].toggle(false);
  101. }
  102. // Cancel
  103. if(docstatus==1 && p[CANCEL])
  104. this.appframe.add_button('Cancel', function() { cur_frm.savecancel() }, 'icon-remove');
  105. // Amend
  106. if(docstatus==2 && p[AMEND])
  107. this.appframe.add_button('Amend', function() { cur_frm.amend_doc() }, 'icon-pencil');
  108. // Help
  109. if(cur_frm.meta.description) {
  110. this.appframe.add_help_button(wn.markdown('## ' + cur_frm.doctype + '\n<br>\n'
  111. + cur_frm.meta.description));
  112. }
  113. },
  114. show: function() {
  115. },
  116. hide: function() {
  117. },
  118. hide_close: function() {
  119. this.$w.find('.close').toggle(false);
  120. }
  121. })