$Input.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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. try{
  69. this.setCustomStyles();
  70. }catch(e){}
  71. }
  72. if (name=="inputStyles"){
  73. try{
  74. this.setCustomInputStyles();
  75. }catch(e){}
  76. }
  77. if (name=="properties"){
  78. this.node.setProperties(this.json.properties);
  79. }
  80. },
  81. _loadNodeStyles: function(){
  82. var icon = this.node.getFirst("div");
  83. var text = this.node.getLast("div");
  84. if (!icon) icon = new Element("div").inject(this.node, "top");
  85. if (!text) text = new Element("div").inject(this.node, "bottom");
  86. icon.setStyles(this.css.textfieldIcon);
  87. text.setStyles(this.css.moduleText);
  88. },
  89. _getCopyNode: function(){
  90. if (!this.copyNode) this._createCopyNode();
  91. this.copyNode.setStyle("display", "inline-block");
  92. return this.copyNode;
  93. },
  94. _setEditStyle_custom: function(name){
  95. if (name=="id"){
  96. this.node.getLast().set("text", this.json.id);
  97. }
  98. },
  99. hasIcon: function(){
  100. return this.json.showIcon!='no' && (!this.form.json || !this.form.json.hideModuleIcon);
  101. },
  102. _preprocessingModuleData: function(){
  103. this.node.clearStyles();
  104. this.recoveryIconNode = this.node.getFirst();
  105. this.recoveryIconNode.dispose();
  106. this.recoveryTextNode = this.node.getFirst();
  107. this.recoveryTextNode.dispose();
  108. var inputNode = new Element("input", {
  109. "styles": {
  110. "background": "transparent",
  111. "width": "100%",
  112. "border": "0px"
  113. }
  114. }).inject(this.node);
  115. this.node.setStyles({
  116. "overflow": this.hasIcon() ? "hidden" : "visible",
  117. "position": "relative",
  118. "margin-right": this.hasIcon() ? "20px" : "0px",
  119. "padding-right": "4px"
  120. });
  121. if (this.json.styles){
  122. this.json.recoveryStyles = Object.clone(this.json.styles);
  123. if (this.json.recoveryStyles) Object.each(this.json.recoveryStyles, function(value, key){
  124. if ((value.indexOf("x_processplatform_assemble_surface")==-1 && value.indexOf("x_portal_assemble_surface")==-1)){
  125. this.node.setStyle(key, value);
  126. delete this.json.styles[key];
  127. }
  128. }.bind(this));
  129. }
  130. if (this.json.inputStyles){
  131. this.json.recoveryInputStyles = Object.clone(this.json.inputStyles);
  132. var inputNode = this.node.getFirst();
  133. if (inputNode){
  134. if (this.json.recoveryInputStyles) Object.each(this.json.recoveryInputStyles, function(value, key){
  135. if ((value.indexOf("x_processplatform_assemble_surface")==-1 && value.indexOf("x_portal_assemble_surface")==-1)){
  136. inputNode.setStyle(key, value);
  137. delete this.json.inputStyles[key];
  138. }
  139. }.bind(this));
  140. }
  141. }
  142. this.json.preprocessing = "y";
  143. },
  144. _recoveryModuleData: function(){
  145. if (this.json.recoveryStyles) this.json.styles = this.json.recoveryStyles;
  146. if (this.json.recoveryInputStyles) this.json.inputStyles = this.json.recoveryInputStyles;
  147. if (this.recoveryTextNode) {
  148. this.node.empty();
  149. this.recoveryTextNode.inject(this.node, "top");
  150. }
  151. if (this.recoveryIconNode) {
  152. this.recoveryIconNode.inject(this.node, "top");
  153. }
  154. this.json.recoveryStyles = null;
  155. this.json.recoveryInputStyles = null;
  156. this.recoveryIconNode = null;
  157. this.recoveryTextNode = null;
  158. },
  159. setCustomStyles: function(){
  160. this._recoveryModuleData();
  161. //var border = this.node.getStyle("border");
  162. this.node.clearStyles();
  163. this.node.setStyles(this.css.moduleNode);
  164. if (this.initialStyles) this.node.setStyles(this.initialStyles);
  165. //this.node.setStyle("border", border);
  166. if (this.json.styles) Object.each(this.json.styles, function(value, key){
  167. if ((value.indexOf("x_processplatform_assemble_surface")!=-1 || value.indexOf("x_portal_assemble_surface")!=-1)){
  168. var host1 = MWF.Actions.getHost("x_processplatform_assemble_surface");
  169. var host2 = MWF.Actions.getHost("x_portal_assemble_surface");
  170. if (value.indexOf("/x_processplatform_assemble_surface")!==-1){
  171. value = value.replace("/x_processplatform_assemble_surface", host1+"/x_processplatform_assemble_surface");
  172. }else if (value.indexOf("x_processplatform_assemble_surface")!==-1){
  173. value = value.replace("x_processplatform_assemble_surface", host1+"/x_processplatform_assemble_surface");
  174. }
  175. if (value.indexOf("/x_portal_assemble_surface")!==-1){
  176. value = value.replace("/x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
  177. }else if (value.indexOf("x_portal_assemble_surface")!==-1){
  178. value = value.replace("x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
  179. }
  180. value = o2.filterUrl(value);
  181. }
  182. var reg = /^border\w*/ig;
  183. if (!key.test(reg)){
  184. if (key){
  185. if (key.toString().toLowerCase()==="display"){
  186. if (value.toString().toLowerCase()==="none"){
  187. this.node.setStyle("opacity", 0.3);
  188. }else{
  189. this.node.setStyle("opacity", 1);
  190. this.node.setStyle(key, value);
  191. }
  192. }else{
  193. this.node.setStyle(key, value);
  194. }
  195. }
  196. }
  197. }.bind(this));
  198. },
  199. setCustomInputStyles: function(){
  200. this._recoveryModuleData();
  201. var inputNode = this.node.getLast();
  202. if (inputNode){
  203. inputNode.clearStyles();
  204. inputNode.setStyles(this.css.moduleText);
  205. if (this.json.inputStyles) Object.each(this.json.inputStyles, function(value, key){
  206. if ((value.indexOf("x_processplatform_assemble_surface")!=-1 || value.indexOf("x_portal_assemble_surface")!=-1)){
  207. var host1 = MWF.Actions.getHost("x_processplatform_assemble_surface");
  208. var host2 = MWF.Actions.getHost("x_portal_assemble_surface");
  209. if (value.indexOf("/x_processplatform_assemble_surface")!==-1){
  210. value = value.replace("/x_processplatform_assemble_surface", host1+"/x_processplatform_assemble_surface");
  211. }else if (value.indexOf("x_processplatform_assemble_surface")!==-1){
  212. value = value.replace("x_processplatform_assemble_surface", host1+"/x_processplatform_assemble_surface");
  213. }
  214. if (value.indexOf("/x_portal_assemble_surface")!==-1){
  215. value = value.replace("/x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
  216. }else if (value.indexOf("x_portal_assemble_surface")!==-1){
  217. value = value.replace("x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
  218. }
  219. value = o2.filterUrl(value);
  220. }
  221. var reg = /^border\w*/ig;
  222. if (!key.test(reg)){
  223. if (key){
  224. if (key.toString().toLowerCase()==="display"){
  225. if (value.toString().toLowerCase()==="none"){
  226. inputNode.setStyle("opacity", 0.3);
  227. }else{
  228. inputNode.setStyle("opacity", 1);
  229. inputNode.setStyle(key, value);
  230. }
  231. }else{
  232. inputNode.setStyle(key, value);
  233. }
  234. }
  235. }
  236. }.bind(this));
  237. }
  238. }
  239. });