Textfield.js 7.3 KB

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