Textfield.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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. },
  81. _resetNodeEdit: function(){
  82. var input = new Element("input", {
  83. "styles": {
  84. "background": "transparent",
  85. "width": "100%",
  86. "display": "block",
  87. "border": "0px"
  88. }
  89. });
  90. var node = new Element("div", {"styles": {
  91. "overflow": "hidden",
  92. "position": "relative",
  93. "margin-right": "20px",
  94. "padding-right": "4px"
  95. }}).inject(this.node, "after");
  96. input.inject(node);
  97. this.node.destroy();
  98. this.node = node;
  99. },
  100. _loadNodeEdit: function(){
  101. if (!this.json.preprocessing) this._resetNodeEdit();
  102. var input = this.node.getFirst();
  103. input.set(this.json.properties);
  104. this.node.set({
  105. "id": this.json.id,
  106. "MWFType": this.json.type,
  107. "events": {
  108. "click": this.clickSelect.bind(this)
  109. }
  110. });
  111. if (this.json.showIcon!='no' && !this.form.json.hideModuleIcon){
  112. this.iconNode = new Element("div", {
  113. "styles": this.form.css[this.iconStyle]
  114. }).inject(this.node, "before");
  115. }else if( this.form.json.nodeStyleWithhideModuleIcon ){
  116. this.node.setStyles(this.form.json.nodeStyleWithhideModuleIcon);
  117. }
  118. this.node.getFirst().addEvent("change", function(){
  119. var v = this.getInputData("change");
  120. this._setBusinessData(v);
  121. this.validationMode();
  122. if (this.validation()) this._setBusinessData(v);
  123. }.bind(this));
  124. if (this.json.ANNModel){
  125. this.node.getFirst().addEvent("focus", function(){
  126. o2.Actions.get("x_query_assemble_surface").calculateNeural(this.json.ANNModel, this.form.businessData.work.id, function(json){
  127. var arr = json.data.filter(function(d){
  128. var value = this.node.getFirst().get("value");
  129. return d.score>0.1 && (value.indexOf(d.value)===-1)
  130. }.bind(this));
  131. if (arr.length){
  132. if (!this.modelNode) this.createModelNode();
  133. this.modelNode.getLast().empty();
  134. this.modelNode.show();
  135. this.modelNode.position({ "relativeTo": this.node, "position": "bottomLeft", "edge": 'upperLeft' });
  136. arr.each(function(v){
  137. var node = new Element("div", {"text": v.value, "styles": this.form.css.modelItemNode}).inject(this.modelNode.getLast());
  138. node.addEvents({
  139. "mouseover": function(){this.setStyle("color", "#0000ff");},
  140. "mouseout": function(){this.setStyle("color", "#a31515");},
  141. "mousedown": function(e){
  142. var str = this.node.getFirst().get("value")
  143. this.node.getFirst().set("value", ((str) ? str+", "+e.target.get("text") : e.target.get("text")));
  144. this.modelNode.hide();
  145. }.bind(this)
  146. });
  147. }.bind(this));
  148. }
  149. }.bind(this));
  150. }.bind(this));
  151. this.node.getFirst().addEvent("blur", function(){
  152. if (this.modelNode) this.modelNode.hide();
  153. }.bind(this));
  154. }
  155. this.node.getFirst().addEvent("blur", function(){
  156. this.validation();
  157. }.bind(this));
  158. this.node.getFirst().addEvent("keyup", function(){
  159. this.validationMode();
  160. }.bind(this));
  161. },
  162. createModelNode: function(){
  163. this.modelNode = new Element("div", {"styles": this.form.css.modelNode}).inject(this.node, "after");
  164. new Element("div", {"styles": this.form.css.modelNodeTitle, "text": MWF.xApplication.process.Xform.LP.ANNInput}).inject(this.modelNode);
  165. new Element("div", {"styles": this.form.css.modelNodeContent, "text": MWF.xApplication.process.Xform.LP.ANNInput}).inject(this.modelNode);
  166. },
  167. getInputData: function(){
  168. if (this.node.getFirst()){
  169. var v = this.node.getElement("input").get("value");
  170. if (this.json.dataType=="number"){
  171. var n = v.toFloat();
  172. return (isNaN(n)) ? 0 : n;
  173. }
  174. }else{
  175. return this._getBusinessData();
  176. }
  177. return v;
  178. }
  179. });