Preview.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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": "/x_desktop/preview.html",
  9. "size": null,
  10. "mode": "pc"
  11. },
  12. initialize: function(form, options){
  13. this.setOptions(options);
  14. var href = window.location.href;
  15. if (href.indexOf("debugger")!=-1) this.options.previewPath = "/x_desktop/preview.html?debugger";
  16. this.path = "/x_component_process_FormDesigner/$Preview/";
  17. this.cssPath = "/x_component_process_FormDesigner/$Preview/"+this.options.style+"/css.wcss";
  18. this._loadCss();
  19. this.form = form;
  20. this.data = (form._getFormData) ? form._getFormData() : form._getPageData();
  21. //this.data = Object.clone(data);
  22. },
  23. load: function(){
  24. var p = this.getPanelPostion();
  25. this.createPreviewNodes();
  26. this.createPanel(p);
  27. this.setEvent();
  28. this.loadForm();
  29. this.addActions();
  30. },
  31. getPanelPostion: function(){
  32. var size = this.form.designer.node.getSize();
  33. var x = size.x*0.7;
  34. var y = size.y*0.8;
  35. if (this.options.size){
  36. x = this.options.size.x;
  37. y = this.options.size.y;
  38. }
  39. var top = ((size.y-y)/2)*0.8;
  40. var left = (size.x-x)/2;
  41. return {"x": x, "y": y, "top": top, "left": left};
  42. },
  43. createPreviewNodes: function(){
  44. this.node = new Element("div", {"styles": this.css.contentNode});
  45. this.topActionAreaNode = new Element("div", {"styles": this.css.topActionAreaNode}).inject(this.node);
  46. this.formFrameNode = new Element("iframe", {"styles": this.css.formFrameNode}).inject(this.node);
  47. this.formJsonNode = new Element("div", {"styles": this.css.formJsonNode}).inject(this.node);
  48. },
  49. addActions: function(){
  50. this.showJsonAction = new Element("div", {
  51. "styles": this.css.actionButton,
  52. "text": "show json"
  53. }).inject(this.topActionAreaNode);
  54. this.showJsonAction.addEvent("click", function(){
  55. this.showJson();
  56. }.bind(this));
  57. this.showFormAction = new Element("div", {
  58. "styles": this.css.actionButton,
  59. "text": "show form"
  60. }).inject(this.topActionAreaNode);
  61. this.showFormAction.setStyle("display", "none");
  62. this.showFormAction.addEvent("click", function(){
  63. this.showForm();
  64. }.bind(this));
  65. },
  66. showForm: function(){
  67. this.formJsonNode.empty();
  68. this.formFrameNode.setStyle("display", "block");
  69. this.formJsonNode.setStyle("display", "none");
  70. this.showJsonAction.setStyle("display", "block");
  71. this.showFormAction.setStyle("display", "none");
  72. },
  73. showJson: function(){
  74. this.showJsonAction.setStyle("display", "none");
  75. this.showFormAction.setStyle("display", "block");
  76. this.formFrameNode.setStyle("display", "none");
  77. this.formJsonNode.setStyle("display", "block");
  78. var layout = this.formFrameNode.contentWindow.layout;
  79. MWF.require("MWF.widget.JsonParse", function(){
  80. this.json = new MWF.widget.JsonParse(layout.appForm.getData(), this.formJsonNode, null);
  81. this.json.load();
  82. }.bind(this));
  83. },
  84. createPanel: function(p){
  85. //alert(p.x);
  86. //alert(p.y);
  87. this.panel = new MWF.widget.Panel(this.node, {
  88. "style": "form",
  89. "title": this.data.json.name,
  90. "width": p.x,
  91. "height": p.y,
  92. "top": p.top,
  93. "left": p.left,
  94. "isExpand": false,
  95. "target": this.form.designer.node,
  96. "onQueryClose": function(){
  97. this.destroy();
  98. }.bind(this)
  99. });
  100. this.panel.load();
  101. },
  102. destroy: function(){
  103. this.node.empty();
  104. o2.release(this);
  105. },
  106. setEvent: function(){
  107. this.setFormFrameSize();
  108. this.panel.addEvent("resize", this.setFormFrameSize.bind(this));
  109. },
  110. setFormFrameSize: function(){
  111. var size = this.panel.content.getSize();
  112. var topSize = this.topActionAreaNode.getSize();
  113. var y = size.y-topSize.y-8;
  114. var x = size.x-8;
  115. this.formFrameNode.setStyle("height", ""+y+"px");
  116. this.formFrameNode.setStyle("width", ""+x+"px");
  117. this.formJsonNode.setStyle("height", ""+y+"px");
  118. this.formJsonNode.setStyle("width", ""+x+"px");
  119. },
  120. loadForm: function(){
  121. this.formFrameNode.store("preview",this);
  122. this.formFrameNode.set("src", this.options.previewPath+"?mode="+this.options.mode);
  123. //window.open(this.options.previewPath);
  124. //this.formDocument = this.formFrameNode.contentDocument;
  125. //this.formWindow = this.formFrameNode.contentWindow;
  126. //this.formFrameNode.preview = this;
  127. },
  128. loadFormData: function(node){
  129. MWF.getJSON("/x_desktop/res/preview/work.json", function(json){
  130. MWF.xDesktop.requireApp("process.Xform", "Form", function(){
  131. this.appForm = new MWF.APPForm(node, this.data);
  132. // this.appForm.businessData = {
  133. // "data": json.data,
  134. // "taskList": json.taskList,
  135. // "work": json.work,
  136. // "workCompleted": json.workCompleted,
  137. // "control": json.control,
  138. // "activity": json.activity,
  139. // "task": json.currentTask,
  140. // "workLogList": json.workLogList,
  141. // "attachmentList": json.attachmentList,
  142. // "status": {
  143. // //"readonly": (this.options.readonly) ? true : false
  144. // "readonly": json.readonly
  145. // }
  146. // };
  147. this.appForm.app = this.form.designer;
  148. this.appForm.load();
  149. }.bind(this));
  150. }.bind(this));
  151. }
  152. });