mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-01-27 09:24:45 +00:00
More TiddlyWeb sync
This commit is contained in:
parent
f07bc18204
commit
baba32e548
@ -32,6 +32,7 @@ TiddlyWebSyncer.prototype.showError = function(error) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
TiddlyWebSyncer.prototype.addConnection = function(connection) {
|
TiddlyWebSyncer.prototype.addConnection = function(connection) {
|
||||||
|
var self = this;
|
||||||
// Check if we've already got a connection
|
// Check if we've already got a connection
|
||||||
if(this.connection) {
|
if(this.connection) {
|
||||||
return Error("TiddlyWebSyncer can only handle a single connection");
|
return Error("TiddlyWebSyncer can only handle a single connection");
|
||||||
@ -41,11 +42,14 @@ TiddlyWebSyncer.prototype.addConnection = function(connection) {
|
|||||||
return Error("Missing connection data")
|
return Error("Missing connection data")
|
||||||
}
|
}
|
||||||
// Mark us as not logged in
|
// 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
|
// Save and return the connection object
|
||||||
this.connection = connection;
|
this.connection = connection;
|
||||||
|
// Listen out for changes to tiddlers
|
||||||
|
this.wiki.addEventListener("",function(changes) {
|
||||||
|
self.syncToServer(changes);
|
||||||
|
});
|
||||||
// Get the login status
|
// Get the login status
|
||||||
var self = this;
|
|
||||||
this.getStatus(function (err,isLoggedIn,json) {
|
this.getStatus(function (err,isLoggedIn,json) {
|
||||||
if(isLoggedIn) {
|
if(isLoggedIn) {
|
||||||
self.syncFromServer();
|
self.syncFromServer();
|
||||||
@ -91,6 +95,7 @@ TiddlyWebSyncer.prototype.getCsrfToken = function() {
|
|||||||
|
|
||||||
TiddlyWebSyncer.prototype.getStatus = function(callback) {
|
TiddlyWebSyncer.prototype.getStatus = function(callback) {
|
||||||
// Get status
|
// Get status
|
||||||
|
var self = this;
|
||||||
this.httpRequest({
|
this.httpRequest({
|
||||||
url: this.connection.host + "status",
|
url: this.connection.host + "status",
|
||||||
callback: function(err,data) {
|
callback: function(err,data) {
|
||||||
@ -107,11 +112,11 @@ TiddlyWebSyncer.prototype.getStatus = function(callback) {
|
|||||||
// Check if we're logged in
|
// Check if we're logged in
|
||||||
var isLoggedIn = json.username !== "GUEST";
|
var isLoggedIn = json.username !== "GUEST";
|
||||||
// Set the various status tiddlers
|
// 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) {
|
if(isLoggedIn) {
|
||||||
$tw.wiki.addTiddler({title: TiddlyWebSyncer.titleUserName,text: json.username});
|
self.wiki.addTiddler({title: TiddlyWebSyncer.titleUserName,text: json.username});
|
||||||
} else {
|
} else {
|
||||||
$tw.wiki.deleteTiddler(TiddlyWebSyncer.titleUserName);
|
self.wiki.deleteTiddler(TiddlyWebSyncer.titleUserName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Invoke the callback if present
|
// 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
|
Lazily load a skinny tiddler if we can
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user