Fix: dirty state for new added applies

This commit is contained in:
eight 2018-10-14 16:36:12 +08:00
parent fb1b49b8bb
commit 14c2fdbb58

View File

@ -329,10 +329,10 @@ function createSection({
if (selectEl) { if (selectEl) {
selectEl.value = type; selectEl.value = type;
selectEl.addEventListener('change', () => { selectEl.addEventListener('change', () => {
const oldKey = type; const oldType = type;
dirty.modify(`${dirtyPrefix}.type`, type, selectEl.value); dirty.modify(`${dirtyPrefix}.type`, type, selectEl.value);
type = selectEl.value; type = selectEl.value;
if (oldKey === 'regexp' || type === 'regexp') { if (oldType === 'regexp' || type === 'regexp') {
updateRegexpTester(); updateRegexpTester();
} }
emitSectionChange(); emitSectionChange();
@ -354,6 +354,8 @@ function createSection({
valueEl.addEventListener('change', validate); valueEl.addEventListener('change', validate);
} }
restore();
const apply = { const apply = {
id: applyId, id: applyId,
all, all,
@ -362,7 +364,7 @@ function createSection({
el, el,
getType: () => type, getType: () => type,
getValue: () => value, getValue: () => value,
valueEl valueEl // used by validator
}; };
const removeButton = $('.remove-applies-to', el); const removeButton = $('.remove-applies-to', el);
@ -389,11 +391,17 @@ function createSection({
} }
function remove() { function remove() {
if (all) {
return;
}
dirty.remove(`${dirtyPrefix}.type`, type); dirty.remove(`${dirtyPrefix}.type`, type);
dirty.remove(`${dirtyPrefix}.value`, value); dirty.remove(`${dirtyPrefix}.value`, value);
} }
function restore() { function restore() {
if (all) {
return;
}
dirty.add(`${dirtyPrefix}.type`, type); dirty.add(`${dirtyPrefix}.type`, type);
dirty.add(`${dirtyPrefix}.value`, value); dirty.add(`${dirtyPrefix}.value`, value);
} }