PdfView.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. MWF.xDesktop.requireApp("process.Xform", "$Module", null, false);
  2. MWF.xApplication.process.Xform.PdfView = MWF.APPPdfView = 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.loadPdfView();
  38. }
  39. },
  40. createEmpty : function (){
  41. this.emptyNode = new Element("div").inject(this.node);
  42. this.emptyNode.set("text",MWF.xApplication.process.Xform.LP.pdfview.nofile);
  43. },
  44. createUpload : function (){
  45. this.uploadNode = new Element("div",{"style":"margin:10px;"}).inject(this.node);
  46. 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);
  47. uploadBtn.addEvent("click",function (){
  48. o2.require("o2.widget.Upload", null, false);
  49. if(this.documentId === ""){
  50. var upload = new o2.widget.Upload(this.form.app.content, {
  51. "action": o2.Actions.get("x_processplatform_assemble_surface").action,
  52. "method": "uploadAttachment",
  53. "parameter": {
  54. "id": this.form.businessData.work.id
  55. },
  56. "accept" : "application/pdf",
  57. "data":{
  58. "site": "pdfAttachement"
  59. },
  60. "onCompleted": function(json){
  61. this.documentId = json.data.id;
  62. this.setData();
  63. this.loadPdfView();
  64. }.bind(this)
  65. });
  66. }else {
  67. var upload = new o2.widget.Upload(this.form.app.content, {
  68. "action": o2.Actions.get("x_processplatform_assemble_surface").action,
  69. "method": "replaceAttachment",
  70. "parameter": {
  71. "id" : this.documentId,
  72. "workid": this.form.businessData.work.id
  73. },
  74. "accept" : "application/pdf",
  75. "data":{
  76. },
  77. "onCompleted": function(json){
  78. this.documentId = json.data.id;
  79. this.setData();
  80. this.loadPdfView();
  81. }.bind(this)
  82. });
  83. }
  84. upload.load();
  85. }.bind(this));
  86. },
  87. getData: function(){
  88. var data = {
  89. "documentId" : ""
  90. };
  91. if(this.form.businessData.data[this.json.id]){
  92. data.documentId = this.form.businessData.data[this.json.id].documentId;
  93. }
  94. return data;
  95. },
  96. setData: function(){
  97. var data = {
  98. "documentId" : this.documentId
  99. };
  100. this._setBusinessData(data);
  101. },
  102. loadPdfView: function(){
  103. this.iframeNode = new Element("div").inject(this.node);
  104. this.iframeNode.setStyles({
  105. "height": "100%"
  106. });
  107. var host = o2.Actions.getHost( "x_processplatform_assemble_surface" );
  108. var fileUrl = o2.filterUrl(host + "/x_processplatform_assemble_surface/jaxrs/attachment/download/" + this.documentId);
  109. if(this.iframe){
  110. this.iframe.set("src","../o2_lib/pdfjs/web/viewer.html?file=" + fileUrl);
  111. }else {
  112. this.iframe = new Element("iframe").inject(this.iframeNode);
  113. this.iframe.set("src","../o2_lib/pdfjs/web/viewer.html?file=" + fileUrl);
  114. this.iframe.set("scrolling","no");
  115. this.iframe.set("frameborder",0);
  116. this.iframe.setStyles({
  117. "height" : "100%",
  118. "width" : "100%"
  119. });
  120. }
  121. if(this.emptyNode) this.emptyNode.hide();
  122. this.fireEvent("afterOpen");
  123. },
  124. hide: function(){
  125. this.node.hide();
  126. },
  127. show: function(){
  128. this.node.show();
  129. },
  130. isEmpty : function(){
  131. },
  132. save: function(){
  133. },
  134. validation: function(){return true}
  135. });