Angularjs 基于J2EE的web应用程序中的在线文档编辑(仅限办公室),但回调Url不起作用
我们正在使用angularJS和spring/hibernate开发一个Web应用程序。 我们在生产环境中使用Linux操作系统,开发环境是Windows。我们正在尝试在我们的应用程序中实现在线文档编辑工具,如ms word 经过一些研究,我们只使用办公室。 我正在使用以下angularJs组件来仅使用Office 我们能够将其与应用程序集成,并且可以在web浏览器的编辑器中看到打开的文档。 但未保存我的更改。控件未到达回调URL 由于angularJs组件使用onSave方法,这在OnlyOffice API中已不再存在。因此,我对html和JS文件中的代码做了一些更改:- HTML文件代码为:-Angularjs 基于J2EE的web应用程序中的在线文档编辑(仅限办公室),但回调Url不起作用,angularjs,document,editing,onlyoffice,Angularjs,Document,Editing,Onlyoffice,我们正在使用angularJS和spring/hibernate开发一个Web应用程序。 我们在生产环境中使用Linux操作系统,开发环境是Windows。我们正在尝试在我们的应用程序中实现在线文档编辑工具,如ms word 经过一些研究,我们只使用办公室。 我正在使用以下angularJs组件来仅使用Office 我们能够将其与应用程序集成,并且可以在web浏览器的编辑器中看到打开的文档。 但未保存我的更改。控件未到达回调URL 由于angularJs组件使用onSave方法,这在OnlyOf
<div ng-controller="DocumentEditController">
<onlyoffice-editor src="{{ trustSrc(document.src) }}"
title="{{ document.name }}">
</onlyoffice-editor>
</div>
angular.module('onlyoffice', []);
angular.module('onlyoffice').directive('onlyofficeEditor', [function () {
function key(k) {
var result = k.replace(new RegExp("[^0-9-.a-zA-Z_=]", "g"), "_") + (new
Date()).getTime();
return result.substring(result.length - Math.min(result.length, 50));
}
var getDocumentType = function (ext) {
if (".docx.doc.odt.rtf.txt.html.htm.mht.pdf.djvu.fb2.epub.xps".indexOf(ext) != -1) return "text";
if (".xls.xlsx.ods.csv".indexOf(ext) != -1) return "spreadsheet";
if (".pps.ppsx.ppt.pptx.odp".indexOf(ext) != -1) return "presentation";
return null;
};
return {
template: '<div id="onlyoffice-editor"></div>',
link: function ($scope, $element, $attrs) {
$scope.$watch(function () {
return $attrs.src;
}, function () {
if (!$attrs.src) return;
var docUrl = $attrs.src;
var docTitle = $attrs.title || docUrl;
var docKey = key(docUrl);
var docType = docUrl.split('?')[0].substring(docUrl.lastIndexOf(".") + 1).trim().toLowerCase();
var documentType = getDocumentType(docType);
var config = {
type: "desktop",
width: '100%',
height: '100%',
documentType: documentType,
document: {
title: docTitle,
url: docUrl,
fileType: docType,
key: docKey,
permissions: {
edit: true,
download: false
}
},
editorConfig: {
mode: 'edit',
callbackUrl:"/documentSave"
},
events: {
onReady: function () {alert("in on ready");
setTimeout(function () {
$scope.$apply(function () {
$scope.ready = true;
});
}, 5000);
},
onError: function (event) {
alert(event.data);
// var url = event.data;
// $scope.save({url: url, close: $scope.close});
},
}
};
//creating object editing
new DocsAPI.DocEditor("onlyoffice-editor", config);
});
}
}
}]);
JS文件代码为:-
<div ng-controller="DocumentEditController">
<onlyoffice-editor src="{{ trustSrc(document.src) }}"
title="{{ document.name }}">
</onlyoffice-editor>
</div>
angular.module('onlyoffice', []);
angular.module('onlyoffice').directive('onlyofficeEditor', [function () {
function key(k) {
var result = k.replace(new RegExp("[^0-9-.a-zA-Z_=]", "g"), "_") + (new
Date()).getTime();
return result.substring(result.length - Math.min(result.length, 50));
}
var getDocumentType = function (ext) {
if (".docx.doc.odt.rtf.txt.html.htm.mht.pdf.djvu.fb2.epub.xps".indexOf(ext) != -1) return "text";
if (".xls.xlsx.ods.csv".indexOf(ext) != -1) return "spreadsheet";
if (".pps.ppsx.ppt.pptx.odp".indexOf(ext) != -1) return "presentation";
return null;
};
return {
template: '<div id="onlyoffice-editor"></div>',
link: function ($scope, $element, $attrs) {
$scope.$watch(function () {
return $attrs.src;
}, function () {
if (!$attrs.src) return;
var docUrl = $attrs.src;
var docTitle = $attrs.title || docUrl;
var docKey = key(docUrl);
var docType = docUrl.split('?')[0].substring(docUrl.lastIndexOf(".") + 1).trim().toLowerCase();
var documentType = getDocumentType(docType);
var config = {
type: "desktop",
width: '100%',
height: '100%',
documentType: documentType,
document: {
title: docTitle,
url: docUrl,
fileType: docType,
key: docKey,
permissions: {
edit: true,
download: false
}
},
editorConfig: {
mode: 'edit',
callbackUrl:"/documentSave"
},
events: {
onReady: function () {alert("in on ready");
setTimeout(function () {
$scope.$apply(function () {
$scope.ready = true;
});
}, 5000);
},
onError: function (event) {
alert(event.data);
// var url = event.data;
// $scope.save({url: url, close: $scope.close});
},
}
};
//creating object editing
new DocsAPI.DocEditor("onlyoffice-editor", config);
});
}
}
}]);
angular.module('onlyoffice',[]);
angular.module('onlyoffice')。指令('onlyofficeEditor',[function(){
功能键(k){
var result=k.replace(新的RegExp(“[^0-9-.a-zA-Z=”,“g”),“”)+(新的
Date()).getTime();
返回result.substring(result.length-Math.min(result.length,50));
}
var getDocumentType=函数(ext){
如果(“.docx.doc.odt.rtf.txt.html.htm.mht.pdf.djvu.fb2.epub.xps”.indexOf(ext)!=-1)返回“text”;
如果(“.xls.xlsx.ods.csv”.indexOf(ext)!=-1)返回“电子表格”;
如果(“.pps.ppsx.ppt.pptx.odp”.indexOf(ext)!=-1)返回“演示”;
返回null;
};
返回{
模板:“”,
链接:函数($scope、$element、$attrs){
$scope.$watch(函数(){
返回$attrs.src;
},函数(){
如果(!$attrs.src)返回;
var docUrl=$attrs.src;
var docTitle=$attrs.title | | docUrl;
var docKey=键(docUrl);
var docType=docUrl.split(“?”)[0]。子字符串(docUrl.lastIndexOf(“.”+1)。trim().toLowerCase();
var documentType=getDocumentType(docType);
变量配置={
键入:“桌面”,
宽度:“100%”,
高度:“100%”,
documentType:documentType,
文件:{
标题:docTitle,
url:docUrl,
文件类型:docType,
关键:多奇,
权限:{
编辑:对,
下载:false
}
},
编辑配置:{
模式:“编辑”,
callbackUrl:“/documentSave”
},
活动:{
onReady:function(){alert(“in on ready”);
setTimeout(函数(){
$scope.$apply(函数(){
$scope.ready=true;
});
}, 5000);
},
onError:功能(事件){
警报(事件数据);
//var url=event.data;
//$scope.save({url:url,close:$scope.close});
},
}
};
//创建对象编辑
新的DocsAPI.DocEditor(“onlyofficeeditor”,config);
});
}
}
}]);
我还使用localhost和appname将documenSave更改为完全限定名,但这也不起作用。
非常感谢您的帮助
编辑
现在浏览器按钮关闭时调用CallBackUrl…但我们的要求是在单击“保存”按钮时保存文档。
提前感谢。事实上,单击“保存”按钮会在文档编辑器中创建一个临时文件。只有在所有用户关闭文档编辑器后(十秒钟内),才会创建工作文档版本。
无法实时下载更改后的文档(在关闭文档之前)。事实上,单击“保存”按钮会在文档编辑器中创建临时文件。只有在所有用户关闭文档编辑器后(十秒钟内),才会创建工作文档版本。 无法实时下载更改的文档(在关闭文档之前)