Textfield.js 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. MWF.xDesktop.requireApp("process.Xform", "$Input", null, false);
  2. MWF.xApplication.process.Xform.Textfield = MWF.APPTextfield = new Class({
  3. Implements: [Events],
  4. Extends: MWF.APP$Input,
  5. iconStyle: "textFieldIcon",
  6. _loadUserInterface: function(){
  7. this._loadNode();
  8. if (this.json.compute === "show"){
  9. this._setValue(this._computeValue());
  10. }else{
  11. this._loadValue();
  12. }
  13. },
  14. _loadNode: function(){
  15. if (this.readonly || this.json.isReadonly){
  16. this._loadNodeRead();
  17. }else{
  18. this._loadNodeEdit();
  19. }
  20. },
  21. loadDescription: function(){
  22. if (this.readonly || this.json.isReadonly)return;
  23. var v = this._getBusinessData();
  24. if (!v){
  25. if (this.json.description){
  26. var size = this.node.getFirst().getSize();
  27. var w = size.x-3;
  28. if( this.json.showIcon!='no' && !this.form.json.hideModuleIcon ){
  29. if (COMMON.Browser.safari) w = w-20;
  30. }
  31. this.descriptionNode = new Element("div", {"styles": this.form.css.descriptionNode, "text": this.json.description}).inject(this.node);
  32. this.descriptionNode.setStyles({
  33. "width": ""+w+"px",
  34. "height": ""+size.y+"px",
  35. "line-height": ""+size.y+"px"
  36. });
  37. this.setDescriptionEvent();
  38. }
  39. }
  40. },
  41. setDescriptionEvent: function(){
  42. if (this.descriptionNode){
  43. if (COMMON.Browser.Platform.name==="ios"){
  44. this.descriptionNode.addEvents({
  45. "click": function(){
  46. this.descriptionNode.setStyle("display", "none");
  47. this.node.getFirst().focus();
  48. this.node.getFirst().fireEvent("click");
  49. }.bind(this)
  50. });
  51. }else if (COMMON.Browser.Platform.name==="android"){
  52. this.descriptionNode.addEvents({
  53. "click": function(){
  54. this.descriptionNode.setStyle("display", "none");
  55. this.node.getFirst().focus();
  56. this.node.getFirst().fireEvent("click");
  57. }.bind(this)
  58. });
  59. }else{
  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. }
  68. this.node.getFirst().addEvents({
  69. "focus": function(){
  70. this.descriptionNode.setStyle("display", "none");
  71. }.bind(this),
  72. "blur": function(){
  73. if (!this.node.getFirst().get("value")) this.descriptionNode.setStyle("display", "block");
  74. }.bind(this)
  75. });
  76. }
  77. },
  78. _loadNodeRead: function(){
  79. this.node.empty();
  80. this.node.set({
  81. "nodeId": this.json.id,
  82. "MWFType": this.json.type
  83. });
  84. },
  85. _resetNodeEdit: function(){
  86. var input = new Element("input", {
  87. "styles": {
  88. "background": "transparent",
  89. "width": "100%",
  90. "display": "block",
  91. "border": "0px"
  92. }
  93. });
  94. var node = new Element("div", {"styles": {
  95. "overflow": "hidden",
  96. "position": "relative",
  97. "margin-right": "20px",
  98. "padding-right": "4px"
  99. }}).inject(this.node, "after");
  100. input.inject(node);
  101. this.node.destroy();
  102. this.node = node;
  103. },
  104. _loadNodeEdit: function(){
  105. if (!this.json.preprocessing) this._resetNodeEdit();
  106. var input = this.node.getFirst();
  107. input.set(this.json.properties);
  108. this.node.set({
  109. "id": this.json.id,
  110. "MWFType": this.json.type,
  111. "events": {
  112. "click": this.clickSelect.bind(this)
  113. }
  114. });
  115. if (this.json.showIcon!='no' && !this.form.json.hideModuleIcon){
  116. this.iconNode = new Element("div", {
  117. "styles": this.form.css[this.iconStyle]
  118. }).inject(this.node, "before");
  119. }else if( this.form.json.nodeStyleWithhideModuleIcon ){
  120. this.node.setStyles(this.form.json.nodeStyleWithhideModuleIcon);
  121. }
  122. this.node.getFirst().addEvent("change", function(){
  123. var v = this.getInputData("change");
  124. this._setBusinessData(v);
  125. this.validationMode();
  126. if (this.validation()) this._setBusinessData(v);
  127. }.bind(this));
  128. if (this.json.ANNModel){
  129. this.node.getFirst().addEvent("focus", function(){
  130. o2.Actions.get("x_query_assemble_surface").calculateNeural(this.json.ANNModel, this.form.businessData.work.id, function(json){
  131. var arr = json.data.filter(function(d){
  132. var value = this.node.getFirst().get("value");
  133. return d.score>0.1 && (value.indexOf(d.value)===-1)
  134. }.bind(this));
  135. if (arr.length){
  136. if (!this.modelNode) this.createModelNode();
  137. this.modelNode.getLast().empty();
  138. this.modelNode.show();
  139. this.modelNode.position({ "relativeTo": this.node, "position": "bottomLeft", "edge": 'upperLeft' });
  140. arr.each(function(v){
  141. var node = new Element("div", {"text": v.value, "styles": this.form.css.modelItemNode}).inject(this.modelNode.getLast());
  142. node.addEvents({
  143. "mouseover": function(){this.setStyle("color", "#0000ff");},
  144. "mouseout": function(){this.setStyle("color", "#a31515");},
  145. "mousedown": function(e){
  146. var str = this.node.getFirst().get("value")
  147. this.node.getFirst().set("value", ((str) ? str+", "+e.target.get("text") : e.target.get("text")));
  148. this.modelNode.hide();
  149. }.bind(this)
  150. });
  151. }.bind(this));
  152. }
  153. }.bind(this));
  154. }.bind(this));
  155. this.node.getFirst().addEvent("blur", function(){
  156. if (this.modelNode) this.modelNode.hide();
  157. }.bind(this));
  158. }
  159. this.node.getFirst().addEvent("blur", function(){
  160. this.validation();
  161. }.bind(this));
  162. this.node.getFirst().addEvent("keyup", function(){
  163. this.validationMode();
  164. }.bind(this));
  165. },
  166. createModelNode: function(){
  167. this.modelNode = new Element("div", {"styles": this.form.css.modelNode}).inject(this.node, "after");
  168. new Element("div", {"styles": this.form.css.modelNodeTitle, "text": MWF.xApplication.process.Xform.LP.ANNInput}).inject(this.modelNode);
  169. new Element("div", {"styles": this.form.css.modelNodeContent, "text": MWF.xApplication.process.Xform.LP.ANNInput}).inject(this.modelNode);
  170. },
  171. getInputData: function(){
  172. if (this.node.getFirst()){
  173. var v = this.node.getElement("input").get("value");
  174. if (this.json.dataType=="number"){
  175. var n = v.toFloat();
  176. return (isNaN(n)) ? 0 : n;
  177. }
  178. }else{
  179. return this._getBusinessData();
  180. }
  181. return v;
  182. }
  183. });