| | |
| | | if (refs.trash) refs.trash.dataset.id = data.id; |
| | | }; |
| | | const imageSetup = function(el, refs, data) { |
| | | if (data?.fields?.post_thumbnail) { |
| | | const thumbnail = data.images[data.fields.post_thumbnail] ?? {}; |
| | | let hasThumbnail = data?.fields?.post_thumbnail || data?.fields?.thumbnail; |
| | | if (hasThumbnail) { |
| | | const thumbnail = data.images[hasThumbnail] ?? {}; |
| | | refs.img.src = thumbnail.medium??''; |
| | | refs.img.alt = thumbnail.alt??data.fields.post_title??''; |
| | | } |
| | |
| | | }, |
| | | date: '[data-filter="date"]' |
| | | }, |
| | | uploader: 'details.uploader' |
| | | uploader: { |
| | | details: 'details.uploader', |
| | | form: 'details.uploader form', |
| | | uploader: 'details.uploader [data-field-type="upload"]' |
| | | } |
| | | } |
| | | |
| | | this.ui = window.uiFromSelectors(this.selectors); |
| | |
| | | this.isTimeline = !!document.querySelector('[data-timeline]'); |
| | | } |
| | | initUploader() { |
| | | if (!this.ui.uploader) return; |
| | | if (!this.ui.uploader.form) return; |
| | | this.uploadForm = this.forms.registerForm(this.ui.uploader.form).id??false; |
| | | |
| | | window.jvbUploads.scanFields(this.ui.uploader); |
| | | // window.jvbUploads.scanFields(this.ui.uploader); |
| | | window.jvbUploads.subscribe((event, data) => { |
| | | if (event === 'sent-to-queue') { |
| | | if (data === this.ui.uploader.dataset.uploader) { |
| | | if (data.field.id === this.ui.uploader.uploader.dataset.uploader) { |
| | | if (this.uploadForm ) { |
| | | this.forms.store.delete(this.uploadForm); |
| | | } |
| | | |
| | | window.debouncer.schedule('crud-complete', ()=> { |
| | | this.store.clearCache(); |
| | | }); |
| | |
| | | { name: 'modified', keyPath: 'modified'}, |
| | | { name: 'title', keyPath: 'title'}, |
| | | ], |
| | | isAuth: true, |
| | | filters: filters, |
| | | ignore: ['content', 'user'], |
| | | TTL: 60 * 60 * 1000, //1 hour cache |
| | |
| | | && 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(); |
| | | } |
| | | |
| | | if (event === 'operation-status' |
| | | && data.status === 'completed' |
| | | && data.type === 'content_update') { |
| | | |
| | | this.store.clearCache(); |
| | | |
| | | // Check for result data (from ContentExecutor) |
| | | if (!data.result || !data.result.posts) { |
| | | console.warn('Content update completed but no result.posts', data); |
| | | if (!data.result || !data.result.success || !data.result.errors) |
| | | { |
| | | console.warn('Content update completed but no results', data); |
| | | return; |
| | | } |
| | | |
| | | // Get successfully processed post IDs |
| | | const successfulIds = Object.keys(data.result.posts); |
| | | |
| | | if (successfulIds.length === 0) { |
| | | if (Object.keys(data.result.success).length > 0) { |
| | | this.checkCompletedChanges(Object.entries(data.result.success)); |
| | | } |
| | | if (Object.keys(data.result.errors).length > 0) { |
| | | this.checkFailedChanges(Object.entries(data.result.errors)); |
| | | return; |
| | | } |
| | | |
| | | // Clear from both persistent and in-memory storage |
| | | this.changesStore.deleteMany(successfulIds); |
| | | successfulIds.forEach(id => this.changes.delete(id)); |
| | | if (Object.keys(data.result.success).length === 0) { |
| | | console.log(data.result.success); |
| | | data.result.success.forEach(id => this.changesStore.delete(id)); |
| | | |
| | | this.store.clearCache(); |
| | | } |
| | | } |
| | | |
| | | if (event === 'sent-to-server') { |
| | | if (data instanceof FormData) return; |
| | | |
| | | 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) 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; |
| | | } |
| | | } |
| | | } |
| | | |
| | | 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. |
| | | } |
| | | |
| | | initSettings() { |
| | | this.defaults = { |
| | |
| | | default: 'closed', |
| | | }, |
| | | showUploader: { |
| | | element: this.ui.uploader, |
| | | element: this.ui.uploader.details, |
| | | default: 'open' |
| | | } |
| | | }; |
| | |
| | | let title = `Saving changes for multiple ${this.plural}`; |
| | | |
| | | this.scheduleSave(0); |
| | | this.modals.edit.handleClose(); |
| | | } |
| | | |
| | | async handleCreateSubmit(modal) { |
| | |
| | | if (this.isPopulating) { |
| | | return; |
| | | } |
| | | name.replace(`[${itemId}]`, ''); |
| | | |
| | | const stored = this.store.get(itemId); |
| | | if (stored) { |
| | |
| | | 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(); |
| | | } |
| | | } |
| | |
| | | this.activeItem = item.id; |
| | | this.ui.modals.edit.modal.dataset.itemId = itemID; |
| | | this.ui.modals.edit.modal.dataset.content = this.content; |
| | | this.ui.modals.edit.h2.textContent = `Editing ${item.fields.post_title === '' ? this.singular : item.fields.post_title}`; |
| | | let title; |
| | | if (Object.hasOwn(item.fields, 'post_title')) { |
| | | title = item.fields.post_title; |
| | | } else if (Object.hasOwn(item.fields, 'name')) { |
| | | title = item.fields.name; |
| | | } |
| | | this.ui.modals.edit.h2.textContent = `Editing ${title === '' ? this.singular : title}`; |
| | | 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 |
| | |
| | | }); |
| | | }); |
| | | |
| | | this.modals.edit.handleOpen(); |
| | | } |
| | | openBulkEditModal() { |
| | | window.removeChildren(this.ui.modals.bulkEdit.selected); |