/*globals $,OC,fileDownloadPath,t,document,odf,alert,require,dojo,runtime,Handlebars */ $.widget('oc.documentGrid', { options : { context : '.documentslist', documents : {}, sessions : {}, members : {} }, render : function(fileId) { var that = this; jQuery.when(this._load(fileId)) .then(function(){ that._render(); documentsMain.renderComplete = true; }); }, _load : function(fileId) { // Handle guest user case (let users which are able to write set their name) if (!richdocuments_directEdit && window.top.oc_current_user == null && this._getGuestNameCookie() == '' && (richdocuments_permissions & OC.PERMISSION_UPDATE)) { $('#documentslist').remove(); var text = document.createElement('div'); $(text).attr('style', 'margin: 0 auto; margin-top: 100px; text-align: center;'); var para = t('richdocuments', 'Please choose your nickname to continue as guest user.'); text.innerHTML = para; var div = document.createElement('div'); $(div).attr('style', 'margin: 0 auto; width: 195px;'); var nick = ''; var btn = ''; div.innerHTML = nick + btn; $('#documents-content').prepend(div); $('#documents-content').prepend(text); var that = this; $('#nickname').keyup(function(event) { if (event.which === 13) { that._setGuestNameCookie(); } }); $('#btn').click(that._setGuestNameCookie); $('#preview').hide(); // return such that the editor rendering is skipped. The (parent) page // will be reloaded with the cookie set when the user submits the form. return; } // standard case, render the editor documentsMain.initSession(); }, _getGuestNameCookie: function() { var name = 'guestUser='; var decodedCookie = decodeURIComponent(document.cookie); var cookieArr = decodedCookie.split(';'); for (var i = 0; i < cookieArr.length; i++) { var c = cookieArr[i]; while (c.charAt(0) == ' ') { c = c.substring(1); } if (c.indexOf(name) == 0) { return c.substring(name.length, c.length); } } return ''; }, _setGuestNameCookie: function() { var username = $('#nickname').val(); if (username != '') { document.cookie = 'guestUser=' + encodeURIComponent(username) + '; path=/'; } location.reload(true); }, _render : function(data) { var that = this, documents = data && data.documents || this.options.documents, sessions = data && data.sessions || this.options.sessions, members = data && data.members || this.options.members, hasDocuments = false ; $(this.options.context + ' .document:not(.template,.progress)').remove(); if (documentsMain.loadError) { $(this.options.context).after('
' + '

' + documentsMain.loadErrorMessage + '

' + documentsMain.loadErrorHint + '

' ); return; } } }); $.widget('oc.documentOverlay', { options : { parent : 'document.body' }, _create : function (){ $(this.element).hide().appendTo(document.body); }, show : function(){ $(this.element).fadeIn('fast'); }, hide : function(){ $(this.element).fadeOut('fast'); } }); var documentsMain = { isEditorMode : false, isViewerMode: false, ready :false, fileName: null, baseName: null, canShare : false, canEdit: false, loadError : false, loadErrorMessage : '', loadErrorHint : '', renderComplete: false, // false till page is rendered with all required data about the document(s) toolbar : '
', $deferredVersionRestoreAck: null, wopiClientFeatures: null, // generates docKey for given fileId _generateDocKey: function(wopiFileId) { var ocurl = OC.generateUrl('apps/richdocuments/wopi/files/{file_id}', {file_id: wopiFileId}); if (richdocuments_canonical_webroot) { if (!richdocuments_canonical_webroot.startsWith('/')) richdocuments_canonical_webroot = '/' + richdocuments_canonical_webroot; ocurl = ocurl.replace(OC.getRootPath(), richdocuments_canonical_webroot); } return ocurl; }, UI : { /* Editor wrapper HTML */ container : '
' + '
', viewContainer: '
' + '
' + '
', /* Previous window title */ mainTitle : '', /* Number of revisions already loaded */ revisionsStart: 0, /* Views: people currently editing the file */ views: [], init : function(){ documentsMain.UI.mainTitle = parent.document.title; //Add the avatar toolbar if possible var headerRight = parent.$('#header .header-right'); headerRight.prepend($('
')); }, renderAvatars: function() { var avatardiv = parent.$('#header .header-right #richdocuments-avatars'); avatardiv.empty(); // Add new avatars this.views.forEach(function(view, viewId) { if (view.UserId === parent.OC.currentUser) { return; } var avatarContainer = $('
'); var avatar = avatarContainer.find('.avatar'); avatardiv.append(avatarContainer); $(avatar).avatar(view.UserId, 32); $(avatar).tooltip({placement: 'bottom'}); $(avatar).contactsMenu(view.UserId, 0, avatarContainer); }); }, showViewer: function(fileId, title){ // remove previous viewer, if open, and set a new one if (documentsMain.isViewerMode) { $('#revViewer').remove(); $('#revViewerContainer').prepend($('
')); } // WOPISrc - URL that loolwsd will access (ie. pointing to ownCloud) var wopiurl = window.location.protocol + '//' + window.location.host + OC.generateUrl('apps/richdocuments/wopi/files/{file_id}', {file_id: fileId}); var wopisrc = encodeURIComponent(wopiurl); // urlsrc - the URL from discovery xml that we access for the particular // document; we add various parameters to that. // The discovery is available at // https://:9980/hosting/discovery var urlsrc = documentsMain.urlsrc + "WOPISrc=" + wopisrc + "&title=" + encodeURIComponent(title) + "&lang=" + OC.getLocale().replace('_', '-') + // loleaflet expects a BCP47 language tag syntax "&permission=readonly"; // access_token - must be passed via a form post var access_token = encodeURIComponent(documentsMain.token); // form to post the access token for WOPISrc var form = '
' + '
'; // iframe that contains the Collabora Online Viewer var frame = '