Textfield.js 7.3 KB

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