Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 
 
 
 

263 рядки
7.5 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. //
  23. // Form Input
  24. // ======================================================================================
  25. _f.ColumnBreak = function() {
  26. this.set_input = function() { };
  27. }
  28. _f.ColumnBreak.prototype.make_body = function() {
  29. this.cell = this.frm.layout.addcell(this.df.width);
  30. $y(this.cell.wrapper, {padding: '8px'});
  31. _f.cur_col_break_width = this.df.width;
  32. var fn = this.df.fieldname || this.df.label;
  33. // header
  34. if(this.df&&this.df.label){
  35. this.label = $a(this.cell.wrapper, 'h4', '', '', wn._(this.df.label));
  36. if(this.df.description)
  37. $('<div class="help small" style="margin-top: 4px; margin-bottom: 8px;">'
  38. +wn._(this.df.description)+'</div>')
  39. .appendTo(this.cell.wrapper)
  40. }
  41. }
  42. _f.ColumnBreak.prototype.refresh = function(layout) {
  43. //if(!this.cell)return; // no perm
  44. var hidden = 0;
  45. // we generate column breaks, but hide it based on perms/hidden value
  46. if((!this.perm[this.df.permlevel]) || (!this.perm[this.df.permlevel][READ]) ||
  47. this.df.hidden) {
  48. // do not display, as no permission
  49. hidden = 1;
  50. }
  51. // hidden
  52. if(this.set_hidden!=hidden) {
  53. if(hidden)
  54. this.cell.hide();
  55. else
  56. this.cell.show();
  57. this.set_hidden = hidden;
  58. }
  59. }
  60. // ======================================================================================
  61. _f.SectionBreak = function() {
  62. this.fields = [];
  63. this.set_input = function() { };
  64. this.make_row = function() {
  65. this.row = this.df.label ? this.frm.layout.addrow() : this.frm.layout.addsubrow();
  66. }
  67. }
  68. _f.SectionBreak.prototype.make_body = function() {
  69. var me = this;
  70. this.make_row();
  71. if(this.df.label) {
  72. if(!this.df.description)
  73. this.df.description = '';
  74. this.df._label = wn._(this.df.label);
  75. this.df._description = wn._(this.df.description);
  76. $(this.row.main_head).html(repl('<div class="form-section-head">\
  77. <h3 class="head">%(_label)s</h3>\
  78. <div class="help small" \
  79. style="margin-top: 4px; margin-bottom: 8px;">%(_description)s</div>\
  80. </div>', this.df));
  81. } else {
  82. // simple
  83. $(this.wrapper).html('<div class="form-section-head"></div>');
  84. }
  85. // collapse section
  86. this.section_collapse = function() {
  87. $(me.row.main_head).find('.head')
  88. .html('<i class="icon-chevron-right"></i> \
  89. <a href="#" onclick="return false;">Show "' + me.df.label + '"</a>');
  90. $(me.row.main_body).toggle(false);
  91. }
  92. // expand section
  93. this.section_expand = function(no_animation) {
  94. $(me.row.main_head).find('.head')
  95. .html('<h3><i class="icon-chevron-down" style="vertical-align: middle; margin-bottom: 2px"></i> '
  96. + me.df.label + '</h3>');
  97. if(no_animation)
  98. $(me.row.main_body).toggle(true);
  99. else
  100. $(me.row.main_body).slideDown();
  101. }
  102. }
  103. _f.SectionBreak.prototype.refresh = function(from_form) {
  104. var hidden = 0;
  105. // we generate section breaks, but hide it based on perms/hidden value
  106. if((!this.perm[this.df.permlevel]) || (!this.perm[this.df.permlevel][READ]) || this.df.hidden) {
  107. // no display
  108. hidden = 1;
  109. }
  110. if(hidden) {
  111. if(this.row)this.row.hide();
  112. } else {
  113. if(this.row)this.row.show();
  114. }
  115. }
  116. // Image field definition
  117. // ======================================================================================
  118. _f.ImageField = function() { this.images = {}; }
  119. _f.ImageField.prototype = new Field();
  120. _f.ImageField.prototype.onrefresh = function() {
  121. $(this.label_span).toggle(false);
  122. $(this.wrapper).find("img").remove();
  123. if(this.df.options && this.frm.doc[this.df.options]) {
  124. $("<img src='"+wn.utils.get_file_link(this.frm.doc[this.df.options])+"' style='max-width: 70%;'>")
  125. .appendTo($(this.wrapper).empty());
  126. } else {
  127. $("<div class='missing-image'><i class='icon-camera'></i></div>")
  128. .appendTo($(this.wrapper).empty())
  129. }
  130. }
  131. _f.ImageField.prototype.set_disp = function (val) { }
  132. _f.ImageField.prototype.set = function (val) { }
  133. // Table
  134. // ======================================================================================
  135. _f.TableField = function() { };
  136. _f.TableField.prototype = new Field();
  137. _f.TableField.prototype.with_label = 0;
  138. _f.TableField.prototype.make_body = function() {
  139. if(this.perm[this.df.permlevel] && this.perm[this.df.permlevel][READ]) {
  140. this.wrapper = $("<div>").appendTo(this.parent).get(0);
  141. this.grid = new _f.FormGrid(this);
  142. if(this.frm)this.frm.grids[this.frm.grids.length] = this;
  143. this.grid.make_buttons();
  144. // description
  145. if(this.df.description) {
  146. this.desc_area = $a(this.wrapper, 'div', 'help small',
  147. {marginBottom:'9px', marginTop:'0px'}, this.df.description)
  148. }
  149. }
  150. }
  151. _f.TableField.prototype.refresh = function() {
  152. if(!this.grid)return;
  153. // hide / show grid
  154. var st = this.get_status();
  155. if(!this.df['default'])
  156. this.df['default']='';
  157. this.grid.can_add_rows = false;
  158. this.grid.can_edit = false;
  159. if(st=='Write') {
  160. this.grid.can_edit = true;
  161. if(this.df['default'].toLowerCase()!='no toolbar')
  162. this.grid.can_add_rows = true;
  163. if(this.df['default'].toLowerCase()=='no add rows') {
  164. this.grid.can_add_rows = false;
  165. }
  166. }
  167. if(st=='Write' || st=="Read") {
  168. $(this.wrapper).toggle(true);
  169. this.grid.show();
  170. } else {
  171. $(this.wrapper).toggle(false);
  172. this.grid.hide();
  173. }
  174. this.grid.refresh();
  175. }
  176. _f.TableField.prototype.set = function(v) { }; // nothing
  177. _f.TableField.prototype.set_input = function(v) { }; // nothing
  178. _f.CodeField = function() { };
  179. _f.CodeField.prototype = new Field();
  180. _f.CodeField.prototype.make_input = function() {
  181. var me = this;
  182. this.label_span.innerHTML = this.df.label;
  183. $(this.input_area).css({"min-height":"360px"});
  184. if(this.df.fieldtype=='Text Editor') {
  185. this.input = new wn.editors.BootstrapWYSIWYG({
  186. parent: this.input_area,
  187. change: function(value) {
  188. me.set_value_and_run_trigger(value);
  189. },
  190. field: this
  191. });
  192. } else {
  193. this.input = new wn.editors.ACE({
  194. parent: this.input_area,
  195. change: function(value) {
  196. me.set_value_and_run_trigger(value);
  197. },
  198. field: this
  199. });
  200. }
  201. }
  202. _f.CodeField.prototype.set_value_and_run_trigger = function(value) {
  203. if(locals[cur_frm.doctype][cur_frm.docname][this.df.fieldname] != value) {
  204. this.set(value);
  205. this.changing_value = true;
  206. this.run_trigger();
  207. this.changing_value = false;
  208. }
  209. }
  210. _f.CodeField.prototype.set_disp = function(val) {
  211. $y(this.disp_area, {width:'90%'})
  212. if(this.df.fieldtype=='Text Editor') {
  213. this.disp_area.innerHTML = val;
  214. } else {
  215. this.disp_area.innerHTML = '<textarea class="code_text" readonly=1>'
  216. +val+'</textarea>';
  217. }
  218. }
  219. // ======================================================================================