OnlyOffice.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. MWF.xDesktop.requireApp("process.Xform", "OnlyOffice", null, false);
  2. MWF.xApplication.cms.Xform.OnlyOffice = MWF.CMSOnlyOffice = new Class({
  3. Extends: MWF.APPOnlyOffice,
  4. createDocument : function (callback){
  5. var data = {
  6. "fileName" : MWF.xApplication.process.Xform.LP.onlyoffice.filetext + "." + this.json.officeType,
  7. "fileType" : this.json.officeType,
  8. "appToken" : "x_cms_assemble_control",
  9. "workId" : this.form.businessData.document.id,
  10. "site" : "filetext"
  11. };
  12. this.action.OnlyofficeAction.createForO2(data,
  13. function( json ){
  14. this.documentId = json.data.fileId;
  15. this.setData();
  16. if (callback) callback();
  17. }.bind(this),null, false
  18. );
  19. },
  20. createDocumentByTemplate : function (callback){
  21. this.action.OnlyofficeAction.get(this.json.template).then(function(json) {
  22. var data = {
  23. "fileName": MWF.xApplication.process.Xform.LP.onlyoffice.filetext + "." + json.data.fileModel.document.fileType,
  24. "fileType": json.data.fileModel.document.fileType,
  25. "appToken" : "x_cms_assemble_control",
  26. "workId" : this.form.businessData.document.id,
  27. "site" : "filetext",
  28. "tempId": this.json.template
  29. };
  30. this.action.OnlyofficeAction.createForO2(data,
  31. function( json ){
  32. this.documentId = json.data.fileId;
  33. this.setData();
  34. if (callback) callback();
  35. }.bind(this),null, false
  36. );
  37. }.bind(this));
  38. },
  39. createUpload : function (){
  40. this.uploadNode = new Element("div",{"style":"margin:10px;"}).inject(this.node);
  41. 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);
  42. uploadBtn.addEvent("click",function (){
  43. o2.require("o2.widget.Upload", null, false);
  44. var upload = new o2.widget.Upload(this.content, {
  45. "action": o2.Actions.get("x_cms_assemble_control").action,
  46. "method": "replaceAttachment",
  47. "accept" : ".docx,.xlsx,.pptx",
  48. "parameter": {
  49. "id" : this.documentId,
  50. "documentid" : this.form.businessData.document.id,
  51. },
  52. "data":{
  53. },
  54. "onCompleted": function(data){
  55. this.documentId = data.id;
  56. this.setData();
  57. this.node.empty();
  58. this.createUpload();
  59. this.loadDocument();
  60. }.bind(this)
  61. });
  62. upload.load();
  63. }.bind(this));
  64. },
  65. getData: function(){
  66. debugger
  67. var data = {
  68. "documentId" : ""
  69. };
  70. var site = this.json.fileSite?this.json.fileSite:"filetext";
  71. if(this.form.businessData.data[this.json.id] && this.form.businessData.data[this.json.id].documentId){
  72. data = this.form.businessData.data[this.json.id];
  73. }else {
  74. //判断对应的site里有没有值
  75. var attachmentList = this.form.businessData.attachmentList;
  76. attachmentList = attachmentList.filter(function(att) {
  77. return att.site === site;
  78. });
  79. if(attachmentList.length>0){
  80. data = {
  81. "documentId": attachmentList[0].id,
  82. "appToken": "x_cms_assemble_control"
  83. };
  84. }
  85. }
  86. return data;
  87. },
  88. setData: function() {
  89. var data = {
  90. "documentId": this.documentId,
  91. "appToken": "x_cms_assemble_control"
  92. };
  93. this.data = data;
  94. this._setBusinessData(data);
  95. var jsonData = {}
  96. jsonData[this.json.id] = data;
  97. o2.Actions.load("x_cms_assemble_control").DataAction.updateWithDocument(this.form.businessData.document.id, jsonData, function (json) {
  98. data = json.data;
  99. });
  100. }
  101. });