From baba32e54878253a1a9d85766960c1795716e732 Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Sun, 18 Nov 2012 21:07:14 +0000 Subject: [PATCH] More TiddlyWeb sync --- plugins/tiddlywiki/tiddlyweb/tiddlyweb.js | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/plugins/tiddlywiki/tiddlyweb/tiddlyweb.js b/plugins/tiddlywiki/tiddlyweb/tiddlyweb.js index 37273553c..6d4e5d8bc 100644 --- a/plugins/tiddlywiki/tiddlyweb/tiddlyweb.js +++ b/plugins/tiddlywiki/tiddlyweb/tiddlyweb.js @@ -32,6 +32,7 @@ TiddlyWebSyncer.prototype.showError = function(error) { }; TiddlyWebSyncer.prototype.addConnection = function(connection) { + var self = this; // Check if we've already got a connection if(this.connection) { return Error("TiddlyWebSyncer can only handle a single connection"); @@ -41,11 +42,14 @@ TiddlyWebSyncer.prototype.addConnection = function(connection) { return Error("Missing connection data") } // Mark us as not logged in - $tw.wiki.addTiddler({title: TiddlyWebSyncer.titleIsLoggedIn,text: "no"}); + this.wiki.addTiddler({title: TiddlyWebSyncer.titleIsLoggedIn,text: "no"}); // Save and return the connection object this.connection = connection; + // Listen out for changes to tiddlers + this.wiki.addEventListener("",function(changes) { + self.syncToServer(changes); + }); // Get the login status - var self = this; this.getStatus(function (err,isLoggedIn,json) { if(isLoggedIn) { self.syncFromServer(); @@ -91,6 +95,7 @@ TiddlyWebSyncer.prototype.getCsrfToken = function() { TiddlyWebSyncer.prototype.getStatus = function(callback) { // Get status + var self = this; this.httpRequest({ url: this.connection.host + "status", callback: function(err,data) { @@ -107,11 +112,11 @@ TiddlyWebSyncer.prototype.getStatus = function(callback) { // Check if we're logged in var isLoggedIn = json.username !== "GUEST"; // Set the various status tiddlers - $tw.wiki.addTiddler({title: TiddlyWebSyncer.titleIsLoggedIn,text: isLoggedIn ? "yes" : "no"}); + self.wiki.addTiddler({title: TiddlyWebSyncer.titleIsLoggedIn,text: isLoggedIn ? "yes" : "no"}); if(isLoggedIn) { - $tw.wiki.addTiddler({title: TiddlyWebSyncer.titleUserName,text: json.username}); + self.wiki.addTiddler({title: TiddlyWebSyncer.titleUserName,text: json.username}); } else { - $tw.wiki.deleteTiddler(TiddlyWebSyncer.titleUserName); + self.wiki.deleteTiddler(TiddlyWebSyncer.titleUserName); } } // Invoke the callback if present @@ -244,6 +249,14 @@ console.log("error in syncFromServer",err); }); }; +/* +Synchronise a set of changes to the server +*/ +TiddlyWebSyncer.prototype.syncToServer = function(changes) { + var self = this; +console.log("changes",changes); +}; + /* Lazily load a skinny tiddler if we can */