';
$('#controls').append(odfToolbarHtml);
var memberId, odfelement, odfcanvas, canvashtml =
'
' +
'
' +
'
' +
' ' +
'
' +
'
' +
'
' +
'
' +
'
' +
' ' +
' ' +
'
' +
'
' +
'
' +
'
';
var serverFactory = new ServerFactory();
$(document.body).addClass("claro");
$('.documentslist, #emptyfolder').after(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.webodfEditorInstance = new Editor({}, documentsMain.webodfServerInstance, serverFactory);
// load the document and get called back when it's live
documentsMain.webodfEditorInstance.loadSession(response.es_id, memberId, function() {
documentsMain.webodfEditorInstance.startEditing();
});
});
});
},
startSession: function(fileid) {
"use strict";
console.log('starting session for fileid '+fileid);
if (documentsMain.initialized === undefined) {
alert("WebODF Editor not yet initialized...");
return;
}
$.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 ($(this).attr('data-esid')){
documentsMain.joinSession($(this).attr('data-esid'));
} else if ($(this).attr('data-id')){
documentsMain.startSession($(this).attr('data-id'));
}
});
$('#content').on('click', '#odf_close', documentsMain.onClose);
$('#content').on('click', '#odf_invite', documentsMain.onInvite);
$('#content').on('click', '#invite-send', documentsMain.sendInvite);
$('#content').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', 'dojo-amalgamation', documentsMain.onStartup);
});