PdfView.js 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. MWF.xDesktop.requireApp("process.Xform", "PdfView", null, false);
  2. MWF.xApplication.cms.Xform.PdfView = MWF.CMSPdfView = new Class({
  3. Extends: MWF.APPPdfView,
  4. createUpload : function (){
  5. this.uploadNode = new Element("div",{"style":"margin:10px;"}).inject(this.node);
  6. 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);
  7. uploadBtn.addEvent("click",function (){
  8. o2.require("o2.widget.Upload", null, false);
  9. if(this.documentId === ""){
  10. var upload = new o2.widget.Upload(this.form.app.content, {
  11. "action": o2.Actions.get("x_cms_assemble_control").action,
  12. "method": "uploadAttachment",
  13. "parameter": {
  14. "id": this.form.businessData.document.id
  15. },
  16. "accept" : "application/pdf",
  17. "data":{
  18. "site": "pdfAttachement"
  19. },
  20. "onCompleted": function(json){
  21. this.documentId = json.data.id;
  22. this.setData();
  23. this.loadPdfView();
  24. }.bind(this)
  25. });
  26. }else {
  27. var upload = new o2.widget.Upload(this.form.app.content, {
  28. "action": o2.Actions.get("x_cms_assemble_control").action,
  29. "method": "replaceAttachment",
  30. "parameter": {
  31. "id" : this.documentId,
  32. "documentid" : this.form.businessData.document.id
  33. },
  34. "accept" : "application/pdf",
  35. "data":{
  36. },
  37. "onCompleted": function(json){
  38. this.documentId = json.data.id;
  39. this.setData();
  40. this.loadPdfView();
  41. }.bind(this)
  42. });
  43. }
  44. upload.load();
  45. }.bind(this));
  46. },
  47. loadPdfView: function(){
  48. this.iframeNode = new Element("div").inject(this.node);
  49. this.iframeNode.setStyles({
  50. "height": "100%"
  51. });
  52. var host = o2.Actions.getHost( "x_cms_assemble_control" );
  53. var fileUrl = o2.filterUrl(host + "/x_cms_assemble_control/jaxrs/fileinfo/download/document/" + this.documentId);
  54. if(this.iframe){
  55. this.iframe.set("src","../o2_lib/pdfjs/web/viewer.html?file=" + fileUrl);
  56. }else {
  57. this.iframe = new Element("iframe").inject(this.iframeNode);
  58. this.iframe.set("src","../o2_lib/pdfjs/web/viewer.html?file=" + fileUrl);
  59. this.iframe.set("scrolling","no");
  60. this.iframe.set("frameborder",0);
  61. this.iframe.setStyles({
  62. "height" : "100%",
  63. "width" : "100%"
  64. });
  65. }
  66. if(this.emptyNode) this.emptyNode.hide();
  67. this.fireEvent("afterOpen");
  68. }
  69. });