refactor(champ): improuve repetition champ
This commit is contained in:
parent
196a9b9a98
commit
1a9f2f0eef
11 changed files with 21 additions and 55 deletions
|
@ -1,33 +0,0 @@
|
|||
import { delegate, fire } from '@utils';
|
||||
|
||||
const CHAMP_SELECTOR = '.editable-champ';
|
||||
const BUTTON_SELECTOR = '.button.remove-row';
|
||||
const DESTROY_INPUT_SELECTOR = 'input[type=hidden][name*=_destroy]';
|
||||
const DOM_ID_INPUT_SELECTOR = 'input[type=hidden][name*=deleted_row_dom_ids]';
|
||||
|
||||
delegate('click', BUTTON_SELECTOR, (evt) => {
|
||||
evt.preventDefault();
|
||||
|
||||
const row = evt.target.closest('.row');
|
||||
|
||||
for (let input of row.querySelectorAll(DESTROY_INPUT_SELECTOR)) {
|
||||
input.disabled = false;
|
||||
input.value = true;
|
||||
}
|
||||
row.querySelector(DOM_ID_INPUT_SELECTOR).disabled = false;
|
||||
|
||||
for (let champ of row.querySelectorAll(CHAMP_SELECTOR)) {
|
||||
champ.remove();
|
||||
}
|
||||
|
||||
evt.target.remove();
|
||||
row.classList.remove('row');
|
||||
|
||||
// We could debounce the autosave request, so that row removal would be batched
|
||||
// with the next changes.
|
||||
// However *adding* a new repetition row isn't debounced (changes are immediately
|
||||
// effective server-side).
|
||||
// So, to avoid ordering issues, enqueue an autosave request as soon as the row
|
||||
// is removed.
|
||||
fire(row, 'autosave:trigger');
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue