update from webodf th/ocpull branch

pull/1/head
Tobias Hintze 11 years ago
parent 84105a20db
commit 883608bcc5

@ -58,8 +58,9 @@ define("webodf/editor/Editor", [
* cursorAddedCallback:function(!string)=,
* cursorRemovedCallback:function(!string)=,
* registerCallbackForShutdown:function(!function())= }} args
* @param {!ops.Server=} server
*/
function Editor(args) {
function Editor(args, server) {
var self = this,
// Private
@ -86,13 +87,6 @@ define("webodf/editor/Editor", [
return myResources[key];
}
runtime.currentDirectory = function () {
return "../../webodf/lib";
};
runtime.libraryPaths = function () {
return [ runtime.currentDirectory() ];
};
/**
* prepare all gui elements and load the given document.
* after loading is completed, the given callback is called.
@ -272,10 +266,12 @@ define("webodf/editor/Editor", [
self.loadSession = function (sessionId, editorReadyCallback) {
initGuiAndDoc("/session/" + sessionId + "/genesis", function () {
// use the nowjs op-router when connected
opRouter = opRouter || new ops.NowjsOperationRouter(sessionId, memberid);
// opRouter = opRouter || new ops.NowjsOperationRouter(sessionId, memberid, server);
opRouter = opRouter || new ops.PullBoxOperationRouter(sessionId, memberid, server);
session.setOperationRouter(opRouter);
userModel = userModel || new ops.NowjsUserModel();
// userModel = userModel || new ops.NowjsUserModel(server);
userModel = userModel || new ops.PullBoxUserModel(server);
session.setUserModel(userModel);
opRouter.requestReplay(function done() {

@ -44,8 +44,10 @@ define("webodf/editor/EditorSession", [
runtime.loadClass("ops.OdtDocument");
runtime.loadClass("ops.Session");
runtime.loadClass("ops.NowjsOperationRouter");
runtime.loadClass("ops.NowjsUserModel");
// runtime.loadClass("ops.NowjsOperationRouter");
// runtime.loadClass("ops.NowjsUserModel");
runtime.loadClass("ops.PullBoxOperationRouter");
runtime.loadClass("ops.PullBoxUserModel");
runtime.loadClass("odf.OdfCanvas");
runtime.loadClass("gui.CaretFactory");
runtime.loadClass("gui.Caret");

@ -0,0 +1,159 @@
/**
* @license
* Copyright (C) 2013 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/
*/
/*global ops, runtime */
function PullBoxSessionList(server) {
"use strict";
var cachedSessionData = {},
subscribers = [],
/** HACK: allow to stop pulling, so that does not mess up the logs
* Remove before merging to master */
pullingActive = true;
function onSessionData(sessionData) {
var i,
isNew = ! cachedSessionData.hasOwnProperty(sessionData.id);
// cache
cachedSessionData[sessionData.id] = sessionData;
runtime.log("get session data for:"+sessionData.title+", is new:"+isNew);
for (i = 0; i < subscribers.length; i += 1) {
if (isNew) {
subscribers[i].onCreated(sessionData);
} else {
subscribers[i].onUpdated(sessionData);
}
}
}
function onSessionRemoved(sessionId) {
var i;
if (cachedSessionData.hasOwnProperty(sessionId)) {
delete cachedSessionData[sessionId];
for (i = 0; i < subscribers.length; i += 1) {
subscribers[i].onRemoved(sessionId);
}
}
}
function pullSessionList() {
if (!pullingActive) { return; }
server.call("session-list", function(responseData) {
var response = runtime.fromJson(responseData),
sessionList, i,
unupdatedSessions = {};
runtime.log("session-list reply: " + responseData);
if (response.hasOwnProperty("session_list")) {
// collect known sessions
for (i in cachedSessionData) {
if (cachedSessionData.hasOwnProperty(i)) {
unupdatedSessions[i] = ""; // some dummy value, unused
}
}
// add/update with all delivered sessions
sessionList = response.session_list;
for (i = 0; i < sessionList.length; i++) {
if (unupdatedSessions.hasOwnProperty(sessionList[i].id)) {
delete unupdatedSessions[sessionList[i].id];
}
onSessionData(sessionList[i]);
}
// remove unupdated sessions
for (i in unupdatedSessions) {
if (unupdatedSessions.hasOwnProperty(i)) {
onSessionRemoved(i);
}
}
// next update in 5 secs
runtime.getWindow().setTimeout(pullSessionList, 5000);
} else {
runtime.log("Meh, sessionlist data broken: " + responseData);
}
});
}
this.getSessions = function (subscriber) {
var i,
sessionList = [];
if (subscriber) {
subscribers.push(subscriber);
}
for (i in cachedSessionData) {
if (cachedSessionData.hasOwnProperty(i)) {
sessionList.push(cachedSessionData[i]);
}
}
return sessionList;
};
this.unsubscribe = function (subscriber) {
var i;
for (i=0; i<subscribers.length; i+=1) {
if (subscribers[i] === subscriber) {
break;
}
}
runtime.assert((i < subscribers.length),
"tried to unsubscribe when not subscribed.");
subscribers.splice(i,1);
};
this.stopPulling = function () {
pullingActive = false;
};
function init() {
pullSessionList();
}
init();
}

@ -1,6 +1,7 @@
/**
* Copyright (C) 2012 KO GmbH <copyright@kogmbh.com>
* @license
* Copyright (C) 2012-2013 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
@ -34,86 +35,16 @@
/*global ops, runtime */
function SessionList(net) {
"use strict";
var cachedSessionData = {},
subscribers = [];
function onSessionData(sessionData) {
var i,
isNew = ! cachedSessionData.hasOwnProperty(sessionData.id);
// cache
cachedSessionData[sessionData.id] = sessionData;
runtime.log("get session data for:"+sessionData.title+", is new:"+isNew);
for (i = 0; i < subscribers.length; i += 1) {
if (isNew) {
subscribers[i].onCreated(sessionData);
} else {
subscribers[i].onUpdated(sessionData);
}
}
}
function onSessionRemoved(sessionId) {
var i;
if (cachedSessionData.hasOwnProperty(sessionId)) {
delete cachedSessionData[sessionId];
for (i = 0; i < subscribers.length; i += 1) {
subscribers[i].onRemoved(sessionId);
}
}
}
this.getSessions = function (subscriber) {
var i,
sessionList = [];
if (subscriber) {
subscribers.push(subscriber);
}
for (i in cachedSessionData) {
if (cachedSessionData.hasOwnProperty(i)) {
sessionList.push(cachedSessionData[i]);
}
}
return sessionList;
};
this.unsubscribe = function (subscriber) {
var i;
for (i=0; i<subscribers.length; i+=1) {
if (subscribers[i] === subscriber) {
break;
}
}
runtime.assert((i < subscribers.length),
"tried to unsubscribe when not subscribed.");
subscribers.splice(i,1);
};
function init() {
net.onSessionAdded = onSessionData;
net.onSessionChanged = onSessionData;
net.onSessionRemoved = onSessionRemoved;
net.getSessionList( function(sessionList) {
var idx;
runtime.log("get sessions on init:"+sessionList.length);
for (idx=0; idx<sessionList.length; idx+=1) {
onSessionData(sessionList[idx])
}
});
}
/**
* A model which provides information about sessions.
* @interface
*/
SessionList = function SessionList() {"use strict"; };
init();
}
/**
* @param {{onCreated:function(!Object),
* onUpdated:function(!Object),
* onRemoved:function(!string) }} subscriber
* @return {undefined}
*/
SessionList.prototype.getSessions = function (subscriber) {"use strict"; };

@ -47,16 +47,24 @@
*
*/
/*global runtime, require, document, alert, gui, window, SessionList, SessionListView, FileReader, Uint8Array */
/*global runtime, require, document, alert, net, window, NowjsSessionList, PullBoxSessionList, SessionListView, ops */
// define the namespace/object we want to provide
// this is the first line of API, the user gets.
var webodfEditor = (function () {
"use strict";
runtime.currentDirectory = function () {
return "../../webodf/lib";
};
runtime.libraryPaths = function () {
return [ runtime.currentDirectory() ];
};
var editorInstance = null,
running = false,
loadedFilename = null;
server = null,
booting = false,
loadedFilename;
/**
* wait for a network connection through nowjs to establish.
@ -69,29 +77,33 @@ var webodfEditor = (function () {
* @param {!function(!string)} callback
* @return {undefined}
*/
function waitForNetwork(callback) {
var net = runtime.getNetwork(), accumulated_waiting_time = 0;
function later_cb() {
if (net.networkStatus === "unavailable") {
runtime.log("connection to server unavailable.");
callback("unavailable");
return;
}
if (net.networkStatus !== "ready") {
if (accumulated_waiting_time > 8000) {
// game over
runtime.log("connection to server timed out.");
callback("timeout");
return;
}
accumulated_waiting_time += 100;
runtime.getWindow().setTimeout(later_cb, 100);
} else {
runtime.log("connection to collaboration server established.");
callback("ready");
}
function connectNetwork(backend, callback) {
if (backend === "pullbox") {
runtime.loadClass("ops.PullBoxServer");
server = new ops.PullBoxServer();
} else if (backend === "nowjs") {
runtime.loadClass("ops.NowjsServer");
server = new ops.NowjsServer();
} else if (backend === "owncloud") {
runtime.loadClass("ops.PullBoxServer");
server = new ops.PullBoxServer({url: "../../ajax/otpoll.php"});
} else {
callback("unavailable");
}
later_cb();
server.connect(8000, callback);
}
/**
* try to auto-sense the server-backend.
*
* NOT IMPLEMENTED / MIGHT BE NICE TO HAVE...
* for now: try to connect to pullbox backend
*
* @param {!function(!string)} callback
* @return {undefined}
*/
function detectNetwork(callback) {
connectNetwork("pullbox", callback);
}
/**
@ -192,7 +204,7 @@ var webodfEditor = (function () {
*/
function createLocalEditor(docUrl, editorOptions, editorReadyCallback) {
var pos;
running = true;
booting = true;
editorOptions = editorOptions || {};
editorOptions.memberid = "localuser";
editorOptions.loadCallback = load;
@ -207,7 +219,6 @@ var webodfEditor = (function () {
function (Editor) {
editorInstance = new Editor(editorOptions);
editorInstance.initAndLoadDocument(docUrl, function (editorSession) {
editorSession.sessionController.setUndoManager(new gui.TrivialUndoManager());
editorSession.startEditing();
editorReadyCallback(editorInstance);
});
@ -239,7 +250,7 @@ var webodfEditor = (function () {
function (Editor) {
// TODO: the networkSecurityToken needs to be retrieved via now.login
// (but this is to be implemented later)
editorInstance = new Editor(editorOptions);
editorInstance = new Editor(editorOptions, server);
// load the document and get called back when it's live
editorInstance.loadSession(sessionId, function (editorSession) {
@ -262,10 +273,9 @@ var webodfEditor = (function () {
* @returns {undefined}
*/
function startLoginProcess(callback) {
var userid, token,
net = runtime.getNetwork();
var userid, token;
running = true;
booting = true;
runtime.assert(editorInstance === null, "cannot boot with instanciated editor");
@ -278,7 +288,8 @@ var webodfEditor = (function () {
function showSessions() {
var sessionListDiv = document.getElementById("sessionList"),
sessionList = new SessionList(net),
// sessionList = new NowjsSessionList(server),
sessionList = new PullBoxSessionList(server),
sessionListView = new SessionListView(sessionList, sessionListDiv, enterSession);
// hide login view
@ -301,7 +312,7 @@ var webodfEditor = (function () {
}
function onLoginSubmit() {
net.login(document.loginForm.login.value, document.loginForm.password.value, loginSuccess, loginFail);
server.login(document.loginForm.login.value, document.loginForm.password.value, loginSuccess, loginFail);
// block the submit button, we already dealt with the input
return false;
@ -334,7 +345,7 @@ var webodfEditor = (function () {
*/
function boot(args) {
var editorOptions = {}, loginProcedure = startLoginProcess;
runtime.assert(!running, "editor creation already in progress");
runtime.assert(!booting, "editor creation already in progress");
args = args || {};
@ -391,7 +402,7 @@ var webodfEditor = (function () {
if (args.collaborative === "auto") {
runtime.log("detecting network...");
waitForNetwork(function (state) {
detectNetwork(function (state) {
if (state === "ready") {
runtime.log("... network available.");
handleNetworkedSituation();
@ -400,11 +411,10 @@ var webodfEditor = (function () {
handleNonNetworkedSituation();
}
});
} else if ((args.collaborative === "true") ||
(args.collaborative === "1") ||
(args.collaborative === "yes")) {
runtime.log("starting collaborative editor.");
waitForNetwork(function (state) {
} else if ((args.collaborative === "pullbox") ||
(args.collaborative === "owncloud")) {
runtime.log("starting collaborative editor for ["+args.collaborative+"].");
connectNetwork(args.collaborative, function (state) {
if (state === "ready") {
handleNetworkedSituation();
}
@ -415,16 +425,7 @@ var webodfEditor = (function () {
}
}
function shutdown() {
running = false;
editorInstance = null;
loadedFilename = null;
}
// exposed API
return {
boot: boot,
shutdown: shutdown
};
return { boot: boot };
}());

@ -116,10 +116,12 @@ define("webodf/editor/widgets/simpleStyles",
appliedStyles.forEach(function(appliedStyle) {
var textProperties = appliedStyle['style:text-properties'];
fontWeight = fontWeight || textProperties['fo:font-weight'] === 'bold';
fontStyle = fontStyle || textProperties['fo:font-style'] === 'italic';
underline = underline || textProperties['style:text-underline-style'] === 'solid';
strikethrough = strikethrough || textProperties['style:text-line-through-style'] === 'solid';
if (textProperties) {
fontWeight = fontWeight || textProperties['fo:font-weight'] === 'bold';
fontStyle = fontStyle || textProperties['fo:font-style'] === 'italic';
underline = underline || textProperties['style:text-underline-style'] === 'solid';
strikethrough = strikethrough || textProperties['style:text-line-through-style'] === 'solid';
}
});
// The 3rd parameter is false to avoid firing onChange when setting the value

@ -59,7 +59,7 @@ var officeMain = {
webodfEditor.boot(
{
collaborative: 0,
collaborative: "owncloud",
docUrl: doclocation,
callback: function() {
// initialized.

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save