Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl 2019-07-04 17:41:09 +02:00
Родитель e188ef3537
Коммит 896d3a402c
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4C614C6ED2CDE6DF
2 изменённых файлов: 41 добавлений и 10 удалений

Просмотреть файл

@ -1,3 +1,5 @@
import { getRootPath } from 'nextcloud-server/dist/router'
import { languageToBCP47 } from './helpers'
/* TODO: move to one object */
/* global richdocuments_directEdit richdocuments_fileId richdocuments_urlsrc richdocuments_token richdocuments_path richdocuments_permissions richdocuments_title getURLParameter richdocuments_canonical_webroot */
@ -142,11 +144,11 @@ var documentsMain = {
// generates docKey for given fileId
_generateDocKey: function(wopiFileId) {
var ocurl = OC.getRootPath() + '/index.php/apps/richdocuments/wopi/files/' + wopiFileId
var ocurl = getRootPath() + '/index.php/apps/richdocuments/wopi/files/' + wopiFileId
if (richdocuments_canonical_webroot) {
if (!richdocuments_canonical_webroot.startsWith('/')) { richdocuments_canonical_webroot = '/' + richdocuments_canonical_webroot }
ocurl = ocurl.replace(OC.getRootPath(), richdocuments_canonical_webroot)
ocurl = ocurl.replace(getRootPath(), richdocuments_canonical_webroot)
}
return ocurl
@ -165,10 +167,6 @@ var documentsMain = {
return null
},
getLanguage: function() {
return OC.getLanguage ? OC.getLanguage() : OC.getLocale()
},
UI: {
/* Editor wrapper HTML */
container: '<div id="mainContainer" class="claro">'
@ -380,7 +378,7 @@ var documentsMain = {
// WOPISrc - URL that loolwsd will access (ie. pointing to ownCloud)
// index.php is forced here to avoid different wopi srcs for the same document
var wopiurl = window.location.protocol + '//' + window.location.host + OC.getRootPath() + '/index.php/apps/richdocuments/wopi/files/' + fileId
var wopiurl = window.location.protocol + '//' + window.location.host + getRootPath() + '/index.php/apps/richdocuments/wopi/files/' + fileId
var wopisrc = encodeURIComponent(wopiurl)
// urlsrc - the URL from discovery xml that we access for the particular
@ -390,7 +388,7 @@ var documentsMain = {
var urlsrc = documentsMain.urlsrc
+ 'WOPISrc=' + wopisrc
+ '&title=' + encodeURIComponent(title)
+ '&lang=' + documentsMain.getLanguage().replace('_', '-') // loleaflet expects a BCP47 language tag syntax
+ '&lang=' + languageToBCP47()
+ '&permission=readonly'
// access_token - must be passed via a form post
@ -562,7 +560,7 @@ var documentsMain = {
$(document.body).prepend(documentsMain.UI.container)
// WOPISrc - URL that loolwsd will access (ie. pointing to ownCloud)
var wopiurl = window.location.protocol + '//' + window.location.host + OC.getRootPath() + '/index.php/apps/richdocuments/wopi/files/' + documentsMain.fileId
var wopiurl = window.location.protocol + '//' + window.location.host + getRootPath() + '/index.php/apps/richdocuments/wopi/files/' + documentsMain.fileId
var wopisrc = encodeURIComponent(wopiurl)
// urlsrc - the URL from discovery xml that we access for the particular
@ -572,7 +570,7 @@ var documentsMain = {
var urlsrc = documentsMain.urlsrc
+ 'WOPISrc=' + wopisrc
+ '&title=' + encodeURIComponent(title)
+ '&lang=' + documentsMain.getLanguage().replace(/^([a-z]{2}).*_([A-Z]{2})$/, function(match, p1, p2) { return p1 + '-' + p2.toLowerCase() }) // loleaflet expects a BCP47 language tag syntax
+ '&lang=' + languageToBCP47()
+ '&closebutton=1'
+ '&revisionhistory=1'
if (!documentsMain.canEdit || action === 'view') {

33
src/helpers/index.js Normal file
Просмотреть файл

@ -0,0 +1,33 @@
/*
* @copyright Copyright (c) 2019 Julius Härtl <jus@bitgrid.net>
*
* @author Julius Härtl <jus@bitgrid.net>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
import { getLanguage } from 'nextcloud-server/dist/l10n'
const languageToBCP47 = () => {
// loleaflet expects a BCP47 language tag syntax
return getLanguage()
.replace(/^([a-z]{2}).*_([A-Z]{2})$/, (match, p1, p2) => p1 + '-' + p2.toLowerCase())
}
export {
languageToBCP47
}