Preview.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. MWF.xDesktop.requireApp("process.FormDesigner", "Preview", null, false);
  2. MWF.xApplication.cms.FormDesigner.Preview = MWF.CMSFCPreview = new Class({
  3. Extends: MWF.FCPreview,
  4. Implements: [Options, Events],
  5. options: {
  6. "style": "default",
  7. "previewPath": "/x_desktop/cmspreview.html",
  8. "size": null
  9. },
  10. initialize: function(form, options){
  11. this.setOptions(options);
  12. var href = window.location.href;
  13. if (href.indexOf("debugger")!=-1) this.options.previewPath = "/x_desktop/preview.html?debugger";
  14. this.path = "/x_component_process_FormDesigner/$Preview/";
  15. this.cssPath = "/x_component_process_FormDesigner/$Preview/"+this.options.style+"/css.wcss";
  16. this._loadCss();
  17. this.form = form;
  18. this.data = form._getFormData();
  19. },
  20. load: function(){
  21. var p = this.getPanelPostion();
  22. this.createPreviewNodes();
  23. this.createPanel(p);
  24. this.setEvent();
  25. this.loadForm();
  26. this.addActions();
  27. },
  28. getPanelPostion: function(){
  29. var size = this.form.designer.node.getSize();
  30. var x = size.x*0.7;
  31. var y = size.y*0.8;
  32. if (this.options.size){
  33. x = this.options.size.x;
  34. y = this.options.size.y;
  35. }
  36. var top = ((size.y-y)/2)*0.8;
  37. var left = (size.x-x)/2;
  38. return {"x": x, "y": y, "top": top, "left": left};
  39. },
  40. createPreviewNodes: function(){
  41. this.node = new Element("div", {"styles": this.css.contentNode});
  42. this.topActionAreaNode = new Element("div", {"styles": this.css.topActionAreaNode}).inject(this.node);
  43. this.formFrameNode = new Element("iframe", {"styles": this.css.formFrameNode}).inject(this.node);
  44. this.formJsonNode = new Element("div", {"styles": this.css.formJsonNode}).inject(this.node);
  45. },
  46. addActions: function(){
  47. this.showJsonAction = new Element("div", {
  48. "styles": this.css.actionButton,
  49. "text": "show json"
  50. }).inject(this.topActionAreaNode);
  51. this.showJsonAction.addEvent("click", function(){
  52. this.showJson();
  53. }.bind(this));
  54. this.showFormAction = new Element("div", {
  55. "styles": this.css.actionButton,
  56. "text": "show form"
  57. }).inject(this.topActionAreaNode);
  58. this.showFormAction.setStyle("display", "none");
  59. this.showFormAction.addEvent("click", function(){
  60. this.showForm();
  61. }.bind(this));
  62. },
  63. showForm: function(){
  64. this.formJsonNode.empty();
  65. this.formFrameNode.setStyle("display", "block");
  66. this.formJsonNode.setStyle("display", "none");
  67. this.showJsonAction.setStyle("display", "block");
  68. this.showFormAction.setStyle("display", "none");
  69. },
  70. showJson: function(){
  71. this.showJsonAction.setStyle("display", "none");
  72. this.showFormAction.setStyle("display", "block");
  73. this.formFrameNode.setStyle("display", "none");
  74. this.formJsonNode.setStyle("display", "block");
  75. var layout = this.formFrameNode.contentWindow.layout;
  76. MWF.require("MWF.widget.JsonParse", function(){
  77. this.json = new MWF.widget.JsonParse(layout.appForm.getData(), this.formJsonNode, null);
  78. this.json.load();
  79. }.bind(this));
  80. },
  81. createPanel: function(p){
  82. //alert(p.x);
  83. //alert(p.y);
  84. this.panel = new MWF.widget.Panel(this.node, {
  85. "style": "form",
  86. "title": this.data.json.name,
  87. "width": p.x,
  88. "height": p.y,
  89. "top": p.top,
  90. "left": p.left,
  91. "isExpand": false,
  92. "target": this.form.designer.node
  93. });
  94. this.panel.load();
  95. },
  96. setEvent: function(){
  97. this.setFormFrameSize();
  98. this.panel.addEvent("resize", this.setFormFrameSize.bind(this));
  99. },
  100. setFormFrameSize: function(){
  101. var size = this.panel.content.getSize();
  102. var topSize = this.topActionAreaNode.getSize();
  103. var y = size.y-topSize.y-8;
  104. var x = size.x-8;
  105. this.formFrameNode.setStyle("height", ""+y+"px");
  106. this.formFrameNode.setStyle("width", ""+x+"px");
  107. this.formJsonNode.setStyle("height", ""+y+"px");
  108. this.formJsonNode.setStyle("width", ""+x+"px");
  109. },
  110. loadForm: function(){
  111. this.formFrameNode.store("preview",this);
  112. this.formFrameNode.set("src", this.options.previewPath);
  113. //window.open(this.options.previewPath);
  114. //this.formDocument = this.formFrameNode.contentDocument;
  115. //this.formWindow = this.formFrameNode.contentWindow;
  116. //this.formFrameNode.preview = this;
  117. },
  118. loadFormData: function(node){
  119. MWF.getJSON("/x_desktop/res/preview/cmsdoc.json", function(json){
  120. MWF.xDesktop.requireApp("cms.Xform", "Form", function(){
  121. this.appForm = new MWF.CMSForm(node, this.data);
  122. this.appForm.app = this.form.designer;
  123. this.appForm.load();
  124. }.bind(this));
  125. }.bind(this));
  126. }
  127. });