$Input.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  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. hasIcon: function(){
  117. return this.json.showIcon!='no' && (!this.form.json || !this.form.json.hideModuleIcon);
  118. },
  119. _preprocessingModuleData: function(){
  120. this.node.clearStyles();
  121. this.recoveryIconNode = this.node.getFirst();
  122. this.recoveryIconNode.dispose();
  123. this.recoveryTextNode = this.node.getFirst();
  124. this.recoveryTextNode.dispose();
  125. var inputNode = new Element("input", {
  126. "styles": {
  127. "background": "transparent",
  128. "width": "100%",
  129. "border": "0px"
  130. }
  131. }).inject(this.node);
  132. this.node.setStyles({
  133. "overflow": this.hasIcon() ? "hidden" : "visible",
  134. "position": "relative",
  135. "margin-right": this.hasIcon() ? "20px" : "0px",
  136. "padding-right": "4px"
  137. });
  138. if (this.json.styles){
  139. this.json.recoveryStyles = Object.clone(this.json.styles);
  140. if (this.json.recoveryStyles) Object.each(this.json.recoveryStyles, function(value, key){
  141. if ((value.indexOf("x_processplatform_assemble_surface")==-1 && value.indexOf("x_portal_assemble_surface")==-1)){
  142. this.node.setStyle(key, value);
  143. delete this.json.styles[key];
  144. }
  145. }.bind(this));
  146. }
  147. if (this.json.inputStyles){
  148. this.json.recoveryInputStyles = Object.clone(this.json.inputStyles);
  149. var inputNode = this.node.getFirst();
  150. if (inputNode){
  151. if (this.json.recoveryInputStyles) Object.each(this.json.recoveryInputStyles, function(value, key){
  152. if ((value.indexOf("x_processplatform_assemble_surface")==-1 && value.indexOf("x_portal_assemble_surface")==-1)){
  153. inputNode.setStyle(key, value);
  154. delete this.json.inputStyles[key];
  155. }
  156. }.bind(this));
  157. }
  158. }
  159. this.json.preprocessing = "y";
  160. },
  161. _recoveryModuleData: function(){
  162. if (this.json.recoveryStyles) this.json.styles = this.json.recoveryStyles;
  163. if (this.json.recoveryInputStyles) this.json.inputStyles = this.json.recoveryInputStyles;
  164. if (this.recoveryTextNode) {
  165. this.node.empty();
  166. this.recoveryTextNode.inject(this.node, "top");
  167. }
  168. if (this.recoveryIconNode) {
  169. this.recoveryIconNode.inject(this.node, "top");
  170. }
  171. this.json.recoveryStyles = null;
  172. this.json.recoveryInputStyles = null;
  173. this.recoveryIconNode = null;
  174. this.recoveryTextNode = null;
  175. },
  176. setCustomStyles: function(){
  177. this._recoveryModuleData();
  178. //debugger;
  179. //var border = this.node.getStyle("border");
  180. this.node.clearStyles();
  181. this.node.setStyles(this.css.moduleNode);
  182. if (this.initialStyles) this.node.setStyles(this.initialStyles);
  183. //this.node.setStyle("border", border);
  184. if (this.json.styles) Object.each(this.json.styles, function(value, key){
  185. if ((value.indexOf("x_processplatform_assemble_surface")!=-1 || value.indexOf("x_portal_assemble_surface")!=-1)){
  186. var host1 = MWF.Actions.getHost("x_processplatform_assemble_surface");
  187. var host2 = MWF.Actions.getHost("x_portal_assemble_surface");
  188. if (value.indexOf("/x_processplatform_assemble_surface")!==-1){
  189. value = value.replace("/x_processplatform_assemble_surface", host1+"/x_processplatform_assemble_surface");
  190. }else if (value.indexOf("x_processplatform_assemble_surface")!==-1){
  191. value = value.replace("x_processplatform_assemble_surface", host1+"/x_processplatform_assemble_surface");
  192. }
  193. if (value.indexOf("/x_portal_assemble_surface")!==-1){
  194. value = value.replace("/x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
  195. }else if (value.indexOf("x_portal_assemble_surface")!==-1){
  196. value = value.replace("x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
  197. }
  198. value = o2.filterUrl(value);
  199. }
  200. var reg = /^border\w*/ig;
  201. if (!key.test(reg)){
  202. if (key){
  203. if (key.toString().toLowerCase()==="display"){
  204. if (value.toString().toLowerCase()==="none"){
  205. this.node.setStyle("opacity", 0.3);
  206. }else{
  207. this.node.setStyle("opacity", 1);
  208. this.node.setStyle(key, value);
  209. }
  210. }else{
  211. this.node.setStyle(key, value);
  212. }
  213. }
  214. }
  215. }.bind(this));
  216. },
  217. setCustomInputStyles: function(){
  218. this._recoveryModuleData();
  219. var inputNode = this.node.getLast();
  220. if (inputNode){
  221. inputNode.clearStyles();
  222. inputNode.setStyles(this.css.moduleText);
  223. if (this.json.inputStyles) Object.each(this.json.inputStyles, function(value, key){
  224. if ((value.indexOf("x_processplatform_assemble_surface")!=-1 || value.indexOf("x_portal_assemble_surface")!=-1)){
  225. var host1 = MWF.Actions.getHost("x_processplatform_assemble_surface");
  226. var host2 = MWF.Actions.getHost("x_portal_assemble_surface");
  227. if (value.indexOf("/x_processplatform_assemble_surface")!==-1){
  228. value = value.replace("/x_processplatform_assemble_surface", host1+"/x_processplatform_assemble_surface");
  229. }else if (value.indexOf("x_processplatform_assemble_surface")!==-1){
  230. value = value.replace("x_processplatform_assemble_surface", host1+"/x_processplatform_assemble_surface");
  231. }
  232. if (value.indexOf("/x_portal_assemble_surface")!==-1){
  233. value = value.replace("/x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
  234. }else if (value.indexOf("x_portal_assemble_surface")!==-1){
  235. value = value.replace("x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
  236. }
  237. value = o2.filterUrl(value);
  238. }
  239. var reg = /^border\w*/ig;
  240. if (!key.test(reg)){
  241. if (key){
  242. if (key.toString().toLowerCase()==="display"){
  243. if (value.toString().toLowerCase()==="none"){
  244. inputNode.setStyle("opacity", 0.3);
  245. }else{
  246. inputNode.setStyle("opacity", 1);
  247. inputNode.setStyle(key, value);
  248. }
  249. }else{
  250. inputNode.setStyle(key, value);
  251. }
  252. }
  253. }
  254. }.bind(this));
  255. }
  256. }
  257. });