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

488 行
13 KiB

  1. //
  2. // Form Input
  3. // ======================================================================================
  4. _f.ColumnBreak = function() {
  5. this.set_input = function() { };
  6. }
  7. _f.ColumnBreak.prototype.make_body = function() {
  8. if((!this.perm[this.df.permlevel]) || (!this.perm[this.df.permlevel][READ]) || this.df.hidden) {
  9. // no display
  10. return;
  11. }
  12. this.cell = this.frm.layout.addcell(this.df.width);
  13. $y(this.cell.wrapper, {padding: '8px'});
  14. _f.cur_col_break_width = this.df.width;
  15. var fn = this.df.fieldname?this.df.fieldname:this.df.label;
  16. // header
  17. if(this.df&&this.df.label){
  18. this.label = $a(this.cell.wrapper, 'h3', '', '', this.df.label);
  19. }
  20. }
  21. _f.ColumnBreak.prototype.refresh = function(layout) {
  22. if(!this.cell)return; // no perm
  23. var fn = this.df.fieldname?this.df.fieldname:this.df.label;
  24. if(fn) {
  25. this.df = get_field(this.doctype, fn, this.docname);
  26. // hidden
  27. if(this.set_hidden!=this.df.hidden) {
  28. if(this.df.hidden)
  29. this.cell.hide();
  30. else
  31. this.cell.show();
  32. this.set_hidden = this.df.hidden;
  33. }
  34. }
  35. }
  36. // ======================================================================================
  37. _f.SectionBreak = function() {
  38. this.set_input = function() { };
  39. }
  40. _f.SectionBreak.prototype.make_row = function() {
  41. this.row = this.df.label ? this.frm.layout.addrow() : this.frm.layout.addsubrow();
  42. }
  43. _f.SectionBreak.prototype.make_collapsible = function(head) {
  44. var me = this;
  45. var div = $a(head,'div','',{paddingBottom: '3px', borderBottom:'1px solid #AAA'});
  46. if(cur_frm.meta.in_dialog) $y(div, {marginLeft:'8px'});
  47. // checkbox
  48. this.chk = $a_input(div, 'checkbox',null,{marginRight:'8px'})
  49. // label
  50. if(this.df.label) {
  51. this.label = $a(div, 'h3', '', {display:'inline'}, this.df.label);
  52. }
  53. // description
  54. var d = this.df.description;
  55. if(d) {
  56. this.desc_area = $a(div, 'span', 'field_description', {marginLeft:'8px'});
  57. this.desc_area.innerHTML = d.substr(0,50) + (d.length > 50 ? '...' : '');
  58. }
  59. // back to top
  60. var span = $a(div, 'div', 'wn-icon ic-arrow_top', {cssFloat:'right', marginRight:'8px', cursor:'pointer', marginTop:'7px'})
  61. span.title = 'Go to top';
  62. //var span = $a(div, 'span', 'link_type', {cssFloat:'right', marginRight:'8px'});
  63. span.onclick = function() { scroll(0, 0); }
  64. // exp / collapse
  65. this.chk.onclick = function() {
  66. if(this.checked) me.expand();
  67. else me.collapse();
  68. }
  69. this.expand = function() {
  70. $(me.row.main_body).slideDown();
  71. }
  72. this.collapse = function() {
  73. $(me.row.main_body).slideUp();
  74. }
  75. // hide by default
  76. if(me.frm.section_count) {
  77. $dh(this.row.main_body);
  78. } else {
  79. this.chk.checked = true;
  80. }
  81. }
  82. // ======================================================================================
  83. _f.SectionBreak.prototype.make_simple_section = function(with_header) {
  84. this.wrapper = $a(this.row.main_head, 'div', '', {margin:'8px 8px 0px 0px'});
  85. var me = this;
  86. // colour
  87. if(this.df.colour) {
  88. var col = this.df.colour.split(':')[1];
  89. if(col!='FFF') {
  90. $y(this.row.sub_wrapper, { margin:'8px', padding: '0px' ,backgroundColor: ('#' + col)} );
  91. }
  92. }
  93. if(with_header) {
  94. if(this.df.label && this.df.options!='Simple') {
  95. this.make_collapsible(this.wrapper);
  96. } else {
  97. // divider
  98. $y(this.wrapper, {paddingBottom:'4px'});
  99. if(this.df.label) {
  100. $a(this.wrapper, 'h3', '', {}, this.df.label);
  101. }
  102. }
  103. }
  104. // indent
  105. $y(this.row.body, { marginLeft:'17px' });
  106. }
  107. // ======================================================================================
  108. _f.SectionBreak.prototype.add_to_sections = function() {
  109. this.sec_id = this.frm.sections.length;
  110. this.frm.sections[this.sec_id] = this;
  111. this.frm.sections_by_label[this.df.label] = this;
  112. }
  113. _f.cur_sec_header = null;
  114. _f.SectionBreak.prototype.make_body = function() {
  115. if((!this.perm[this.df.permlevel]) || (!this.perm[this.df.permlevel][READ]) || this.df.hidden) {
  116. // no display
  117. return;
  118. }
  119. var me = this;
  120. if(this.df){
  121. this.make_row();
  122. this.make_simple_section(1, 1);
  123. }
  124. }
  125. // ======================================================================================
  126. _f.SectionBreak.prototype.refresh = function(layout) {
  127. var fn = this.df.fieldname?this.df.fieldname:this.df.label;
  128. if(fn)
  129. this.df = get_field(this.doctype, fn, this.docname);
  130. // hidden
  131. if(this.set_hidden!=this.df.hidden) {
  132. if(this.df.hidden) {
  133. if(this.frm.meta.section_style=='Tabbed') {
  134. $dh(this.mytab);
  135. } else if(this.tray_item)
  136. this.tray_item.hide();
  137. if(this.row)this.row.hide();
  138. } else {
  139. if(this.frm.meta.section_style=='Tabbed') {
  140. $di(this.mytab);
  141. } else if(this.tray_item)
  142. this.tray_item.show();
  143. if(this.expanded)this.row.show();
  144. }
  145. this.set_hidden = this.df.hidden;
  146. }
  147. }
  148. // Image field definition
  149. // ======================================================================================
  150. _f.ImageField = function() { this.images = {}; }
  151. _f.ImageField.prototype = new Field();
  152. _f.ImageField.prototype.onmake = function() {
  153. this.no_img = $a(this.wrapper, 'div','no_img');
  154. this.no_img.innerHTML = "No Image";
  155. $dh(this.no_img);
  156. }
  157. _f.ImageField.prototype.get_image_src = function(doc) {
  158. if(doc.file_list) {
  159. file = doc.file_list.split(',');
  160. // if image
  161. extn = file[0].split('.');
  162. extn = extn[extn.length - 1].toLowerCase();
  163. var img_extn_list = ['gif', 'jpg', 'bmp', 'jpeg', 'jp2', 'cgm', 'ief', 'jpm', 'jpx', 'png', 'tiff', 'jpe', 'tif'];
  164. if(in_list(img_extn_list, extn)) {
  165. var src = outUrl + "?cmd=downloadfile&file_id="+file[1];
  166. }
  167. } else {
  168. var src = "";
  169. }
  170. return src;
  171. }
  172. _f.ImageField.prototype.onrefresh = function() {
  173. var me = this;
  174. if(!this.images[this.docname]) this.images[this.docname] = $a(this.wrapper, 'img');
  175. else $di(this.images[this.docname]);
  176. var img = this.images[this.docname]
  177. // hide all other
  178. for(var dn in this.images) if(dn!=this.docname)$dh(this.images[dn]);
  179. var doc = locals[this.frm.doctype][this.frm.docname];
  180. if(!this.df.options) var src = this.get_image_src(doc);
  181. else var src = outUrl + '?cmd=get_file&fname='+this.df.options+"&__account="+account_id + (__sid150 ? ("&sid150="+__sid150) : '');
  182. if(src) {
  183. $dh(this.no_img);
  184. if(img.getAttribute('src')!=src) img.setAttribute('src',src);
  185. canvas = this.wrapper;
  186. canvas.img = this.images[this.docname];
  187. canvas.style.overflow = "auto";
  188. $w(canvas, "100%");
  189. if(!this.col_break_width)this.col_break_width = '100%';
  190. var allow_width = cint(1000 * (cint(this.col_break_width)-10) / 100);
  191. if((!img.naturalWidth) || cint(img.naturalWidth)>allow_width)
  192. $w(img, allow_width + 'px');
  193. } else {
  194. $ds(this.no_img);
  195. }
  196. }
  197. _f.ImageField.prototype.set_disp = function (val) { }
  198. _f.ImageField.prototype.set = function (val) { }
  199. // ======================================================================================
  200. _f.ButtonField = function() { };
  201. _f.ButtonField.prototype = new Field();
  202. _f.ButtonField.prototype.with_label = 0;
  203. _f.ButtonField.prototype.init = function() {
  204. this.prev_button = null;
  205. // if previous field is a button, add it to the same div!
  206. // button-set structure
  207. // + wrapper (1st button)
  208. // + input_area
  209. // + button_area
  210. // + button_area
  211. // + button_area
  212. if(!this.frm) return;
  213. if(cur_frm &&
  214. cur_frm.fields[cur_frm.fields.length-1] &&
  215. cur_frm.fields[cur_frm.fields.length-1].df.fieldtype=='Button') {
  216. this.make_body = function() {
  217. this.prev_button = cur_frm.fields[cur_frm.fields.length-1];
  218. if(!this.prev_button.prev_button) {
  219. // first button, make the button area
  220. this.prev_button.button_area = $a(this.prev_button.input_area, 'span');
  221. }
  222. this.wrapper = this.prev_button.wrapper;
  223. this.input_area = this.prev_button.input_area;
  224. this.disp_area = this.prev_button.disp_area;
  225. // all buttons in the same input_area
  226. this.button_area = $a(this.prev_button.input_area, 'span');
  227. }
  228. }
  229. }
  230. _f.ButtonField.prototype.make_input = function() { var me = this;
  231. if(!this.prev_button) {
  232. $y(this.input_area,{marginTop:'4px', marginBottom: '4px'});
  233. }
  234. // make a button area for one button
  235. if(!this.button_area) this.button_area = $a(this.input_area, 'span','',{marginRight:'4px'});
  236. // make the input
  237. this.input = $btn(this.button_area,
  238. me.df.label.substr(0,20) + ((me.df.label.length>20) ? '..' : ''), {width:'170px', fontWeight:'bold'}, null, 1)
  239. this.input.onclick = function() {
  240. if(me.not_in_form) return;
  241. this.set_disabled();
  242. if(cur_frm.cscript[me.df.label] && (!me.in_filter)) {
  243. cur_frm.runclientscript(me.df.label, me.doctype, me.docname);
  244. this.set_enabled();
  245. } else {
  246. this.set_working();
  247. cur_frm.runscript(me.df.options, me);
  248. }
  249. }
  250. }
  251. _f.ButtonField.prototype.hide = function() {
  252. $dh(this.button_area);
  253. };
  254. _f.ButtonField.prototype.show = function() {
  255. $ds(this.button_area);
  256. };
  257. _f.ButtonField.prototype.set = function(v) { }; // No Setter
  258. _f.ButtonField.prototype.set_disp = function(val) { } // No Disp on readonly
  259. // Table
  260. // ======================================================================================
  261. _f.TableField = function() { };
  262. _f.TableField.prototype = new Field();
  263. _f.TableField.prototype.with_label = 0;
  264. _f.TableField.prototype.make_body = function() {
  265. if(this.perm[this.df.permlevel] && this.perm[this.df.permlevel][READ]) {
  266. // add comment area
  267. if(this.df.description) {
  268. this.desc_area = $a(this.parent, 'div', 'field_description', '', this.df.description)
  269. }
  270. this.grid = new _f.FormGrid(this);
  271. if(this.frm)this.frm.grids[this.frm.grids.length] = this;
  272. this.grid.make_buttons();
  273. }
  274. }
  275. _f.TableField.prototype.refresh = function() {
  276. if(!this.grid)return;
  277. // hide / show grid
  278. var st = this.get_status();
  279. if(!this.df['default'])
  280. this.df['default']='';
  281. this.grid.can_add_rows = false;
  282. this.grid.can_edit = false
  283. if(st=='Write') {
  284. if(cur_frm.editable && this.perm[this.df.permlevel] && this.perm[this.df.permlevel][WRITE]) {
  285. this.grid.can_edit = true;
  286. if(this.df['default'].toLowerCase()!='no toolbar')
  287. this.grid.can_add_rows = true;
  288. }
  289. if(cur_frm.editable
  290. && this.df.allow_on_submit
  291. && cur_frm.doc.docstatus == 1
  292. && this.df['default'].toLowerCase()!='no toolbar') {
  293. this.grid.can_add_rows = true;
  294. this.grid.can_edit = true;
  295. }
  296. }
  297. if(this.old_status!=st) {
  298. if(st=='Write') {
  299. // nothing
  300. this.grid.show();
  301. } else if(st=='Read') {
  302. this.grid.show();
  303. } else {
  304. this.grid.hide();
  305. }
  306. this.old_status = st; // save this if next time
  307. }
  308. this.grid.refresh();
  309. }
  310. _f.TableField.prototype.set = function(v) { }; // nothing
  311. _f.TableField.prototype.set_input = function(v) { }; // nothing
  312. // ==============================================================
  313. _f.CodeField = function() { };
  314. _f.CodeField.prototype = new Field();
  315. _f.CodeField.prototype.make_input = function() {
  316. var me = this;
  317. this.label_span.innerHTML = this.df.label;
  318. this.input = $a(this.input_area, 'textarea','code_text',{fontSize:'12px'});
  319. this.myid = wn.dom.set_unique_id(this.input);
  320. this.input.setAttribute('wrap', 'off');
  321. this.input.set_input = function(v) {
  322. if(me.editor) {
  323. me.editor.setContent(v);
  324. } else {
  325. me.input.value = v;
  326. me.input.innerHTML = v;
  327. }
  328. }
  329. this.input.onchange = function() {
  330. if(me.editor) {
  331. //me.set(tinymce.get(me.myid).getContent());
  332. } else {
  333. me.set(me.input.value);
  334. }
  335. me.run_trigger();
  336. }
  337. this.get_value = function() {
  338. if(me.editor) {
  339. return me.editor.getContent(); // tinyMCE
  340. } else {
  341. return this.input.value;
  342. }
  343. }
  344. if(this.df.fieldtype=='Text Editor') {
  345. // setup tiny mce
  346. $(me.input).tinymce({
  347. // Location of TinyMCE script
  348. script_url : 'js/tiny_mce_33/tiny_mce.js',
  349. // General options
  350. theme : "advanced",
  351. plugins : "style,inlinepopups,table",
  352. extended_valid_elements: "div[id|dir|class|align|style]",
  353. // w/h
  354. width: '100%',
  355. height: '360px',
  356. // buttons
  357. theme_advanced_buttons1 : "bold,italic,underline,strikethrough,hr,|,justifyleft,justifycenter,justifyright,|,formatselect,fontselect,fontsizeselect",
  358. theme_advanced_buttons2 : "bullist,numlist,|,outdent,indent,|,undo,redo,|,link,unlink,code,|,forecolor,backcolor,|,tablecontrols",
  359. theme_advanced_buttons3 : "",
  360. theme_advanced_toolbar_location : "top",
  361. theme_advanced_toolbar_align : "left",
  362. content_css: "js/tiny_mce_33/custom_content.css",
  363. oninit: function() { me.init_editor(); }
  364. });
  365. } else {
  366. $y(me.input, {fontFamily:'Courier, Fixed'});
  367. }
  368. }
  369. _f.CodeField.prototype.init_editor = function() {
  370. // attach onchange methods
  371. var me = this;
  372. this.editor = tinymce.get(this.myid);
  373. this.editor.onKeyUp.add(function(ed, e) {
  374. me.set(ed.getContent());
  375. });
  376. this.editor.onPaste.add(function(ed, e) {
  377. me.set(ed.getContent());
  378. });
  379. this.editor.onSetContent.add(function(ed, e) {
  380. me.set(ed.getContent());
  381. });
  382. // reset content
  383. var c = locals[cur_frm.doctype][cur_frm.docname][this.df.fieldname];
  384. if(cur_frm && c) {
  385. this.editor.setContent(c);
  386. }
  387. }
  388. _f.CodeField.prototype.set_disp = function(val) {
  389. $y(this.disp_area, {width:'90%'})
  390. if(this.df.fieldtype=='Text Editor') {
  391. this.disp_area.innerHTML = val;
  392. } else {
  393. this.disp_area.innerHTML = '<textarea class="code_text" readonly=1>'+val+'</textarea>';
  394. }
  395. }
  396. // ======================================================================================