Jake Vanderwerf
2026-01-28 8c6502de2f8ec2bd8382cd6945c327d7be400e14
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
@@ -737,7 +741,6 @@
         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 +749,7 @@
      this.changes.get(itemId)[name] = value;
      this.scheduleBackup();
      this.scheduleSave();
   }
   scheduleBackup() {
      window.debouncer.schedule(
@@ -763,8 +767,35 @@
      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;