OfficeOnline.js 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. MWF.xDesktop.requireApp("process.Xform", "$Module", null, false);
  2. MWF.xApplication.process.Xform.OfficeOnline = MWF.APPOfficeOnline = new Class({
  3. Extends: MWF.APP$Module,
  4. isActive: false,
  5. options:{
  6. "moduleEvents": ["queryLoad","beforeOpen",
  7. "afterOpen",
  8. "afterSave"
  9. ]
  10. },
  11. initialize: function(node, json, form, options){
  12. this.node = $(node);
  13. this.node.store("module", this);
  14. this.json = json;
  15. this.form = form;
  16. this.documentId = "";
  17. this.mode = "write";
  18. this.appToken = "x_processplatform_assemble_surface";
  19. this.workId = this.form.businessData.work.id;
  20. },
  21. _loadUserInterface: function(){
  22. this.node.empty();
  23. this.node.setStyles({
  24. "min-height": "800px"
  25. });
  26. },
  27. _afterLoaded: function(){
  28. this.fireEvent("queryLoad");
  29. if(!layout.serviceAddressList["x_officeonline_assemble_control"]){
  30. this.node.set("html","<h3><font color=red>"+MWF.xApplication.process.Xform.LP.officeonline.noInstall+"</font></h3>");
  31. return false;
  32. }
  33. if (this.isReadonly()){
  34. this.mode = "view";
  35. }else{
  36. if (this.json.readScript && this.json.readScript.code){
  37. var flag = this.form.Macro.exec(this.json.readScript.code, this);
  38. if (flag){
  39. this.mode = "view";
  40. }
  41. }
  42. }
  43. if(this.mode !== "read" && this.json.allowUpload){
  44. this.createUpload();
  45. }
  46. this.action = o2.Actions.load("x_officeonline_assemble_control");
  47. if (!this.json.isNotLoadNow){
  48. this.data = this.getData();
  49. if(this.data.documentId === ""){
  50. if (this.json.officeType === "other" && this.json.templateType === "script"){
  51. this.json.template = this.form.Macro.exec(this.json.templeteScript.code, this);
  52. }
  53. this[this.json.officeType === "other"&&this.json.template !== ""? "createDocumentByTemplate":"createDocument"](function (){
  54. this.loadDocument();
  55. }.bind(this));
  56. }else {
  57. this.documentId = this.data.documentId;
  58. this.loadDocument();
  59. }
  60. }
  61. },
  62. createDocument : function (callback){
  63. var data = {
  64. "fileName" : MWF.xApplication.process.Xform.LP.officeonline.filetext + "." + this.json.officeType,
  65. "fileType" : this.json.officeType,
  66. "appToken" : this.appToken,
  67. "workId" : this.workId,
  68. "site" : "filetext"
  69. };
  70. this.action.OnlineAction.createForO2(data,
  71. function( json ){
  72. this.documentId = json.data.fileId;
  73. this.setData();
  74. if (callback) callback();
  75. }.bind(this),null, false
  76. );
  77. },
  78. createDocumentByTemplate : function (callback){
  79. this.action.OnlineAction.getInfo(this.json.template).then(function(json) {
  80. var data = {
  81. "fileName": MWF.xApplication.process.Xform.LP.officeonline.filetext + "." + json.data.extension,
  82. "fileType": json.data.extension,
  83. "appToken" : this.appToken,
  84. "workId" : this.workId,
  85. "site" : "filetext",
  86. "tempId": this.json.template
  87. };
  88. this.action.OnlineAction.createForO2(data,
  89. function( json ){
  90. this.documentId = json.data.fileId;
  91. this.setData();
  92. if (callback) callback();
  93. }.bind(this),null, false
  94. );
  95. }.bind(this))
  96. },
  97. createUpload : function (){
  98. this.uploadNode = new Element("div",{"style":"margin:10px;"}).inject(this.node);
  99. 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);
  100. uploadBtn.addEvent("click",function (){
  101. o2.require("o2.widget.Upload", null, false);
  102. var upload = new o2.widget.Upload(this.content, {
  103. "action": o2.Actions.get(this.appToken).action,
  104. "method": "uploadAttachment",
  105. "accept" : ".docx,.xlsx,.pptx,.pdf",
  106. "parameter": {
  107. "id": this.workId
  108. },
  109. "data":{
  110. "site": "filetext"
  111. },
  112. "onCompleted": function(data){
  113. o2.Actions.load(this.appToken).AttachmentAction.delete(this.documentId,function( json ){
  114. }.bind(this));
  115. this.documentId = data.id;
  116. this.reload();
  117. }.bind(this)
  118. });
  119. upload.load();
  120. }.bind(this));
  121. },
  122. reload : function (){
  123. this.setData();
  124. this.node.empty();
  125. this.createUpload();
  126. this.loadDocument();
  127. },
  128. loadDocument: function () {
  129. this.loadApi(function () {
  130. this.getEditor(function (){
  131. this.loadEditor();
  132. }.bind(this));
  133. }.bind(this));
  134. },
  135. loadApi : function (callback){
  136. this.officeAPI = {
  137. "pdf" : {
  138. "view" : "/wv/wordviewerframe.aspx?PdfMode=1",
  139. "write" : "/wv/wordviewerframe.aspx?PdfMode=1"
  140. },
  141. "docx" : {
  142. "view" : "/wv/wordviewerframe.aspx?1=1",
  143. "write" : "/we/wordeditorframe.aspx?1=1"
  144. },
  145. "doc" : {
  146. "view" : "/wv/wordviewerframe.aspx?1=1",
  147. "write" : "/we/wordeditorframe.aspx?1=1"
  148. },
  149. "xlsx" : {
  150. "view" : "/x/_layouts/xlviewerinternal.aspx?ui=zh-CN&rs=zh-CN",
  151. "write" : "/x/_layouts/xlviewerinternal.aspx?edit=1"
  152. },
  153. "xls" : {
  154. "view" : "/x/_layouts/xlviewerinternal.aspx?ui=zh-CN&rs=zh-CN",
  155. "write" : "/x/_layouts/xlviewerinternal.aspx?edit=1"
  156. },
  157. "pptx" : {
  158. "view" : "/p/PowerPointFrame.aspx?PowerPointView=ReadingView",
  159. "write" : "/p/PowerPointFrame.aspx?PowerPointView=EditView"
  160. },
  161. "ppt" : {
  162. "view" : "/p/PowerPointFrame.aspx?PowerPointView=ReadingView",
  163. "write" : "/p/PowerPointFrame.aspx?PowerPointView=EditView"
  164. }
  165. };
  166. this.action.ConfigAction.getCallBackUrl().then(function (json){
  167. this.WOPISrc = json.data.value;
  168. if(this.WOPISrc === ""){
  169. this.WOPISrc = o2.Actions.getHost( "x_officeonline_assemble_control" );
  170. }
  171. if (callback) callback();
  172. }.bind(this));
  173. },
  174. getEditor: function (callback) {
  175. var action = o2.Actions.load(this.appToken);
  176. action.AttachmentAction.getOnlineInfo(this.documentId, function( json ){
  177. this.document = json.data;
  178. this.fileName = this.document.name;
  179. var extension = this.document.extension;
  180. var WOPISrc = this.WOPISrc +"/x_officeonline_assemble_control/jaxrs/wopi/files/" + this.documentId + "?mode=" + this.mode;
  181. console.log(WOPISrc);
  182. WOPISrc = WOPISrc + "&appToken=" + this.appToken;
  183. this.action.ConfigAction.getOfficeOnlineUrl().then(function (json){
  184. console.log(json)
  185. this.officeOnlineUrl = json.data.value;
  186. this.fileUrl = this.officeOnlineUrl + this.officeAPI[extension][this.mode] + "&WOPISrc=" + encodeURIComponent(WOPISrc);
  187. console.log(WOPISrc);
  188. console.log(this.fileUrl );
  189. if (callback) callback();
  190. }.bind(this));
  191. }.bind(this),null,false);
  192. },
  193. loadEditor: function () {
  194. this.fireEvent("beforeOpen");
  195. this.officeNode = new Element("div#_" + this.documentId,{"style":"height:100%;overflow:hidden"}).inject(this.node);
  196. var form = new Element("form",{"target" : "office_frame_"+this.documentId,"action":this.fileUrl,"type":"hidden","method":"post"}).inject(this.officeNode);
  197. new Element("input",{"name":"access_token","value":layout.session.token,"type":"hidden"}).inject(form);
  198. var iframe = new Element("iframe#office_frame_"+this.documentId,{"name":"office_frame_"+this.documentId}).inject(this.officeNode);
  199. // iframe.set("src",this.fileUrl);
  200. iframe.set("scrolling","no");
  201. iframe.set("frameborder",0);
  202. iframe.setStyles({
  203. "height" : "95%",
  204. "width" : "100%"
  205. });
  206. form.submit();
  207. },
  208. hide: function(){
  209. this.node.hide();
  210. },
  211. show: function(){
  212. this.node.show();
  213. },
  214. isEmpty : function(){
  215. var data = this.getData();
  216. if(data.documentId === ""){
  217. return true;
  218. }else {
  219. return false;
  220. }
  221. },
  222. getData: function(){
  223. var data = {
  224. "documentId" : ""
  225. }
  226. if(this.form.businessData.data[this.json.id]){
  227. data = this.form.businessData.data[this.json.id]
  228. }
  229. if(!data.documentId) data.documentId = "";
  230. return data;
  231. },
  232. setData: function() {
  233. var data = {
  234. "documentId": this.documentId,
  235. "appToken": this.appToken
  236. }
  237. this.data = data;
  238. this._setBusinessData(data);
  239. var jsonData = {}
  240. jsonData[this.json.id] = data;
  241. o2.Actions.load(this.appToken).DataAction.updateWithJob(this.form.businessData.work.job, jsonData, function (json) {
  242. data = json.data;
  243. })
  244. }
  245. });