Merge branch 'develop' of https://github.com/tainacan/tainacan into develop
This commit is contained in:
commit
6fc655e5b6
|
@ -208,7 +208,7 @@ class TAINACAN_REST_Item_Metadata_Controller extends TAINACAN_REST_Controller {
|
|||
}
|
||||
|
||||
return new WP_REST_Response([
|
||||
'error_message' => __('The body could not be empty', 'tainacan'),
|
||||
'error_message' => 'The body could not be empty',
|
||||
'body' => $body
|
||||
], 400);
|
||||
}
|
||||
|
|
|
@ -3,10 +3,10 @@
|
|||
:message="getErrorMessage"
|
||||
:type="fieldTypeMessage">
|
||||
<div>
|
||||
<component :is="extractFieldType(field.field.field_type)" v-model="inputs[0]" :field="field" @blur="changeValue()"></component>
|
||||
<component :is="field.field_type_object.component" v-model="inputs[0]" :field="field" @blur="changeValue()"></component>
|
||||
<div v-if="field.field.multiple == 'yes'">
|
||||
<div v-if="index > 0" v-for="(input, index) in inputsList " v-bind:key="index" class="multiple-inputs">
|
||||
<component :is="extractFieldType(field.field.field_type)" v-model="inputs[index]" :field="field" @blur="changeValue()"></component><a class="button" v-if="index > 0" @click="removeInput(index)">-</a>
|
||||
<component :is="field.field_type_object.component" v-model="inputs[index]" :field="field" @blur="changeValue()"></component><a class="button" v-if="index > 0" @click="removeInput(index)">-</a>
|
||||
</div>
|
||||
<a class="button" @click="addInput">+</a>
|
||||
</div>
|
||||
|
@ -25,7 +25,6 @@
|
|||
data(){
|
||||
return {
|
||||
inputs: [],
|
||||
oldInputs: [],
|
||||
fieldTypeMessage:''
|
||||
}
|
||||
},
|
||||
|
@ -52,28 +51,19 @@
|
|||
},
|
||||
methods: {
|
||||
changeValue(){
|
||||
//console.log(this.inputs);
|
||||
//console.log(this.oldInputs);
|
||||
eventBus.$emit('input', { item_id: this.field.item.id, field_id: this.field.field.id, values: this.inputs, old_values: this.oldInputs } );
|
||||
eventBus.$emit('input', { item_id: this.field.item.id, field_id: this.field.field.id, values: this.inputs } );
|
||||
},
|
||||
getValue(){
|
||||
|
||||
getValue(){
|
||||
if (this.field.value instanceof Array) {
|
||||
this.inputs = this.field.value;
|
||||
if (this.inputs.length == 0)
|
||||
this.inputs.push('');
|
||||
if (this.inputs.length == 0)
|
||||
this.inputs.push('');
|
||||
} else {
|
||||
this.field.value == null || this.field.value == undefined ? this.inputs.push('') : this.inputs.push(this.field.value);
|
||||
if (this.field.value == null || this.field.value == undefined)
|
||||
this.inputs.push('');
|
||||
else
|
||||
this.inputs.push(this.field.value);
|
||||
}
|
||||
// Can't use this.oldInputs = this.inputs, would still affect oldInputs after inputs change
|
||||
this.oldInputs = this.inputs;
|
||||
// for (let input of this.inputs) {
|
||||
// this.oldInputs.push(input);
|
||||
// }
|
||||
},
|
||||
extractFieldType(field_type) {
|
||||
let parts = field_type.split('\\');
|
||||
return 'tainacan-' + parts.pop().toLowerCase();
|
||||
},
|
||||
addInput(){
|
||||
this.inputs.push('');
|
||||
|
|
|
@ -24,18 +24,11 @@ export const eventBus = new Vue({
|
|||
for (let eventElement of components){
|
||||
eventElement.addEventListener('input', (event) => {
|
||||
if (event.detail && event.detail[0] ){
|
||||
const promisse = this.$store.dispatch('item/updateMetadata',
|
||||
{ item_id: $(eventElement).attr("item_id"), field_id: $(eventElement).attr("field_id"), values: event.detail, old_values: $(eventElement).attr("old_values") });
|
||||
|
||||
promisse.then( response => {
|
||||
// eventElement.errorsMsg = JSON.stringify( [] );
|
||||
// eventElement.value = response.value;
|
||||
$(eventElement).val(response.value);
|
||||
}, error => {
|
||||
const field = this.errors.find(error => error.field_id === event.detail[0].field_id );
|
||||
// eventElement.errorsMsg = JSON.stringify( field.error );
|
||||
// eventElement.value = event.detail[0].values;
|
||||
});
|
||||
this.updateValue({
|
||||
item_id: $(eventElement).attr("item_id"),
|
||||
field_id: $(eventElement).attr("field_id"),
|
||||
values: event.detail
|
||||
})
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -43,7 +36,7 @@ export const eventBus = new Vue({
|
|||
updateValue(data){
|
||||
if ( data.item_id ){
|
||||
const promisse = this.$store.dispatch('item/updateMetadata',
|
||||
{ item_id: data.item_id, field_id: data.field_id, values: data.values, old_values: data.old_values });
|
||||
{ item_id: data.item_id, field_id: data.field_id, values: data.values });
|
||||
promisse.then( response => {
|
||||
let index = this.errors.findIndex( errorItem => errorItem.field_id === data.field_id );
|
||||
if ( index >= 0){
|
||||
|
|
|
@ -17,36 +17,10 @@ export const sendField = ( { commit }, { item_id, field_id, values }) => {
|
|||
};
|
||||
|
||||
|
||||
export const updateMetadata = ({ commit }, { item_id, field_id, values, old_values }) => {
|
||||
export const updateMetadata = ({ commit }, { item_id, field_id, values }) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
let metadata_values = [];
|
||||
|
||||
// values = ["a", "b", "c"]
|
||||
// old_values = ["a", "b"]
|
||||
if (values.lenght >= old_values.length) {
|
||||
// New values in metadata array
|
||||
for (let i = 0; i < values.length; i++) {
|
||||
if (old_values[i])
|
||||
metadata_values.push({"new": values[i], "prev": old_values[i]});
|
||||
else
|
||||
metadata_values.push({"new": values[i], "prev": null });
|
||||
}
|
||||
}
|
||||
// values = ["a", "c"]
|
||||
// old_values = ["a", "b", "c"]
|
||||
else {
|
||||
// Values removed from metadata array
|
||||
for (let i = 0; i < old_values.length; i++) {
|
||||
if (values[i])
|
||||
metadata_values.push({"new": values[i], "prev": old_values[i]});
|
||||
else
|
||||
metadata_values.push({"new": null, "prev": old_values[i]});
|
||||
}
|
||||
}
|
||||
//console.log(metadata_values);
|
||||
axios.patch(`/item/${item_id}/metadata/${field_id}`, {
|
||||
values: metadata_values,
|
||||
values: values,
|
||||
})
|
||||
.then( res => {
|
||||
let field = res.data;
|
||||
|
|
Loading…
Reference in New Issue