Statusmeldungen hinzugefügt; Reservierungen funktionabel; kleine Bugfixes
This commit is contained in:
@@ -8,7 +8,28 @@ var menuJSON = {
|
||||
var REGEX_CREATE = /^[fd]-[0-9]+-new$/;
|
||||
var REGEX_UPDATE = /^[fd]-[0-9]+-[0-9]+$/;
|
||||
var REGEX_DELETE = /^[fd]-[0-9]+-[0-9]+-del$/;
|
||||
var REGEX_FLOAT = /^(\-|\+)?([0-9]+(\.[0-9]+)?)$/;
|
||||
|
||||
var REGEX_FLOAT = /^([0-9]+(\.[0-9]+)?)$/;
|
||||
|
||||
var LANG = {};
|
||||
LANG["ACTIONS"] = {
|
||||
1: "Das Ertellen des Menüeintrags",
|
||||
2: "Das Aktualisieren der Informationen",
|
||||
3: "Das Löschen des Menüeintrags"
|
||||
};
|
||||
LANG["ERROR_MESSAGES"] = {
|
||||
1: "Das Feld \"Name\" darf nicht leer sein.",
|
||||
2: "Das Feld \"Beschreibung\" darf nicht leer sein.",
|
||||
4: "Das Feld \"Preis\" darf nicht leer und muss eine positive Zahl sein.",
|
||||
8: "Beim Verarbeiten der Anfrage ist ein interner Fehler aufgetreten."
|
||||
};
|
||||
LANG["MESSAGES"] = {
|
||||
"success": "%action% war erfolgreich.",
|
||||
"failure": "%action% konnte nicht durchgeführt werden."
|
||||
};
|
||||
LANG["INTERNAL"] = {
|
||||
"noinput": "No input file for menu JSON specified!"
|
||||
};
|
||||
|
||||
var FILENAME = false;
|
||||
|
||||
@@ -18,7 +39,7 @@ module.exports.init = function(menufile) {
|
||||
}
|
||||
|
||||
module.exports.loadFile = function() {
|
||||
if (!FILENAME) throw "No file for menu JSON specified";
|
||||
if (!FILENAME) throw LANG["MESSAGES"]["noinput"];
|
||||
fs.readFile(FILENAME, 'utf8', function(err, data) {
|
||||
if (err) throw err;
|
||||
menuJSON = JSON.parse(data);
|
||||
@@ -26,7 +47,7 @@ module.exports.loadFile = function() {
|
||||
}
|
||||
|
||||
module.exports.saveJSON = function() {
|
||||
if (!FILENAME) throw "No file for menu JSON specified";
|
||||
if (!FILENAME) throw LANG["MESSAGES"]["noinput"];
|
||||
fs.writeFile(FILENAME, JSON.stringify(menuJSON, null, 4), function(err) {
|
||||
if(err) {
|
||||
console.log(err);
|
||||
@@ -50,6 +71,36 @@ module.exports.ErrorCode = {
|
||||
NOFLOAT_PRICE: 4,
|
||||
WRONG_ACTION: 8
|
||||
}
|
||||
module.exports.ErrorCode["MAX"] = sum(module.exports.ErrorCode);
|
||||
|
||||
module.exports.getStatusMessage = function(errorCode, action, nametag) {
|
||||
if (action) {
|
||||
var position = splitNameTag(nametag, action);
|
||||
if (!errorCode) {
|
||||
return {
|
||||
type: "success",
|
||||
message: LANG["MESSAGES"]["success"].replace("%action%", LANG["ACTIONS"][action]),
|
||||
reasons: null,
|
||||
anchor: menuJSON[position.category][position.section]["anchor"]
|
||||
}
|
||||
} else {
|
||||
var reasons = [];
|
||||
for (var i = 1; i < module.exports.ErrorCode["MAX"]; i=i*2) {
|
||||
if (errorCode & i) { // bit-wise comparing
|
||||
reasons.push(LANG["ERROR_MESSAGES"][i]);
|
||||
}
|
||||
}
|
||||
return {
|
||||
type: "danger",
|
||||
message: LANG["MESSAGES"]["failure"].replace("%action%", LANG["ACTIONS"][action]),
|
||||
reasons: reasons,
|
||||
anchor: menuJSON[position.category][position.section]["anchor"]
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports.determineAction = function(nametag) {
|
||||
if (nametag && REGEX_CREATE.test(nametag)) { // new
|
||||
@@ -136,6 +187,16 @@ var filterFloat = function(value) {
|
||||
return NaN;
|
||||
}
|
||||
|
||||
function sum(obj) {
|
||||
var sum = 0;
|
||||
for(var el in obj) {
|
||||
if(obj.hasOwnProperty(el)) {
|
||||
sum += parseFloat(obj[el]);
|
||||
}
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
var splitNameTag = function(nametag, action) {
|
||||
if (action) { // create, update & delete
|
||||
var splitArr = nametag.split("-");
|
||||
|
||||
Reference in New Issue
Block a user