forked from PeachCloud/peach-workspace
remove duplicate flashMsg code
This commit is contained in:
parent
e54ff8829a
commit
e5f9a9be83
|
@ -10,7 +10,6 @@ corresponding to the web route `/network/wifi/add`
|
|||
methods:
|
||||
|
||||
PEACH_NETWORK.add();
|
||||
PEACH_NETWORK.flashMsg(status, msg);
|
||||
|
||||
*/
|
||||
|
||||
|
@ -34,7 +33,7 @@ PEACH_NETWORK.add = function() {
|
|||
// perform json serialization
|
||||
var jsonData = JSON.stringify(object);
|
||||
// write in-progress status message to ui
|
||||
PEACH_NETWORK.flashMsg("info", "Adding WiFi credentials...");
|
||||
PEACH.flashMsg("info", "Adding WiFi credentials...");
|
||||
// send add_wifi POST request
|
||||
fetch("/api/v1/network/wifi", {
|
||||
method: "post",
|
||||
|
@ -48,46 +47,11 @@ PEACH_NETWORK.add = function() {
|
|||
})
|
||||
.then( (jsonData) => {
|
||||
// write json response message to ui
|
||||
PEACH_NETWORK.flashMsg(jsonData.status, jsonData.msg);
|
||||
PEACH.flashMsg(jsonData.status, jsonData.msg);
|
||||
})
|
||||
}, 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 addInstance = PEACH_NETWORK;
|
||||
addInstance.add();
|
||||
|
|
Loading…
Reference in New Issue