/*globals $,OC,fileDownloadPath,t,document,odf,alert,require,dojo,runtime */ $.widget('oc.documentGrid', { options : { context : '.documentslist', documents : {}, sessions : {}, members : {} }, _create : function (){ }, render : function(){ var that = this; jQuery.when(this._load()) .then(function(){ that._render(); }); }, add : function(document) { var docElem = $(this.options.context + ' .template').clone(), a = docElem.find('a') ; //Fill an element docElem.removeClass('template').attr('data-id', document.fileid); a.css('background-image', 'url("'+document.icon+'")') .attr('href', OC.generateUrl('apps/files/download{file}',{file:document.path})) .attr('original-title', document.path) .find('label').text(document.name) ; docElem.appendTo(this.options.context).show(); //Preview var previewURL, urlSpec = { file : document.path.replace(/^\/\//, '/'), x : 200, y : 200, c : document.etag, forceIcon : 0 }; if ( $('#isPublic').length ) { urlSpec.t = $('#dirToken').val(); } if (!urlSpec.x) { urlSpec.x = $('#filestable').data('preview-x'); } if (!urlSpec.y) { urlSpec.y = $('#filestable').data('preview-y'); } urlSpec.y *= window.devicePixelRatio; urlSpec.x *= window.devicePixelRatio; previewURL = OC.generateUrl('/core/preview.png?') + $.param(urlSpec); previewURL = previewURL.replace('(', '%28').replace(')', '%29'); if ( $('#previews_enabled').length && document.hasPreview) { var img = new Image(); img.onload = function(){ var ready = function (node){ return function(path){ node.css('background-image', 'url("'+ path +'")'); }; }(a); ready(previewURL); }; img.src = previewURL; } }, _load : function (){ var that = this; var def = new $.Deferred(); $.getJSON(OC.generateUrl('apps/richdocuments/ajax/documents/list')) .done(function (data) { that.options.documents = data.documents; that.options.sessions = data.sessions; that.options.members = data.members; def.resolve(); }) .fail(function(data){ console.log(t('richdocuments','Failed to load documents.')); }); return def; }, _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(); $.each(documents, function(i, document){ hasDocuments = true; that.add(document); }); $.each(sessions, function(i, session){ if (members[session.es_id].length > 0) { var docElem = $(that.options.context + ' .document[data-id="'+session.file_id+'"]'); if (docElem.length > 0) { docElem.attr('data-esid', session.es_id); docElem.find('label').after(''); docElem.addClass('session'); } else { console.log('Could not find file '+session.file_id+' for session '+session.es_id); } } }); if (!hasDocuments){ $(this.options.context).before('
' + t('richdocuments', 'No documents were found. Upload or create a document to get started!') + '
' ); } else { $('#emptycontent').remove(); } } }); $.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, isGuest : false, memberId : false, esId : false, ready :false, fileName: null, baseName: null, url: null, canShare : false, toolbar : '
', UI : { /* Editor wrapper HTML */ container : '
' + '
', /* Previous window title */ mainTitle : '', init : function(){ documentsMain.UI.mainTitle = $('title').text(); }, showEditor : function(title){ if (documentsMain.isGuest){ // !Login page mess wih WebODF toolbars $(document.body).attr('id', 'body-user'); } $(document.body).addClass("claro"); $(document.body).prepend(documentsMain.UI.container); $('title').text(title + ' - ' + documentsMain.UI.mainTitle); var viewer = window.location.protocol + '//' + window.location.host + '/cloudsuite/cloudsuite.html?' + 'file_path=' + documentsMain.url + '&host=' + 'ws://' + window.location.hostname + ':9980' + '&edit=' + 'false' + '×tamp=' + ''; var frame = '