From 42fa8304ddb811b0f725f245130f70c0f5e86a6c Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Tue, 04 Nov 2025 06:12:02 +0000
Subject: [PATCH] =Refactored LoginManager to be more extensible and configurable, as well as an AjaxRateLimiter
---
assets/js/dash/CRUD.js | 50 +++++++++++++++++++++++++++++++++++++++-----------
1 files changed, 39 insertions(+), 11 deletions(-)
diff --git a/assets/js/dash/CRUD.js b/assets/js/dash/CRUD.js
index 7bd4d50..670f625 100644
--- a/assets/js/dash/CRUD.js
+++ b/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);
--
Gitblit v1.10.0