Refactored project
This commit is contained in:
parent
b6581e74ba
commit
9fc3062fde
|
@ -49,14 +49,14 @@ const saveSession = (elm = null, message = message1) => {
|
||||||
const editSession = (elm = null, message = message1) => {
|
const editSession = (elm = null, message = message1) => {
|
||||||
let id = elm.innerText;
|
let id = elm.innerText;
|
||||||
let inputTag = document.createElement("INPUT");
|
let inputTag = document.createElement("INPUT");
|
||||||
let newSessionCheckTag = document.createElement("INPUT");
|
let newSessionTag = document.createElement("INPUT");
|
||||||
let labelTag = document.createElement("LABEL");
|
let labelTag = document.createElement("LABEL");
|
||||||
let brTag = document.createElement("BR");
|
let brTag = document.createElement("BR");
|
||||||
|
|
||||||
inputTag.value = id;
|
inputTag.value = id;
|
||||||
newSessionCheckTag.type = "checkbox";
|
newSessionTag.type = "checkbox";
|
||||||
newSessionCheckTag.id = "newSession";
|
newSessionTag.id = "newSession";
|
||||||
newSessionCheckTag.checked = false;
|
newSessionTag.checked = false;
|
||||||
labelTag.innerText = "Create New Session";
|
labelTag.innerText = "Create New Session";
|
||||||
labelTag.htmlFor = "newSession";
|
labelTag.htmlFor = "newSession";
|
||||||
|
|
||||||
|
@ -66,7 +66,7 @@ const editSession = (elm = null, message = message1) => {
|
||||||
let keysLength = Object.keys(json).length;
|
let keysLength = Object.keys(json).length;
|
||||||
let container = generateSelectionWindow(json, keys, keysLength);
|
let container = generateSelectionWindow(json, keys, keysLength);
|
||||||
container.prepend(labelTag);
|
container.prepend(labelTag);
|
||||||
container.prepend(newSessionCheckTag);
|
container.prepend(newSessionTag);
|
||||||
container.prepend(brTag);
|
container.prepend(brTag);
|
||||||
container.prepend(inputTag);
|
container.prepend(inputTag);
|
||||||
|
|
||||||
|
@ -85,30 +85,28 @@ const editSession = (elm = null, message = message1) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
json = getSelectionData(container, keys, keysLength);
|
json = getSelectionData(container, keys, keysLength);
|
||||||
// If creating from collection new session
|
|
||||||
if (newSessionCheckTag.checked) {
|
// If creating new session
|
||||||
if (newName !== elm.innerText) {
|
if (newSessionTag.checked) {
|
||||||
newName = checkSessionListForDuplicate(newName);
|
newName = checkSessionListForDuplicate(newName);
|
||||||
saveToStorage(newName, JSON.stringify(json), "save");
|
saveToStorage(newName, JSON.stringify(json), "save");
|
||||||
} else { // Enforce unique name
|
|
||||||
let min = 1;
|
|
||||||
let max = 200000;
|
|
||||||
var random = Math.floor(Math.random() * (+max - +min)) + +min;
|
|
||||||
newName += "-" + random + "-" + Math.floor(Math.random() * (+10 - +1)) + +1;
|
|
||||||
saveToStorage(newName, JSON.stringify(json), "edit");
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// If not creating new session and diff name enforced; generate new name
|
// If not creating new session and are the same name
|
||||||
if (newName !== elm.innerText) {
|
if (newName == id) {
|
||||||
newName = checkSessionListForDuplicate(newName);
|
|
||||||
storageApi.get(id).then((results) => {
|
storageApi.get(id).then((results) => {
|
||||||
storageApi.remove(id);
|
storageApi.remove(id);
|
||||||
|
saveToStorage(newName, JSON.stringify(json), "edit", true);
|
||||||
|
}).then(() => {
|
||||||
|
elm.innerText = newName;
|
||||||
|
});
|
||||||
|
} else { // If not creating new session and names are not the same rename
|
||||||
|
storageApi.get(id).then((results) => {
|
||||||
|
storageApi.remove(id);
|
||||||
|
newName = checkSessionListForDuplicate(newName);
|
||||||
saveToStorage(newName, JSON.stringify(json), "edit");
|
saveToStorage(newName, JSON.stringify(json), "edit");
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
elm.textContent = newName;
|
elm.innerText = newName;
|
||||||
});
|
});
|
||||||
} else { // Replace found session
|
|
||||||
saveToStorage(newName, JSON.stringify(json), "edit", true);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue