Begins implementation of parent term selection inside Term Edition Form.

This commit is contained in:
Mateus Machado Luna 2018-08-22 08:45:35 -03:00
parent 03e512e2f6
commit 07c53e29bc
4 changed files with 113 additions and 3 deletions

View File

@ -45,7 +45,7 @@
</div>
</b-field>
<!-- Name -------------- -->
<b-field
:addons="false"
:type="((formErrors.name !== '' || formErrors.repeated !== '') && (formErrors.name !== undefined || formErrors.repeated !== undefined )) ? 'is-danger' : ''"
@ -63,6 +63,7 @@
@focus="clearErrors({ name: 'name', repeated: 'repeated' })"/>
</b-field>
<!-- Description -------------- -->
<b-field
:addons="false"
:type="formErrors['description'] !== '' && formErrors['description'] !== undefined ? 'is-danger' : ''"
@ -80,7 +81,51 @@
@focus="clearErrors('description')"/>
</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>
<help-button
:title="$i18n.get('label_parent_term')"
:message="$i18n.get('info_help_term_parent')"/>
</label>
<b-autocomplete
id="tainacan-text-cover-page"
:placeholder="$i18n.get('instruction_parent_term')"
:data="parentTerms"
v-model="parentTermName"
@select="onSelectParentTerm($event)"
:loading="isFetchingParentTerms"
@input="fecthParentTerms($event)"
@focus="clearErrors('parent')">
<template slot-scope="props">
{{ props.option.name }}
</template>
<template slot="empty">{{ $i18n.get('info_no_parent_term_found') }}</template>
</b-autocomplete>
</b-field>
<!-- Submit buttons -------------- -->
<div class="field is-grouped form-submit">
<div class="control">
<button
@ -121,7 +166,10 @@
return {
formErrors: {},
headerPlaceholderPath: tainacan_plugin.base_url + '/admin/images/placeholder_rectangle.png',
headerImageMediaFrame: undefined
headerImageMediaFrame: undefined,
isFetchingParentTerms: false,
parentTerms: [],
parentTermName: ''
}
},
props: {
@ -132,6 +180,8 @@
...mapActions('taxonomy', [
'sendChildTerm',
'updateChildTerm',
'fetchParentName',
'fetchPossibleParentTerms'
]),
...mapGetters('taxonomy', [
'getTerms'
@ -223,9 +273,42 @@
this.formErrors[attributes] = undefined;
}
},
fecthParentTerms(search) {
this.isFetchingParentTerms = true;
this.fetchPossibleParentTerms({
taxonomyId: this.taxonomyId,
termId: this.editForm.id,
search: search })
.then((parentTerms) => {
this.parentTerms = parentTerms;
this.isFetchingParentTerms = false;
})
.catch((error) => {
this.$console.error(error);
this.isFetchingParentTerms = false;
});
},
onSelectParentTerm(selectedParentTerm) {
this.editForm.parent = selectedParentTerm.id;
this.selectedParentTerm = selectedParentTerm;
this.parentTermName = selectedParentTerm.name;
console.log(this.parentTermName);
}
},
mounted() {
this.initializeMediaFrames();
this.isFetchingParentTerms = true;
this.fetchParentName({ taxonomyId: this.taxonomyId, parentId: this.editForm.parent })
.then((parentName) => {
this.parentTermName = parentName;
this.isFetchingParentTerms = false;
})
.catch((error) => {
this.$console.error(error);
this.isFetchingParentTerms = false;
});
}
}
</script>

View File

@ -79,7 +79,6 @@
:index="childIndex"
:taxonomy-id="taxonomyId"
:order="order"/>
</div>
<a
class="view-more-terms"

View File

@ -317,6 +317,7 @@ return apply_filters( 'tainacan-admin-i18n', [
'instruction_insert_mapper_metadatum_info' => __( 'Insert the new mapper\'s metadatum info', 'tainacan' ),
'instruction_select_max_options_to_show' => __( 'Select max options to show', 'tainacan' ),
'instruction_select_collection_fetch_items' => __( 'Select a collection to fecth items', 'tainacan' ),
'instruction_parent_term' => __( 'Type to search a Parent Term to choose.', 'tainacan' ),
// Info. Other feedback to user.
'info_search_results' => __( 'Search Results', 'tainacan' ),
@ -384,6 +385,7 @@ return apply_filters( 'tainacan-admin-i18n', [
'info_possible_external_sources' => __( 'Possible external sources: CSV, Instagram, Youtube, etc.', 'tainacan' ),
'info_help_term_name' => __( 'The term name', 'tainacan' ),
'info_help_term_description' => __( 'The description of the Term.', 'tainacan' ),
'info_help_parent_term' => __( 'The parent term', 'tainacan' ),
'info_no_attachments_on_item_yet' => __( 'The are no attachments on this item so far.', 'tainacan' ),
'info_repository_metadata_inheritance' => __( 'Repository Metadata will be inherited by all collections.', 'tainacan' ),
'info_repository_filters_inheritance' => __( 'Repository Filters will be inherited by all collections.', 'tainacan' ),
@ -415,6 +417,7 @@ return apply_filters( 'tainacan-admin-i18n', [
'info_there_are_no_metadata_in_repository_level' => __( 'There are no metadata in repository level', 'tainacan' ),
'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' ),
// Tainacan Metadatum Types
'tainacan-text' => __( 'Text', 'tainacan' ),

View File

@ -301,3 +301,28 @@ export const clearTerms = ({ commit }) => {
commit('clearTerms');
};
// 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")
.then(res => {
let parentTerms = res.data;
resolve( parentTerms );
})
.catch(error => {
reject( error );
});
});
};
export const fetchParentName = ({ commit }, { taxonomyId, parentId } ) => {
return new Promise((resolve, reject) => {
axios.tainacan.get('/taxonomy/' + taxonomyId + '/terms/' + parentId + '?fetch_only=name')
.then(res => {
let parentName = res.data.name;
resolve( parentName );
})
.catch(error => {
reject( error );
});
});
};