Textfield.js 7.5 KB

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