Preview.js 5.8 KB

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