1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-23 18:17:20 +00:00

Fix coding standards for put.js

A few minor things, but the accidental use of "const" is serious: TW5 is intended to run on ES5.
This commit is contained in:
Jermolene 2018-06-13 15:50:47 +01:00
parent bacf500d50
commit aba9c94f5a

View File

@ -18,16 +18,22 @@ to the current URL, such as a WebDAV server.
/* /*
Retrieve ETag if available Retrieve ETag if available
*/ */
var RetrieveETag = function(self) { var retrieveETag = function(self) {
var headers = { "Accept": "*/*;charset=UTF-8" }; var headers = {
Accept: "*/*;charset=UTF-8"
};
$tw.utils.httpRequest({ $tw.utils.httpRequest({
url: self.uri(), url: self.uri(),
type: "HEAD", type: "HEAD",
headers: headers, headers: headers,
callback: function(err, data, xhr) { callback: function(err,data,xhr) {
if(err) return; if(err) {
return;
}
var etag = xhr.getResponseHeader("ETag"); var etag = xhr.getResponseHeader("ETag");
if(!etag) return; if(!etag) {
return;
}
self.etag = etag.replace(/^W\//,""); self.etag = etag.replace(/^W\//,"");
} }
}); });
@ -46,14 +52,14 @@ var PutSaver = function(wiki) {
$tw.utils.httpRequest({ $tw.utils.httpRequest({
url: uri, url: uri,
type: "OPTIONS", type: "OPTIONS",
callback: function(err, data, xhr) { callback: function(err,data,xhr) {
// Check DAV header http://www.webdav.org/specs/rfc2518.html#rfc.section.9.1 // Check DAV header http://www.webdav.org/specs/rfc2518.html#rfc.section.9.1
if(!err) { if(!err) {
self.serverAcceptsPuts = xhr.status === 200 && !!xhr.getResponseHeader("dav"); self.serverAcceptsPuts = xhr.status === 200 && !!xhr.getResponseHeader("dav");
} }
} }
}); });
RetrieveETag(this); retrieveETag(this);
}; };
PutSaver.prototype.uri = function() { PutSaver.prototype.uri = function() {
@ -63,12 +69,14 @@ PutSaver.prototype.uri = function() {
// TODO: in case of edit conflict // TODO: in case of edit conflict
// Prompt: Do you want to save over this? Y/N // Prompt: Do you want to save over this? Y/N
// Merging would be ideal, and may be possible using future generic merge flow // Merging would be ideal, and may be possible using future generic merge flow
PutSaver.prototype.save = function(text, method, callback) { PutSaver.prototype.save = function(text,method,callback) {
if(!this.serverAcceptsPuts) { if(!this.serverAcceptsPuts) {
return false; return false;
} }
var self = this; var self = this;
var headers = { "Content-Type": "text/html;charset=UTF-8" }; var headers = {
"Content-Type": "text/html;charset=UTF-8"
};
if(this.etag) { if(this.etag) {
headers["If-Match"] = this.etag; headers["If-Match"] = this.etag;
} }
@ -77,10 +85,10 @@ PutSaver.prototype.save = function(text, method, callback) {
type: "PUT", type: "PUT",
headers: headers, headers: headers,
data: text, data: text,
callback: function(err, data, xhr) { callback: function(err,data,xhr) {
if(err) { if(err) {
// response is textual: "XMLHttpRequest error code: 412" // response is textual: "XMLHttpRequest error code: 412"
const status = Number(err.substring(err.indexOf(':') + 2, err.length)) var status = Number(err.substring(err.indexOf(':') + 2, err.length))
if(status === 412) { // edit conflict if(status === 412) { // edit conflict
var message = $tw.language.getString("Error/EditConflict"); var message = $tw.language.getString("Error/EditConflict");
callback(message); callback(message);
@ -89,8 +97,8 @@ PutSaver.prototype.save = function(text, method, callback) {
} }
} else { } else {
self.etag = xhr.getResponseHeader("ETag"); self.etag = xhr.getResponseHeader("ETag");
if (self.etag == null) { if(self.etag == null) {
RetrieveETag(self); retrieveETag(self);
} }
callback(null); // success callback(null); // success
} }
@ -105,7 +113,7 @@ Information about this saver
PutSaver.prototype.info = { PutSaver.prototype.info = {
name: "put", name: "put",
priority: 2000, priority: 2000,
capabilities: ["save", "autosave"] capabilities: ["save","autosave"]
}; };
/* /*