Jake Vanderwerf
2026-02-04 2127b1bdd73ecd2423e443992da4b442f5a3c1a3
assets/js/concise/CRUD.js
@@ -371,6 +371,12 @@
                     if (name === 'date') {
                        this.handleCustomDateSelection()
                     }
                     if (['edit','bulkEdit','create'].includes(name)) {
                        //handle escapes (not form submits)
                        if (window.debouncer.timeouts.has(`save-${this.content}`)) {
                           this.scheduleSave(0);
                        }
                     }
                     break;
                  case 'modal-open':
@@ -628,9 +634,7 @@
      } else if (modal.classList.contains('create')) {
         title = `Creating your new ${this.singular}`;
      }
      this.cancelBackup();
      this.handleBackup().then(()=>{});
      this.savePosts(title,false).then(()=>{});
      this.scheduleSave(0);
   }
   handleChange(e) {
      // Early bailout - target must be in an item or be a filter
@@ -733,11 +737,13 @@
      if (!item) return;
      item.dataset.itemId.split(',').forEach(itemId => {
         let field = this.forms.getField(e.target);
         if (['repeater', 'tag-list'].includes(field.dataset.fieldType)) {
            return;
         }
         let name = field.dataset.field;
         let value = this.forms.getFieldValue(e.target);
         this.updateItem(itemId, name, value);
      });
      this.savePosts('', true).then(()=>{});
   }
   updateItem(itemId, name, value) {
      if (!this.changes.has(itemId)) {
@@ -746,6 +752,7 @@
      this.changes.get(itemId)[name] = value;
      this.scheduleBackup();
      this.scheduleSave();
   }
   scheduleBackup() {
      window.debouncer.schedule(
@@ -758,13 +765,39 @@
         2000
      );
   }
   cancelBackup() {
      window.debouncer.cancel(`changes-${this.content}`);
   }
   async handleBackup() {
      await this.changesStore.saveMany(this.changes);
      const changesArray = Array.from(this.changes.values());
      this.changes.clear();
      const ids = changesArray.map(c => c.id);
      const existing = await Promise.all(
         ids.map(id => this.changesStore.get(id))
      );
      const changes = changesArray.map((change, i) =>
         existing[i] ? window.deepMerge(existing[i], change) : change
      );
      await this.changesStore.saveMany(changes);
   }
   scheduleSave(delay = 10000) {
      window.debouncer.schedule(
         `save-${this.content}`,
         async () => {
            // Ensure latest changes are in IndexedDB
            if (this.changes.size > 0) {
               this.cancelBackup();
               await this.handleBackup();
            }
            await this.savePosts('', false);
         },
         delay
      );
   }
   handleFilterChange(target) {
      let filter = target.dataset.filter;
@@ -1139,7 +1172,7 @@
         await this.handleBackup();
      }
      const changes = await this.changesStore.getAll();
      console.log('Saving Changes: ', changes);
      if (changes.length === 0) return;
      if (title === '') {