mirror of
https://github.com/cesanta/mongoose.git
synced 2026-11-21 19:51:50 +00:00
Fix edit/cancel paths
This commit is contained in:
1 parent
ca86f70152
commit
4b2c137c5f
1 file changed
+14
-23
+14
-23
@@ -173,7 +173,7 @@
|
|||||||
el.classList.toggle("error", false);
|
el.classList.toggle("error", false);
|
||||||
val = v;
|
val = v;
|
||||||
}
|
}
|
||||||
} else if (typeof(v) === 'boolean') {
|
} else if (typeof(dv) === 'boolean') {
|
||||||
val = !!val;
|
val = !!val;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -185,16 +185,13 @@
|
|||||||
el.classList.toggle("edited", true);
|
el.classList.toggle("edited", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (el.dataset.autosave) save([key]);
|
if (el.dataset.autosave) save(key);
|
||||||
rescan();
|
rescan();
|
||||||
};
|
};
|
||||||
|
|
||||||
// Return if any of the keys matching pattern is edited
|
// Return if any of the keys matching pattern is edited
|
||||||
function edited(keys) {
|
function edited(key) {
|
||||||
for (const key of Object.keys(settings.edits)) {
|
return has(settings.edits, key);
|
||||||
if (keys.includes(key)) return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
function handle_bind(el, key, context) {
|
function handle_bind(el, key, context) {
|
||||||
@@ -222,31 +219,26 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Save the edits for keys that match pattern
|
// Save the edits for keys that match pattern
|
||||||
function save(keys) {
|
function save(key) {
|
||||||
const changes = {};
|
const changes = {};
|
||||||
for (const key of keys) {
|
set(changes, key, get(settings.edits, key));
|
||||||
if (!has(settings.edits, key)) continue;
|
|
||||||
set(changes, key, get(settings.edits, key));
|
|
||||||
}
|
|
||||||
rpc.call('set', changes).then(r => apply_and_rescan(settings.data, r));
|
rpc.call('set', changes).then(r => apply_and_rescan(settings.data, r));
|
||||||
};
|
};
|
||||||
|
|
||||||
// Cancel the edits for keys that match pattern
|
// Cancel the edits for keys that match pattern
|
||||||
function cancel(keys) {
|
function cancel(key) {
|
||||||
for (const key of Object.keys(settings.edits)) {
|
del(settings.edits, key);
|
||||||
if (keys.includes(key)) delete settings.edits[key];
|
|
||||||
}
|
|
||||||
rescan();
|
rescan();
|
||||||
};
|
};
|
||||||
|
|
||||||
function handle_save(el, keys) {
|
function handle_save(el, key) {
|
||||||
el.disabled = !edited(keys);
|
el.disabled = !edited(key);
|
||||||
if (!el.bound) el.addEventListener("click", ev => save(keys)), el.bound = true;
|
if (!el.bound) el.addEventListener("click", ev => save(key)), el.bound = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
function handle_cancel(el, keys) {
|
function handle_cancel(el, key) {
|
||||||
if (!el.bound) el.addEventListener("click", ev => cancel(keys)), el.bound = true;
|
if (!el.bound) el.addEventListener("click", ev => cancel(key)), el.bound = true;
|
||||||
el.disabled = !edited(keys);
|
el.disabled = !edited(key);
|
||||||
};
|
};
|
||||||
|
|
||||||
function handle_repeat(el, key, context) {
|
function handle_repeat(el, key, context) {
|
||||||
@@ -323,7 +315,6 @@
|
|||||||
if (v !== attr.value) attr.value = v;
|
if (v !== attr.value) attr.value = v;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//const datakeys = { bind: 1, save: 1, cancel: 1, repeat: 1, upload: 1, ota: 1 };
|
|
||||||
const handlers = {
|
const handlers = {
|
||||||
bind: handle_bind,
|
bind: handle_bind,
|
||||||
save: handle_save,
|
save: handle_save,
|
||||||
|
|||||||
Reference in new issue
Block a user