/*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){ var that = this; var url = 'apps/richdocuments/ajax/documents/list'; var dataObj = {}; if (fileId){ url = 'apps/richdocuments/ajax/documents/get/{fileId}'; dataObj = { fileId: fileId }; } return $.getJSON(OC.generateUrl(url, dataObj)) .done(function (result) { if (!result || result.status === 'error') { documentsMain.loadError = true; if (result && result.message) { documentsMain.loadErrorMessage = result.message; } else { documentsMain.loadErrorMessage = t('richdocuments', 'Failed to load the document, please contact your administrator.'); } if (result && result.hint) { documentsMain.loadErrorHint = result.hint; } } else { that.options.documents = result.documents; that.options.sessions = result.sessions; that.options.members = result.members; documentsMain.urlsrc = result.documents[0].urlsrc; documentsMain.fullPath = result.documents[0].path; } }) .fail(function(data){ console.log(t('richdocuments','Failed to load documents.')); }); }, _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, isGuest : false, memberId : false, esId : 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 : '
', returnToDir : null, // directory where we started from in the 'Files' app UI : { /* Editor wrapper HTML */ container : '
' + '
', viewContainer: '
' + '
' + '
', revHistoryContainerTemplate: '
' + '
' + '

Revision History

' + '{{filename}}' + '' + '
' + '
' + '' + '
' + '' + '
', revHistoryItemTemplate: '
  • ' + '' + '{{relativeTimestamp}}' + '' + '' + '
  • ', /* Previous window title */ mainTitle : '', /* Number of revisions already loaded */ revisionsStart: 0, init : function(){ documentsMain.UI.mainTitle = $('title').text(); }, showViewer: function(fileId, title){ // remove previous viewer, if open, and set a new one if (documentsMain.isViewerMode) { $('#revViewer').remove(); $('#revViewerContainer').prepend($('
    ')); } $.get(OC.generateUrl('apps/richdocuments/wopi/token/{fileId}', { fileId: fileId }), function (result) { // 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() + "&permission=readonly"; // access_token - must be passed via a form post var access_token = encodeURIComponent(result.token); // form to post the access token for WOPISrc var form = '
    ' + '
    '; // iframe that contains the Collabora Online Viewer var frame = '