Iframe.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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.Iframe = MWF.FCIframe = new Class({
  4. Extends: MWF.FC$Element,
  5. Implements: [Options, Events],
  6. options: {
  7. "style": "default",
  8. "propertyPath": "../x_component_process_FormDesigner/Module/Iframe/iframe.html"
  9. },
  10. initialize: function(form, options){
  11. this.setOptions(options);
  12. this.path = "../x_component_process_FormDesigner/Module/Iframe/";
  13. this.cssPath = "../x_component_process_FormDesigner/Module/Iframe/"+this.options.style+"/css.wcss";
  14. this._loadCss();
  15. this.moduleType = "element";
  16. this.moduleName = "iframe";
  17. this.form = form;
  18. this.container = null;
  19. this.containerNode = null;
  20. },
  21. load : function(json, node, parent){
  22. this.json = json;
  23. this.node= node;
  24. this.node.store("module", this);
  25. var iframe = this.node.getElement("iframe");
  26. if (iframe) iframe.destroy();
  27. this.node.setStyles(this.css.moduleNode);
  28. this._loadNodeStyles();
  29. this._initModule();
  30. this._loadTreeNode(parent);
  31. this.setCustomStyles();
  32. this.parentContainer = this.treeNode.parentNode.module;
  33. this._setEditStyle_custom("id");
  34. this.parseModules();
  35. this.json.moduleName = this.moduleName;
  36. },
  37. _resetModuleDomNode: function(){
  38. // if (this.json.preprocessing){
  39. // var node = new Element("div", {
  40. // "MWFType": "iframe",
  41. // "id": this.json.id,
  42. // "styles": this.css.moduleNodeMove,
  43. // "events": {
  44. // "selectstart": function(){
  45. // return false;
  46. // }
  47. // }
  48. // }).inject(this.node, "after");
  49. // this.node.destroy();
  50. // this._createNode(node);
  51. //}
  52. },
  53. _preprocessingModuleData: function(){
  54. // var iframe = new Element("iframe", {
  55. // "src": src
  56. // }).inject(this.node, "after");
  57. // iframe.setStyles({
  58. // "width": "100%",
  59. // "border": "0"
  60. // });
  61. // this.recoveryNode = this.node.dispose();
  62. //
  63. // if (this.json.styles){
  64. // this.json.recoveryStyles = Object.clone(this.json.styles);
  65. // if (this.json.recoveryStyles) Object.each(this.json.recoveryStyles, function(value, key){
  66. // if ((value.indexOf("x_processplatform_assemble_surface")==-1 && value.indexOf("x_portal_assemble_surface")==-1)){
  67. // iframe.setStyle(key, value);
  68. // delete this.json.styles[key];
  69. // }
  70. // }.bind(this));
  71. // }
  72. // this.json.preprocessing = "y";
  73. },
  74. _recoveryModuleData: function(){
  75. // if (this.json.recoveryStyles) this.json.styles = this.json.recoveryStyles;
  76. //
  77. // if (this.recoveryNode) {
  78. // this.node.empty();
  79. // this.recoveryTextNode.inject(this.node, "top");
  80. // }
  81. // if (this.recoveryIconNode) {
  82. // this.recoveryIconNode.inject(this.node, "top");
  83. // }
  84. // this.json.recoveryStyles = null;
  85. // this.recoveryNode = null;
  86. },
  87. _createMoveNode: function(){
  88. this.moveNode = new Element("div", {
  89. "MWFType": "iframe",
  90. "id": this.json.id,
  91. "styles": this.css.moduleNodeMove,
  92. "events": {
  93. "selectstart": function(){
  94. return false;
  95. }
  96. }
  97. }).inject(this.form.container);
  98. },
  99. _createNode: function(node){
  100. this.node = node || this.moveNode.clone(true, true);
  101. this.node.setStyles(this.css.moduleNode);
  102. this.node.set("id", this.json.id);
  103. this.node.addEvent("selectstart", function(){
  104. return false;
  105. });
  106. this.iconNode = new Element("div", {
  107. "styles": this.css.iconNode
  108. }).inject(this.node);
  109. new Element("div", {
  110. "styles": this.css.iconNodeIcon
  111. }).inject(this.iconNode);
  112. new Element("div", {
  113. "styles": this.css.iconNodeText,
  114. "text": "iframe"
  115. }).inject(this.iconNode);
  116. this.iconNode.addEvent("click", function(){
  117. this.loadIframe();
  118. }.bind(this));
  119. },
  120. _loadNodeStyles: function(){
  121. this.iconNode = this.node.getElement("div");
  122. if (!this.iconNode) this.iconNode = new Element("div").inject(this.node, "top");
  123. this.iconNode.setStyles(this.css.iconNode);
  124. var icon = this.iconNode.getFirst("div");
  125. var text = this.iconNode.getLast("div");
  126. icon.setStyles(this.css.iconNodeIcon);
  127. text.setStyles(this.css.iconNodeText);
  128. this.iconNode.addEvent("click", function(){
  129. this.loadIframe();
  130. }.bind(this));
  131. },
  132. getIconPosition: function(){
  133. var p = this.node.getPosition(this.node.getOffsetParent());
  134. var size = this.node.getSize();
  135. var iconSize = this.iconNode.getSize();
  136. return {"x": p.x+size.x-iconSize.x-1, "y": p.y+1};
  137. },
  138. loadIframe: function(){
  139. if (this.iframe){
  140. this.closeSrc();
  141. }else{
  142. this.loadSrc();
  143. }
  144. },
  145. closeSrc: function(){
  146. this.iframe.destroy();
  147. this.iframe = null;
  148. this.iconNode.setStyles(this.css.iconNode);
  149. this.iconNode.getFirst().setStyles(this.css.iconNodeIcon);
  150. },
  151. loadSrc: function(){
  152. if (this.json.valueType!="script"){
  153. if (this.json.src){
  154. var p = this.getIconPosition();
  155. this.iconNode.setStyles({
  156. "float": "right",
  157. "margin-top": "0px",
  158. "position": "absolute",
  159. "top": p.y,
  160. "left": p.x-18
  161. });
  162. this.iconNode.getFirst().setStyles({
  163. "background": "url("+this.path+this.options.style+"/icon/close.png) 5px center no-repeat"
  164. });
  165. this.iframe = new Element("iframe", {
  166. "styles": this.css.iframe,
  167. "border": "0",
  168. "src": this.json.src
  169. });
  170. this.iframe.inject(this.node, "top");
  171. }
  172. }
  173. }
  174. });