Textfield.js 6.7 KB

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