From 3aada9949d51024a92a8b5c6cb70d12f9c3cac16 Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Sun, 21 Dec 2025 19:59:48 +0000
Subject: [PATCH] =auth refactored via rest, referral system set up for Jane, some javascript consolidation

---
 assets/js/concise/CRUD.js |   53 +++++++++++++++++++++++++++++------------------------
 1 files changed, 29 insertions(+), 24 deletions(-)

diff --git a/assets/js/dash/CRUD.js b/assets/js/concise/CRUD.js
similarity index 93%
rename from assets/js/dash/CRUD.js
rename to assets/js/concise/CRUD.js
index 0a2144b..f6eee56 100644
--- a/assets/js/dash/CRUD.js
+++ b/assets/js/concise/CRUD.js
@@ -7,7 +7,7 @@
 		this.config = config;
 		this.content = config.content || false;
 		this.settings = window.jvbUserSettings;
-
+		this.a11y = window.jvbA11y;
 		if (!this.content) {
 			return;
 		}
@@ -25,7 +25,7 @@
 				keyPath: 'id',
 				endpoint: 'content',
 				headers: {
-					'action_nonce': jvbSettings.dash,
+					'action_nonce': window.auth.getNonce('dash'),
 				},
 				indexes: [
 					{name: 'id', keyPath: 'id'},
@@ -36,7 +36,7 @@
 				],
 				filters: {
 					content: this.content,
-					user: jvbSettings.currentUser,
+					user: window.auth.getUser(),
 					page: 1,
 					status: 'all',
 					orderby: 'modified', //or title
@@ -92,7 +92,6 @@
 
 		this.queue.subscribe((event, data) => {
 			if (!Object.hasOwn(data, 'endpoint') || data.endpoint !== 'content') return;
-			console.log('Queue Subscription in CRUD.js: ', data);
 			if (event === 'operation-completed') {
 				this.handleQueueSuccess(event, data);
 			} else if (event === 'operation-failed-permanent') {
@@ -168,7 +167,7 @@
 			}
 		}
 
-		if (window.isEmptyObject(theChanges)) {
+		if (Object.keys(theChanges).length === 0) {
 			return;
 		}
 
@@ -181,7 +180,7 @@
 	}
 
 	savePosts(changes, title) {
-		if (window.isEmptyObject(changes)) {
+		if (Object.keys(changes).length === 0) {
 			return;
 		}
 
@@ -194,7 +193,7 @@
 		let operation = {
 			endpoint: 'content',
 			headers: {
-				'action_nonce': jvbSettings.dash,
+				'action_nonce': window.auth.getNonce('dash'),
 			},
 			data: {
 				posts: changes,
@@ -238,11 +237,12 @@
 		this.isTimeline = !!document.querySelector('[data-timeline]');
 	}
 	init() {
-		this.settings.addSetting(this.ui.uploader, 'open');
-		this.ui.uploader.addEventListener('toggle', (e) =>{
-			this.settings.saveSetting('open', this.ui.uploader.open ? 'on' : 'off');
-		});
-
+		if (this.ui.uploader){
+			this.settings.addSetting(this.ui.uploader, 'open');
+			this.ui.uploader.addEventListener('toggle', (e) =>{
+				this.settings.saveSetting('open', this.ui.uploader.open ? 'on' : 'off');
+			});
+		}
 
 		// Set up filter controls
 		this.filterHandler = this.handleFilterChange.bind(this);
@@ -558,7 +558,7 @@
 		this.viewController.clearSelection();
 
 
-		if (!window.isEmptyObject(changes)) {
+		if (Object.keys(changes).length !== 0) {
 			this.savePosts(changes, `${title} ${this.viewController.selectedItems.size} ${this.plural}...`);
 		}
 	}
@@ -579,7 +579,7 @@
 	}
 	updateBulkOptions(status = 'all') {
 		if (status === 'trash') {
-			if (this.ui.bulkSelectActions.querySelector('[value="edit"]')) {
+			if (this.ui.bulkSelectActions?.querySelector('[value="edit"]')) {
 				window.removeChildren(this.ui.bulkSelectActions);
 				let options = window.getTemplate('trashOptions');
 				options.querySelectorAll('option').forEach((option, index) => {
@@ -590,7 +590,7 @@
 				});
 			}
 		} else {
-			if (!this.ui.bulkSelectActions.querySelector('[value="edit"]')) {
+			if (this.ui.bulkSelectActions && !this.ui.bulkSelectActions.querySelector('[value="edit"]')) {
 				window.removeChildren(this.ui.bulkSelectActions);
 
 				let options = window.getTemplate('notTrashOptions');
@@ -599,7 +599,9 @@
 				});
 			}
 		}
-		this.ui.bulkSelectActions.value = '';
+		if (this.ui.bulkSelectActions) {
+			this.ui.bulkSelectActions.value = '';
+		}
 	}
 
 	populateBulkEdit() {
@@ -685,12 +687,15 @@
 }
 
 // Initialize when ready
-document.addEventListener('DOMContentLoaded', () => {
-	let container = document.querySelector('[data-content]');
-	if (container) {
-		window.crudManager = new CRUDManager({
-			content: container.dataset.content,
-		});
-	}
-
+document.addEventListener('DOMContentLoaded', async function()  {
+	window.auth.subscribe((event) => {
+		if (event === 'auth-loaded') {
+			let container = document.querySelector('[data-content]');
+			if (container && !Object.hasOwn(container.dataset, 'ignore')) {
+				window.crudManager = new CRUDManager({
+					content: container.dataset.content,
+				});
+			}
+		}
+	});
 });

--
Gitblit v1.10.0