richdocuments/js/office.js

180 lines
5.1 KiB
JavaScript
Raw Normal View History

/*globals $,OC,fileDownloadPath,t,document,odf,webodfEditor,alert,require,dojo,runtime */
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) {
2013-08-13 19:38:30 +03:00
ready(function() {
require({}, ["webodf/editor/Editor"], function(Editor) {
if (Editor && typeof(Editor) === 'function') {
officeMain.initialized = 1;
} else {
2013-08-13 19:38:30 +03:00
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-12 19:07:18 +03:00
officeMain.updateSessions();
setInterval(officeMain.updateSessions, 10000);
2013-07-12 16:00:07 +02:00
},
2013-08-10 01:49:20 +03:00
initSession: function(response) {
"use strict";
2013-08-07 02:35:46 +03:00
OC.addScript('office', 'editor/boot_editor').done(function() {
2013-08-09 19:31:20 +03:00
var doclocation = response.es_id;
2013-08-13 19:38:30 +03:00
// fade out file list and show WebODF canvas
$('.documentslist, #emptyfolder, #editing-sessions').fadeOut('slow').promise().done(function() {
// odf action toolbar
var odfToolbarHtml =
2013-08-13 19:38:30 +03:00
'<div id="odf-toolbar">'
+ '<button id="odf_close">'
+ t('files_odfviewer', 'Close')
+ '</button>'
+ '<button id="odf_invite">'
+ t('files_odfviewer', 'Invite')
+ '</button>'
+ '<span id="toolbar" class="claro"></span>'
+ '</div>';
$('#controls').append(odfToolbarHtml);
2013-08-13 19:38:30 +03:00
$('#office-content').addClass('wide');
var memberId, odfelement, odfcanvas, canvashtml =
2013-08-13 19:38:30 +03:00
'<div id = "mainContainer" class="claro" style="">' +
'<div id = "editor">' +
'<div id = "container">' +
'<div id="canvas"></div>' +
'</div>' +
'</div>' +
'<div id = "collaboration">' +
'<div id = "collabContainer">' +
'<div id = "people">' +
'<div id = "inviteButton"></div>' +
'<div id = "memberList"></div>' +
'</div>' +
'</div>' +
'</div>' +
'</div>';
2013-08-09 19:15:47 +03:00
$(document.body).addClass("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-08-13 19:38:30 +03:00
2013-08-07 13:04:42 +02:00
runtime.assert(response.es_id, "invalid session id.");
2013-08-10 01:00:25 +03:00
memberId = response.member_id;
webodfEditor.boot(
2013-08-13 19:38:30 +03:00
{
collaborative: "owncloud",
docUrl: doclocation,
loginProcedure: function(cb) {
cb(response.es_id, OC.currentUser, "token");
},
joinSession: function(userId, sessionId, cb) {
cb(memberId);
},
callback: function() {
// initialized.
}
2013-07-12 23:48:42 +02:00
}
);
});
2013-07-01 22:36:17 +03:00
});
},
2013-08-13 19:38:30 +03:00
startSession: 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-13 19:38:30 +03:00
$.post(OC.Router.generate('office_session_start'),
{'path': filepath},
officeMain.initSession
);
2013-08-10 01:49:20 +03:00
},
2013-08-13 19:38:30 +03:00
joinSession: function(esId) {
$.post(OC.Router.generate('office_session_join') + '/' + esId,
{},
officeMain.initSession
);
2013-08-07 02:35:46 +03:00
},
2013-08-13 19:38:30 +03:00
updateSessions: function() {
2013-08-12 19:07:18 +03:00
$('#editing-sessions').load(OC.Router.generate('office_session_listhtml'), {}, officeMain.onSessions);
2013-08-07 18:02:20 +03:00
},
2013-08-13 19:38:30 +03:00
onSessions: function() {
2013-08-12 19:07:18 +03:00
$('#editing-sessions a').click(
2013-08-13 19:38:30 +03:00
function(event) {
2013-08-08 14:17:26 +03:00
event.preventDefault();
2013-08-12 19:07:18 +03:00
officeMain.joinSession($(this).attr('data-esid'));
}
2013-08-08 14:17:26 +03:00
);
2013-08-07 18:02:20 +03:00
},
2013-08-13 19:38:30 +03:00
onInvite: function() {
$('#invite-block').toggle();
},
sendInvite: function() {
var users = [];
$('input[name=invitee\\[\\]]').each(function(i, e) {
users.push($(e).val());
});
$.post(OC.Router.generate('office_user_invite'), {users: users});
},
2013-07-01 22:36:17 +03:00
onClose: function() {
"use strict";
2013-08-09 19:15:47 +03:00
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-13 19:38:30 +03:00
$('.documentslist, #emptyfolder, #editing-sessions').fadeIn('slow');
2013-08-09 19:15:47 +03:00
$(document.body).removeClass('claro');
2013-08-13 19:38:30 +03:00
$('#office-content').removeClass('wide');
webodfEditor.shutdown();
2013-07-01 22:36:17 +03:00
});
}
};
$(document).ready(function() {
$('.documentslist tr').click(function(event) {
event.preventDefault();
2013-08-09 19:15:47 +03:00
officeMain.startSession($(this).attr('data-file'));
2013-07-01 22:36:17 +03:00
});
$('#odf_close').live('click', officeMain.onClose);
2013-08-12 19:07:18 +03:00
$('#odf_invite').live('click', officeMain.onInvite);
2013-08-13 19:38:30 +03:00
$('#invite-send').live('click', officeMain.sendInvite);
$('#inivite-input').autocomplete({
minLength: 1,
source: function(search, response) {
$.get(OC.Router.generate('office_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) {
var item = $(
'<li>'
+ el.item.label
+ '<input type="hidden" name="invitee[]" value="'
+ el.item.value
+ '" />'
+ '</li>'
);
$('#invitee-list').append(item);
}
});
2013-08-09 18:31:46 +03:00
OC.addScript('office', 'dojo-amalgamation', officeMain.onStartup);
2013-07-01 22:36:17 +03:00
});