WpsOffice.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. MWF.xDesktop.requireApp("process.Xform", "WpsOffice", null, false);
  2. MWF.xApplication.cms.Xform.WpsOffice = MWF.CMSWpsOffice = new Class({
  3. Extends: MWF.APPWpsOffice,
  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.officeType = {
  12. "docx" : "Writer",
  13. "doc" : "Writer",
  14. "xlsx" : "Spreadsheet",
  15. "xls" : "Spreadsheet",
  16. "pptx" : "Presentation",
  17. "ppt" : "Presentation",
  18. "pdf" : "Pdf",
  19. "ofd" : "Pdf"
  20. };
  21. this.appToken = "x_cms_assemble_control";
  22. },
  23. createUpload : function (){
  24. this.uploadNode = new Element("div",{"style":"margin:10px;"}).inject(this.node);
  25. 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);
  26. uploadBtn.addEvent("click",function (){
  27. o2.require("o2.widget.Upload", null, false);
  28. var upload = new o2.widget.Upload(this.content, {
  29. "action": o2.Actions.get(this.appToken).action,
  30. "method": "uploadAttachment",
  31. "accept" : ".docx,.xlsx,.pptx,.pdf,.ofd",
  32. "parameter": {
  33. "id" : this.form.businessData.document.id,
  34. },
  35. "data":{
  36. },
  37. "onCompleted": function(data){
  38. o2.Actions.load(this.appToken).FileInfoAction.delete(this.documentId,function( json ){
  39. }.bind(this));
  40. this.documentId = data.id;
  41. this.reload();
  42. }.bind(this)
  43. });
  44. upload.load();
  45. }.bind(this));
  46. },
  47. createDocumentByTemplate : function (callback){
  48. this.action.CustomAction.getInfo(this.json.template).then(function(json) {
  49. var data = {
  50. "fileName": MWF.xApplication.process.Xform.LP.onlyoffice.filetext + "." + json.data.extension,
  51. "fileType": json.data.extension,
  52. "appToken" : "x_cms_assemble_control",
  53. "workId" : this.form.businessData.document.id,
  54. "site" : "filetext",
  55. "tempId": this.json.template
  56. };
  57. this.action.CustomAction.createForO2(data,
  58. function( json ){
  59. this.documentId = json.data.fileId;
  60. this.setData();
  61. if (callback) callback();
  62. }.bind(this),null, false
  63. );
  64. }.bind(this))
  65. },
  66. createDocument : function (callback){
  67. var data = {
  68. "fileName" : MWF.xApplication.process.Xform.LP.onlyoffice.filetext + "." + this.json.officeType,
  69. "appToken" : "x_cms_assemble_control",
  70. "workId" : this.form.businessData.document.id,
  71. "site" : "filetext"
  72. };
  73. this.action.CustomAction.createForO2(data,
  74. function( json ){
  75. this.documentId = json.data.fileId;
  76. this.setData();
  77. if (callback) callback();
  78. }.bind(this),null, false
  79. );
  80. },
  81. loadDocument: function () {
  82. o2.Actions.load(this.appToken).FileInfoAction.getOnlineInfo(this.documentId, function( json ){
  83. this.documentData = json.data;
  84. this.fileName = this.documentData.name;
  85. this.extension = this.documentData.extension;
  86. this.getEditor(function () {
  87. this.loadApi(function (){
  88. this.loadEditor();
  89. }.bind(this));
  90. }.bind(this));
  91. }.bind(this),null,false);
  92. },
  93. setData: function() {
  94. var data = {
  95. "documentId": this.documentId,
  96. "appToken": "x_cms_assemble_control"
  97. };
  98. this.data = data;
  99. this._setBusinessData(data);
  100. var jsonData = {}
  101. jsonData[this.json.id] = data;
  102. o2.Actions.load("x_cms_assemble_control").DataAction.updateWithDocument(this.form.businessData.document.id, jsonData, function (json) {
  103. data = json.data;
  104. });
  105. }
  106. });