moved processRequestFailure and other multi-use methods into Helpers.js

This commit is contained in:
chris.watts90@outlook.com 2017-03-17 22:38:33 +00:00
parent 398e61a36d
commit 88b62a23a3

View File

@ -32,4 +32,57 @@
} }
return url; return url;
}; };
self.goToMenuOption = function(page) {
location.hash = page;
console.log("goToMenuOption: " + page);
};
self.processRequestFailure = function(xmlHttpRequest, textStatus, errorThrown) {
if (xmlHttpRequest.readyState === 4) {
return {
errorCode: xmlHttpRequest.status,
errorMessage: xmlHttpRequest.statusText,
errorSource: ""
};
}
else if (xmlHttpRequest.readyState === 0) {
return {
errorCode: xmlHttpRequest.status,
errorMessage: "Network Error - Is the server available?",
errorSource: ""
};
}
else {
return {
errorCode: xmlHttpRequest.status,
errorMessage: "Unknown Error",
errorSource: ""
};
}
}
/**
* Function to redirect to a page in the sammy.js eco system.
* Relies on "pagedestination" tag in the html. This is a button click handler.
* @param {Object<unknown>} data - dunno?
* @param {Object<buttonhandle>} event - handle to the button that was clicked.
* @returns {nothing} - redirects to the url referenced by the pageDestination tag.
*/
self.getPageDestination = function(data, event) {
var target = null;
if (event.target) target = event.target;
else if (event.srcElement) target = event.srcElement;
var destination = "";
if (target != null) {
for (var i = 0; i < target.attributes.length; i++) {
if (target.attributes[i].nodeName === "pagedestination") {
destination = target.attributes[i].value;
break;
}
}
if (destination !== "") {
return destination;
}
} else {
console.log("target is null, going nowhere");
}
};
}; };