richdocuments/js/office.js

148 lines
4.4 KiB
JavaScript
Raw Normal View History

2013-07-12 22:16:08 +02:00
/*globals $,OC,fileDownloadPath,t,document,odf,webodfEditor,alert,require,dojo */
2013-07-01 22:36:17 +03:00
var officeMain = {
2013-07-12 16:00:07 +02:00
onStartup: function() {
2013-07-12 22:16:08 +02:00
"use strict";
2013-07-12 16:28:33 +02:00
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...");
}
});
2013-07-12 16:28:33 +02:00
});
});
});
2013-07-12 16:00:07 +02:00
});
},
2013-08-07 02:35:46 +03:00
onView: function(response) {
"use strict";
2013-08-07 02:35:46 +03:00
OC.addScript('office', 'editor/boot_editor').done(function() {
2013-08-07 02:35:46 +03:00
var doclocation = response.genesis_url;
// fade out files menu and add odf menu
2013-08-08 19:55:30 +03:00
$('.documentslist, #emptyfolder').fadeOut('slow').promise().done(function() {
// odf action toolbar
var odfToolbarHtml =
'<div id="odf-toolbar">' +
'<button style="float:left" id="odf_close">' + t('files_odfviewer', 'Close') + '</button>' +
'<span id="toolbar" class="claro"></span>' +
'</div>';
$('#controls').append(odfToolbarHtml);
//$('#controls').append('<span id="toolbar" class="claro"></span>');
});
// fade out file list and show WebODF canvas
2013-08-08 19:55:30 +03:00
$('.documentslist, #emptyfolder').fadeOut('slow').promise().done(function() {
var odfelement, odfcanvas, canvashtml =
2013-08-05 21:58:56 +02:00
'<div id = "mainContainer" class="claro" style="">'+
'<div id = "editor">'+
2013-07-12 23:48:42 +02:00
//'<span id = "toolbar" class="claro"></span>'+
2013-07-12 16:28:33 +02:00
'<div id = "container">'+
'<div id="canvas"></div>'+
2013-07-12 16:28:33 +02:00
'</div>'+
'</div>'+
'<div id = "collaboration">'+
'<div id = "collabContainer">'+
'<div id = "people">'+
'<div id = "inviteButton"></div>'+
'<div id = "peopleList"></div>'+
'</div>'+
'</div>'+
'</div>'+
'</div>',
bodyelement = document.getElementsByTagName('body')[0];
bodyelement.className += " claro";
2013-08-08 19:55:30 +03:00
$('.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);
2013-07-01 22:36:17 +03:00
2013-08-07 13:04:42 +02:00
runtime.assert(response.es_id, "invalid session id.");
webodfEditor.boot(
{
2013-07-17 00:17:58 +02:00
collaborative: "owncloud",
docUrl: doclocation,
loginProcedure: function(cb) {
2013-08-07 13:04:42 +02:00
cb(response.es_id, OC.currentUser, "token");
},
callback: function() {
2013-07-12 23:48:42 +02:00
// initialized.
}
}
);
2013-07-01 22:36:17 +03:00
// odfelement = document.getElementById("odf-canvas");
// odfcanvas = new odf.OdfCanvas(odfelement);
// odfcanvas.load(doclocation);
});
2013-07-01 22:36:17 +03:00
});
},
2013-08-07 21:14:36 +03:00
registerSession : function(filepath){
2013-08-07 02:35:46 +03:00
"use strict";
if (officeMain.initialized === undefined) {
alert("WebODF Editor not yet initialized...");
return;
}
2013-08-07 21:14:36 +03:00
2013-08-08 17:05:58 +03:00
$.post(OC.Router.generate('office_session_start'),
{ 'path' : filepath },
2013-08-07 02:35:46 +03:00
officeMain.onView
);
},
2013-08-07 18:02:20 +03:00
showSessions : function(){
if ($('#allsessions').length){
$('#allsessions').remove();
return;
}
$.post(OC.filePath('office', 'ajax', 'sessions.php'), {}, officeMain.onSessions);
},
onSessions : function(response){
if (response && response.sessions){
$(response.sessions).each( function(i, s){ officeMain.addSession(s) } );
}
},
addSession : function(s){
if (!$('#allsessions').length){
$(document.body).append('<div id="allsessions"></div>');
}
2013-08-08 14:17:26 +03:00
$('<div><a href="">'+s.es_id+ '</a></div>').appendTo('#allsessions').click(
2013-08-09 18:31:46 +03:00
function(event){
2013-08-08 14:17:26 +03:00
event.preventDefault();
officeMain.onView(s);
}
);
2013-08-07 18:02:20 +03:00
},
2013-07-01 22:36:17 +03:00
onClose: function() {
"use strict";
var bodyelement = document.getElementsByTagName('body')[0];
2013-07-01 22:36:17 +03:00
// Fade out odf-toolbar
$('#odf-toolbar').fadeOut('slow');
// Fade out editor
$('#mainContainer').fadeOut('slow', function() {
$('#mainContainer').remove();
2013-07-01 22:36:17 +03:00
$('#odf-canvas').remove();
$('.actions,#file_access_panel').fadeIn('slow');
2013-08-08 19:55:30 +03:00
$('.documentslist, #emptyfolder').fadeIn('slow');
bodyelement.className.replace(' claro', '');
webodfEditor.shutdown();
2013-07-01 22:36:17 +03:00
});
}
};
$(document).ready(function() {
$('.documentslist tr').click(function(event) {
event.preventDefault();
2013-08-07 21:14:36 +03:00
officeMain.registerSession($(this).attr('data-file'));
2013-07-01 22:36:17 +03:00
});
$('#odf_close').live('click', officeMain.onClose);
2013-08-07 18:02:20 +03:00
$('#session-list').click(officeMain.showSessions);
2013-08-09 18:31:46 +03:00
OC.addScript('office', 'dojo-amalgamation', officeMain.onStartup);
2013-07-01 22:36:17 +03:00
});