Common.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. MWF.xApplication.process.FormDesigner.Module.Common = MWF.FCCommon = new Class({
  2. Extends: MWF.FCDiv,
  3. Implements: [Options, Events],
  4. options: {
  5. "style": "default",
  6. "propertyPath": "../x_component_process_FormDesigner/Module/Common/common.html"
  7. },
  8. initialize: function(form, options){
  9. this.setOptions(options);
  10. this.path = "../x_component_process_FormDesigner/Module/Common/";
  11. this.cssPath = "../x_component_process_FormDesigner/Module/Common/"+this.options.style+"/css.wcss";
  12. this._loadCss();
  13. this.moduleType = "container";
  14. this.moduleName = "common";
  15. this.Node = null;
  16. this.form = form;
  17. },
  18. _setNodeProperty: function(){
  19. this.node.store("module", this);
  20. if (this.form.moduleList.indexOf(this)==-1) this.form.moduleList.push(this);
  21. if (this.form.moduleNodeList.indexOf(this.node)==-1) this.form.moduleNodeList.push(this.node);
  22. if (this.form.moduleContainerNodeList.indexOf(this.node)==-1) this.form.moduleContainerNodeList.push(this.node);
  23. this.node.store("module", this);
  24. this._setEditStyle_custom("innerHTML");
  25. },
  26. _setEditStyle_custom: function(name, obj, oldValue){
  27. if (name==="tagName"){
  28. var tagName = this.json.tagName.toString().toLowerCase();
  29. var nodeTag = this.node.tagName.toString().toLowerCase();
  30. if (tagName !== nodeTag){
  31. var node = new Element(tagName).inject(this.node, "before");
  32. var nodes = this.node.childNodes;
  33. for (var i = 0; i < nodes.length; i++){
  34. node.appendChild(nodes[i]);
  35. }
  36. this.node.destroy();
  37. this.node = node;
  38. this.node.set("mwftype", "common");
  39. this.node.set("id", this.json.id);
  40. this.isSetEvents = false;
  41. this._initModule();
  42. var title = this.json.name || this.json.id;
  43. var text = text = this.json.tagName+"(Common)";
  44. this.treeNode.setText("<"+text+"> "+title);
  45. }
  46. }
  47. if (name==="innerHTML"){
  48. try{
  49. if (this.json.innerHTML){
  50. var nodes = this.node.childNodes;
  51. for (var i=0; i<nodes.length; i++){
  52. if (nodes[i].nodeType===Node.ELEMENT_NODE){
  53. if (!nodes[i].get("MWFtype")){
  54. nodes[i].destroy();
  55. i--;
  56. }
  57. }else{
  58. if (nodes[i].removeNode){
  59. nodes[i].removeNode();
  60. }else{
  61. nodes[i].parentNode.removeChild(nodes[i]);
  62. }
  63. i--;
  64. //nodes[i]
  65. }
  66. }
  67. this.node.appendHTML(this.json.innerHTML);
  68. }
  69. }catch(e){}
  70. }
  71. },
  72. setPropertiesOrStyles: function(name, oldData){
  73. if (name=="styles"){
  74. try{
  75. this.setCustomStyles();
  76. }catch(e){}
  77. }
  78. if (name==="properties"){
  79. try{
  80. if (oldData){
  81. Object.each(oldData, function(v,k){
  82. this.node.removeProperty(k);
  83. }.bind(this));
  84. }
  85. Object.each(this.json.properties, function(v,k){
  86. if (k.toString().toLowerCase()==="href"){
  87. this.node.setProperty(k, "#");
  88. }else if (k.toString().toLowerCase()==="target") {
  89. this.node.removeProperty("target");
  90. }else{
  91. this.node.setProperty(k, v);
  92. }
  93. }.bind(this));
  94. }catch(e){}
  95. }
  96. },
  97. setCustomStyles: function(){
  98. this._recoveryModuleData();
  99. var border = this.node.getStyle("border");
  100. this.node.clearStyles();
  101. var styles = this.node.getStyles("display", "padding");
  102. this.node.setStyles(this.css.moduleNode);
  103. var style = Object.clone(this.json.styles);
  104. //style = Object.merge(style, styles);
  105. if (styles.display.toString().toLowerCase()==="inline"){
  106. if (!style.display) style.display = "inline-block";
  107. if (!style.padding && !style["padding-left"] && !style["padding-right"]) style.padding = "0px 2px";
  108. }
  109. if (this.json.tagName==="button"){
  110. if (!style["min-height"]) style["min-height"] = "20px";
  111. }
  112. if (this.initialStyles) this.node.setStyles(this.initialStyles);
  113. this.node.setStyle("border", border);
  114. if (style) Object.each(style, function(value, key){
  115. if ((value.indexOf("x_processplatform_assemble_surface")!=-1 || value.indexOf("x_portal_assemble_surface")!=-1)){
  116. var host1 = MWF.Actions.getHost("x_processplatform_assemble_surface");
  117. var host2 = MWF.Actions.getHost("x_portal_assemble_surface");
  118. if (value.indexOf("/x_processplatform_assemble_surface")!==-1){
  119. value = value.replace("/x_processplatform_assemble_surface", host1+"/x_processplatform_assemble_surface");
  120. }else if (value.indexOf("x_processplatform_assemble_surface")!==-1){
  121. value = value.replace("x_processplatform_assemble_surface", host1+"/x_processplatform_assemble_surface");
  122. }
  123. if (value.indexOf("/x_portal_assemble_surface")!==-1){
  124. value = value.replace("/x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
  125. }else if (value.indexOf("x_portal_assemble_surface")!==-1){
  126. value = value.replace("x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
  127. }
  128. value = o2.filterUrl(value);
  129. }
  130. var reg = /^border\w*/ig;
  131. if (!key.test(reg)){
  132. if (key){
  133. if (key.toString().toLowerCase()==="display"){
  134. if (value.toString().toLowerCase()==="none"){
  135. this.node.setStyle("opacity", 0.3);
  136. }else{
  137. this.node.setStyle("opacity", 1);
  138. this.node.setStyle(key, value);
  139. }
  140. }else{
  141. this.node.setStyle(key, value);
  142. }
  143. }
  144. }
  145. }.bind(this));
  146. }
  147. });