Preview.js 4.7 KB

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