remove duplicate flashMsg code
This commit is contained in:
parent
554997a5c0
commit
e54ff8829a
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
|
|
||||||
behavioural layer for the `network_detail.html.tera` template,
|
behavioural layer for the `network_detail.html.tera` template,
|
||||||
corresponding to the web route `/network/wifi?<ssid>`
|
corresponding to the web route `/settings/network/wifi?<ssid>`
|
||||||
|
|
||||||
- intercept button clicks for connect, disconnect and forget
|
- intercept button clicks for connect, disconnect and forget
|
||||||
- perform json api call
|
- perform json api call
|
||||||
|
@ -12,7 +12,6 @@ methods:
|
||||||
PEACH_NETWORK.connect();
|
PEACH_NETWORK.connect();
|
||||||
PEACH_NETWORK.disconnect();
|
PEACH_NETWORK.disconnect();
|
||||||
PEACH_NETWORK.forget();
|
PEACH_NETWORK.forget();
|
||||||
PEACH_NETWORK.flashMsg(status, msg);
|
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -33,7 +32,7 @@ PEACH_NETWORK.connect = function() {
|
||||||
// perform json serialization
|
// perform json serialization
|
||||||
var jsonData = JSON.stringify(ssidData);
|
var jsonData = JSON.stringify(ssidData);
|
||||||
// write in-progress status message to ui
|
// write in-progress status message to ui
|
||||||
PEACH_NETWORK.flashMsg("info", "Connecting to access point...");
|
PEACH.flashMsg("info", "Connecting to access point...");
|
||||||
// send add_wifi POST request
|
// send add_wifi POST request
|
||||||
fetch("/api/v1/network/wifi/connect", {
|
fetch("/api/v1/network/wifi/connect", {
|
||||||
method: "post",
|
method: "post",
|
||||||
|
@ -47,7 +46,7 @@ PEACH_NETWORK.connect = function() {
|
||||||
})
|
})
|
||||||
.then( (jsonData) => {
|
.then( (jsonData) => {
|
||||||
// write json response message to ui
|
// write json response message to ui
|
||||||
PEACH_NETWORK.flashMsg(jsonData.status, jsonData.msg);
|
PEACH.flashMsg(jsonData.status, jsonData.msg);
|
||||||
})
|
})
|
||||||
}, false);
|
}, false);
|
||||||
};
|
};
|
||||||
|
@ -69,7 +68,7 @@ PEACH_NETWORK.disconnect = function() {
|
||||||
// perform json serialization
|
// perform json serialization
|
||||||
var jsonData = JSON.stringify(ssidData);
|
var jsonData = JSON.stringify(ssidData);
|
||||||
// write in-progress status message to ui
|
// write in-progress status message to ui
|
||||||
PEACH_NETWORK.flashMsg("info", "Disconnecting from access point...");
|
PEACH.flashMsg("info", "Disconnecting from access point...");
|
||||||
// send disconnect_wifi POST request
|
// send disconnect_wifi POST request
|
||||||
fetch("/api/v1/network/wifi/disconnect", {
|
fetch("/api/v1/network/wifi/disconnect", {
|
||||||
method: "post",
|
method: "post",
|
||||||
|
@ -83,7 +82,7 @@ PEACH_NETWORK.disconnect = function() {
|
||||||
})
|
})
|
||||||
.then( (jsonData) => {
|
.then( (jsonData) => {
|
||||||
// write json response message to ui
|
// write json response message to ui
|
||||||
PEACH_NETWORK.flashMsg(jsonData.status, jsonData.msg);
|
PEACH.flashMsg(jsonData.status, jsonData.msg);
|
||||||
})
|
})
|
||||||
}, false);
|
}, false);
|
||||||
};
|
};
|
||||||
|
@ -105,7 +104,7 @@ PEACH_NETWORK.forget = function() {
|
||||||
// perform json serialization
|
// perform json serialization
|
||||||
var jsonData = JSON.stringify(ssidData);
|
var jsonData = JSON.stringify(ssidData);
|
||||||
// write in-progress status message to ui
|
// write in-progress status message to ui
|
||||||
PEACH_NETWORK.flashMsg("info", "Removing credentials for access point...");
|
PEACH.flashMsg("info", "Removing credentials for access point...");
|
||||||
// send forget_ap POST request
|
// send forget_ap POST request
|
||||||
fetch("/api/v1/network/wifi/forget", {
|
fetch("/api/v1/network/wifi/forget", {
|
||||||
method: "post",
|
method: "post",
|
||||||
|
@ -119,48 +118,13 @@ PEACH_NETWORK.forget = function() {
|
||||||
})
|
})
|
||||||
.then( (jsonData) => {
|
.then( (jsonData) => {
|
||||||
// write json response message to ui
|
// write json response message to ui
|
||||||
PEACH_NETWORK.flashMsg(jsonData.status, jsonData.msg);
|
PEACH.flashMsg(jsonData.status, jsonData.msg);
|
||||||
})
|
})
|
||||||
}, false);
|
}, false);
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// display a message by appending a paragraph element
|
|
||||||
PEACH_NETWORK.flashMsg = function(status, msg) {
|
|
||||||
// set the class of the element according to status
|
|
||||||
var elementClass;
|
|
||||||
if (status === "success") {
|
|
||||||
elementClass = "capsule center-text flash-message font-success";
|
|
||||||
} else if (status === "info") {
|
|
||||||
elementClass = "capsule center-text flash-message font-info";
|
|
||||||
} else {
|
|
||||||
elementClass = "capsule center-text flash-message font-failure";
|
|
||||||
};
|
|
||||||
|
|
||||||
var flashElement = document.getElementById("flashMsg");
|
|
||||||
// if flashElement exists, update the class & text
|
|
||||||
if (flashElement) {
|
|
||||||
flashElement.className = elementClass;
|
|
||||||
flashElement.innerText = msg;
|
|
||||||
// if flashElement does not exist, create it, set id, class, text & append
|
|
||||||
} else {
|
|
||||||
// create new div for flash message
|
|
||||||
var flashDiv = document.createElement("DIV");
|
|
||||||
// set div attributes
|
|
||||||
flashDiv.id = "flashMsg";
|
|
||||||
flashDiv.className = elementClass;
|
|
||||||
// add json response message to flash message div
|
|
||||||
var flashMsg = document.createTextNode(msg);
|
|
||||||
flashDiv.appendChild(flashMsg);
|
|
||||||
// insert the flash message div below the button div
|
|
||||||
var buttonDiv = document.getElementById("buttonDiv");
|
|
||||||
// flashDiv will be added to the end since buttonDiv is the last
|
|
||||||
// child within the parent element (card-container div)
|
|
||||||
buttonDiv.parentNode.insertBefore(flashDiv, buttonDiv.nextSibling);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var detailInstance = PEACH_NETWORK;
|
var detailInstance = PEACH_NETWORK;
|
||||||
detailInstance.connect();
|
detailInstance.connect();
|
||||||
detailInstance.disconnect();
|
detailInstance.disconnect();
|
||||||
|
|
|
@ -9,7 +9,6 @@ behavioural layer for the `network_modify.html.tera` template
|
||||||
methods:
|
methods:
|
||||||
|
|
||||||
PEACH_NETWORK.modify();
|
PEACH_NETWORK.modify();
|
||||||
PEACH_NETWORK.flashMsg(status, msg);
|
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -33,7 +32,7 @@ PEACH_NETWORK.modify = function() {
|
||||||
// perform json serialization
|
// perform json serialization
|
||||||
var jsonData = JSON.stringify(object);
|
var jsonData = JSON.stringify(object);
|
||||||
// write in-progress status message to ui
|
// write in-progress status message to ui
|
||||||
PEACH_NETWORK.flashMsg("info", "Updating WiFi password...");
|
PEACH.flashMsg("info", "Updating WiFi password...");
|
||||||
// send new_password POST request
|
// send new_password POST request
|
||||||
fetch("/api/v1/network/wifi/modify", {
|
fetch("/api/v1/network/wifi/modify", {
|
||||||
method: "post",
|
method: "post",
|
||||||
|
@ -47,46 +46,11 @@ PEACH_NETWORK.modify = function() {
|
||||||
})
|
})
|
||||||
.then( (jsonData) => {
|
.then( (jsonData) => {
|
||||||
// write json response message to ui
|
// write json response message to ui
|
||||||
PEACH_NETWORK.flashMsg(jsonData.status, jsonData.msg);
|
PEACH.flashMsg(jsonData.status, jsonData.msg);
|
||||||
})
|
})
|
||||||
}, false);
|
}, false);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// display a message by appending a paragraph element
|
|
||||||
PEACH_NETWORK.flashMsg = function(status, msg) {
|
|
||||||
// set the class of the element according to status
|
|
||||||
var elementClass;
|
|
||||||
if (status === "success") {
|
|
||||||
elementClass = "capsule center-text flash-message font-success";
|
|
||||||
} else if (status === "info") {
|
|
||||||
elementClass = "capsule center-text flash-message font-info";
|
|
||||||
} else {
|
|
||||||
elementClass = "capsule center-text flash-message font-failure";
|
|
||||||
};
|
|
||||||
|
|
||||||
var flashElement = document.getElementById("flashMsg");
|
|
||||||
// if flashElement exists, update the class & text
|
|
||||||
if (flashElement) {
|
|
||||||
flashElement.className = elementClass;
|
|
||||||
flashElement.innerText = msg;
|
|
||||||
// if flashElement does not exist, create it, set id, class, text & append
|
|
||||||
} else {
|
|
||||||
// create new div for flash message
|
|
||||||
var flashDiv = document.createElement("DIV");
|
|
||||||
// set div attributes
|
|
||||||
flashDiv.id = "flashMsg";
|
|
||||||
flashDiv.className = elementClass;
|
|
||||||
// add json response message to flash message div
|
|
||||||
var flashMsg = document.createTextNode(msg);
|
|
||||||
flashDiv.appendChild(flashMsg);
|
|
||||||
// insert the flash message div below the button div
|
|
||||||
var buttonDiv = document.getElementById("buttonDiv");
|
|
||||||
// flashDiv will be added to the end since buttonDiv is the last
|
|
||||||
// child within the parent element (card-container div)
|
|
||||||
buttonDiv.parentNode.insertBefore(flashDiv, buttonDiv.nextSibling);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var modifyInstance = PEACH_NETWORK;
|
var modifyInstance = PEACH_NETWORK;
|
||||||
modifyInstance.modify();
|
modifyInstance.modify();
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
|
|
||||||
behavioural layer for the `network_usage.html.tera` template,
|
behavioural layer for the `network_usage.html.tera` template,
|
||||||
corresponding to the web route `/network/wifi/usage`
|
corresponding to the web route `/settings/network/wifi/usage`
|
||||||
|
|
||||||
- intercept form submissions
|
- intercept form submissions
|
||||||
- perform json api calls
|
- perform json api calls
|
||||||
|
@ -13,7 +13,6 @@ methods:
|
||||||
PEACH_NETWORK.resetUsage();
|
PEACH_NETWORK.resetUsage();
|
||||||
PEACH_NETWORK.toggleWarning();
|
PEACH_NETWORK.toggleWarning();
|
||||||
PEACH_NETWORK.toggleCutoff();
|
PEACH_NETWORK.toggleCutoff();
|
||||||
PEACH_NETWORK.flashMsg(status, msg);
|
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -51,7 +50,7 @@ PEACH_NETWORK.updateAlerts = function() {
|
||||||
})
|
})
|
||||||
.then( (jsonData) => {
|
.then( (jsonData) => {
|
||||||
// write json response message to ui
|
// write json response message to ui
|
||||||
PEACH_NETWORK.flashMsg(jsonData.status, jsonData.msg);
|
PEACH.flashMsg(jsonData.status, jsonData.msg);
|
||||||
})
|
})
|
||||||
}, false);
|
}, false);
|
||||||
});
|
});
|
||||||
|
@ -79,7 +78,7 @@ PEACH_NETWORK.resetUsage = function() {
|
||||||
.then( (jsonData) => {
|
.then( (jsonData) => {
|
||||||
console.log(jsonData.msg);
|
console.log(jsonData.msg);
|
||||||
// write json response message to ui
|
// write json response message to ui
|
||||||
PEACH_NETWORK.flashMsg(jsonData.status, jsonData.msg);
|
PEACH.flashMsg(jsonData.status, jsonData.msg);
|
||||||
// if reset is successful, update the ui
|
// if reset is successful, update the ui
|
||||||
if (jsonData.status === "success") {
|
if (jsonData.status === "success") {
|
||||||
console.log(jsonData.data);
|
console.log(jsonData.data);
|
||||||
|
@ -133,39 +132,6 @@ PEACH_NETWORK.toggleCutoff = function() {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// display a message by appending a paragraph element
|
|
||||||
PEACH_NETWORK.flashMsg = function(status, msg) {
|
|
||||||
// set the class of the element according to status
|
|
||||||
var elementClass;
|
|
||||||
if (status === "success") {
|
|
||||||
elementClass = "capsule center-text flash-message font-success";
|
|
||||||
} else if (status === "info") {
|
|
||||||
elementClass = "capsule center-text flash-message font-info";
|
|
||||||
} else {
|
|
||||||
elementClass = "capsule center-text flash-message font-failure";
|
|
||||||
};
|
|
||||||
|
|
||||||
var flashElement = document.getElementById("flashMsg");
|
|
||||||
// if flashElement exists, update the class & text
|
|
||||||
if (flashElement) {
|
|
||||||
flashElement.className = elementClass;
|
|
||||||
flashElement.innerText = msg;
|
|
||||||
// if flashElement does not exist, create it, set id, class, text & append
|
|
||||||
} else {
|
|
||||||
// create new div for flash message
|
|
||||||
var flashDiv = document.createElement("DIV");
|
|
||||||
// set div attributes
|
|
||||||
flashDiv.id = "flashMsg";
|
|
||||||
flashDiv.className = elementClass;
|
|
||||||
// add json response message to flash message div
|
|
||||||
var flashMsg = document.createTextNode(msg);
|
|
||||||
flashDiv.appendChild(flashMsg);
|
|
||||||
// insert the flash message div below the button div
|
|
||||||
var buttonDiv = document.getElementById("buttonDiv");
|
|
||||||
buttonDiv.parentNode.insertBefore(flashDiv, buttonDiv.nextSibling);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var usageInstance = PEACH_NETWORK;
|
var usageInstance = PEACH_NETWORK;
|
||||||
usageInstance.resetUsage();
|
usageInstance.resetUsage();
|
||||||
usageInstance.toggleWarning();
|
usageInstance.toggleWarning();
|
||||||
|
|
|
@ -11,7 +11,6 @@ methods:
|
||||||
|
|
||||||
PEACH_DEVICE.reboot();
|
PEACH_DEVICE.reboot();
|
||||||
PEACH_DEVICE.shutdown();
|
PEACH_DEVICE.shutdown();
|
||||||
PEACH_DEVICE.flashMsg(status, msg);
|
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -26,7 +25,7 @@ PEACH_DEVICE.reboot = function() {
|
||||||
// prevent redirect on button press (default behavior)
|
// prevent redirect on button press (default behavior)
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
// write reboot flash message
|
// write reboot flash message
|
||||||
PEACH_DEVICE.flashMsg("success", "Rebooting the device...");
|
PEACH.flashMsg("success", "Rebooting the device...");
|
||||||
// send reboot_device POST request
|
// send reboot_device POST request
|
||||||
fetch("/api/v1/admin/reboot", {
|
fetch("/api/v1/admin/reboot", {
|
||||||
method: "post",
|
method: "post",
|
||||||
|
@ -41,7 +40,7 @@ PEACH_DEVICE.reboot = function() {
|
||||||
.then( (jsonData) => {
|
.then( (jsonData) => {
|
||||||
console.log(jsonData.msg);
|
console.log(jsonData.msg);
|
||||||
// write json response message to ui
|
// write json response message to ui
|
||||||
PEACH_DEVICE.flashMsg(jsonData.status, jsonData.msg);
|
PEACH.flashMsg(jsonData.status, jsonData.msg);
|
||||||
})
|
})
|
||||||
}, false);
|
}, false);
|
||||||
}
|
}
|
||||||
|
@ -57,7 +56,7 @@ PEACH_DEVICE.shutdown = function() {
|
||||||
// prevent form submission (default behavior)
|
// prevent form submission (default behavior)
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
// write shutdown flash message
|
// write shutdown flash message
|
||||||
PEACH_DEVICE.flashMsg("success", "Shutting down the device...");
|
PEACH.flashMsg("success", "Shutting down the device...");
|
||||||
// send shutdown_device POST request
|
// send shutdown_device POST request
|
||||||
fetch("/api/v1/shutdown", {
|
fetch("/api/v1/shutdown", {
|
||||||
method: "post",
|
method: "post",
|
||||||
|
@ -72,48 +71,13 @@ PEACH_DEVICE.shutdown = function() {
|
||||||
.then( (jsonData) => {
|
.then( (jsonData) => {
|
||||||
console.log(jsonData.msg);
|
console.log(jsonData.msg);
|
||||||
// write json response message to ui
|
// write json response message to ui
|
||||||
PEACH_DEVICE.flashMsg(jsonData.status, jsonData.msg);
|
PEACH.flashMsg(jsonData.status, jsonData.msg);
|
||||||
})
|
})
|
||||||
}, false);
|
}, false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// display a message by appending a paragraph element
|
|
||||||
PEACH_DEVICE.flashMsg = function(status, msg) {
|
|
||||||
// set the class of the element according to status
|
|
||||||
var elementClass;
|
|
||||||
if (status === "success") {
|
|
||||||
elementClass = "capsule center-text flash-message font-success";
|
|
||||||
} else if (status === "info") {
|
|
||||||
elementClass = "capsule center-text flash-message font-info";
|
|
||||||
} else {
|
|
||||||
elementClass = "capsule center-text flash-message font-failure";
|
|
||||||
};
|
|
||||||
|
|
||||||
var flashElement = document.getElementById("flashMsg");
|
|
||||||
// if flashElement exists, update the class & text
|
|
||||||
if (flashElement) {
|
|
||||||
flashElement.className = elementClass;
|
|
||||||
flashElement.innerText = msg;
|
|
||||||
// if flashElement does not exist, create it, set id, class, text & append
|
|
||||||
} else {
|
|
||||||
// create new div for flash message
|
|
||||||
var flashDiv = document.createElement("DIV");
|
|
||||||
// set div attributes
|
|
||||||
flashDiv.id = "flashMsg";
|
|
||||||
flashDiv.className = elementClass;
|
|
||||||
// add json response message to flash message div
|
|
||||||
var flashMsg = document.createTextNode(msg);
|
|
||||||
flashDiv.appendChild(flashMsg);
|
|
||||||
// insert the flash message div below the button div
|
|
||||||
var buttonDiv = document.getElementById("buttonDiv");
|
|
||||||
// flashDiv will be added to the end since buttonDiv is the last
|
|
||||||
// child within the parent element (card-container div)
|
|
||||||
buttonDiv.parentNode.insertBefore(flashDiv, buttonDiv.nextSibling);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var deviceInstance = PEACH_DEVICE;
|
var deviceInstance = PEACH_DEVICE;
|
||||||
deviceInstance.reboot();
|
deviceInstance.reboot();
|
||||||
deviceInstance.shutdown();
|
deviceInstance.shutdown();
|
||||||
|
|
Loading…
Reference in New Issue