OfficeOnline.js 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. MWF.xDesktop.requireApp("process.Xform", "OfficeOnline", null, false);
  2. MWF.xApplication.cms.Xform.OfficeOnline = MWF.CMSOfficeOnline = new Class({
  3. Extends: MWF.APPOfficeOnline,
  4. initialize: function(node, json, form, options){
  5. this.node = $(node);
  6. this.node.store("module", this);
  7. this.json = json;
  8. this.form = form;
  9. this.documentId = "";
  10. this.mode = "write";
  11. this.appToken = "x_cms_assemble_control";
  12. this.workId = this.form.businessData.document.id;
  13. },
  14. createUpload : function (){
  15. this.uploadNode = new Element("div",{"style":"margin:10px;"}).inject(this.node);
  16. 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);
  17. uploadBtn.addEvent("click",function (){
  18. o2.require("o2.widget.Upload", null, false);
  19. var upload = new o2.widget.Upload(this.content, {
  20. "action": o2.Actions.get(this.appToken).action,
  21. "method": "uploadAttachment",
  22. "accept" : ".docx,.xlsx,.pptx,.pdf",
  23. "parameter": {
  24. "id": this.workId
  25. },
  26. "data":{
  27. "site": "filetext"
  28. },
  29. "onCompleted": function(data){
  30. o2.Actions.load(this.appToken).FileInfoAction.delete(this.documentId,function( json ){
  31. }.bind(this));
  32. this.documentId = data.id;
  33. this.reload();
  34. }.bind(this)
  35. });
  36. upload.load();
  37. }.bind(this));
  38. },
  39. setData: function() {
  40. var data = {
  41. "documentId": this.documentId,
  42. "appToken": this.appToken
  43. }
  44. this.data = data;
  45. this._setBusinessData(data);
  46. var jsonData = {}
  47. jsonData[this.json.id] = data;
  48. o2.Actions.load(this.appToken).DataAction.updateWithDocument(this.form.businessData.document.id, jsonData, function (json) {
  49. data = json.data;
  50. })
  51. },
  52. getEditor: function (callback) {
  53. var action = o2.Actions.load(this.appToken);
  54. action.FileInfoAction.getOnlineInfo(this.documentId, function( json ){
  55. this.document = json.data;
  56. this.fileName = this.document.name;
  57. var extension = this.document.extension;
  58. var WOPISrc = this.WOPISrc +"/x_officeonline_assemble_control/jaxrs/wopi/files/" + this.documentId + "?mode=" + this.mode;
  59. console.log(WOPISrc);
  60. WOPISrc = WOPISrc + "&appToken=" + this.appToken;
  61. this.action.ConfigAction.getOfficeOnlineUrl().then(function (json){
  62. this.officeOnlineUrl = json.data.value;
  63. this.fileUrl = this.officeOnlineUrl + this.officeAPI[extension][this.mode] + "&WOPISrc=" + encodeURIComponent(WOPISrc);
  64. console.log(WOPISrc);
  65. console.log(this.fileUrl );
  66. if (callback) callback();
  67. }.bind(this));
  68. }.bind(this),null,false);
  69. },
  70. });