Textfield.js 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. MWF.xDesktop.requireApp("process.Xform", "$Input", null, false);
  2. /** @class Textfield 文本输入框类。
  3. * @example
  4. * //可以在脚本中获取该组件
  5. * //方法1:
  6. * var field = this.form.get("fieldName"); //获取组件对象
  7. * //方法2
  8. * var field = this.target; //在组件本身的脚本中获取,比如事件脚本、默认值脚本、校验脚本等等
  9. *
  10. * var data = field.getData(); //获取值
  11. * field.setData("字符串值"); //设置值
  12. * field.hide(); //隐藏字段
  13. * var id = field.json.id; //获取字段标识
  14. * var flag = field.isEmpty(); //字段是否为空
  15. * field.resetData(); //重置字段的值为默认值或置空
  16. * @extends MWF.xApplication.process.Xform.$Input
  17. */
  18. MWF.xApplication.process.Xform.Textfield = MWF.APPTextfield = new Class({
  19. Implements: [Events],
  20. Extends: MWF.APP$Input,
  21. iconStyle: "textFieldIcon",
  22. _loadUserInterface: function(){
  23. this._loadNode();
  24. if (this.json.compute === "show"){
  25. this._setValue(this._computeValue());
  26. }else{
  27. this._loadValue();
  28. }
  29. },
  30. _loadNode: function(){
  31. if (this.readonly || this.json.isReadonly){
  32. this._loadNodeRead();
  33. }else{
  34. this._loadNodeEdit();
  35. }
  36. },
  37. loadDescription: function(){
  38. if (this.readonly || this.json.isReadonly)return;
  39. var v = this._getBusinessData();
  40. if (!v){
  41. if (this.json.description){
  42. var size = this.node.getFirst().getSize();
  43. var w = size.x-3;
  44. if( this.json.showIcon!='no' && !this.form.json.hideModuleIcon ){
  45. if (COMMON.Browser.safari) w = w-20;
  46. }
  47. this.descriptionNode = new Element("div", {"styles": this.form.css.descriptionNode, "text": this.json.description}).inject(this.node);
  48. this.descriptionNode.setStyles({
  49. "width": ""+w+"px",
  50. "height": ""+size.y+"px",
  51. "line-height": ""+size.y+"px"
  52. });
  53. this.setDescriptionEvent();
  54. }
  55. }
  56. },
  57. setDescriptionEvent: function(){
  58. if (this.descriptionNode){
  59. if (COMMON.Browser.Platform.name==="ios"){
  60. this.descriptionNode.addEvents({
  61. "click": function(){
  62. this.descriptionNode.setStyle("display", "none");
  63. this.node.getFirst().focus();
  64. this.node.getFirst().fireEvent("click");
  65. }.bind(this)
  66. });
  67. }else if (COMMON.Browser.Platform.name==="android"){
  68. this.descriptionNode.addEvents({
  69. "click": function(){
  70. this.descriptionNode.setStyle("display", "none");
  71. this.node.getFirst().focus();
  72. this.node.getFirst().fireEvent("click");
  73. }.bind(this)
  74. });
  75. }else{
  76. this.descriptionNode.addEvents({
  77. "click": function(){
  78. this.descriptionNode.setStyle("display", "none");
  79. this.node.getFirst().focus();
  80. this.node.getFirst().fireEvent("click");
  81. }.bind(this)
  82. });
  83. }
  84. this.node.getFirst().addEvents({
  85. "focus": function(){
  86. this.descriptionNode.setStyle("display", "none");
  87. }.bind(this),
  88. "blur": function(){
  89. if (!this.node.getFirst().get("value")) this.descriptionNode.setStyle("display", "block");
  90. }.bind(this)
  91. });
  92. }
  93. },
  94. _loadNodeRead: function(){
  95. this.node.empty();
  96. this.node.set({
  97. "nodeId": this.json.id,
  98. "MWFType": this.json.type
  99. });
  100. },
  101. _resetNodeEdit: function(){
  102. var input = new Element("input", {
  103. "styles": {
  104. "background": "transparent",
  105. "width": "100%",
  106. "display": "block",
  107. "border": "0px"
  108. }
  109. });
  110. var node = new Element("div", {"styles": {
  111. "overflow": "hidden",
  112. "position": "relative",
  113. "margin-right": "20px",
  114. "padding-right": "4px"
  115. }}).inject(this.node, "after");
  116. input.inject(node);
  117. this.node.destroy();
  118. this.node = node;
  119. },
  120. _loadNodeEdit: function(){
  121. if (!this.json.preprocessing) this._resetNodeEdit();
  122. var input = this.node.getFirst();
  123. input.set(this.json.properties);
  124. this.node.set({
  125. "id": this.json.id,
  126. "MWFType": this.json.type,
  127. "events": {
  128. "click": this.clickSelect.bind(this)
  129. }
  130. });
  131. if (this.json.showIcon!='no' && !this.form.json.hideModuleIcon){
  132. this.iconNode = new Element("div", {
  133. "styles": this.form.css[this.iconStyle]
  134. }).inject(this.node, "before");
  135. }else if( this.form.json.nodeStyleWithhideModuleIcon ){
  136. this.node.setStyles(this.form.json.nodeStyleWithhideModuleIcon);
  137. }
  138. this.node.getFirst().addEvent("change", function(){
  139. var v = this.getInputData("change");
  140. this._setBusinessData(v);
  141. this.validationMode();
  142. if (this.validation()) this._setBusinessData(v);
  143. }.bind(this));
  144. if (this.json.ANNModel){
  145. this.node.getFirst().addEvent("focus", function(){
  146. o2.Actions.get("x_query_assemble_surface").calculateNeural(this.json.ANNModel, this.form.businessData.work.id, function(json){
  147. var arr = json.data.filter(function(d){
  148. var value = this.node.getFirst().get("value");
  149. return d.score>0.1 && (value.indexOf(d.value)===-1)
  150. }.bind(this));
  151. if (arr.length){
  152. if (!this.modelNode) this.createModelNode();
  153. this.modelNode.getLast().empty();
  154. this.modelNode.show();
  155. this.modelNode.position({ "relativeTo": this.node, "position": "bottomLeft", "edge": 'upperLeft' });
  156. arr.each(function(v){
  157. var node = new Element("div", {"text": v.value, "styles": this.form.css.modelItemNode}).inject(this.modelNode.getLast());
  158. node.addEvents({
  159. "mouseover": function(){this.setStyle("color", "#0000ff");},
  160. "mouseout": function(){this.setStyle("color", "#a31515");},
  161. "mousedown": function(e){
  162. var str = this.node.getFirst().get("value")
  163. this.node.getFirst().set("value", ((str) ? str+", "+e.target.get("text") : e.target.get("text")));
  164. this.modelNode.hide();
  165. }.bind(this)
  166. });
  167. }.bind(this));
  168. }
  169. }.bind(this));
  170. }.bind(this));
  171. this.node.getFirst().addEvent("blur", function(){
  172. if (this.modelNode) this.modelNode.hide();
  173. }.bind(this));
  174. }
  175. this.node.getFirst().addEvent("blur", function(){
  176. this.validation();
  177. }.bind(this));
  178. this.node.getFirst().addEvent("keyup", function(){
  179. this.validationMode();
  180. }.bind(this));
  181. },
  182. createModelNode: function(){
  183. this.modelNode = new Element("div", {"styles": this.form.css.modelNode}).inject(this.node, "after");
  184. new Element("div", {"styles": this.form.css.modelNodeTitle, "text": MWF.xApplication.process.Xform.LP.ANNInput}).inject(this.modelNode);
  185. new Element("div", {"styles": this.form.css.modelNodeContent, "text": MWF.xApplication.process.Xform.LP.ANNInput}).inject(this.modelNode);
  186. },
  187. getInputData: function(){
  188. if (this.node.getFirst()){
  189. var v = this.node.getElement("input").get("value");
  190. if (this.json.dataType=="number"){
  191. var n = v.toFloat();
  192. return (isNaN(n)) ? 0 : n;
  193. }
  194. }else{
  195. return this._getBusinessData();
  196. }
  197. return v;
  198. }
  199. });