Textfield.js 7.8 KB

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