Common.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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._setEditStyle_custom("innerHTML");
  20. },
  21. _setEditStyle_custom: function(name, obj, oldValue){
  22. if (name==="tagName"){
  23. var tagName = this.json.tagName.toString().toLowerCase();
  24. var nodeTag = this.node.tagName.toString().toLowerCase();
  25. if (tagName !== nodeTag){
  26. var node = new Element(tagName).inject(this.node, "before");
  27. var nodes = this.node.childNodes;
  28. for (var i = 0; i < nodes.length; i++){
  29. node.appendChild(nodes[i]);
  30. }
  31. this.node.destroy();
  32. this.node = node;
  33. this.node.set("mwftype", "common");
  34. this.node.set("id", this.json.id);
  35. this.isSetEvents = false;
  36. this._initModule();
  37. var title = this.json.name || this.json.id;
  38. var text = text = this.json.tagName+"(Common)";
  39. this.treeNode.setText("<"+text+"> "+title);
  40. }
  41. }
  42. if (name==="innerHTML"){
  43. try{
  44. if (this.json.innerHTML){
  45. var nodes = this.node.childNodes;
  46. for (var i=0; i<nodes.length; i++){
  47. if (nodes[i].nodeType===Node.ELEMENT_NODE){
  48. if (!nodes[i].get("MWFtype")){
  49. nodes[i].destroy();
  50. i--;
  51. }
  52. }else{
  53. if (nodes[i].removeNode){
  54. nodes[i].removeNode();
  55. }else{
  56. nodes[i].parentNode.removeChild(nodes[i]);
  57. }
  58. i--;
  59. //nodes[i]
  60. }
  61. }
  62. this.node.appendHTML(this.json.innerHTML);
  63. }
  64. }catch(e){}
  65. }
  66. },
  67. setPropertiesOrStyles: function(name, oldData){
  68. if (name=="styles"){
  69. try{
  70. this.setCustomStyles();
  71. }catch(e){}
  72. }
  73. if (name==="properties"){
  74. try{
  75. if (oldData){
  76. Object.each(oldData, function(v,k){
  77. this.node.removeProperty(k);
  78. }.bind(this));
  79. }
  80. Object.each(this.json.properties, function(v,k){
  81. if (k.toString().toLowerCase()==="href"){
  82. this.node.setProperty(k, "#");
  83. }else if (k.toString().toLowerCase()==="target") {
  84. this.node.removeProperty("target");
  85. }else{
  86. this.node.setProperty(k, v);
  87. }
  88. }.bind(this));
  89. }catch(e){}
  90. }
  91. },
  92. setCustomStyles: function(){
  93. var border = this.node.getStyle("border");
  94. this.node.clearStyles();
  95. var styles = this.node.getStyles("display", "padding");
  96. this.node.setStyles(this.css.moduleNode);
  97. var style = Object.clone(this.json.styles);
  98. //style = Object.merge(style, styles);
  99. if (styles.display.toString().toLowerCase()==="inline"){
  100. if (!style.display) style.display = "inline-block";
  101. if (!style.padding && !style["padding-left"] && !style["padding-right"]) style.padding = "0px 2px";
  102. }
  103. if (this.json.tagName==="button"){
  104. if (!style["min-height"]) style["min-height"] = "20px";
  105. }
  106. if (this.initialStyles) this.node.setStyles(this.initialStyles);
  107. this.node.setStyle("border", border);
  108. if (style) Object.each(style, function(value, key){
  109. if ((value.indexOf("x_processplatform_assemble_surface")!=-1 || value.indexOf("x_portal_assemble_surface")!=-1)){
  110. var host1 = MWF.Actions.getHost("x_processplatform_assemble_surface");
  111. var host2 = MWF.Actions.getHost("x_portal_assemble_surface");
  112. if (value.indexOf("/x_processplatform_assemble_surface")!==-1){
  113. value = value.replace("/x_processplatform_assemble_surface", host1+"/x_processplatform_assemble_surface");
  114. }else if (value.indexOf("x_processplatform_assemble_surface")!==-1){
  115. value = value.replace("x_processplatform_assemble_surface", host1+"/x_processplatform_assemble_surface");
  116. }
  117. if (value.indexOf("/x_portal_assemble_surface")!==-1){
  118. value = value.replace("/x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
  119. }else if (value.indexOf("x_portal_assemble_surface")!==-1){
  120. value = value.replace("x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
  121. }
  122. }
  123. var reg = /^border\w*/ig;
  124. if (!key.test(reg)){
  125. if (key){
  126. if (key.toString().toLowerCase()==="display"){
  127. if (value.toString().toLowerCase()==="none"){
  128. this.node.setStyle("opacity", 0.3);
  129. }else{
  130. this.node.setStyle("opacity", 1);
  131. this.node.setStyle(key, value);
  132. }
  133. }else{
  134. this.node.setStyle(key, value);
  135. }
  136. }
  137. }
  138. }.bind(this));
  139. }
  140. });