Foxit.js 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. MWF.xDesktop.requireApp("process.Xform", "$Module", null, false);
  2. MWF.xApplication.process.Xform.Foxit = MWF.APPFoxit = 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. if (this.json.isReadonly || this.form.json.isReadonly){
  15. this.mode = "read";
  16. }else{
  17. if (this.json.readScript && this.json.readScript.code){
  18. var flag = this.form.Macro.exec(this.json.readScript.code, this);
  19. if (flag){
  20. this.mode = "read";
  21. }
  22. }
  23. }
  24. },
  25. _loadUserInterface: function(){
  26. this.node.empty();
  27. },
  28. _afterLoaded: function(){
  29. if(this.mode !== "read"){
  30. this.createUpload();
  31. }
  32. this.data = this.getData();
  33. this.documentId = this.data.documentId;
  34. if(this.data.documentId === ""){
  35. this.createEmpty();
  36. }else {
  37. this.loadFoxit();
  38. }
  39. },
  40. createEmpty : function (){
  41. this.emptyNode = new Element("div",{"style" : "margin:20px;"}).inject(this.node);
  42. this.emptyNode.set("text",MWF.xApplication.process.Xform.LP.pdfview.nofile);
  43. },
  44. upload : function (){
  45. o2.require("o2.widget.Upload", null, false);
  46. var upload;
  47. if(this.documentId === ""){
  48. upload = new o2.widget.Upload(this.form.app.content, {
  49. "action": o2.Actions.get("x_processplatform_assemble_surface").action,
  50. "method": "uploadAttachment",
  51. "parameter": {
  52. "id": this.form.businessData.work.id
  53. },
  54. "accept" : ".ofd",
  55. "data":{
  56. "site": "foxitAttachement"
  57. },
  58. "onCompleted": function(json){
  59. this.documentId = json.data.id;
  60. this.setData();
  61. this.loadFoxit();
  62. }.bind(this)
  63. });
  64. }else {
  65. upload = new o2.widget.Upload(this.form.app.content, {
  66. "action": o2.Actions.get("x_processplatform_assemble_surface").action,
  67. "method": "replaceAttachment",
  68. "parameter": {
  69. "id" : this.documentId,
  70. "workid": this.form.businessData.work.id
  71. },
  72. "accept" : ".ofd",
  73. "data":{
  74. },
  75. "onCompleted": function(json){
  76. this.documentId = json.data.id;
  77. this.setData();
  78. this.loadFoxit();
  79. }.bind(this)
  80. });
  81. }
  82. upload.load();
  83. },
  84. createUpload : function (){
  85. this.uploadNode = new Element("div",{"style":"margin:10px;"}).inject(this.node);
  86. var upload;
  87. var uploadBtn = new Element("button",{"text":MWF.xApplication.process.Xform.LP.pdfview.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);
  88. uploadBtn.addEvent("click",function (){
  89. o2.require("o2.widget.Upload", null, false);
  90. if(this.documentId === ""){
  91. upload = new o2.widget.Upload(this.form.app.content, {
  92. "action": o2.Actions.get("x_processplatform_assemble_surface").action,
  93. "method": "uploadAttachment",
  94. "parameter": {
  95. "id": this.form.businessData.work.id
  96. },
  97. "accept" : ".ofd",
  98. "data":{
  99. "site": "foxitAttachement"
  100. },
  101. "onCompleted": function(json){
  102. this.documentId = json.data.id;
  103. this.setData();
  104. this.loadFoxit();
  105. }.bind(this)
  106. });
  107. }else {
  108. upload = new o2.widget.Upload(this.form.app.content, {
  109. "action": o2.Actions.get("x_processplatform_assemble_surface").action,
  110. "method": "replaceAttachment",
  111. "parameter": {
  112. "id" : this.documentId,
  113. "workid": this.form.businessData.work.id
  114. },
  115. "accept" : ".ofd",
  116. "data":{
  117. },
  118. "onCompleted": function(json){
  119. this.documentId = json.data.id;
  120. this.setData();
  121. this.loadFoxit();
  122. }.bind(this)
  123. });
  124. }
  125. upload.load();
  126. }.bind(this));
  127. },
  128. getData: function(){
  129. var data = {
  130. "documentId" : ""
  131. };
  132. if(this.form.businessData.data[this.json.id]){
  133. data.documentId = this.form.businessData.data[this.json.id].documentId;
  134. }
  135. return data;
  136. },
  137. setData: function(){
  138. var data = {
  139. "documentId" : this.documentId
  140. };
  141. this._setBusinessData(data);
  142. },
  143. loadFoxitByAttId : function (attId){
  144. var host = o2.Actions.getHost( "x_processplatform_assemble_surface" );
  145. var fileUrl = o2.filterUrl(host + "/x_processplatform_assemble_surface/jaxrs/attachment/download/" + attId + "/stream");
  146. var xtoken = layout.session.token;
  147. fileUrl = fileUrl + "?"+o2.tokenName+"=" + xtoken;
  148. //var callbackUrl = o2.filterUrl(host + "/x_processplatform_assemble_surface/jaxrs/attachment/update/"+attId+"/work/" + this.form.businessData.work.id);
  149. //callbackUrl = callbackUrl + "?"+o2.tokenName+"=" + xtoken + "&fileName=文件正文.ofd";
  150. if(this.iframe){
  151. this.iframe.set("src",this.json.api + "?docuri=" + encodeURIComponent(fileUrl) );
  152. }else {
  153. this.iframe = new Element("iframe").inject(this.iframeNode);
  154. this.iframe.set("src",this.json.api + "?docuri=" + encodeURIComponent(fileUrl));
  155. this.iframe.set("scrolling","no");
  156. this.iframe.set("frameborder",0);
  157. this.iframe.setStyles({
  158. "height" : "100%",
  159. "width" : "100%"
  160. });
  161. }
  162. if(this.emptyNode) {
  163. this.emptyNode.hide();
  164. }
  165. this.fireEvent("afterOpen");
  166. },
  167. loadFoxit: function(){
  168. this.iframeNode = new Element("div").inject(this.node);
  169. this.iframeNode.setStyles({
  170. "height": "100%"
  171. });
  172. var host = o2.Actions.getHost( "x_processplatform_assemble_surface" );
  173. var fileUrl = o2.filterUrl(host + "/x_processplatform_assemble_surface/jaxrs/attachment/download/" + this.documentId + "/stream");
  174. var xtoken = layout.session.token;
  175. fileUrl = fileUrl + "?"+o2.tokenName+"=" + xtoken;
  176. var callbackUrl = o2.filterUrl(host + "/x_processplatform_assemble_surface/jaxrs/attachment/update/"+this.documentId+"/work/" + this.form.businessData.work.id);
  177. callbackUrl = callbackUrl + "?"+o2.tokenName+"=" + xtoken + "&fileName=文件正文.ofd";
  178. if(this.iframe){
  179. this.iframe.set("src",this.json.api + "?docuri=" + encodeURIComponent(fileUrl) + "&saveuri=" + encodeURIComponent(callbackUrl));
  180. }else {
  181. this.iframe = new Element("iframe").inject(this.iframeNode);
  182. this.iframe.set("src",this.json.api + "?docuri=" + encodeURIComponent(fileUrl)+ "&saveuri=" + encodeURIComponent(callbackUrl));
  183. this.iframe.set("scrolling","no");
  184. this.iframe.set("frameborder",0);
  185. this.iframe.setStyles({
  186. "height" : "100%",
  187. "width" : "100%"
  188. });
  189. }
  190. if(this.emptyNode) {
  191. this.emptyNode.hide();
  192. }
  193. this.fireEvent("afterOpen");
  194. },
  195. hide: function(){
  196. this.node.hide();
  197. },
  198. show: function(){
  199. this.node.show();
  200. },
  201. isEmpty : function(){
  202. },
  203. save: function(){
  204. },
  205. validation: function(){return true}
  206. });