Preview.js 4.8 KB

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