Have got saving working

This commit is contained in:
Leon Mika 2026-03-28 21:42:35 +11:00
parent f9a65c8ca9
commit c8a276b248
21 changed files with 248 additions and 22 deletions

View file

@ -1,3 +1,4 @@
import feather from "feather-icons/dist/feather.js";
import Handlebars from "handlebars";
import {Controller} from "@hotwired/stimulus";
@ -7,12 +8,12 @@ Handlebars.registerHelper("submit_on", function (id, event) {
const processorFrame = Handlebars.compile(`
<div class="card mb-3">
<div class="card-header d-flex justify-content-between">
<div class="card-header d-flex justify-content-between align-items-center">
<span>{{name}}</span>
<a href="#" class="btn btn-sm btn-secondary float-end"
<a href="#" class="float-end"
data-action="edit-upload#removeProcessor"
data-edit-upload-id-param="{{id}}"
>X</a>
><i data-feather="x" width="18" height="18"></i></a>
</div>
<div class="card-body">
<form data-role="processor-params" data-params-id="{{id}}">{{{props}}}</form>
@ -78,6 +79,16 @@ export default class UploadEditController extends Controller {
await this._removeProcessor(id);
}
async saveUpload(ev) {
ev.preventDefault();
await this._save("replace");
}
async saveNewUpload(ev) {
ev.preventDefault();
await this._save("copy");
}
async updateProcessor(ev) {
ev.preventDefault();
let id = ev.params.id;
@ -108,6 +119,8 @@ export default class UploadEditController extends Controller {
});
el.innerHTML += cardOuter;
}
feather.replace();
}
async _createSession() {
@ -179,6 +192,33 @@ export default class UploadEditController extends Controller {
})
}
async _save(mode) {
if (!this._state || !this._state.session) {
return;
}
try {
let resp = await fetch(`/sites/${this.siteIdValue}/imageedit/${this._state.session.guid}/save`, {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({ mode })
});
if (!resp.ok) {
console.error("Save failed:", resp.statusText);
return;
}
let result = await resp.json();
window.location.href = `/sites/${this.siteIdValue}/uploads/${result.upload_id}`;
} catch (e) {
console.error(e);
}
}
async _doReturningState(fn) {
try {
this._state = await fn();