import { getRootUrl } from '@nextcloud/router' import { getRequestToken } from '@nextcloud/auth' import Config from './services/config' import { setGuestNameCookie, shouldAskForGuestName } from './helpers/guestName' import PostMessageService from './services/postMessage' 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 }) var checkingProxyStatus = false const checkProxyStatus = () => { checkingProxyStatus = true var 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 = '' } const generateCSSVarTokens = () => { /* NC versus COOL */ var cssVarMap = { '--color-main-text': '--co-color-main-text', '--color-main-background': '--co-body-bg', '--color-primary-text': '--co-primary-text', '--color-primary-element': '--co-primary-element:--co-text-accent', '--color-primary-element-light': '--co-primary-element-light', '--color-error': '--co-color-error', '--color-warning': '--co-color-warning', '--color-success': '--co-color-success', '--border-radius': '--co-border-radius', '--border-radius-large': '--co-border-radius-large', '--color-background-hover': '--co-background-hover', '--color-background-dark': '--co-background-dark', '--color-text-light': '--co-text-light', '--color-text-lighter': '--co-text-lighter', '--color-loading-light': '--co-loading-light', '--color-loading-dark': '--co-loading-dark', '--color-box-shadow': '--co-box-shadow', '--color-border': '--co-border', '--color-border-dark': '--co-border-dark', '--border-radius-pill': '--co-border-radius-pill' } var str = '' try { for (var cssVarKey in cssVarMap) { var cStyle = window.parent.getComputedStyle(document.documentElement).getPropertyValue(cssVarKey) if (!cStyle) { // try suffix -dark instead cStyle = window.parent.getComputedStyle(document.documentElement).getPropertyValue(cssVarKey + '-dark') } if (!cStyle) continue // skip if it is not set var varNames = cssVarMap[cssVarKey].split(':') for (var i = 0; i < varNames.length; ++i) { str += varNames[i] + '=' + cStyle + ';' } } } catch (e) { // Skip extracting css vars if we cannot access parent } return str } showLoadingIndicator() $.widget('oc.guestNamePicker', { _create: function() { 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() setGuestNameCookie(username) window.location.reload(true) } $('#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, 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: function(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: function(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 }) // 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 = '