Continues implementation of parent selection on term edition form.

This commit is contained in:
Mateus Machado Luna 2018-08-22 16:18:43 -03:00
parent 07c53e29bc
commit 157bd4d441
9 changed files with 43 additions and 38 deletions

View File

@ -82,47 +82,43 @@
</b-field>
<!-- Parent -------------- -->
<b-field
:addons="false"
:type="((formErrors.parent !== '' || formErrors.repeated !== '') && (formErrors.parent !== undefined || formErrors.repeated !== undefined )) ? 'is-danger' : ''"
:message="formErrors.parent ? formErrors : formErrors.repeated">
<label class="label is-inline">
{{ $i18n.get('label_parent_term') }}
<span class="required-term-asterisk">*</span>
<help-button
:title="$i18n.get('label_parent_term')"
:message="$i18n.get('info_help_term_parent')"/>
</label>
<b-input
v-model="editForm.parent"
name="parent"
@focus="clearErrors({ name: 'parent', repeated: 'repeated' })"/>
</b-field>
<b-field
:addons="false"
:type="((formErrors.parent !== '' || formErrors.repeated !== '') && (formErrors.parent !== undefined || formErrors.repeated !== undefined )) ? 'is-danger' : ''"
:message="formErrors.parent ? formErrors : formErrors.repeated">
<label class="label is-inline">
{{ $i18n.get('label_parent_term') }}
<span class="required-term-asterisk">*</span>
<b-switch
id="tainacan-checkbox-has-parent"
size="is-small"
v-model="hasParent" />
<help-button
:title="$i18n.get('label_parent_term')"
:message="$i18n.get('info_help_term_parent')"/>
:message="$i18n.get('info_help_parent_term')"/>
</label>
<b-autocomplete
id="tainacan-text-cover-page"
:placeholder="$i18n.get('instruction_parent_term')"
:data="parentTerms"
field="name"
v-model="parentTermName"
@select="onSelectParentTerm($event)"
:loading="isFetchingParentTerms"
@input="fecthParentTerms($event)"
@focus="clearErrors('parent')">
@focus="showCheckboxesWarning = true; clearErrors('parent');"
:disabled="!hasParent">
<template slot-scope="props">
{{ props.option.name }}
</template>
<template slot="empty">{{ $i18n.get('info_no_parent_term_found') }}</template>
</b-autocomplete>
<transition name="fade">
<p
class="checkboxes-warning"
v-show="showCheckboxesWarning">
{{ $i18n.get('info_warning_changing_parent_term') }}
</p>
</transition>
</b-field>
<!-- Submit buttons -------------- -->
@ -169,7 +165,9 @@
headerImageMediaFrame: undefined,
isFetchingParentTerms: false,
parentTerms: [],
parentTermName: ''
parentTermName: '',
showCheckboxesWarning: false,
hasParent: false
}
},
props: {
@ -193,7 +191,7 @@
taxonomyId: this.taxonomyId,
name: this.editForm.name,
description: this.editForm.description,
parent: this.editForm.parent,
parent: this.hasParent ? this.editForm.parent : 0,
headerImageId: this.editForm.header_image_id,
})
.then((term) => {
@ -211,12 +209,13 @@
});
} else {
this.updateChildTerm({
taxonomyId: this.taxonomyId,
termId: this.editForm.id,
name: this.editForm.name,
description: this.editForm.description,
parent: this.editForm.parent,
parent: this.hasParent ? this.editForm.parent : 0,
headerImageId: this.editForm.header_image_id,
})
.then(() => {
@ -293,12 +292,13 @@
this.editForm.parent = selectedParentTerm.id;
this.selectedParentTerm = selectedParentTerm;
this.parentTermName = selectedParentTerm.name;
console.log(this.parentTermName);
}
},
mounted() {
this.hasParent = this.editForm.parent != undefined && this.editForm.parent > 0;
this.initializeMediaFrames();
this.isFetchingParentTerms = true;
this.fetchParentName({ taxonomyId: this.taxonomyId, parentId: this.editForm.parent })
.then((parentName) => {
@ -404,6 +404,11 @@
position: relative;
}
}
.checkboxes-warning {
color: $gray5;
font-style: italic;
padding: 0.2rem 0.75rem;
}
}
</style>

View File

@ -297,7 +297,7 @@ export default {
span {
text-overflow: ellipsis;
white-space: nowrap;
overflow-x: hidden;
overflow: hidden;
max-width: 115px;
margin: 0 0.1rem;
display: inline-block;

View File

@ -176,7 +176,7 @@ export default {
span {
text-overflow: ellipsis;
white-space: nowrap;
overflow-x: hidden;
overflow: hidden;
max-width: 75%;
margin: 0 0.1rem;
display: inline-block;

View File

@ -46,7 +46,7 @@ export default {
}
.help-tooltip {
z-index: 99999999999999999999;
color: $blue5;
color: $turquoise5;
background-color: $turquoise2;
border: none;
display: block;

View File

@ -30,6 +30,7 @@
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
vertical-align: top;
}
.required-metadatum-asterisk {
color: $gray3;
@ -74,7 +75,7 @@
padding-left: 0.8em;
font-size: 12px;
text-overflow: ellipsis;
overflow-x: hidden;
overflow: hidden;
white-space: nowrap;
}
.select {

View File

@ -418,6 +418,7 @@ return apply_filters( 'tainacan-admin-i18n', [
'info_import_collection' => __( 'Import from external sources.', 'tainacan' ),
'info_import_items' => __( 'Import items from external sources.', 'tainacan' ),
'info_no_parent_term_found' => __( 'No valid parent term was found with this name.', 'tainacan' ),
'info_warning_changing_parent_term' => __( 'Warning! Changing parent term will reload the terms list, thus uncheking any selection.', 'tainacan' ),
// Tainacan Metadatum Types
'tainacan-text' => __( 'Text', 'tainacan' ),

View File

@ -42,11 +42,9 @@ class REST_Controller extends \WP_REST_Controller {
* @return \Tainacan\Entities\Entity
*/
protected function prepare_item_for_updating($object, $new_values){
foreach ($new_values as $key => $value) {
$object->set($key, $value);
}
return $object;
}
@ -84,10 +82,10 @@ class REST_Controller extends \WP_REST_Controller {
'postin' => 'post__in',
'relation' => 'relation',
'nopaging' => 'nopaging',
'meta_key' => 'meta_key',
'meta_type' => 'meta_type',
'metatype' => 'meta_type',
'hierarchical' => 'hierarchical',
'exclude' => 'exclude'
'exclude' => 'exclude',
'excludetree' => 'exclude_tree'
];
$meta_query = [

View File

@ -79,16 +79,16 @@ export const setOrderBy = ({ state, commit }, orderBy ) => {
} else if (orderBy.slug == 'author_name') {
commit('setPostQueryAttribute', { attr: 'orderby', value: 'author_name' } );
} else if (orderBy.metadata_type_object.primitive_type == 'float' || orderBy.metadata_type_object.primitive_type == 'int') {
commit('setPostQueryAttribute', { attr: 'meta_key', value: orderBy.id } );
commit('setPostQueryAttribute', { attr: 'metakey', value: orderBy.id } );
commit('setPostQueryAttribute', { attr: 'orderby', value: 'meta_value_num' } );
} else if (orderBy.metadata_type_object.primitive_type == 'date') {
commit('setPostQueryAttribute', { attr: 'meta_key', value: orderBy.id } );
commit('setPostQueryAttribute', { attr: 'meta_type', value: 'DATETIME' } );
commit('setPostQueryAttribute', { attr: 'metakey', value: orderBy.id } );
commit('setPostQueryAttribute', { attr: 'metatype', value: 'DATETIME' } );
commit('setPostQueryAttribute', { attr: 'orderby', value: 'meta_value' } );
} else if (orderBy.metadata_type_object.core) {
commit('setPostQueryAttribute', { attr: 'orderby', value: orderBy.metadata_type_object.related_mapped_prop } );
} else {
commit('setPostQueryAttribute', { attr: 'meta_key', value: orderBy.id } );
commit('setPostQueryAttribute', { attr: 'metakey', value: orderBy.id } );
commit('setPostQueryAttribute', { attr: 'orderby', value: 'meta_value' } );
}

View File

@ -304,7 +304,7 @@ export const clearTerms = ({ commit }) => {
// Used only on Term Edition form, for autocomplete searhc for parents
export const fetchPossibleParentTerms = ({ commit }, { taxonomyId, termId, search } ) => {
return new Promise((resolve, reject) => {
axios.tainacan.get('/taxonomy/' + taxonomyId + '/terms?searchterm=' + search + '&hierarchical=1&exclude=' + termId + "&hideempty=0&offset=0&number=20")
axios.tainacan.get('/taxonomy/' + taxonomyId + '/terms?searchterm=' + search + '&hierarchical=1&exclude_tree=' + termId + "&hideempty=0&offset=0&number=20")
.then(res => {
let parentTerms = res.data;
resolve( parentTerms );