Checks if user can edit taxonomy before displaying add new term button.
This commit is contained in:
parent
cd44dc5bca
commit
8c958127d4
|
@ -132,7 +132,7 @@ class REST_Item_Metadata_Controller extends REST_Controller {
|
||||||
public function prepare_item_for_response( $item, $request ) {
|
public function prepare_item_for_response( $item, $request ) {
|
||||||
$item_arr = $item->_toArray(true, true);
|
$item_arr = $item->_toArray(true, true);
|
||||||
|
|
||||||
if($request['context'] === 'edit'){
|
if ($request['context'] === 'edit') {
|
||||||
$item_arr['current_user_can_edit'] = $item->can_edit();
|
$item_arr['current_user_can_edit'] = $item->can_edit();
|
||||||
$item_arr['current_user_can_delete'] = $item->can_delete();
|
$item_arr['current_user_can_delete'] = $item->can_delete();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1172,6 +1172,11 @@ export default {
|
||||||
|
|
||||||
this.isLoading = false;
|
this.isLoading = false;
|
||||||
|
|
||||||
|
if ( wp && wp.hooks && wp.hooks.hasFilter(`tainacan_item_edition_form_submit--redirect`) ) {
|
||||||
|
window.location = wp.hooks.applyFilters(`tainacan_item_edition_form_submit--redirect`, this.item, this.form.collectionId, tainacan_plugin.admin_url);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!this.$adminOptions.itemEditionMode && !this.$adminOptions.mobileAppMode) {
|
if (!this.$adminOptions.itemEditionMode && !this.$adminOptions.mobileAppMode) {
|
||||||
|
|
||||||
if (!this.isOnSequenceEdit) {
|
if (!this.isOnSequenceEdit) {
|
||||||
|
|
|
@ -233,7 +233,9 @@
|
||||||
originalForm: Object,
|
originalForm: Object,
|
||||||
taxonomyId: '',
|
taxonomyId: '',
|
||||||
isHierarchical: Boolean,
|
isHierarchical: Boolean,
|
||||||
isTermInsertionFlow: false
|
isTermInsertionFlow: false,
|
||||||
|
metadatumId: [String, Number],
|
||||||
|
itemId: [String, Number]
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
|
@ -308,7 +310,9 @@
|
||||||
this.isLoading = true;
|
this.isLoading = true;
|
||||||
this.sendChildTerm({
|
this.sendChildTerm({
|
||||||
taxonomyId: this.taxonomyId,
|
taxonomyId: this.taxonomyId,
|
||||||
term: data
|
term: data,
|
||||||
|
metadatumId: this.metadatumId,
|
||||||
|
itemId: this.itemId
|
||||||
})
|
})
|
||||||
.then((term) => {
|
.then((term) => {
|
||||||
this.$emit('onEditionFinished', {term: term, hasChangedParent: this.hasChangedParent, initialParent: this.initialParentId });
|
this.$emit('onEditionFinished', {term: term, hasChangedParent: this.hasChangedParent, initialParent: this.initialParentId });
|
||||||
|
@ -342,7 +346,9 @@
|
||||||
this.isLoading = true;
|
this.isLoading = true;
|
||||||
this.updateTerm({
|
this.updateTerm({
|
||||||
taxonomyId: this.taxonomyId,
|
taxonomyId: this.taxonomyId,
|
||||||
term: data
|
term: data,
|
||||||
|
metadatumId: this.metadatumId,
|
||||||
|
itemId: this.itemId
|
||||||
})
|
})
|
||||||
.then((term) => {
|
.then((term) => {
|
||||||
this.formErrors = {};
|
this.formErrors = {};
|
||||||
|
|
|
@ -59,6 +59,8 @@
|
||||||
custom-class="tainacan-modal"
|
custom-class="tainacan-modal"
|
||||||
:close-button-aria-label="$i18n.get('close')">
|
:close-button-aria-label="$i18n.get('close')">
|
||||||
<term-edition-form
|
<term-edition-form
|
||||||
|
:metadatum-id="itemMetadatum.metadatum.id"
|
||||||
|
:item-id="itemMetadatum.item.id"
|
||||||
:is-hierarchical="isHierarchical"
|
:is-hierarchical="isHierarchical"
|
||||||
:taxonomy-id="taxonomyId"
|
:taxonomy-id="taxonomyId"
|
||||||
:original-form="{ id: 'new', name: newTermName ? newTermName : '' }"
|
:original-form="{ id: 'new', name: newTermName ? newTermName : '' }"
|
||||||
|
@ -71,6 +73,8 @@
|
||||||
<!-- Term creation panel, used on item submission block for a simpler term creation -->
|
<!-- Term creation panel, used on item submission block for a simpler term creation -->
|
||||||
<transition name="filter-item">
|
<transition name="filter-item">
|
||||||
<term-creation-panel
|
<term-creation-panel
|
||||||
|
:metadatum-id="itemMetadatum.metadatum.id"
|
||||||
|
:item-id="itemMetadatum.item.id"
|
||||||
:is-hierarchical="isHierarchical"
|
:is-hierarchical="isHierarchical"
|
||||||
v-if="isTermCreationPanelOpen"
|
v-if="isTermCreationPanelOpen"
|
||||||
:taxonomy-id="taxonomyId"
|
:taxonomy-id="taxonomyId"
|
||||||
|
@ -162,7 +166,7 @@
|
||||||
this.taxonomyId = metadata_type_options.taxonomy_id;
|
this.taxonomyId = metadata_type_options.taxonomy_id;
|
||||||
this.taxonomy = metadata_type_options.taxonomy;
|
this.taxonomy = metadata_type_options.taxonomy;
|
||||||
|
|
||||||
this.allowNewFromOptions = this.allowNew === false ? false : metadata_type_options.allow_new_terms == 'yes';
|
this.allowNewFromOptions = this.allowNew === false ? false : metadata_type_options.allow_new_terms == 'yes' && this.$userCaps.hasCapability('tnc_rep_edit_taxonomies');
|
||||||
|
|
||||||
this.getTermsId();
|
this.getTermsId();
|
||||||
},
|
},
|
||||||
|
|
|
@ -159,7 +159,14 @@ export const fetchTerms = ({}, {taxonomyId, fetchOnly, search, all, order, offse
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const sendChildTerm = ({ commit }, { taxonomyId, term }) => {
|
export const sendChildTerm = ({ commit }, { taxonomyId, term, itemId, metadatumId }) => {
|
||||||
|
|
||||||
|
if ( itemId != undefined )
|
||||||
|
term['item_id'] = itemId;
|
||||||
|
|
||||||
|
if ( metadatumId != undefined )
|
||||||
|
term['metadatum_id'] = metadatumId;
|
||||||
|
|
||||||
return new Promise(( resolve, reject ) => {
|
return new Promise(( resolve, reject ) => {
|
||||||
axios.tainacan.post(`/taxonomy/${taxonomyId}/terms/`, term)
|
axios.tainacan.post(`/taxonomy/${taxonomyId}/terms/`, term)
|
||||||
.then( res => {
|
.then( res => {
|
||||||
|
@ -172,7 +179,14 @@ export const sendChildTerm = ({ commit }, { taxonomyId, term }) => {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const updateTerm = ({}, { taxonomyId, term }) => {
|
export const updateTerm = ({}, { taxonomyId, term, itemId, metadatumId }) => {
|
||||||
|
|
||||||
|
if ( itemId != undefined )
|
||||||
|
term['item_id'] = itemId;
|
||||||
|
|
||||||
|
if ( metadatumId != undefined )
|
||||||
|
term['metadatum_id'] = metadatumId;
|
||||||
|
|
||||||
return new Promise(( resolve, reject ) => {
|
return new Promise(( resolve, reject ) => {
|
||||||
axios.tainacan.patch(`/taxonomy/${taxonomyId}/terms/${term.id}`, term)
|
axios.tainacan.patch(`/taxonomy/${taxonomyId}/terms/${term.id}`, term)
|
||||||
.then( res => {
|
.then( res => {
|
||||||
|
|
|
@ -284,7 +284,7 @@ function tainacan_blocks_get_category_icon_script() {
|
||||||
wp_enqueue_script(
|
wp_enqueue_script(
|
||||||
'tainacan-blocks-register-category-icon',
|
'tainacan-blocks-register-category-icon',
|
||||||
$TAINACAN_BASE_URL . '/assets/js/tainacan_blocks_category_icon.js',
|
$TAINACAN_BASE_URL . '/assets/js/tainacan_blocks_category_icon.js',
|
||||||
array('wp-blocks'),
|
array('wp-blocks', 'wp-element'),
|
||||||
$TAINACAN_VERSION
|
$TAINACAN_VERSION
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue