/*globals $,OC,fileDownloadPath,t,document,odf,webodfEditor,alert,require,dojo,runtime */ var documentsMain = { _documents: [], _sessions: [], _members: [], isEditormode : false, useUnstable : false, onStartup: function() { "use strict"; $('
').hide().appendTo(document.body); OC.addScript('documents', 'dojo-amalgamation', function() { OC.addScript('documents', 'webodf-debug').done(function() { // preload stuff in the background require({}, ["dojo/ready"], function(ready) { ready(function() { require({}, ["webodf/editor/Editor"], function(Editor) { }); }); }); }); }); //setInterval(documentsMain.updateInfo, 10000); }, initSession: function(response) { "use strict"; runtime.assert(response.status, "Server error"); if (response.status==='error'){ OC.Notification.show(t('documents', 'Oops! This document has been either unshared or deleted recently.')); setTimeout(OC.Notification.hide, 3000); documentsMain.hideOverlay(); return; } require({ }, ["webodf/editor/server/owncloud/ServerFactory", "webodf/editor/Editor"], function (ServerFactory, Editor) { // fade out file list and show WebODF canvas $('#content').fadeOut('slow').promise().done(function() { // odf action toolbar var odfToolbarHtml = '
' + ' ' + ' ' + ' ' + '
'; $(document.body).prepend(odfToolbarHtml); var memberId, odfelement, odfcanvas, canvashtml = '
' + '
' + '
' + '
' + '
' + '
' + '
' + '
' + '
' + '
' + '
' + '
' + '
' + '
' + '
'; var serverFactory = new ServerFactory(); $(document.body).addClass("claro"); $(document.body).prepend(canvashtml); // in case we are on the public sharing page we shall display the odf into the preview tag $('#preview').html(canvashtml); runtime.assert(response.es_id, "invalid session id."); memberId = response.member_id; documentsMain.webodfServerInstance = serverFactory.createServer(); documentsMain.webodfServerInstance.setToken(oc_requesttoken); documentsMain.webodfEditorInstance = new Editor({unstableFeaturesEnabled: documentsMain.useUnstable}, documentsMain.webodfServerInstance, serverFactory); // load the document and get called back when it's live documentsMain.webodfEditorInstance.openSession(response.es_id, memberId, function() { documentsMain.webodfEditorInstance.startEditing(); documentsMain.hideOverlay(); }); }); }); }, startSession: function(fileid) { "use strict"; console.log('starting session for fileid '+fileid); $.post( OC.Router.generate('documents_session_start'), {'fileid': fileid}, documentsMain.initSession ); }, joinSession: function(esId) { console.log('joining session '+esId); $.post( OC.Router.generate('documents_session_join') + '/' + esId, {}, documentsMain.initSession ); }, /** * FIXME * updateInfo : function(){ var fileIds = []; $('.documentslist li').each(function(i, e){ fileIds.push($(e).attr('data-file')); }); $.post( OC.Router.generate('documents_session_info'), {items: fileIds}, function (response){ if (response && response.info && response.info.length){ for (var i=0;i 0) { var docElem = $('.documentslist .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); } } }); } }; /** * TODO copy from files, move from files to core? load files.js? * @param {type} mime * @returns {getMimeIcon} */ function getMimeIcon(mime){ var def = new $.Deferred(); if(getMimeIcon.cache[mime]){ def.resolve(getMimeIcon.cache[mime]); }else{ jQuery.getJSON( OC.filePath('documents','ajax','mimeicon.php'), {mime: mime}) .done(function(data){ getMimeIcon.cache[mime]=data.path; def.resolve(getMimeIcon.cache[mime]); }) .error(function(jqXHR, textStatus, errorThrown){ console.log(textStatus + ': ' + errorThrown); console.log(jqXHR); }); } return def; } getMimeIcon.cache={}; $(document).ready(function() { "use strict"; $('.documentslist').on('click', 'li', function(event) { event.preventDefault(); if (documentsMain.isEditorMode){ return; } documentsMain.isEditorMode = true; documentsMain.showOverlay(); if ($(this).attr('data-esid')){ documentsMain.joinSession($(this).attr('data-esid')); } else if ($(this).attr('data-id')){ documentsMain.startSession($(this).attr('data-id')); } }); $(document.body).on('click', '#odf-close', documentsMain.onClose); $(document.body).on('click', '#odf-invite', documentsMain.onInvite); $(document.body).on('click', '#invite-send', documentsMain.sendInvite); $(document.body).on('click', '#invitee-list li', function(){ $(this).remove(); }); $('#inivite-input').autocomplete({ minLength: 1, source: function(search, response) { $.get( OC.Router.generate('documents_user_search'), {search: $('#inivite-input').val()}, function(result) { if (result.status === 'success' && result.data.length > 0) { response(result.data); } else { response([t('core', 'No people found')]); } } ); }, select: function(event, el) { event.preventDefault(); var item = $( '
  • ' + el.item.label + '' + '
  • ' ); $('#invitee-list').prepend(item); } }); jQuery.when(documentsMain.loadDocuments()) .then(function(){ documentsMain.renderDocuments(); }); //TODO show "no docs, please upload" //TODO when ending a session as the last user close session? OC.addScript('documents', 'webodf_bootstrap', documentsMain.onStartup); });