| 15 | | // Open the specified host/server |
|---|
| | 14 | FileAdaptor.prototype.setContext = function(context,userParams,callback) |
|---|
| | 15 | { |
|---|
| | 16 | if(!context) context = {}; |
|---|
| | 17 | context.userParams = userParams; |
|---|
| | 18 | if(callback) context.callback = callback; |
|---|
| | 19 | context.adaptor = this; |
|---|
| | 20 | if(!context.host) |
|---|
| | 21 | context.host = this.host; |
|---|
| | 22 | context.host = FileAdaptor.fullHostName(context.host); |
|---|
| | 23 | if(!context.workspace) |
|---|
| | 24 | context.workspace = this.workspace; |
|---|
| | 25 | return context; |
|---|
| | 26 | }; |
|---|
| | 27 | |
|---|
| | 28 | FileAdaptor.fullHostName = function(host) |
|---|
| | 29 | { |
|---|
| | 30 | if(!host) |
|---|
| | 31 | return ''; |
|---|
| | 32 | if(!host.match(/:\/\//)) |
|---|
| | 33 | host = 'http://' + host; |
|---|
| | 34 | return host; |
|---|
| | 35 | }; |
|---|
| | 36 | |
|---|
| | 37 | FileAdaptor.minHostName = function(host) |
|---|
| | 38 | { |
|---|
| | 39 | return host ? host.replace(/^http:\/\//,'').replace(/\/$/,'') : ''; |
|---|
| | 40 | }; |
|---|
| | 41 | |
|---|
| | 42 | // Open the specified host |
|---|
| 28 | | if(!context) |
|---|
| 29 | | context = {}; |
|---|
| 30 | | context.adaptor = this; |
|---|
| 31 | | context.callback = callback; |
|---|
| 32 | | context.userParams = userParams; |
|---|
| 33 | | var ret = loadRemoteFile(host,FileAdaptor.openHostCallback,context); |
|---|
| 34 | | return typeof(ret) == "string" ? ret : true; |
|---|
| 35 | | }; |
|---|
| 36 | | |
|---|
| 37 | | FileAdaptor.openHostCallback = function(status,context,responseText,url,xhr) |
|---|
| 38 | | { |
|---|
| 39 | | var adaptor = context.adaptor; |
|---|
| | 56 | context = this.setContext(context,userParams,callback); |
|---|
| | 57 | context.status = true; |
|---|
| | 58 | if(callback) |
|---|
| | 59 | window.setTimeout(function() {callback(context,userParams);},10); |
|---|
| | 60 | return true; |
|---|
| | 61 | }; |
|---|
| | 62 | |
|---|
| | 63 | FileAdaptor.loadTiddlyWikiCallback = function(status,context,responseText,url,xhr) |
|---|
| | 64 | { |
|---|
| 49 | | context.callback(context,context.userParams); |
|---|
| 50 | | }; |
|---|
| 51 | | |
|---|
| 52 | | // Gets the list of workspaces on a given server |
|---|
| 53 | | //# context is itself passed on as a parameter to the callback function |
|---|
| 54 | | //# callback - optional function to be called on completion |
|---|
| | 74 | context.complete(context,context.userParams); |
|---|
| | 75 | }; |
|---|
| | 76 | |
|---|
| | 77 | // Get the list of workspaces on a given server |
|---|
| | 78 | //# context - passed on as a parameter to the callback function |
|---|
| | 79 | //# userParams - user settable object object that is passed on unchanged to the callback function |
|---|
| | 80 | //# callback - function to be called on completion |
|---|
| 57 | | //# The callback parameters are callback(context) |
|---|
| 58 | | //# context.status - true if OK, false if error |
|---|
| 59 | | //# context.statusText - error message if there was an error |
|---|
| 60 | | //# context.adaptor - reference to this adaptor object |
|---|
| 61 | | //# context - parameters as originally passed into the getWorkspaceList function |
|---|
| | 83 | //# The callback parameters are callback(context,userParams) |
|---|
| | 84 | //# context.status - true if OK, false if error |
|---|
| | 85 | //# context.statusText - error message if there was an error |
|---|
| | 86 | //# context.adaptor - reference to this adaptor object |
|---|
| | 87 | //# userParams - parameters as originally passed into the getWorkspaceList function |
|---|
| 78 | | //# The callback parameters are callback(status,adaptor,context) |
|---|
| 79 | | //# status - true if OK, string if error |
|---|
| 80 | | //# adaptor - reference to this adaptor object |
|---|
| 81 | | //# context - parameters as originally passed into the openWorkspace function |
|---|
| | 105 | //# The callback parameters are callback(context,userParams) |
|---|
| | 106 | //# context.status - true if OK, false if error |
|---|
| | 107 | //# context.statusText - error message if there was an error |
|---|
| | 108 | //# context.adaptor - reference to this adaptor object |
|---|
| | 109 | //# userParams - parameters as originally passed into the openWorkspace function |
|---|
| 98 | | //# The callback parameters are callback(status,adaptor,context,tiddlerList) |
|---|
| 99 | | //# status - true if OK, false if error |
|---|
| 100 | | //# adaptor - reference to this adaptor object |
|---|
| 101 | | //# context - parameters as originally passed into the getTiddlerList function |
|---|
| | 127 | //# The callback parameters are callback(context,userParams) |
|---|
| | 128 | //# context.status - true if OK, false if error |
|---|
| | 129 | //# context.statusText - error message if there was an error |
|---|
| | 130 | //# context.adaptor - reference to this adaptor object |
|---|
| 105 | | if(!this.store) |
|---|
| 106 | | return FileAdaptor.NotLoadedError; |
|---|
| 107 | | if(!context) |
|---|
| 108 | | context = {}; |
|---|
| 109 | | if(filter) { |
|---|
| 110 | | context.tiddlers = this.store.filterTiddlers(filter); |
|---|
| | 135 | context = this.setContext(context,userParams,callback); |
|---|
| | 136 | if(!context.filter) |
|---|
| | 137 | context.filter = filter; |
|---|
| | 138 | context.complete = FileAdaptor.getTiddlerListComplete; |
|---|
| | 139 | return this.store ? |
|---|
| | 140 | context.complete(context,context.userParams) : |
|---|
| | 141 | loadRemoteFile(context.host,FileAdaptor.loadTiddlyWikiCallback,context); |
|---|
| | 142 | }; |
|---|
| | 143 | |
|---|
| | 144 | FileAdaptor.getTiddlerListComplete = function(context,userParams) |
|---|
| | 145 | { |
|---|
| | 146 | if(context.filter) { |
|---|
| | 147 | context.tiddlers = context.adaptor.store.filterTiddlers(context.filter); |
|---|
| 113 | | this.store.forEachTiddler(function(title,tiddler) {context.tiddlers.push(tiddler);}); |
|---|
| 114 | | } |
|---|
| 115 | | for(var t=0; t<context.tiddlers.length; t++) { |
|---|
| 116 | | context.tiddlers[t].fields['server.page.revision'] = context.tiddlers[t].modified.convertToYYYYMMDDHHMM(); |
|---|
| 117 | | } |
|---|
| 118 | | context.status = true; |
|---|
| 119 | | window.setTimeout(function() {callback(context,userParams);},10); |
|---|
| | 150 | context.adaptor.store.forEachTiddler(function(title,tiddler) {context.tiddlers.push(tiddler);}); |
|---|
| | 151 | } |
|---|
| | 152 | for(var i=0; i<context.tiddlers.length; i++) { |
|---|
| | 153 | context.tiddlers[i].fields['server.type'] = FileAdaptor.serverType; |
|---|
| | 154 | context.tiddlers[i].fields['server.host'] = FileAdaptor.minHostName(context.host); |
|---|
| | 155 | context.tiddlers[i].fields['server.page.revision'] = context.tiddlers[i].modified.convertToYYYYMMDDHHMM(); |
|---|
| | 156 | } |
|---|
| | 157 | context.status = true; |
|---|
| | 158 | if(context.callback) { |
|---|
| | 159 | window.setTimeout(context.callback,10,context,userParams); |
|---|
| | 160 | } |
|---|
| 136 | | //# The callback parameters are callback(status,adaptor,context,tiddler) |
|---|
| 137 | | //# status - true if OK, false if error |
|---|
| 138 | | //# adaptor - reference to this adaptor object |
|---|
| 139 | | //# context - as passed into the function |
|---|
| 140 | | //# tiddler - the retrieved tiddler, or null if it cannot be found |
|---|
| | 178 | //# The callback parameters are callback(context,userParams) |
|---|
| | 179 | //# context.status - true if OK, false if error |
|---|
| | 180 | //# context.statusText - error message if there was an error |
|---|
| | 181 | //# context.adaptor - reference to this adaptor object |
|---|
| | 182 | //# context.tiddler - the retrieved tiddler, or null if it cannot be found |
|---|
| | 183 | //# userParams - parameters as originally passed into the getTiddler function |
|---|
| 143 | | if(!this.store) |
|---|
| 144 | | return FileAdaptor.NotLoadedError; |
|---|
| 145 | | if(!context) |
|---|
| 146 | | context = {}; |
|---|
| 147 | | context.tiddler = this.store.fetchTiddler(title); |
|---|
| 148 | | if(context.tiddler) { |
|---|
| 149 | | context.tiddler.fields['server.type'] = FileAdaptor.serverType; |
|---|
| 150 | | context.tiddler.fields['server.host'] = this.host; |
|---|
| 151 | | context.tiddler.fields['server.page.revision'] = context.tiddler.modified.convertToYYYYMMDDHHMM(); |
|---|
| 152 | | } |
|---|
| | 186 | context = this.setContext(context,userParams,callback); |
|---|
| | 187 | context.title = title; |
|---|
| | 188 | context.complete = FileAdaptor.getTiddlerComplete; |
|---|
| | 189 | return context.adaptor.store ? |
|---|
| | 190 | context.complete(context,context.userParams) : |
|---|
| | 191 | loadRemoteFile(context.host,FileAdaptor.loadTiddlyWikiCallback,context); |
|---|
| | 192 | }; |
|---|
| | 193 | |
|---|
| | 194 | FileAdaptor.getTiddlerComplete = function(context,userParams) |
|---|
| | 195 | { |
|---|
| | 196 | var t = context.adaptor.store.fetchTiddler(context.title); |
|---|
| | 197 | t.fields['server.type'] = FileAdaptor.serverType; |
|---|
| | 198 | t.fields['server.host'] = FileAdaptor.minHostName(context.host); |
|---|
| | 199 | t.fields['server.page.revision'] = t.modified.convertToYYYYMMDDHHMM(); |
|---|
| | 200 | context.tiddler = t; |
|---|