import { emit } from '@nextcloud/event-bus' import { getRootUrl } from '@nextcloud/router' import { getRequestToken } from '@nextcloud/auth' import Config from './services/config.tsx' import { setGuestName, shouldAskForGuestName } from './helpers/guestName' import { getUIDefaults, generateCSSVarTokens, getCollaboraTheme } from './helpers/coolParameters' import PostMessageService from './services/postMessage.tsx' import { callMobileMessage, isDirectEditing, isMobileInterfaceAvailable, } from './helpers/mobile' import { getWopiUrl, getSearchParam } from './helpers/url' import '../css/document.scss' const PostMessages = new PostMessageService({ parent: window.parent, loolframe: () => document.getElementById('loleafletframe').contentWindow, }) let checkingProxyStatus = false const checkProxyStatus = () => { checkingProxyStatus = true const url = Config.get('urlsrc').substr(0, Config.get('urlsrc').indexOf('proxy.php') + 'proxy.php'.length) $.get(url + '?status').done(function(val) { if (val && val.status && val.status !== 'OK') { if (val.status === 'starting' || val.status === 'stopped') { document.getElementById('proxyLoadingIcon').classList.add('icon-loading-small') document.getElementById('proxyLoadingMessage').textContent = t('richdocuments', 'Built-in CODE Server is starting up shortly, please wait.') } else if (val.status === 'restarting') { document.getElementById('proxyLoadingIcon').classList.add('icon-loading-small') document.getElementById('proxyLoadingMessage').textContent = t('richdocuments', 'Built-in CODE Server is restarting, please wait.') } else if (val.status === 'error') { if (val.error === 'appimage_missing') { document.getElementById('proxyLoadingMessage').textContent = t('richdocuments', 'Error: Cannot find the AppImage, please reinstall the Collabora Online Built-in server.') } else if (val.error === 'chmod_failed' || val.error === 'appimage_not_executable') { document.getElementById('proxyLoadingMessage').textContent = t('richdocuments', 'Error: Unable to make the AppImage executable, please setup a standalone server.') } else if (val.error === 'exec_disabled') { document.getElementById('proxyLoadingMessage').textContent = t('richdocuments', 'Error: Exec disabled in PHP, please enable it, or setup a standalone server.') } else if (val.error === 'not_linux' || val.error === 'not_x86_64' || val.error === 'not_aarch64') { document.getElementById('proxyLoadingMessage').textContent = t('richdocuments', 'Error: Not running on x86-64 or ARM64 (aarch64) Linux, please setup a standalone server.') } else if (val.error === 'no_fontconfig') { document.getElementById('proxyLoadingMessage').textContent = t('richdocuments', 'Error: The fontconfig library is not installed on your server, please install it or setup a standalone server.') } else if (val.error === 'no_glibc') { document.getElementById('proxyLoadingMessage').textContent = t('richdocuments', 'Error: Not running on glibc-based Linux, please setup a standalone server.') } else { document.getElementById('proxyLoadingMessage').textContent = t('richdocuments', 'Error: Cannot start the Collabora Online Built-in server, please setup a standalone one.') } // probably not even worth re-trying return } // retry... setTimeout(function() { checkProxyStatus() }, 100) return } checkingProxyStatus = false }) } const showLoadingIndicator = () => { if ((OC.appswebroots.richdocumentscode || OC.appswebroots.richdocumentscode_arm64) && Config.get('urlsrc').indexOf('proxy.php') >= 0) { checkProxyStatus() } else { document.getElementById('loadingContainer').classList.add('icon-loading') } } const hideLoadingIndicator = () => { if (checkingProxyStatus) { setTimeout(function() { hideLoadingIndicator() }, 100) return } document.getElementById('loadingContainer').classList.remove('icon-loading') document.getElementById('proxyLoadingIcon').classList.remove('icon-loading-small') document.getElementById('proxyLoadingMessage').textContent = '' } showLoadingIndicator() $.widget('oc.guestNamePicker', { _create() { hideLoadingIndicator() const text = document.createElement('div') text.setAttribute('style', 'margin: 0 auto; margin-top: 100px; text-align: center;') text.innerHTML = t('richdocuments', 'Please choose your nickname to continue as guest user.') const div = document.createElement('div') div.setAttribute('style', 'margin: 0 auto; width: 250px; display: flex;') const nick = '' const btn = '' div.innerHTML = nick + btn $('#documents-content').prepend(div) $('#documents-content').prepend(text) const setGuestNameSubmit = () => { const username = $('#nickname').val() div.remove() text.innerText = '' text.classList.add('icon-loading') setGuestName(username).then(() => { $('#documents-content').remove() documentsMain.initSession() }) } $('#nickname').keyup(function(event) { if (event.which === 13) { setGuestNameSubmit() } }) $('#btn').click(() => setGuestNameSubmit()) }, }) /** * Type definitions for WOPI Post message objects * * @typedef {Object} View * @property {Number} ViewId * @property {string} UserName * @property {string} UserId * @property {Number} Color * @property {Boolean} ReadOnly * @property {Boolean} IsCurrentView */ const documentsMain = { isEditorMode: false, isViewerMode: false, isFrameReady: false, isPublic: false, ready: false, fileName: null, baseName: null, canShare: false, canEdit: false, renderComplete: false, // false till page is rendered with all required data about the document(s) $deferredVersionRestoreAck: null, wopiClientFeatures: null, // generates docKey for given fileId _generateDocKey(wopiFileId) { let canonicalWebroot = Config.get('canonical_webroot') let ocurl = getRootUrl() + '/index.php/apps/richdocuments/wopi/files/' + wopiFileId if (canonicalWebroot) { if (!canonicalWebroot.startsWith('/')) { canonicalWebroot = '/' + canonicalWebroot } Config.update('canonical_webroot', canonicalWebroot) ocurl = ocurl.replace(getRootUrl(), canonicalWebroot) } return ocurl }, UI: { /* Editor wrapper HTML */ container: '
' + '
', viewContainer: '
' + '
' + '
', showViewer(fileId, title) { // remove previous viewer, if open, and set a new one if (documentsMain.isViewerMode) { $('#revViewer').remove() $('#revViewerContainer').prepend($('
')) } const urlsrc = getWopiUrl({ fileId, title, readOnly: true, closeButton: !documentsMain.isPublic || documentsMain.originalFileId }) // access_token - must be passed via a form post const accessToken = encodeURIComponent(documentsMain.token) // form to post the access token for WOPISrc const form = '
' + '' + '' + '' + '' + '
' // iframe that contains the Collabora Online Viewer const frame = '