選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 
 
 

221 行
6.3 KiB

  1. _f.FrmHeader = function(parent, frm) {
  2. var me = this;
  3. this.wrapper = $a(parent, 'div');
  4. if(frm.meta.in_dialog) $y(this.wrapper, {marginLeft:'8px', marginRight:'8px'});
  5. this.page_head = new PageHeader(this.wrapper);
  6. // doctype
  7. this.dt_area = $a(this.page_head.main_head, 'h1', '', {marginRight:'8px', display:'inline'})
  8. // name
  9. var div = $a(null, 'div', '', {marginBottom:'4px'});
  10. this.page_head.lhs.insertBefore(div, this.page_head.sub_head);
  11. this.dn_area = $a(div, 'span', '', {fontSize:'14px', fontWeight:'normal', marginRight:'8px'})
  12. // status
  13. this.status_area = $a(div, 'span', '', {marginRight:'8px', marginBottom:'2px', cursor:'pointer', textShadow:'none'})
  14. // timestamp
  15. this.timestamp_area = $a($a(div,'div','',{marginTop:'3px'}), 'span', 'field_description', {fontSize:'11px'});
  16. }
  17. _f.FrmHeader.prototype.show = function() { $ds(this.wrapper); }
  18. _f.FrmHeader.prototype.hide = function() { $dh(this.wrapper); }
  19. // toolbar buttons
  20. // =======================================================================
  21. _f.FrmHeader.prototype.refresh= function() {
  22. var me = this;
  23. var p = cur_frm.get_doc_perms();
  24. this.page_head.clear_toolbar();
  25. // Edit
  26. if(cur_frm.meta.read_only_onload && !cur_frm.doc.__islocal) {
  27. if(!cur_frm.editable)
  28. this.page_head.add_button('Edit', function() {
  29. cur_frm.edit_doc();
  30. }, 1, 'ui-icon-document', 1
  31. );
  32. else
  33. this.page_head.add_button('Print View', function() {
  34. cur_frm.is_editable[cur_frm.docname] = 0;
  35. cur_frm.refresh(); }, 1, 'ui-icon-document' );
  36. }
  37. // Save
  38. if(cur_frm.editable && cint(cur_frm.doc.docstatus)==0 && p[WRITE])
  39. this.page_head.add_button('Save', function() { cur_frm.save('Save');}, 1, 'ui-icon-disk',1);
  40. // Submit
  41. if(cint(cur_frm.doc.docstatus)==0 && p[SUBMIT] && (!cur_frm.doc.__islocal))
  42. this.page_head.add_button('Submit', function() { cur_frm.savesubmit(); }, 0, 'ui-icon-locked');
  43. // Update after sumit
  44. if(cint(cur_frm.doc.docstatus)==1 && p[SUBMIT]) {
  45. this.update_btn = this.page_head.add_button('Update', function() { cur_frm.saveupdate(); }, 1, 'ui-icon-disk', 1);
  46. if(!cur_frm.doc.__unsaved) $dh(this.update_btn);
  47. }
  48. // Cancel
  49. if(cint(cur_frm.doc.docstatus)==1 && p[CANCEL])
  50. this.page_head.add_button('Cancel', function() { cur_frm.savecancel() }, 0, 'ui-icon-closethick');
  51. // Amend
  52. if(cint(cur_frm.doc.docstatus)==2 && p[AMEND])
  53. this.page_head.add_button('Amend', function() { cur_frm.amend_doc() }, 0, 'ui-icon-scissors');
  54. }
  55. _f.FrmHeader.prototype.show_toolbar = function() { $ds(this.wrapper); this.refresh(); }
  56. _f.FrmHeader.prototype.hide_toolbar = function() { $dh(this.wrapper); }
  57. // refresh toolbar
  58. // -------------------------------------------------------------------
  59. _f.FrmHeader.prototype.refresh_toolbar = function() {
  60. var m = cur_frm.meta;
  61. if(m.hide_heading || cur_frm.in_dialog) {
  62. // no heading... poof
  63. this.hide();
  64. } else {
  65. this.show();
  66. // with or without toolbar?
  67. if(m.hide_toolbar) {
  68. this.hide_toolbar();
  69. } else {
  70. this.show_toolbar();
  71. }
  72. }
  73. //this.refresh_comments();
  74. }
  75. /*_f.FrmHeader.prototype.refresh_comments = function() {
  76. var n = cint(cur_frm.n_comments[cur_frm.doc.name]);
  77. if(this.comment_btn && !cur_frm.doc.__islocal)
  78. this.comment_btn.innerHTML = 'Comments ('+n+')';
  79. }*/
  80. // refresh heading and labels
  81. // -------------------------------------------------------------------
  82. _f.FrmHeader.prototype.get_timestamp = function(doc) {
  83. var scrub_date = function(d) {
  84. if(d)t=d.split(' ');else return '';
  85. return dateutil.str_to_user(t[0]) + ' ' + t[1];
  86. }
  87. return repl("Created: %(c_by)s %(c_on)s %(m_by)s %(m_on)s",
  88. {c_by:doc.owner
  89. ,c_on:scrub_date(doc.creation ? doc.creation:'')
  90. ,m_by:doc.modified_by?(' | Modified: '+doc.modified_by):''
  91. ,m_on:doc.modified ? ('on '+scrub_date(doc.modified)) : ''} );
  92. }
  93. // make the status tag
  94. // -------------------------------------------------------------------
  95. _f.FrmHeader.prototype.get_status_tags = function(doc, f) {
  96. var make_tag = function(label, col) {
  97. var s= $a(null, 'span', '', {padding: '2px', backgroundColor:col, color:'#FFF', fontWeight:'bold', marginLeft:(f.meta.issingle ? '0px' : '8px'), fontSize:'11px'});
  98. $(s).css('-moz-border-radius','3px').css('-webkit-border-radius','3px')
  99. s.innerHTML = label;
  100. return s;
  101. }
  102. var sp1 = null; var sp2 = null;
  103. if(doc.__islocal) {
  104. label = 'Unsaved Draft'; col = '#F81';
  105. } else if(cint(doc.__unsaved)) {
  106. label = 'Not Saved'; col = '#F81';
  107. if(doc.docstatus==1 && this.update_btn) $ds(this.update_btn);
  108. } else if(cint(doc.docstatus)==0) {
  109. label = 'Saved'; col = '#0A1';
  110. // if submittable, show it
  111. if(f.get_doc_perms()[SUBMIT]) {
  112. sp2 = make_tag('To Be Submitted', '#888');
  113. }
  114. } else if(cint(doc.docstatus)==1) {
  115. label = 'Submitted'; col = '#44F';
  116. } else if(cint(doc.docstatus)==2) {
  117. label = 'Cancelled'; col = '#F44';
  118. }
  119. sp1 = make_tag(label, col);
  120. this.set_in_recent(doc, col);
  121. return [sp1, sp2];
  122. }
  123. // refresh "recent" tag colour
  124. // -------------------------------------------------------------------
  125. _f.FrmHeader.prototype.set_in_recent = function(doc, col) {
  126. var tn = $i('rec_'+doc.doctype+'-'+doc.name);
  127. if(tn)
  128. $y(tn,{backgroundColor:col});
  129. }
  130. // set the button color of save / submit
  131. _f.FrmHeader.prototype.set_save_submit_color = function(doc) {
  132. var save_btn = this.page_head.buttons['Save'];
  133. var submit_btn = this.page_head.buttons['Submit'];
  134. if(cint(doc.docstatus)==0 && submit_btn && save_btn) {
  135. if(cint(doc.__unsaved)) {
  136. save_btn.wid_color = 'green';
  137. submit_btn.wid_color = 'normal';
  138. } else {
  139. save_btn.wid_color = 'normal';
  140. submit_btn.wid_color = 'green';
  141. }
  142. $wid_normal(save_btn); $wid_normal(submit_btn);
  143. }
  144. }
  145. // refresh the labels!
  146. // -------------------------------------------------------------------
  147. _f.FrmHeader.prototype.refresh_labels = function(f) {
  148. var ph = this.page_head;
  149. var me = this;
  150. // main title
  151. this.dt_area.innerHTML = get_doctype_label(f.doctype);
  152. // sub title
  153. this.dn_area.innerHTML = '';
  154. if(!f.meta.issingle)
  155. this.dn_area.innerHTML = f.docname;
  156. // get the doc
  157. var doc = locals[f.doctype][f.docname];
  158. // get the tags
  159. var sl = this.get_status_tags(doc, f);
  160. // set save, submit color
  161. this.set_save_submit_color(doc);
  162. // add the tags
  163. var t = this.status_area;
  164. t.innerHTML = '';
  165. t.appendChild(sl[0]);
  166. if(sl[1])t.appendChild(sl[1]);
  167. // timestamp
  168. this.timestamp_area.innerHTML = me.get_timestamp(doc);
  169. }