|
|
@ -32,7 +32,7 @@ const template = `
|
|
|
|
<label :for="uuid+field.field">{{ field.name }}</label>
|
|
|
|
<label :for="uuid+field.field">{{ field.name }}</label>
|
|
|
|
<select
|
|
|
|
<select
|
|
|
|
:id="uuid+field.field"
|
|
|
|
:id="uuid+field.field"
|
|
|
|
class="form-control"
|
|
|
|
:class="['form-control', (field.type.endsWith('.multiple') ? 'multi' : 'normal')]"
|
|
|
|
v-model="data[field.field]"
|
|
|
|
v-model="data[field.field]"
|
|
|
|
:required="Array.isArray(field.required) ? field.required.includes(mode) : field.required"
|
|
|
|
:required="Array.isArray(field.required) ? field.required.includes(mode) : field.required"
|
|
|
|
:readonly="mode === 'view' || (Array.isArray(field.readonly) ? field.readonly.includes(mode) : field.readonly)"
|
|
|
|
:readonly="mode === 'view' || (Array.isArray(field.readonly) ? field.readonly.includes(mode) : field.readonly)"
|
|
|
@ -238,10 +238,19 @@ export default class FormComponent extends Component {
|
|
|
|
async on_create() {
|
|
|
|
async on_create() {
|
|
|
|
this.id = this.data.id
|
|
|
|
this.id = this.data.id
|
|
|
|
this.mode = 'update'
|
|
|
|
this.mode = 'update'
|
|
|
|
|
|
|
|
if ( this.definition.handlers && this.definition.handlers.insert ) {
|
|
|
|
|
|
|
|
await action_service.perform(this.definition.handlers.insert)
|
|
|
|
|
|
|
|
}
|
|
|
|
await this.vue_on_create(true)
|
|
|
|
await this.vue_on_create(true)
|
|
|
|
location_service.set_query(`mode=update&id=${this.id}`)
|
|
|
|
location_service.set_query(`mode=update&id=${this.id}`)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async on_update() {
|
|
|
|
|
|
|
|
if ( this.definition.handlers && this.definition.handlers.update ) {
|
|
|
|
|
|
|
|
await action_service.perform(this.definition.handlers.update)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
data_to_save() {
|
|
|
|
data_to_save() {
|
|
|
|
const data = Object.assign({}, this.data)
|
|
|
|
const data = Object.assign({}, this.data)
|
|
|
|
for ( const field of this.definition.fields ) {
|
|
|
|
for ( const field of this.definition.fields ) {
|
|
|
@ -270,6 +279,7 @@ export default class FormComponent extends Component {
|
|
|
|
await this.on_create()
|
|
|
|
await this.on_create()
|
|
|
|
} else if (this.mode === 'update') {
|
|
|
|
} else if (this.mode === 'update') {
|
|
|
|
await this.resource_class.update(this.id, this.data_to_save())
|
|
|
|
await this.resource_class.update(this.id, this.data_to_save())
|
|
|
|
|
|
|
|
await this.on_update()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
this.error_message = ''
|
|
|
|
this.error_message = ''
|
|
|
|