Added empty session alerts where needed.

This commit is contained in:
Maxim Stewart 2019-04-19 16:39:16 -05:00
parent 9b940f1d7a
commit 48b0ef340d
3 changed files with 17 additions and 39 deletions

View File

@ -20,9 +20,7 @@ document.addEventListener("click", (e) => {
else if (name == "edit") else if (name == "edit")
editSession(selectedItem); editSession(selectedItem);
} else { } else {
swal("Select a session first...", { messageWindow("warning", "Select a session first...");
icon: "warning",
});
} }
} else if (name == "save") { } else if (name == "save") {
saveSession(selectedItem); saveSession(selectedItem);
@ -81,9 +79,7 @@ document.addEventListener("dblclick", (e) => {
if (keysLength > 0) { if (keysLength > 0) {
loadSession(json, replaceTabs.checked); loadSession(json, replaceTabs.checked);
} else { } else {
swal("Canceled operation; no tabs were selected...", { messageWindow("warning", "Canceled operation; no tabs were selected...");
icon: "warning",
});
} }
} }
}); });

View File

@ -46,14 +46,10 @@ const saveSession = (elm = null, message = "Session Name\nAllowed: a-z, A-Z, 0-9
sessionData = selectionData(container, keys, keysLength); sessionData = selectionData(container, keys, keysLength);
saveToStorage(enteryName, JSON.stringify(sessionData)); saveToStorage(enteryName, JSON.stringify(sessionData));
} else { } else {
swal("Canceled save...", { messageWindow("warning", "Canceled save...");
icon: "warning",
});
} }
} else { } else {
swal("Canceled save...", { messageWindow("warning", "Canceled save...");
icon: "warning",
});
} }
}); });
}); });
@ -122,14 +118,10 @@ const editSession = (elm = null, message = "Editing selected session...\nAllowed
} }
} }
} else { } else {
swal("Canceled edit...", { messageWindow("warning", "Canceled edit...");
icon: "warning",
});
} }
} else { } else {
swal("Canceled edit...", { messageWindow("warning", "Canceled edit...");
icon: "warning",
});
} }
}); });
}); });
@ -195,9 +187,7 @@ const loadSession = (json = null, replaceTabs = false) => {
if (replaceTabs) { // Clear all windows but main then load... if (replaceTabs) { // Clear all windows but main then load...
if (keysLength == 0) { if (keysLength == 0) {
swal("Canceled operation; no tabs in session...", { messageWindow("error", "Canceled operation; no tabs in session...");
icon: "error",
});
return ; return ;
} }
@ -232,9 +222,7 @@ const loadSession = (json = null, replaceTabs = false) => {
if (keysLength == 1) { if (keysLength == 1) {
windowMaker(0, keysLength, keys, json) windowMaker(0, keysLength, keys, json)
} else if (keysLength == 0) { } else if (keysLength == 0) {
swal("Canceled operation; no tabs in session...", { messageWindow("error", "Canceled operation; no tabs in session...");
icon: "error",
});
} }
} }
}); });

View File

@ -1,3 +1,7 @@
const messageWindow = (type = "warning", message = "No message passed in...") => {
swal(message, { icon: type, });
}
const getSavedSessionIDs = () => { const getSavedSessionIDs = () => {
console.log("Getting saved sessions..."); console.log("Getting saved sessions...");
storage.get(null).then((storageResults) => { storage.get(null).then((storageResults) => {
@ -48,19 +52,13 @@ const saveToStorage = (name, data, fromEdit = false) => {
let json = null; let json = null;
try { try {
json = JSON.parse(storageResults[name]); json = JSON.parse(storageResults[name]);
swal("Overwrote session...", { messageWindow("warning", "Overwrote session...");
icon: "warning",
});
} catch (e) { } catch (e) {
if (fromEdit) { // minor logic fix if (fromEdit) { // minor logic fix
swal("Overwrote session...", { messageWindow("warning", "Overwrote session...");
icon: "warning",
});
} else { } else {
appendToSavedSessionsList(name); appendToSavedSessionsList(name);
swal("Saved session...", { messageWindow("success", "Saved session...");
icon: "success",
});
} }
} finally { } finally {
storage.set({[name]: data}); storage.set({[name]: data});
@ -81,13 +79,9 @@ const deleteFromStorage = (elm = null) => {
elm.parentElement.removeChild(elm); elm.parentElement.removeChild(elm);
}); });
selectedItem = null; // reset selectedItem selectedItem = null; // reset selectedItem
swal("Deleted session successfully...", { messageWindow("success", "Deleted session successfully...");
icon: "success",
});
} else { } else {
swal("Canceled deletion...", { messageWindow("warning", "Canceled deletion...");
icon: "warning",
});
} }
}); });
} }