diff --git a/src/components/html/EcAdminSettingsForm.html b/src/components/html/EcAdminSettingsForm.html index 3c679e3..1c91f6b 100644 --- a/src/components/html/EcAdminSettingsForm.html +++ b/src/components/html/EcAdminSettingsForm.html @@ -19,9 +19,64 @@
+ + i18n(i19add), + i19edit: () => i18n(i19edit), + i19editing: () => 'Editando', + i19empty: () => 'Vazio', i19general: () => 'Geral', i19save: () => i18n(i19save), @@ -61,6 +70,10 @@ export default { return schema.type === 'object' || schema.type === 'array' }, + checkNestedObjectsArray (schema) { + return schema.type === 'array' && schema.items && schema.items.type === 'object' + }, + getDescriptionHtml (description) { return description.replace( /(http(s)?:\/\/[^\s]+)/g, @@ -68,18 +81,49 @@ export default { ) }, - parseAdminSettingsField ({ field, schema, hide, data, parent = '' }) { + getObjectValues (obj) { + let str = '' + for (const prop in obj) { + if (obj[prop]) { + switch (typeof obj[prop]) { + case 'number': + case 'string': + str += `${obj[prop].toString()} / ` + } + } + } + return str.length > 3 ? str : `${this.i19empty} ...` + }, + + parseAdminSettingsField ({ field, schema, hide, data, parentFields = '' }) { if (!data) { data = hide ? this.hiddenData : this.data } let fieldObjects = [] - const { localSchema, component } = getSchemaInput(field, schema) + let refSchema + if (this.checkNestedObjectsArray(schema)) { + if (!data[field] || !data[field].length) { + if (parentFields === '') { + this.$set(data, field, [{}]) + this.$set(this.dataListsIndexes, field, 0) + } else { + data[field] = [{}] + } + } + data = data[field] + refSchema = schema.items + field = this.dataListsIndexes[field] || 0 + } else { + refSchema = schema + } + const { localSchema, component } = getSchemaInput(field, refSchema) + parentFields = `${parentFields}.${field}` if (component) { fieldObjects.push({ field, schema, data, - name: `${parent}.${field}`, + name: parentFields, component }) } @@ -96,7 +140,7 @@ export default { field: nestedField, schema: childSchema, data: data[field], - parent: `${parent}.${nestedField}` + parentFields: `${parentFields}.${nestedField}` }) ) }