| File was renamed from assets/js/dash/CRUD.js |
| | |
| | | this.config = config; |
| | | this.content = config.content || false; |
| | | this.settings = window.jvbUserSettings; |
| | | |
| | | this.a11y = window.jvbA11y; |
| | | if (!this.content) { |
| | | return; |
| | | } |
| | |
| | | keyPath: 'id', |
| | | endpoint: 'content', |
| | | headers: { |
| | | 'action_nonce': jvbSettings.dash, |
| | | 'action_nonce': window.auth.getNonce('dash'), |
| | | }, |
| | | indexes: [ |
| | | {name: 'id', keyPath: 'id'}, |
| | |
| | | ], |
| | | filters: { |
| | | content: this.content, |
| | | user: jvbSettings.currentUser, |
| | | user: window.auth.getUser(), |
| | | page: 1, |
| | | status: 'all', |
| | | orderby: 'modified', //or title |
| | |
| | | |
| | | 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') { |
| | |
| | | } |
| | | } |
| | | |
| | | if (window.isEmptyObject(theChanges)) { |
| | | if (Object.keys(theChanges).length === 0) { |
| | | return; |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | savePosts(changes, title) { |
| | | if (window.isEmptyObject(changes)) { |
| | | if (Object.keys(changes).length === 0) { |
| | | return; |
| | | } |
| | | |
| | |
| | | let operation = { |
| | | endpoint: 'content', |
| | | headers: { |
| | | 'action_nonce': jvbSettings.dash, |
| | | 'action_nonce': window.auth.getNonce('dash'), |
| | | }, |
| | | data: { |
| | | posts: changes, |
| | |
| | | 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); |
| | |
| | | this.viewController.clearSelection(); |
| | | |
| | | |
| | | if (!window.isEmptyObject(changes)) { |
| | | if (Object.keys(changes).length !== 0) { |
| | | this.savePosts(changes, `${title} ${this.viewController.selectedItems.size} ${this.plural}...`); |
| | | } |
| | | } |
| | |
| | | } |
| | | 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) => { |
| | |
| | | }); |
| | | } |
| | | } 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'); |
| | |
| | | }); |
| | | } |
| | | } |
| | | this.ui.bulkSelectActions.value = ''; |
| | | if (this.ui.bulkSelectActions) { |
| | | this.ui.bulkSelectActions.value = ''; |
| | | } |
| | | } |
| | | |
| | | populateBulkEdit() { |
| | |
| | | } |
| | | |
| | | // 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, |
| | | }); |
| | | } |
| | | } |
| | | }); |
| | | }); |