YozoOffice.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. MWF.xDesktop.requireApp("process.Xform", "$Module", null, false);
  2. MWF.xApplication.process.Xform.YozoOffice = MWF.APPYozoOffice = new Class({
  3. Extends: MWF.APP$Module,
  4. options:{
  5. "moduleEvents": [
  6. "afterOpen",
  7. "afterCreate",
  8. "beforeSave",
  9. "afterSave"
  10. ]
  11. },
  12. initialize: function(node, json, form, options){
  13. this.node = $(node);
  14. this.node.store("module", this);
  15. this.json = json;
  16. this.form = form;
  17. this.mode = "write";
  18. this.appToken = "x_processplatform_assemble_surface";
  19. },
  20. _loadUserInterface: function(){
  21. this.node.empty();
  22. this.node.setStyles({
  23. "min-height": "100px"
  24. });
  25. },
  26. _afterLoaded: function(){
  27. if(!layout.serviceAddressList["x_yozofile_assemble_control"]){
  28. this.node.set("html","<h3><font color=red>please install weboffice !!!</font></h3>");
  29. return false;
  30. }
  31. if(this.mode !== "read" && this.json.allowUpload){
  32. this.createUpload();
  33. }
  34. this.action = o2.Actions.load("x_yozofile_assemble_control");
  35. if (!this.json.isNotLoadNow){
  36. this.data = this.getData();
  37. if(this.data.documentId === ""){
  38. if (this.json.officeType === "other" && this.json.templateType === "script"){
  39. this.json.template = this.form.Macro.exec(this.json.templeteScript.code, this);
  40. }
  41. this[this.json.officeType === "other"&&this.json.template !== ""? "createDocumentByTemplate":"createDocument"](function (){
  42. this.loadOffice();
  43. }.bind(this));
  44. }else {
  45. this.documentId = this.data.documentId;
  46. this.loadOffice();
  47. }
  48. }
  49. },
  50. reload : function (){
  51. this.officeLoaded = false;
  52. this.setData();
  53. this.node.empty();
  54. if(this.mode !== "read" && this.json.allowUpload){
  55. this.createUpload();
  56. }
  57. this.loadOffice();
  58. },
  59. createDocumentByTemplate : function (callback){
  60. this.action.CustomAction.getInfo(this.json.template).then(function(json) {
  61. var data = {
  62. "fileName": MWF.xApplication.process.Xform.LP.onlyoffice.filetext + "." + json.data.extension,
  63. "fileType": json.data.extension,
  64. "appToken" : "x_processplatform_assemble_surface",
  65. "workId" : this.form.businessData.work.id,
  66. "site" : "filetext",
  67. "tempId": this.json.template
  68. };
  69. this.action.CustomAction.createForO2(data, function( json ){
  70. debugger
  71. this.documentId = json.data.fileId;
  72. this.setData();
  73. if (callback) callback();
  74. }.bind(this),null, false
  75. );
  76. }.bind(this))
  77. },
  78. createDocument : function (callback){
  79. var data = {
  80. "fileName" : MWF.xApplication.process.Xform.LP.onlyoffice.filetext + "." + this.getFileType(this.json.officeType),
  81. "appToken" : this.appToken,
  82. "workId" : this.form.businessData.work.id,
  83. "site" : "filetext"
  84. };
  85. this.action.CustomAction.createForO2(data,
  86. function( json ){
  87. debugger
  88. this.documentId = json.data.fileId;
  89. this.setData();
  90. if (callback) callback();
  91. }.bind(this),null, false
  92. );
  93. },
  94. createUpload : function (){
  95. this.uploadNode = new Element("div",{"style":"margin:10px;"}).inject(this.node);
  96. 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);
  97. uploadBtn.addEvent("click",function (){
  98. o2.require("o2.widget.Upload", null, false);
  99. var upload = new o2.widget.Upload(this.content, {
  100. "action": o2.Actions.get("x_processplatform_assemble_surface").action,
  101. "method": "uploadAttachment",
  102. "accept" : ".docx,.xlsx,.pptx",
  103. "parameter": {
  104. "id" : this.form.businessData.work.id
  105. },
  106. "data":{
  107. },
  108. "onCompleted": function(data){
  109. o2.Actions.load("x_processplatform_assemble_surface").AttachmentAction.delete(this.documentId,function( json ){
  110. }.bind(this));
  111. this.documentId = data.id;
  112. this.reload();
  113. }.bind(this)
  114. });
  115. upload.load();
  116. }.bind(this));
  117. },
  118. getData: function(){
  119. var data = {
  120. "documentId" : ""
  121. };
  122. if(this.form.businessData.data[this.json.id]){
  123. data.documentId = this.form.businessData.data[this.json.id].documentId;
  124. }
  125. return data;
  126. },
  127. setData: function() {
  128. var data = {
  129. "documentId": this.documentId,
  130. "appToken": this.appToken
  131. }
  132. this.data = data;
  133. this._setBusinessData(data);
  134. var jsonData = {}
  135. jsonData[this.json.id] = data;
  136. o2.Actions.load(this.appToken).DataAction.updateWithJob(this.form.businessData.work.job, jsonData, function (json) {
  137. data = json.data;
  138. })
  139. },
  140. loadOffice: function(){
  141. if (!this.officeLoaded){
  142. this.loadOfficeContorl();
  143. this.officeLoaded = true;
  144. }
  145. },
  146. loadOfficeContorl: function(file){
  147. if (this.node.getSize().y<800) this.node.setStyle("height", "800px");
  148. if (this.isReadonly()){
  149. this.mode = "view";
  150. }else{
  151. if (this.json.readScript && this.json.readScript.code){
  152. var flag = this.form.Macro.exec(this.json.readScript.code, this);
  153. if (flag){
  154. this.mode = "view";
  155. }
  156. }
  157. }
  158. this.loadOfficeEditor();
  159. },
  160. hide: function(){
  161. this.node.hide();
  162. },
  163. show: function(){
  164. this.node.show();
  165. },
  166. isEmpty : function(){
  167. var data = this.getData();
  168. if(data.documentId === ""){
  169. return true;
  170. }else {
  171. return false;
  172. }
  173. },
  174. getFileType: function(){
  175. var ename = "docx";
  176. switch (this.json.officeType){
  177. case "word":
  178. ename = "docx";
  179. break;
  180. case "excel":
  181. ename = "xlsx";
  182. break;
  183. case "ppt":
  184. ename = "pptx";
  185. }
  186. return ename;
  187. },
  188. //书签赋值
  189. setBookMarkValue : function(name,value){
  190. var YozoOffice = this.iframe.contentWindow.YozoOffice;
  191. if (YozoOffice.Application.ActiveDocument.Bookmarks.Exists(name)) {
  192. YozoOffice.Application.Selection.GoTo(-1, null, null, name);
  193. YozoOffice.Application.Selection.Text = value;
  194. }
  195. },
  196. loadOfficeEditor: function(){
  197. this.action.CustomAction.getFileUrl(this.documentId,{"mode":this.mode,"appToken":this.appToken}, function( json ){
  198. var iframe = new Element("iframe").inject(this.node);
  199. iframe.set("src",json.data.fileUrl);
  200. iframe.set("id","_" + this.documentId);
  201. iframe.set("scrolling","no");
  202. iframe.set("frameborder",0);
  203. iframe.setStyles({
  204. "height" : "100%",
  205. "width" : "100%"
  206. });
  207. this.iframe = iframe;
  208. }.bind(this),null, false);
  209. }
  210. });