$Input.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. MWF.xApplication.process.FormDesigner.Module = MWF.xApplication.process.FormDesigner.Module || {};
  2. MWF.xDesktop.requireApp("process.FormDesigner", "Module.$Element", null, false);
  3. MWF.xApplication.process.FormDesigner.Module.$Input = MWF.FC$Input = new Class({
  4. Extends: MWF.FC$Element,
  5. Implements: [Options, Events],
  6. options: {
  7. "style": "default",
  8. "type": "textfield",
  9. "path": "../x_component_process_FormDesigner/Module/Textfield/",
  10. "propertyPath": "../x_component_process_FormDesigner/Module/Textfield/textfield.html"
  11. },
  12. initialize: function(form, options){
  13. this.setOptions(options);
  14. this.path = this.options.path;
  15. this.cssPath = this.path+this.options.style+"/css.wcss";
  16. this._loadCss();
  17. this.moduleType = "element";
  18. this.moduleName = this.options.type;
  19. this.form = form;
  20. this.container = null;
  21. this.containerNode = null;
  22. },
  23. clearTemplateStyles: function(styles){
  24. if (styles){
  25. if (styles.styles) this.removeStyles(styles.styles, "styles");
  26. if (styles.inputStyles) this.removeStyles(styles.inputStyles, "inputStyles");
  27. if (styles.properties) this.removeStyles(styles.properties, "properties");
  28. }
  29. },
  30. setTemplateStyles: function(styles){
  31. if (styles.styles) this.copyStyles(styles.styles, "styles");
  32. if (styles.inputStyles) this.copyStyles(styles.inputStyles, "inputStyles");
  33. if (styles.properties) this.copyStyles(styles.properties, "properties");
  34. },
  35. _resetModuleDomNode: function(){
  36. if (this.json.preprocessing){
  37. this.node.empty();
  38. var icon = new Element("div", {
  39. "styles": this.css.textfieldIcon
  40. }).inject(this.node);
  41. var text = new Element("div", {
  42. "styles": this.css.moduleText,
  43. "text": this.json.id
  44. }).inject(this.node);
  45. }
  46. },
  47. _createMoveNode: function(){
  48. this.moveNode = new Element("div", {
  49. "MWFType": "textfield",
  50. "id": this.json.id,
  51. "styles": this.css.moduleNodeMove,
  52. "events": {
  53. "selectstart": function(){
  54. return false;
  55. }
  56. }
  57. }).inject(this.form.container);
  58. var icon = new Element("div", {
  59. "styles": this.css.textfieldIcon
  60. }).inject(this.moveNode);
  61. var text = new Element("div", {
  62. "styles": this.css.moduleText,
  63. "text": this.json.id
  64. }).inject(this.moveNode);
  65. },
  66. setPropertiesOrStyles: function(name){
  67. if (name=="styles"){
  68. // if (this.parentContainer){
  69. // if (this.parentContainer.moduleName == "datagrid$Data"){
  70. // //if (!this.json.styles.width) this.json.styles.width = "90%";
  71. // }
  72. // }
  73. try{
  74. this.setCustomStyles();
  75. }catch(e){}
  76. //this.setCustomStyles();
  77. }
  78. if (name=="inputStyles"){
  79. try{
  80. this.setCustomInputStyles();
  81. }catch(e){}
  82. //
  83. // var text = this.node.getLast("div");
  84. // text.clearStyles();
  85. // text.setStyles(this.css.moduleText);
  86. //
  87. // Object.each(this.json.inputStyles, function(value, key){
  88. // var reg = /^border\w*/ig;
  89. // if (!key.test(reg)){
  90. // text.setStyle(key, value);
  91. // }
  92. // }.bind(this));
  93. }
  94. if (name=="properties"){
  95. this.node.setProperties(this.json.properties);
  96. }
  97. },
  98. _loadNodeStyles: function(){
  99. var icon = this.node.getFirst("div");
  100. var text = this.node.getLast("div");
  101. if (!icon) icon = new Element("div").inject(this.node, "top");
  102. if (!text) text = new Element("div").inject(this.node, "bottom");
  103. icon.setStyles(this.css.textfieldIcon);
  104. text.setStyles(this.css.moduleText);
  105. },
  106. _getCopyNode: function(){
  107. if (!this.copyNode) this._createCopyNode();
  108. this.copyNode.setStyle("display", "inline-block");
  109. return this.copyNode;
  110. },
  111. _setEditStyle_custom: function(name){
  112. if (name=="id"){
  113. this.node.getLast().set("text", this.json.id);
  114. }
  115. },
  116. _preprocessingModuleData: function(){
  117. this.node.clearStyles();
  118. this.recoveryIconNode = this.node.getFirst();
  119. this.recoveryIconNode.dispose();
  120. this.recoveryTextNode = this.node.getFirst();
  121. this.recoveryTextNode.dispose();
  122. var inputNode = new Element("input", {
  123. "styles": {
  124. "background": "transparent",
  125. "width": "100%",
  126. "border": "0px"
  127. }
  128. }).inject(this.node);
  129. this.node.setStyles({
  130. "overflow": "hidden",
  131. "position": "relative",
  132. "margin-right": "20px",
  133. "padding-right": "4px"
  134. })
  135. if (this.json.styles){
  136. this.json.recoveryStyles = Object.clone(this.json.styles);
  137. if (this.json.recoveryStyles) Object.each(this.json.recoveryStyles, function(value, key){
  138. if ((value.indexOf("x_processplatform_assemble_surface")==-1 && value.indexOf("x_portal_assemble_surface")==-1)){
  139. this.node.setStyle(key, value);
  140. delete this.json.styles[key];
  141. }
  142. }.bind(this));
  143. }
  144. if (this.json.inputStyles){
  145. this.json.recoveryInputStyles = Object.clone(this.json.inputStyles);
  146. var inputNode = this.node.getFirst();
  147. if (inputNode){
  148. if (this.json.recoveryInputStyles) Object.each(this.json.recoveryInputStyles, function(value, key){
  149. if ((value.indexOf("x_processplatform_assemble_surface")==-1 && value.indexOf("x_portal_assemble_surface")==-1)){
  150. inputNode.setStyle(key, value);
  151. delete this.json.inputStyles[key];
  152. }
  153. }.bind(this));
  154. }
  155. }
  156. this.json.preprocessing = "y";
  157. },
  158. _recoveryModuleData: function(){
  159. if (this.json.recoveryStyles) this.json.styles = this.json.recoveryStyles;
  160. if (this.json.recoveryInputStyles) this.json.inputStyles = this.json.recoveryInputStyles;
  161. if (this.recoveryTextNode) {
  162. this.node.empty();
  163. this.recoveryTextNode.inject(this.node, "top");
  164. }
  165. if (this.recoveryIconNode) {
  166. this.recoveryIconNode.inject(this.node, "top");
  167. }
  168. this.json.recoveryStyles = null;
  169. this.json.recoveryInputStyles = null;
  170. this.recoveryIconNode = null;
  171. this.recoveryTextNode = null;
  172. },
  173. setCustomStyles: function(){
  174. this._recoveryModuleData();
  175. //debugger;
  176. var border = this.node.getStyle("border");
  177. this.node.clearStyles();
  178. this.node.setStyles(this.css.moduleNode);
  179. if (this.initialStyles) this.node.setStyles(this.initialStyles);
  180. this.node.setStyle("border", border);
  181. if (this.json.styles) Object.each(this.json.styles, function(value, key){
  182. if ((value.indexOf("x_processplatform_assemble_surface")!=-1 || value.indexOf("x_portal_assemble_surface")!=-1)){
  183. var host1 = MWF.Actions.getHost("x_processplatform_assemble_surface");
  184. var host2 = MWF.Actions.getHost("x_portal_assemble_surface");
  185. if (value.indexOf("/x_processplatform_assemble_surface")!==-1){
  186. value = value.replace("/x_processplatform_assemble_surface", host1+"/x_processplatform_assemble_surface");
  187. }else if (value.indexOf("x_processplatform_assemble_surface")!==-1){
  188. value = value.replace("x_processplatform_assemble_surface", host1+"/x_processplatform_assemble_surface");
  189. }
  190. if (value.indexOf("/x_portal_assemble_surface")!==-1){
  191. value = value.replace("/x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
  192. }else if (value.indexOf("x_portal_assemble_surface")!==-1){
  193. value = value.replace("x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
  194. }
  195. }
  196. var reg = /^border\w*/ig;
  197. if (!key.test(reg)){
  198. if (key){
  199. if (key.toString().toLowerCase()==="display"){
  200. if (value.toString().toLowerCase()==="none"){
  201. this.node.setStyle("opacity", 0.3);
  202. }else{
  203. this.node.setStyle("opacity", 1);
  204. this.node.setStyle(key, value);
  205. }
  206. }else{
  207. this.node.setStyle(key, value);
  208. }
  209. }
  210. }
  211. }.bind(this));
  212. },
  213. setCustomInputStyles: function(){
  214. this._recoveryModuleData();
  215. var inputNode = this.node.getLast();
  216. if (inputNode){
  217. inputNode.clearStyles();
  218. inputNode.setStyles(this.css.moduleText);
  219. if (this.json.inputStyles) Object.each(this.json.inputStyles, function(value, key){
  220. if ((value.indexOf("x_processplatform_assemble_surface")!=-1 || value.indexOf("x_portal_assemble_surface")!=-1)){
  221. var host1 = MWF.Actions.getHost("x_processplatform_assemble_surface");
  222. var host2 = MWF.Actions.getHost("x_portal_assemble_surface");
  223. if (value.indexOf("/x_processplatform_assemble_surface")!==-1){
  224. value = value.replace("/x_processplatform_assemble_surface", host1+"/x_processplatform_assemble_surface");
  225. }else if (value.indexOf("x_processplatform_assemble_surface")!==-1){
  226. value = value.replace("x_processplatform_assemble_surface", host1+"/x_processplatform_assemble_surface");
  227. }
  228. if (value.indexOf("/x_portal_assemble_surface")!==-1){
  229. value = value.replace("/x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
  230. }else if (value.indexOf("x_portal_assemble_surface")!==-1){
  231. value = value.replace("x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
  232. }
  233. }
  234. var reg = /^border\w*/ig;
  235. if (!key.test(reg)){
  236. if (key){
  237. if (key.toString().toLowerCase()==="display"){
  238. if (value.toString().toLowerCase()==="none"){
  239. inputNode.setStyle("opacity", 0.3);
  240. }else{
  241. inputNode.setStyle("opacity", 1);
  242. inputNode.setStyle(key, value);
  243. }
  244. }else{
  245. inputNode.setStyle(key, value);
  246. }
  247. }
  248. }
  249. }.bind(this));
  250. }
  251. }
  252. });