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

152 行
4.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. // Image field definition
  23. // ======================================================================================
  24. _f.ImageField = function() { this.images = {}; }
  25. _f.ImageField.prototype = new Field();
  26. _f.ImageField.prototype.onrefresh = function() {
  27. $(this.label_span).toggle(false);
  28. $(this.wrapper).find("img").remove();
  29. if(this.df.options && this.frm.doc[this.df.options]) {
  30. $("<img src='"+wn.utils.get_file_link(this.frm.doc[this.df.options])+"' style='max-width: 70%;'>")
  31. .appendTo($(this.wrapper).empty());
  32. } else {
  33. $("<div class='missing-image'><i class='icon-camera'></i></div>")
  34. .appendTo($(this.wrapper).empty())
  35. }
  36. }
  37. _f.ImageField.prototype.set_disp = function (val) { }
  38. _f.ImageField.prototype.set = function (val) { }
  39. // Table
  40. // ======================================================================================
  41. _f.TableField = function() { };
  42. _f.TableField.prototype = new Field();
  43. _f.TableField.prototype.with_label = 0;
  44. _f.TableField.prototype.make_body = function() {
  45. if(this.perm[this.df.permlevel] && this.perm[this.df.permlevel][READ]) {
  46. this.wrapper = $("<div>").appendTo(this.parent).get(0);
  47. this.grid = new _f.FormGrid(this);
  48. if(this.frm)this.frm.grids[this.frm.grids.length] = this;
  49. this.grid.make_buttons();
  50. // description
  51. if(this.df.description) {
  52. $('<p class="muted small">' + this.df.description + '</p>');
  53. }
  54. }
  55. }
  56. _f.TableField.prototype.refresh = function() {
  57. if(!this.grid)return;
  58. // hide / show grid
  59. var st = this.get_status();
  60. if(!this.df['default'])
  61. this.df['default']='';
  62. this.grid.can_add_rows = false;
  63. this.grid.can_edit = false;
  64. if(st=='Write') {
  65. this.grid.can_edit = true;
  66. if(this.df['default'].toLowerCase()!='no toolbar')
  67. this.grid.can_add_rows = true;
  68. if(this.df['default'].toLowerCase()=='no add rows') {
  69. this.grid.can_add_rows = false;
  70. }
  71. }
  72. if(st=='Write' || st=="Read") {
  73. $(this.wrapper).toggle(true);
  74. this.grid.show();
  75. } else {
  76. $(this.wrapper).toggle(false);
  77. this.grid.hide();
  78. }
  79. this.grid.refresh();
  80. }
  81. _f.TableField.prototype.set = function(v) { }; // nothing
  82. _f.TableField.prototype.set_input = function(v) { }; // nothing
  83. _f.CodeField = function() { };
  84. _f.CodeField.prototype = new Field();
  85. _f.CodeField.prototype.make_input = function() {
  86. var me = this;
  87. this.label_span.innerHTML = this.df.label;
  88. $(this.input_area).css({"min-height":"360px"});
  89. if(this.df.fieldtype=='Text Editor') {
  90. this.input = new wn.editors.BootstrapWYSIWYG({
  91. parent: this.input_area,
  92. change: function(value) {
  93. me.set_value_and_run_trigger(value);
  94. },
  95. field: this
  96. });
  97. } else {
  98. this.input = new wn.editors.ACE({
  99. parent: this.input_area,
  100. change: function(value) {
  101. me.set_value_and_run_trigger(value);
  102. },
  103. field: this
  104. });
  105. }
  106. this.get_value = function() {
  107. return this.input.get_value();
  108. }
  109. }
  110. _f.CodeField.prototype.set_value_and_run_trigger = function(value) {
  111. if(locals[cur_frm.doctype][cur_frm.docname][this.df.fieldname] != value) {
  112. this.set(value);
  113. this.changing_value = true;
  114. this.run_trigger();
  115. this.changing_value = false;
  116. }
  117. }
  118. _f.CodeField.prototype.set_disp = function(val) {
  119. $y(this.disp_area, {width:'90%'})
  120. if(this.df.fieldtype=='Text Editor') {
  121. this.disp_area.innerHTML = val;
  122. } else {
  123. this.disp_area.innerHTML = '<textarea class="code_text" readonly=1>'
  124. +val+'</textarea>';
  125. }
  126. }
  127. // ======================================================================================