From 64028d527b5d13fe76bd0dacdea4ca8eb146ac1a Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Wed, 11 Feb 2026 00:37:56 +0000
Subject: [PATCH] =Upload mapping when creating a new post with the create modal

---
 assets/js/concise/CRUD.js |   61 +++++++++++++++++++++++++++---
 1 files changed, 55 insertions(+), 6 deletions(-)

diff --git a/assets/js/concise/CRUD.js b/assets/js/concise/CRUD.js
index 8c29ab2..74d6cdb 100644
--- a/assets/js/concise/CRUD.js
+++ b/assets/js/concise/CRUD.js
@@ -639,14 +639,62 @@
 		const form = e.target;
 		const modal = form.closest('dialog');
 		if (!modal) return;
-		let title = `Saving changes for multiple ${this.plural}`;
-		if (modal.classList.contains('edit')) {
-			title = 'Saving your edits...';
-		} else if (modal.classList.contains('create')) {
-			title = `Creating your new ${this.singular}`;
+
+		if (modal.classList.contains('create')) {
+			this.handleCreateSubmit(modal);
+			return;
 		}
+
+		let title = `Saving changes for multiple ${this.plural}`;
+
 		this.scheduleSave(0);
 	}
+
+	async handleCreateSubmit(modal) {
+		const itemId = modal.dataset.itemId;
+
+		// 1. Flush changes to store
+		if (this.changes.size > 0) {
+			this.cancelBackup();
+			await this.handleBackup();
+		}
+
+		const changes = await this.changesStore.getAll();
+		if (changes.length === 0) return;
+
+		let allChanges = {};
+		changes.forEach(change => {
+			const { id, ...rest } = change;
+			allChanges[id] = rest;
+		});
+
+		// 2. Queue content creation, get operationId
+		let contentOpId = this.queue.addToQueue({
+			endpoint: this.endpoint,
+			headers: {
+				'X-Action-Nonce': window.auth.getNonce('dash'),
+			},
+			data: {
+				posts: allChanges,
+			},
+			popup: `Creating your new ${this.singular}`,
+			title: `Creating your new ${this.singular}`,
+		});
+
+		if (!contentOpId) return;
+
+		// 3. Queue any pending uploads with dependency on content creation
+		const uploadFields = modal.querySelectorAll('[data-upload-field]');
+		for (const fieldEl of uploadFields) {
+			const fieldId = fieldEl.dataset.uploader;
+			if (!fieldId) continue;
+
+			const uploads = window.jvbUploads.stores.uploads.filterByIndex({ field: fieldId });
+			if (uploads.length === 0) continue;
+
+			await window.jvbUploads.queueUploads('uploads', fieldId, contentOpId);
+		}
+	}
 	handleChange(e) {
 		// Early bailout - target must be in an item or be a filter
 		const inItem = e.target.closest('[data-item-id]');
@@ -1137,7 +1185,8 @@
 		this.ui.modals.edit.h2.textContent = `Editing ${item.fields.post_title === '' ? this.singular : item.fields.post_title}`;
 		this.ui.modals.edit.form.dataset.formId = `edit-${itemID}`;
 
-		this.forms.registerForm(this.ui.modals.edit.form, {cache: false});
+		this.forms.registerForm(this.ui.modals.edit.form, {cache: false,
+			autoUpload: true,});
 
 		this.isPopulating = true;
 		this.populate.populate(this.ui.modals.edit.form, item);

--
Gitblit v1.10.0