| | |
| | | populateField(field, name, value) { |
| | | |
| | | let type = this.formHelper.getFieldType(field); |
| | | if (!type || this.isEmptyValue(name) || this.isEmptyValue(value)) return; |
| | | if (!type || this.isEmptyValue(name)) return; |
| | | |
| | | const handlers = { |
| | | 'repeater': this.populateRepeater.bind(this), |
| | |
| | | } |
| | | |
| | | populateRepeater(field, name, value) { |
| | | if (!value || !Array.isArray(value)) return; |
| | | |
| | | const container = field.querySelector('.repeater-items'); |
| | | let template = field.querySelector('template')?.className ?? false; |
| | | if (!container || !template) return; |
| | | |
| | | // Normalize: server/store may return an object with numeric keys instead of an array |
| | | if (typeof value === 'string') { |
| | | try { value = JSON.parse(value); } catch(e) { value = []; } |
| | | } |
| | | if (value && !Array.isArray(value) && typeof value === 'object') { |
| | | value = Object.values(value); |
| | | } |
| | | |
| | | if (!value || !Array.isArray(value) || value.length === 0) { |
| | | window.removeChildren(container); |
| | | return; |
| | | } |
| | | |
| | | window.removeChildren(container); |
| | | |
| | | value.forEach((data, index) => { |
| | |
| | | }); |
| | | } |
| | | populateTagList(field, name, value) { |
| | | if (!value || !Array.isArray(value)) return; |
| | | |
| | | const container = field.querySelector('.tag-items'); |
| | | let template = field.querySelector('template')?.className ?? false; |
| | | if (!container || !template) return; |
| | | |
| | | if (typeof value === 'string') { |
| | | try { value = JSON.parse(value); } catch(e) { value = []; } |
| | | } |
| | | if (value && !Array.isArray(value) && typeof value === 'object') { |
| | | value = Object.values(value); |
| | | } |
| | | |
| | | if (!value || !Array.isArray(value) || value.length === 0) { |
| | | window.removeChildren(container); |
| | | return; |
| | | } |
| | | |
| | | window.removeChildren(container); |
| | | |
| | | value.forEach((data, index) => { |
| | |
| | | } |
| | | populateGroup(field, name, value) { |
| | | if (!value || typeof value !== 'object') return; |
| | | |
| | | console.log(value, 'Populating Group Value: ') |
| | | for (let [subName, subValue] of Object.entries(value)) { |
| | | let subField = field.querySelector(`[data-field="${subName}"]`); |
| | | if (subField) { |
| | |
| | | } |
| | | populateTaxonomy(field, name, value) { |
| | | let termIds = this.splitIDs(value); |
| | | if (termIds.length === 0) return; |
| | | |
| | | const hiddenInput = field.querySelector(`input[type="hidden"][name="${name}"]`); |
| | | if (hiddenInput) { |
| | |
| | | return; |
| | | } |
| | | |
| | | if (this.isEmptyValue(value)) return; |
| | | const ids = this.splitIDs(value); |
| | | if (ids.length === 0) return; |
| | | const hiddenInput = field.querySelector(`input[type="hidden"]`); |
| | |
| | | }; |
| | | data.id = id; |
| | | grid.append(this.templates.create('uploadItem', data)); |
| | | let items = grid.children; |
| | | |
| | | let item = Array.from(items).filter(it => { return it.dataset.id === `${id}`}); |
| | | item = item[0]??false; |
| | | if (item) { |
| | | this.populateUploadMeta(item, null, id); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | this.populateUploadMeta(field, name, value); |
| | | } |
| | | populateUploadMeta(element, name, id) { |
| | | // Find the image_data field group |
| | | const imageDataField = element.querySelector('[data-field="image_data"]'); |
| | | if (!imageDataField) return; |
| | | let data = this.data.images[id]??false; |
| | | if (!data) return; |
| | | populateUploadMeta(element, name, id) { |
| | | // Find the image_data field group |
| | | const imageDataField = element.querySelector('[data-field="image_data"]'); |
| | | if (!imageDataField) return; |
| | | let data = this.data.images[id]??false; |
| | | if (!data) return; |
| | | |
| | | // Set upload ID or attachment ID |
| | | imageDataField.dataset.attachmentId = data.id; |
| | | imageDataField.setAttribute('data-ignore', ''); |
| | | // Set upload ID or attachment ID |
| | | imageDataField.dataset.attachmentId = data.id; |
| | | imageDataField.setAttribute('data-ignore', ''); |
| | | |
| | | // Populate the metadata fields |
| | | const meta = [ |
| | | 'image-title', |
| | | 'image-alt-text', |
| | | 'image-caption' |
| | | ]; |
| | | // Populate the metadata fields |
| | | const meta = [ |
| | | 'image-title', |
| | | 'image-alt-text', |
| | | 'image-caption' |
| | | ]; |
| | | |
| | | for (const m of meta) { |
| | | const input = imageDataField.querySelector(`[data-field="${m}"] input, [data-field="${m}"] textarea`); |
| | | if (input && data[m]!=='') { |
| | | input.value = window.decodeHTMLEntities(data[m]); |
| | | for (const m of meta) { |
| | | const input = imageDataField.querySelector(`[data-field="image_data|${m}"] input, [data-field="image_data|${m}"] textarea`); |
| | | if (input && data[m]!=='') { |
| | | input.value = window.decodeHTMLEntities(data[m]); |
| | | } |
| | | } |
| | | } |
| | | populateTimelineGallery(field,name, value) { |
| | | if (!value || !Array.isArray(value) || value.length === 0) return; |
| | | |
| | | let grid = field.querySelector('.item-grid'); |
| | | |
| | | if (grid) { |
| | | window.removeChildren(grid); |
| | | |
| | | field.querySelector('.progress')?.remove(); |
| | | for (let data of value) { |
| | | let point = this.templates.create('timelineItem', data); |
| | | if (point) { |
| | | grid.append(point); |
| | | } |
| | | } |
| | | } |
| | | populateTimelineGallery(field,name, value) { |
| | | if (!value || !Array.isArray(value) || value.length === 0) return; |
| | | |
| | | let grid = field.querySelector('.item-grid'); |
| | | |
| | | if (grid) { |
| | | window.removeChildren(grid); |
| | | |
| | | field.querySelector('.progress')?.remove(); |
| | | for (let data of value) { |
| | | let point = this.templates.create('timelineItem', data); |
| | | if (point) { |
| | | grid.append(point); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | populateMultiValue(field, name, value) { |
| | | if (typeof value === 'string') { |
| | | try { |