OfdView.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. MWF.xDesktop.requireApp("process.Xform", "$Module", null, false);
  2. MWF.xApplication.process.Xform.OfdView = MWF.APPOfdView = new Class({
  3. Extends: MWF.APP$Module,
  4. options:{
  5. "moduleEvents": [
  6. "afterOpen"
  7. ]
  8. },
  9. initialize: function(node, json, form, options){
  10. this.node = $(node);
  11. this.node.store("module", this);
  12. this.json = json;
  13. this.form = form;
  14. this.fileTemplate = false;
  15. if (this.json.isReadonly || this.form.json.isReadonly){
  16. this.mode = "read";
  17. }else{
  18. if (this.json.readScript && this.json.readScript.code){
  19. var flag = this.form.Macro.exec(this.json.readScript.code, this);
  20. if (flag){
  21. this.mode = "read";
  22. }
  23. }
  24. }
  25. },
  26. _loadUserInterface: function(){
  27. this.node.empty();
  28. },
  29. _afterLoaded: function(){
  30. if(this.mode !== "read"){
  31. this.createUpload();
  32. }
  33. if(this.json.template && (this.json.templateType === "value" && this.json.template !=="")){
  34. this.fileTemplate = true;
  35. }
  36. if(this.json.templeteScript && (this.json.templateType === "script" && this.json.templeteScript !=="")){
  37. this.fileTemplate = true;
  38. }
  39. this.data = this.getData();
  40. this.documentId = this.data.documentId;
  41. if(this.data.documentId === "" && !this.fileTemplate){
  42. this.createEmpty();
  43. }else {
  44. this.loadOfdView();
  45. }
  46. },
  47. createEmpty : function (){
  48. this.emptyNode = new Element("div").inject(this.node);
  49. this.emptyNode.set("text",MWF.xApplication.process.Xform.LP.ofdview.nofile);
  50. },
  51. createUpload : function (){
  52. this.uploadNode = new Element("div",{"style":"margin:10px;"}).inject(this.node);
  53. var uploadBtn = new Element("button",{"text":MWF.xApplication.process.Xform.LP.ofdview.upload,"style":"margin-left: 15px; color: rgb(255, 255, 255); cursor: pointer; height: 26px; line-height: 26px; padding: 0px 10px; min-width: 40px; background-color: rgb(74, 144, 226); border: 1px solid rgb(82, 139, 204); border-radius: 15px;"}).inject(this.uploadNode);
  54. uploadBtn.addEvent("click",function (){
  55. o2.require("o2.widget.Upload", null, false);
  56. if(this.documentId === ""){
  57. var upload = new o2.widget.Upload(this.form.app.content, {
  58. "action": o2.Actions.get("x_processplatform_assemble_surface").action,
  59. "method": "uploadAttachment",
  60. "parameter": {
  61. "id": this.form.businessData.work.id
  62. },
  63. "accept" : ".ofd",
  64. "data":{
  65. "site": "ofdAttachement"
  66. },
  67. "onCompleted": function(json){
  68. this.documentId = json.data.id;
  69. this.setData();
  70. this.loadOfdView();
  71. }.bind(this)
  72. });
  73. }else {
  74. var upload = new o2.widget.Upload(this.form.app.content, {
  75. "action": o2.Actions.get("x_processplatform_assemble_surface").action,
  76. "method": "replaceAttachment",
  77. "parameter": {
  78. "id" : this.documentId,
  79. "workid": this.form.businessData.work.id
  80. },
  81. "accept" : ".ofd",
  82. "data":{
  83. },
  84. "onCompleted": function(json){
  85. this.documentId = json.data.id;
  86. this.setData();
  87. this.loadOfdView();
  88. }.bind(this)
  89. });
  90. }
  91. upload.load();
  92. }.bind(this));
  93. },
  94. getData: function(){
  95. var data = {
  96. "documentId" : ""
  97. };
  98. if(this.form.businessData.data[this.json.id]){
  99. data.documentId = this.form.businessData.data[this.json.id].documentId;
  100. }
  101. return data;
  102. },
  103. setData: function(){
  104. var data = {
  105. "documentId" : this.documentId
  106. };
  107. this._setBusinessData(data);
  108. },
  109. loadOfdView: function(){
  110. debugger
  111. this.iframeNode = new Element("div").inject(this.node);
  112. this.iframeNode.setStyles({
  113. "height": "100%"
  114. });
  115. var fileUrl;
  116. if(this.json.template && (this.json.templateType === "value" && this.json.template !=="")){
  117. fileUrl = this.json.template;
  118. }else if(this.json.templeteScript && (this.json.templateType === "script" && this.json.templeteScript !=="")){
  119. fileUrl = this.form.Macro.exec(this.json.templeteScript.code, this);
  120. }else {
  121. var host = o2.Actions.getHost( "x_processplatform_assemble_surface" );
  122. fileUrl = o2.filterUrl(host + "/x_processplatform_assemble_surface/jaxrs/attachment/download/" + this.documentId);
  123. }
  124. if(this.iframe){
  125. this.iframe.set("src","../o2_lib/ofdjs/index.html?file=" + fileUrl);
  126. }else {
  127. this.iframe = new Element("iframe").inject(this.iframeNode);
  128. this.iframe.set("src","../o2_lib/ofdjs/index.html?file=" + fileUrl);
  129. this.iframe.set("scrolling","no");
  130. this.iframe.set("frameborder",0);
  131. this.iframe.setStyles({
  132. "height" : "100%",
  133. "width" : "100%"
  134. });
  135. }
  136. if(this.emptyNode) this.emptyNode.hide();
  137. this.fireEvent("afterOpen");
  138. },
  139. loadOfdViewByUrl : function (fileUrl){
  140. if(this.iframe){
  141. this.iframe.set("src","../o2_lib/ofdjs/index.html?file=" + fileUrl);
  142. }else {
  143. this.iframe = new Element("iframe").inject(this.iframeNode);
  144. this.iframe.set("src","../o2_lib/ofdjs/index.html?file=" + fileUrl);
  145. this.iframe.set("scrolling","no");
  146. this.iframe.set("frameborder",0);
  147. this.iframe.setStyles({
  148. "height" : "100%",
  149. "width" : "100%"
  150. });
  151. }
  152. if(this.emptyNode) this.emptyNode.hide();
  153. this.fireEvent("afterOpen");
  154. },
  155. hide: function(){
  156. this.node.hide();
  157. },
  158. show: function(){
  159. this.node.show();
  160. },
  161. isEmpty : function(){
  162. },
  163. save: function(){
  164. },
  165. validation: function(){return true}
  166. });