From ac444cba221832c012c0435fdc8339fe9f37febb Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Mon, 11 May 2026 18:35:04 +0000
Subject: [PATCH] =Some changes to the CRUD.js editing, timeline post configuration

---
 assets/js/concise/CRUD.js |   44 ++++++++++++++++++++++++++++++++++----------
 1 files changed, 34 insertions(+), 10 deletions(-)

diff --git a/assets/js/concise/CRUD.js b/assets/js/concise/CRUD.js
index 3a61fd5..4ecdf90 100644
--- a/assets/js/concise/CRUD.js
+++ b/assets/js/concise/CRUD.js
@@ -422,6 +422,7 @@
 						{ name: 'modified', keyPath: 'modified'},
 						{ name: 'title', keyPath: 'title'},
 					],
+					isAuth: true,
 					filters: filters,
 					ignore: ['content', 'user'],
 					TTL: 60 * 60 * 1000, 		//1 hour cache
@@ -513,6 +514,7 @@
 				&& data.status === 'completed'
 				&& data.endpoint === 'uploads/groups') {
 				if (data.result && data.result.group_mappings) {
+					console.log('Handling group mapping from queue response');
 					this.handleGroupMappings(data.result.group_mappings);
 				}
 				this.store.clearCache();
@@ -539,39 +541,54 @@
 				}
 
 				if (Object.keys(data.result.success).length === 0) {
-					this.changesStore.delete(id);
+					console.log(data.result.success);
+					data.result.success.forEach(id => this.changesStore.delete(id));
+
 					this.store.clearCache();
 				}
 			}
 
+			if (event === 'sent-to-server') {
+				console.log('Sent to server in CRUD.js with data: ', data);
+				for ( let [id, changes] of Object.entries(data.posts)) {
+					this.compareStored(id, changes);
+				}
+			}
+
 		});
 	}
 	checkCompletedChanges(items) {
 		for (let [id, data] of items) {
-
+			this.compareStored(id, data);
+		}
+	}
+		compareStored(id, data) {
 			let stored = this.changesStore.get(id);
-			if (!stored) continue;
+			if (!stored) return;
 
 			for (let [field, value] of Object.entries(data)) {
 				if (Object.hasOwn(stored, field)) {
 					let changes = window.getDifferences.map(stored[field], value);
-
 					if (!changes) {
 						delete stored[field];
+					} else {
+						stored[field] = changes;
 					}
-
 				}
 			}
 
-			//It'll have the id and the content still
-			if (Object.values(stored).length === 2) {
+			let hasID = Object.hasOwn(stored, 'id');
+			let hasContent = Object.hasOwn(stored, 'content');
+			if ((hasID && hasContent && Object.keys(stored).length === 2)
+				|| ((hasID || hasContent) && Object.keys(stored).length === 1)
+				|| Object.keys(stored).length === 0
+			) {
 				this.changesStore.delete(id);
 				this.store.clearCache();
 			} else {
 				this.changesStore.save(stored);
 			}
 		}
-	}
 	checkFailedChanges(items) {
 		//TODO do something.
 	}
@@ -689,6 +706,7 @@
 		let title = `Saving changes for multiple ${this.plural}`;
 
 		this.scheduleSave(0);
+		this.modals.edit.handleClose();
 	}
 
 	async handleCreateSubmit(modal) {
@@ -848,6 +866,9 @@
 			value = this.forms.getFieldValue(e.target);
 		}
 
+		console.log('Name: ', name);
+		console.log('Value: ', value);
+
 		item.dataset.itemId.split(',').forEach(itemId => {
 			this.updateItem(itemId, name, value);
 		});
@@ -856,6 +877,7 @@
 		if (this.isPopulating) {
 			return;
 		}
+		name.replace(`[${itemId}]`, '');
 
 		const stored = this.store.get(itemId);
 		if (stored) {
@@ -1037,7 +1059,7 @@
 			return;
 		}
 
-		if (e.target.matches(this.selectors.buttons.create)) {
+		if (e.target.matches(this.selectors.buttons.create) || e.target.closest(this.selectors.buttons.create)) {
 			this.openCreateModal();
 		}
 	}
@@ -1264,8 +1286,11 @@
 		this.ui.modals.edit.form.dataset.formId = `edit-${itemID}`;
 
 
+		this.modals.edit.handleOpen();
 		this.forms.registerForm(this.ui.modals.edit.form, {cache: false,
 			autoUpload: true,});
+
+
 		this.isPopulating = true;
 		this.populate.populate(this.ui.modals.edit.form, item);
 		//For quill/taxonomy selector's async setups
@@ -1275,7 +1300,6 @@
 			});
 		});
 
-		this.modals.edit.handleOpen();
 	}
 	openBulkEditModal() {
 		window.removeChildren(this.ui.modals.bulkEdit.selected);

--
Gitblit v1.10.0