2012-10-21 20:46:20 +02:00
|
|
|
/**
|
|
|
|
|
* Copyright (C) 2012 KO GmbH <copyright@kogmbh.com>
|
|
|
|
|
*
|
|
|
|
|
* @licstart
|
|
|
|
|
* The JavaScript code in this page is free software: you can redistribute it
|
|
|
|
|
* and/or modify it under the terms of the GNU Affero General Public License
|
|
|
|
|
* (GNU AGPL) as published by the Free Software Foundation, either version 3 of
|
|
|
|
|
* the License, or (at your option) any later version. The code is distributed
|
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU AGPL for more details.
|
|
|
|
|
*
|
|
|
|
|
* As additional permission under GNU AGPL version 3 section 7, you
|
|
|
|
|
* may distribute non-source (e.g., minimized or compacted) forms of
|
|
|
|
|
* that code without the copy of the GNU GPL normally required by
|
|
|
|
|
* section 4, provided you include this license notice and a URL
|
|
|
|
|
* through which recipients can access the Corresponding Source.
|
|
|
|
|
*
|
|
|
|
|
* As a special exception to the AGPL, any HTML file which merely makes function
|
|
|
|
|
* calls to this code, and for that purpose includes it by reference shall be
|
|
|
|
|
* deemed a separate work for copyright law purposes. In addition, the copyright
|
|
|
|
|
* holders of this code give you permission to combine this code with free
|
|
|
|
|
* software libraries that are released under the GNU LGPL. You may copy and
|
|
|
|
|
* distribute such a system following the terms of the GNU AGPL for this code
|
|
|
|
|
* and the LGPL for the libraries. If you modify this code, you may extend this
|
|
|
|
|
* exception to your version of the code, but you are not obligated to do so.
|
|
|
|
|
* If you do not wish to do so, delete this exception statement from your
|
|
|
|
|
* version.
|
|
|
|
|
*
|
|
|
|
|
* This license applies to this entire compilation.
|
|
|
|
|
* @licend
|
|
|
|
|
* @source: http://www.webodf.org/
|
|
|
|
|
* @source: http://gitorious.org/webodf/webodf/
|
|
|
|
|
*/
|
2013-03-05 13:57:27 +05:30
|
|
|
/*global runtime,define,document,odf,require,ops,gui*/
|
2012-12-03 16:24:08 +01:00
|
|
|
|
2012-12-17 19:10:53 +05:30
|
|
|
define("webodf/editor", [
|
|
|
|
|
"webodf/editor/UserList",
|
|
|
|
|
"webodf/editor/widgets"],
|
|
|
|
|
function (UserList, loadWidgets) {
|
|
|
|
|
"use strict";
|
|
|
|
|
var self = {};
|
2012-10-21 22:55:04 +02:00
|
|
|
|
2012-12-17 19:10:53 +05:30
|
|
|
runtime.currentDirectory = function () {
|
|
|
|
|
return "../../webodf/lib";
|
|
|
|
|
};
|
|
|
|
|
runtime.libraryPaths = function () {
|
|
|
|
|
return [ runtime.currentDirectory() ];
|
2012-11-23 19:42:25 +01:00
|
|
|
};
|
2012-10-30 17:23:19 +01:00
|
|
|
|
2012-12-17 19:10:53 +05:30
|
|
|
/**
|
|
|
|
|
* Utility method for testing
|
|
|
|
|
* @param {?string} memberId
|
|
|
|
|
*/
|
|
|
|
|
function addCursorToDoc(session, memberId) {
|
|
|
|
|
var op = new ops.OpAddCursor(session);
|
|
|
|
|
op.init({memberid : memberId});
|
|
|
|
|
session.enqueue(op);
|
|
|
|
|
}
|
2012-11-04 18:03:54 +01:00
|
|
|
|
2012-11-16 16:21:54 +05:30
|
|
|
|
2013-02-14 17:32:09 +01:00
|
|
|
function init_gui_and_doc(doclocation, userid, sessionid) {
|
2012-12-17 19:10:53 +05:30
|
|
|
runtime.loadClass('odf.OdfCanvas');
|
2012-11-04 18:03:54 +01:00
|
|
|
|
2013-02-14 17:32:09 +01:00
|
|
|
var odfElement, odfCanvas, filename, isConnectedWithNetwork;
|
2012-12-17 19:10:53 +05:30
|
|
|
|
|
|
|
|
if (userid === undefined) {
|
|
|
|
|
userid = "undefined";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
isConnectedWithNetwork = (runtime.getNetwork().networkStatus !== "unavailable");
|
|
|
|
|
|
|
|
|
|
odfElement = document.getElementById("canvas");
|
|
|
|
|
runtime.assert(odfElement, "init_gui_and_doc failed to get odf canvas from html");
|
|
|
|
|
odfCanvas = new odf.OdfCanvas(odfElement);
|
2013-03-11 18:30:47 +01:00
|
|
|
// make the canvas accessible to users of editor.js
|
|
|
|
|
self.odfCanvas = odfCanvas;
|
2012-12-17 19:10:53 +05:30
|
|
|
|
|
|
|
|
// Editor Translations, Widgets and Avatars
|
|
|
|
|
require({
|
|
|
|
|
paths : {
|
|
|
|
|
"webodf" : "/webodf",
|
|
|
|
|
"webodf/editor" : "/programs/editor"
|
|
|
|
|
}
|
|
|
|
|
}, [
|
|
|
|
|
'dojo/i18n!webodf/editor/nls/myResources',
|
|
|
|
|
'webodf/editor/EditorSession',
|
|
|
|
|
'webodf/editor/UserList'
|
|
|
|
|
], function (myResources, EditorSession, UserList) {
|
2013-02-13 22:18:03 +05:30
|
|
|
function translator(key, context) {
|
2012-12-17 19:10:53 +05:30
|
|
|
if (undefined === myResources[key]) {
|
|
|
|
|
return "translation missing: " + key;
|
2012-10-30 11:38:02 +01:00
|
|
|
}
|
2012-12-17 19:10:53 +05:30
|
|
|
return myResources[key];
|
2013-02-13 22:18:03 +05:30
|
|
|
}
|
2012-12-17 19:10:53 +05:30
|
|
|
document.translator = translator;
|
2013-02-13 20:57:11 +05:30
|
|
|
|
2013-02-13 22:18:03 +05:30
|
|
|
function translateContent(node) {
|
2013-02-13 20:57:11 +05:30
|
|
|
var i,
|
|
|
|
|
element,
|
|
|
|
|
tag,
|
|
|
|
|
placeholder,
|
|
|
|
|
translatable = node.querySelectorAll("*[text-i18n]");
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < translatable.length; i += 1) {
|
|
|
|
|
element = translatable[i];
|
|
|
|
|
tag = element.localName;
|
|
|
|
|
placeholder = element.getAttribute('text-i18n');
|
|
|
|
|
if (tag === "label"
|
|
|
|
|
|| tag === "span"
|
|
|
|
|
|| /h\d/i.test(tag)) {
|
|
|
|
|
element.textContent = document.translator(placeholder);
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-02-13 22:18:03 +05:30
|
|
|
}
|
2013-02-13 20:57:11 +05:30
|
|
|
document.translateContent = translateContent;
|
2013-03-01 14:31:00 +05:30
|
|
|
|
2012-12-17 19:10:53 +05:30
|
|
|
odfCanvas.addListener("statereadychange", function () {
|
|
|
|
|
var session,
|
|
|
|
|
editorSession,
|
2013-02-11 18:04:22 +01:00
|
|
|
localUserMemberId = userid + "___" + Date.now(),
|
2012-12-17 19:10:53 +05:30
|
|
|
userList,
|
|
|
|
|
opRouter = null;
|
|
|
|
|
|
|
|
|
|
session = new ops.SessionImplementation(odfCanvas);
|
2013-02-11 18:04:22 +01:00
|
|
|
editorSession = new EditorSession(session, localUserMemberId);
|
2012-12-17 19:10:53 +05:30
|
|
|
userList = new UserList(editorSession, document.getElementById('peopleList'));
|
|
|
|
|
|
|
|
|
|
if (isConnectedWithNetwork) {
|
|
|
|
|
// use the nowjs op-router when connected
|
2013-02-11 18:04:22 +01:00
|
|
|
session.setOperationRouter(opRouter = new ops.NowjsOperationRouter(sessionid, localUserMemberId));
|
2012-12-17 19:10:53 +05:30
|
|
|
|
|
|
|
|
runtime.log("editor: setting UserModel and requesting replay");
|
2012-12-21 18:17:41 +01:00
|
|
|
session.setUserModel(new ops.NowjsUserModel());
|
|
|
|
|
|
|
|
|
|
editorSession.sessionView.disableEditHighlighting();
|
|
|
|
|
opRouter.requestReplay(function done() {
|
|
|
|
|
editorSession.sessionView.enableEditHighlighting();
|
|
|
|
|
|
|
|
|
|
// start editing: let the controller send the OpAddCursor
|
|
|
|
|
editorSession.startEditing();
|
2012-12-21 22:47:44 +01:00
|
|
|
});
|
2012-12-17 19:10:53 +05:30
|
|
|
} else {
|
|
|
|
|
// offline
|
|
|
|
|
editorSession.startEditing();
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-22 07:50:57 +01:00
|
|
|
// gracefull cursor removal on pag closing
|
|
|
|
|
window.onunload = function() {
|
|
|
|
|
editorSession.endEditing();
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-11 18:30:47 +01:00
|
|
|
loadWidgets(editorSession, self.saveOdtFile);
|
2012-12-17 19:10:53 +05:30
|
|
|
});
|
|
|
|
|
odfCanvas.load(doclocation);
|
|
|
|
|
odfCanvas.setEditable(false);
|
|
|
|
|
|
|
|
|
|
// App Widgets
|
|
|
|
|
require([
|
|
|
|
|
"dijit/layout/BorderContainer",
|
|
|
|
|
"dijit/layout/ContentPane",
|
2013-03-16 07:43:19 +05:30
|
|
|
],
|
2012-12-17 19:10:53 +05:30
|
|
|
function (BorderContainer, ContentPane, ExpandoPane) {
|
|
|
|
|
var mainContainer = new BorderContainer({}, 'mainContainer'),
|
|
|
|
|
filename = doclocation.replace('/^.*[\\\/]/', ''),
|
|
|
|
|
editorPane,
|
2013-03-16 07:43:19 +05:30
|
|
|
peoplePane;
|
2012-12-17 19:10:53 +05:30
|
|
|
|
|
|
|
|
editorPane = new ContentPane({
|
|
|
|
|
region: 'center'
|
|
|
|
|
}, 'editor');
|
|
|
|
|
peoplePane = new ContentPane({
|
2013-03-16 07:43:19 +05:30
|
|
|
region: 'right',
|
2012-12-17 19:10:53 +05:30
|
|
|
title: translator("people")
|
|
|
|
|
}, 'people');
|
|
|
|
|
|
|
|
|
|
mainContainer.addChild(editorPane);
|
2013-03-16 07:43:19 +05:30
|
|
|
mainContainer.addChild(peoplePane);
|
2012-12-17 19:10:53 +05:30
|
|
|
|
|
|
|
|
mainContainer.startup();
|
|
|
|
|
|
2013-03-18 18:12:35 +05:30
|
|
|
if (window.inviteButtonProxy) {
|
|
|
|
|
var inviteButton = document.getElementById('inviteButton');
|
|
|
|
|
inviteButton.innerText = translator("invitePeople");
|
|
|
|
|
inviteButton.style.display = "block";
|
|
|
|
|
inviteButton.onclick = window.inviteButtonProxy.clicked;
|
|
|
|
|
}
|
|
|
|
|
});
|
2012-12-17 19:10:53 +05:30
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-21 18:17:41 +01:00
|
|
|
self.boot = function (docurl, userid, sessionid) {
|
2012-12-17 19:10:53 +05:30
|
|
|
var net = runtime.getNetwork(), accumulated_waiting_time = 0;
|
|
|
|
|
|
|
|
|
|
//alert("booting: ["+docurl+"] userlist: "+UserList);
|
|
|
|
|
|
|
|
|
|
userid = userid || "you";
|
|
|
|
|
|
|
|
|
|
function later_cb() {
|
|
|
|
|
if (net.networkStatus === "unavailable") {
|
|
|
|
|
runtime.log("connection to server unavailable.");
|
|
|
|
|
init_gui_and_doc(docurl, userid);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (net.networkStatus !== "ready") {
|
|
|
|
|
if (accumulated_waiting_time > 8000) {
|
|
|
|
|
// game over
|
|
|
|
|
runtime.log("connection to server timed out.");
|
|
|
|
|
init_gui_and_doc(docurl, userid);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
accumulated_waiting_time += 100;
|
|
|
|
|
runtime.getWindow().setTimeout(later_cb, 100);
|
|
|
|
|
} else {
|
|
|
|
|
runtime.log("connection to collaboration server established.");
|
2012-12-21 18:17:41 +01:00
|
|
|
init_gui_and_doc(docurl, userid, sessionid);
|
2012-12-17 19:10:53 +05:30
|
|
|
}
|
2012-10-30 11:38:02 +01:00
|
|
|
}
|
2012-12-17 19:10:53 +05:30
|
|
|
later_cb();
|
|
|
|
|
};
|
|
|
|
|
return self;
|
2012-10-04 18:51:03 +05:30
|
|
|
});
|
2012-08-08 17:40:09 +05:30
|
|
|
|
2012-12-17 19:10:53 +05:30
|
|
|
/*
|
|
|
|
|
TODO:
|
|
|
|
|
window.onunload = function() {
|
|
|
|
|
editor.editorSession.endEditing();
|
2012-11-05 20:56:25 +01:00
|
|
|
}
|
2012-12-17 19:10:53 +05:30
|
|
|
*/
|
|
|
|
|
// vim:expandtab
|