/*globals $,OC,fileDownloadPath,t,document,odf,webodfEditor,alert,require,dojo,runtime */
var officeMain = {
useUnstable : false,
onStartup: function() {
"use strict";
OC.addScript('office', 'webodf_bootstrap', function() {
OC.addScript('office', 'webodf-debug').done(function() {
require({}, ["dojo/ready"], function(ready) {
ready(function() {
require({}, ["webodf/editor/Editor"], function(Editor) {
if (Editor && typeof(Editor) === 'function') {
officeMain.initialized = 1;
} else {
alert("initialization of webodf/editor/Editor\n" +
"failed somehow...");
}
});
});
});
});
});
setInterval(officeMain.updateInfo, 10000);
},
initSession: function(response) {
"use strict";
OC.addScript('office', 'editor/boot_editor').done(function() {
var doclocation = response.es_id;
// fade out file list and show WebODF canvas
$('.documentslist, #emptyfolder, #editing-sessions').fadeOut('slow').promise().done(function() {
// odf action toolbar
var odfToolbarHtml =
'
' +
' ' +
' ' +
' ' +
'
';
$('#controls').append(odfToolbarHtml);
$('#office-content').addClass('wide');
var memberId, odfelement, odfcanvas, canvashtml =
'';
$(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;
webodfEditor.boot(
{
collaborative: "owncloud",
docUrl: doclocation,
loginProcedure: function(cb) {
cb(response.es_id, OC.currentUser, "token");
},
joinSession: function(userId, sessionId, cb) {
cb(memberId);
},
callback: function(webodfEditorInstance) {
officeMain.webodfEditorInstance = webodfEditorInstance;
}
}
);
});
});
},
startSession: function(filepath) {
"use strict";
if (officeMain.initialized === undefined) {
alert("WebODF Editor not yet initialized...");
return;
}
$.post(OC.Router.generate('office_session_start'),
{'fileid': filepath},
officeMain.initSession
);
},
joinSession: function(esId) {
$.post(OC.Router.generate('office_session_join') + '/' + esId,
{},
officeMain.initSession
);
},
updateInfo : function(){
var fileIds = [];
$('.documentslist tr').each(function(i, e){
fileIds.push($(e).attr('data-file'));
});
$.post(
OC.Router.generate('office_session_info'),
{items: fileIds},
function (response){
if (response && response.info && response.info.length){
for (var i=0;i 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);
}
});
$('#settingsbtn').on('click keydown', function() {
try {
OC.appSettings({appid:'office', loadJS:true, cache:false});
} catch(e) {
console.log(e);
}
});
OC.addScript('office', 'dojo-amalgamation', officeMain.onStartup);
});