Jake Vanderwerf
2025-11-04 42fa8304ddb811b0f725f245130f70c0f5e86a6c
assets/js/dash/CRUD.js
@@ -7,6 +7,7 @@
      console.log(this.queue);
      this.config = config;
      this.content = config.content || false;
      this.settings = window.jvbUserSettings;
      if (!this.content) {
         return;
@@ -18,23 +19,30 @@
      // Initialize components
      this.store = new window.jvbStore({
         name: this.content,
         storeName: this.content,
         endpoint: 'content',
         headers: {
            'action_nonce': jvbSettings.dash,
         },
         indexes: [
            { name: 'status', keyPath: 'post_status'},
            { name: 'modified', keyPath: 'modified'},
         ],
         filters: {
            content: this.content,
            user: jvbSettings.currentUser,
            page: 1,
            status: 'all'
         }
         },
         TTL: 3600000,
         cacheDOM: true
      });
      this.status = 'all';
      this.filterTimeout = null;
      this.viewController = new window.jvbViews(this.ui.container, this.store);
      this.formController = new window.jvbForm(this.store);
      this.formController = new window.jvbForm();
      this.formController.subscribe((event, data) => {
         switch(event) {
@@ -173,16 +181,27 @@
            create: 'dialog.create form',
            edit: 'dialog.edit form',
            bulkEdit: 'dialog.bulkEdit form'
         }
         },
         uploader: 'details.uploader'
      };
      this.ui = window.uiFromSelectors(this.elements);
   }
   init() {
      this.settings.addSetting(this.ui.uploader, 'open');
      this.ui.uploader.addEventListener('toggle', (e) =>{
         console.log(e);
         console.log('Is Open: ', this.ui.uploader.open);
         console.log(this.ui.uploader.open ? 'on' : 'off');
         this.settings.saveSetting('open', this.ui.uploader.open ? 'on' : 'off');
      });
      // Set up filter controls
      this.filterHandler = this.handleFilterChange.bind(this);
      this.changeHandler = this.handleChange.bind(this);
      this.modals = {};
      for (let [name, modal] of Object.entries(this.ui.modals)) {
         this.modals[name] = new window.jvbModal(modal);
@@ -206,8 +225,14 @@
      this.setupFilters();
      // Load initial data
      this.store.fetch();
      this.queue.subscribe((event, data) => {
         switch (event) {
            case 'operation-status':
               //update items?
               break;
         }
      });
      this.initialized = true;
   }
@@ -238,7 +263,7 @@
                     };
                     window.fade(actionBtn.closest('.item'), false);
                     this.savePosts(changes, `Sending ${this.singular} to trash...`);
                     this.store.deleteItem(id);
                     this.store.delete(id);
                  }
                  break;
               case 'trash':
@@ -268,17 +293,17 @@
               case 'bulk-delete':
                  const toDelete = Array.from(this.viewController.selectedItems);
                  if (toDelete.length > 0 && confirm(`Delete ${toDelete.length} items?`)) {
                     toDelete.forEach(id => this.store.deleteItem(id));
                     toDelete.forEach(id => this.store.delete(id));
                     this.viewController.clearSelection();
                  }
                  break;
               case 'sync':
                  this.store.syncQueue();
                  // this.store.syncQueue();
                  break;
               case 'refresh':
                  this.store.fetchFromServer(this.store.filters);
                  this.store.fetch();
                  break;
            }
         }
@@ -469,7 +494,7 @@
      window.removeChildren(container);
      for (let selected of this.viewController.selectedItems) {
         console.log(selected);
         let item = this.store.getItem(selected);
         let item = this.store.get(selected);
         console.log(item);
         const img = window.getTemplate('bulkItem');
         if (!img) return;
@@ -502,7 +527,9 @@
   }
   populateEditForm(itemID) {
      let item = this.store.getItem(itemID);
      console.log(itemID);
      let item = this.store.get(parseInt(itemID));
      console.log(item);
      if (item) {
         this.ui.modals.edit.dataset.itemID = itemID;
@@ -524,6 +551,7 @@
   setupFilters() {
      document.querySelectorAll('[data-filter]').forEach(filter => {
         this.settings.addSetting(filter)
         filter.addEventListener('change', (e) => {
            if (this.filterTimeout) {
               clearTimeout(this.filterTimeout);