Gets rid of other event bus. #794.
This commit is contained in:
parent
7044563df1
commit
19b2f9099d
|
@ -80,7 +80,7 @@
|
|||
</h1>
|
||||
</transition>
|
||||
<button
|
||||
v-if="!formErrors.length || isUpdatingValues"
|
||||
v-if="!errors.length || isUpdatingValues"
|
||||
@click="isMobileSubheaderOpen = !isMobileSubheaderOpen">
|
||||
<span
|
||||
v-if="isUpdatingValues"
|
||||
|
@ -106,7 +106,7 @@
|
|||
</button>
|
||||
<item-metadatum-errors-tooltip
|
||||
v-else
|
||||
:form-errors="formErrors" />
|
||||
:form-errors="errors" />
|
||||
</div>
|
||||
|
||||
<transition name="item-appear">
|
||||
|
@ -127,7 +127,7 @@
|
|||
{{ $i18n.get('title_edit_item') + ' ' }}
|
||||
<span style="font-weight: 600;">{{ (item != null && item != undefined) ? item.title : '' }}</span>
|
||||
</h1>
|
||||
<span v-if="!formErrors.length">{{ ($i18n.get('info_updated_at') + ' ' + lastUpdated) }}</span>
|
||||
<span v-if="!errors.length">{{ ($i18n.get('info_updated_at') + ' ' + lastUpdated) }}</span>
|
||||
<span
|
||||
v-else
|
||||
class="help is-danger">
|
||||
|
@ -388,8 +388,8 @@
|
|||
class="icon">
|
||||
<i
|
||||
:class="{
|
||||
'tainacan-icon-arrowdown' : (metadataSectionCollapses[sectionIndex] || errorMessage) && !isSectionHidden(metadataSection.id),
|
||||
'tainacan-icon-arrowright' : !(metadataSectionCollapses[sectionIndex] || errorMessage) || isSectionHidden(metadataSection.id)
|
||||
'tainacan-icon-arrowdown' : (metadataSectionCollapses[sectionIndex] || formErrorMessage) && !isSectionHidden(metadataSection.id),
|
||||
'tainacan-icon-arrowright' : !(metadataSectionCollapses[sectionIndex] || formErrorMessage) || isSectionHidden(metadataSection.id)
|
||||
}"
|
||||
class="has-text-secondary tainacan-icon tainacan-icon-1-25em"/>
|
||||
</span>
|
||||
|
@ -441,6 +441,7 @@
|
|||
:is-last-metadatum="index > 2 && (index == itemMetadata.length - 1)"
|
||||
:is-focused="focusedMetadatum === index"
|
||||
:is-metadata-navigation="isMetadataNavigation"
|
||||
@input="updateItemMetadataValue"
|
||||
@changeCollapse="onChangeCollapse($event, index)"
|
||||
@touchstart="isMetadataNavigation ? setMetadatumFocus({ index: index, scrollIntoView: false }): ''"
|
||||
@mousedown="isMetadataNavigation ? setMetadatumFocus({ index: index, scrollIntoView: false }) : ''"
|
||||
|
@ -659,8 +660,8 @@
|
|||
<span class="help is-danger">
|
||||
{{ formErrorMessage }}
|
||||
<item-metadatum-errors-tooltip
|
||||
v-if="formErrors.length"
|
||||
:form-errors="formErrors" />
|
||||
v-if="errors.length"
|
||||
:form-errors="errors" />
|
||||
</span>
|
||||
</p>
|
||||
|
||||
|
@ -713,9 +714,9 @@
|
|||
import { nextTick } from 'vue';
|
||||
import { mapActions, mapGetters } from 'vuex';
|
||||
|
||||
import { eventBusItemMetadata } from '../../js/event-bus-item-metadata';
|
||||
import wpMediaFrames from '../../js/wp-media-frames';
|
||||
import { formHooks } from '../../js/mixins';
|
||||
import { itemMetadataMixin } from '../../js/item-metadata-mixin';
|
||||
|
||||
import RelatedItemsList from '../lists/related-items-list.vue';
|
||||
import CustomDialog from '../other/custom-dialog.vue';
|
||||
|
@ -744,7 +745,7 @@ export default {
|
|||
ItemAttachmentsEditionForm,
|
||||
ItemFormFooterButtons
|
||||
},
|
||||
mixins: [ formHooks ],
|
||||
mixins: [ formHooks, itemMetadataMixin ],
|
||||
beforeRouteLeave ( to, from, next ) {
|
||||
if (this.item.status == 'auto-draft') {
|
||||
this.$buefy.modal.open({
|
||||
|
@ -870,12 +871,6 @@ export default {
|
|||
totalRelatedItems() {
|
||||
return (this.item && this.item.related_items) ? Object.values(this.item.related_items).reduce((totalItems, aRelatedItemsGroup) => totalItems + parseInt(aRelatedItemsGroup.total_items), 0) : false;
|
||||
},
|
||||
formErrors() {
|
||||
return eventBusItemMetadata && eventBusItemMetadata.errors && eventBusItemMetadata.errors.length ? eventBusItemMetadata.errors : []
|
||||
},
|
||||
conditionalSections() {
|
||||
return eventBusItemMetadata && eventBusItemMetadata.conditionalSections ? eventBusItemMetadata.conditionalSections : [];
|
||||
},
|
||||
isEditingItemMetadataInsideIframe() {
|
||||
return this.$route.query && this.$route.query.editingmetadata;
|
||||
},
|
||||
|
@ -929,7 +924,7 @@ export default {
|
|||
|
||||
// Clear form variables
|
||||
this.cleanItemMetadata();
|
||||
eventBusItemMetadata.clearAllErrors();
|
||||
this.clearAllErrors();
|
||||
this.formErrorMessage = '';
|
||||
|
||||
this.isLoading = true;
|
||||
|
@ -984,7 +979,7 @@ export default {
|
|||
created() {
|
||||
// Obtains collection ID
|
||||
this.cleanItemMetadata();
|
||||
eventBusItemMetadata.clearAllErrors();
|
||||
this.clearAllErrors();
|
||||
this.formErrorMessage = '';
|
||||
this.collectionId = this.$route.params.collectionId;
|
||||
this.form.collectionId = this.collectionId;
|
||||
|
@ -1046,12 +1041,12 @@ export default {
|
|||
* Creates the conditional metadata set to later watch values
|
||||
* of certain metadata that control sections visibility.
|
||||
*/
|
||||
eventBusItemMetadata.conditionalSections = {};
|
||||
this.conditionalSections = {};
|
||||
for (let metadataSection of metadataSections) {
|
||||
if ( metadataSection.is_conditional_section == 'yes') {
|
||||
const conditionalSectionId = Object.keys(metadataSection.conditional_section_rules);
|
||||
if ( conditionalSectionId.length ) {
|
||||
eventBusItemMetadata.conditionalSections[metadataSection.id] = {
|
||||
this.conditionalSections[metadataSection.id] = {
|
||||
sectionId: metadataSection.id,
|
||||
metadatumId: conditionalSectionId[0],
|
||||
metadatumValues: metadataSection.conditional_section_rules[conditionalSectionId[0]],
|
||||
|
@ -1067,22 +1062,13 @@ export default {
|
|||
});
|
||||
|
||||
// Sets feedback variables
|
||||
eventBusItemMetadata.$emitter.on('isUpdatingValue', (status) => {
|
||||
this.isUpdatingValues = status;
|
||||
});
|
||||
eventBusItemMetadata.$emitter.on('hasErrorsOnForm', (hasErrors) => {
|
||||
if (hasErrors)
|
||||
this.formErrorMessage = this.formErrorMessage ? this.formErrorMessage : this.$i18n.get('info_errors_in_form');
|
||||
else
|
||||
this.formErrorMessage = '';
|
||||
});
|
||||
this.cleanLastUpdated();
|
||||
|
||||
// Updates variables for metadata navigation from compound childs
|
||||
eventBusItemMetadata.$emitter.on('isOnFirstMetadatumOfCompoundNavigation', (isOnFirstMetadatumOfCompoundNavigation) => {
|
||||
this.$emitter.on('isOnFirstMetadatumOfCompoundNavigation', (isOnFirstMetadatumOfCompoundNavigation) => {
|
||||
this.isOnFirstMetadatumOfCompoundNavigation = isOnFirstMetadatumOfCompoundNavigation
|
||||
});
|
||||
eventBusItemMetadata.$emitter.on('isOnLastMetadatumOfCompoundNavigation', (isOnLastMetadatumOfCompoundNavigation) => {
|
||||
this.$emitter.on('isOnLastMetadatumOfCompoundNavigation', (isOnLastMetadatumOfCompoundNavigation) => {
|
||||
this.isOnLastMetadatumOfCompoundNavigation = isOnLastMetadatumOfCompoundNavigation
|
||||
});
|
||||
|
||||
|
@ -1095,10 +1081,8 @@ export default {
|
|||
this.isMobileSubheaderOpen = true;
|
||||
},
|
||||
beforeUnmount () {
|
||||
eventBusItemMetadata.$emitter.off('isUpdatingValue');
|
||||
eventBusItemMetadata.$emitter.off('hasErrorsOnForm');
|
||||
eventBusItemMetadata.$emitter.off('isOnFirstMetadatumOfCompoundNavigation');
|
||||
eventBusItemMetadata.$emitter.off('isOnLastMetadatumOfCompoundNavigation');
|
||||
this.$emitter.off('isOnFirstMetadatumOfCompoundNavigation');
|
||||
this.$emitter.off('isOnLastMetadatumOfCompoundNavigation');
|
||||
window.removeEventListener('resize', this.handleWindowResize);
|
||||
if (typeof this.swiper.destroy == 'function')
|
||||
this.swiper.destroy();
|
||||
|
@ -1166,7 +1150,7 @@ export default {
|
|||
promise = this.updateItem(data);
|
||||
|
||||
// Clear errors so we don't have them duplicated from api
|
||||
eventBusItemMetadata.errors = [];
|
||||
this.errors = [];
|
||||
|
||||
promise.then(updatedItem => {
|
||||
|
||||
|
@ -1225,7 +1209,7 @@ export default {
|
|||
if (errors.errors) {
|
||||
for (let error of errors.errors) {
|
||||
for (let metadatum of Object.keys(error)){
|
||||
eventBusItemMetadata.errors.push({
|
||||
this.errors.push({
|
||||
metadatum_id: metadatum,
|
||||
errors: error[metadatum]
|
||||
});
|
||||
|
@ -1239,6 +1223,12 @@ export default {
|
|||
this.isLoading = false;
|
||||
});
|
||||
},
|
||||
hasErrorsOnForm(hasErrors) {
|
||||
if (hasErrors)
|
||||
this.formErrorMessage = this.formErrorMessage ? this.formErrorMessage : this.$i18n.get('info_errors_in_form');
|
||||
else
|
||||
this.formErrorMessage = '';
|
||||
},
|
||||
onDiscard() {
|
||||
if (!this.$adminOptions.itemEditionMode && !this.$adminOptions.mobileAppMode)
|
||||
this.$router.go(-1);
|
||||
|
@ -1261,7 +1251,7 @@ export default {
|
|||
]);
|
||||
|
||||
// Clear errors so we don't have them duplicated from api
|
||||
eventBusItemMetadata.errors = [];
|
||||
this.errors = [];
|
||||
|
||||
// Creates draft Item
|
||||
this.form.comment_status = this.form.comment_status == 'open' ? 'open' : 'closed';
|
||||
|
@ -1290,7 +1280,7 @@ export default {
|
|||
|
||||
// If a parameter was passed with a suggestion of item title, also send a patch to item metadata
|
||||
if (this.$route.query.newitemtitle) {
|
||||
eventBusItemMetadata.$emit('input', {
|
||||
this.updateItemMetadataValue({
|
||||
itemId: this.itemId,
|
||||
metadatumId: this.$route.query.newmetadatumid,
|
||||
values: this.$route.query.newitemtitle,
|
||||
|
@ -1334,8 +1324,8 @@ export default {
|
|||
const currentItemMetadatum = metadata.find(anItemMetadatum => anItemMetadatum.metadatum.id == this.conditionalSections[conditionalSectionId].metadatumId);
|
||||
if (currentItemMetadatum) {
|
||||
const itemMetadatumValues = Array.isArray(currentItemMetadatum.value) ? currentItemMetadatum.value : [ currentItemMetadatum.value ];
|
||||
const conditionalValues = Array.isArray(eventBusItemMetadata.conditionalSections[conditionalSectionId].metadatumValues) ? eventBusItemMetadata.conditionalSections[conditionalSectionId].metadatumValues : [eventBusItemMetadata.conditionalSections[conditionalSectionId].metadatumValues];
|
||||
eventBusItemMetadata.conditionalSections[conditionalSectionId].hide = itemMetadatumValues.every(aValue => conditionalValues.indexOf(aValue) < 0);
|
||||
const conditionalValues = Array.isArray(this.conditionalSections[conditionalSectionId].metadatumValues) ? this.conditionalSections[conditionalSectionId].metadatumValues : [this.conditionalSections[conditionalSectionId].metadatumValues];
|
||||
this.conditionalSections[conditionalSectionId].hide = itemMetadatumValues.every(aValue => conditionalValues.indexOf(aValue) < 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1389,7 +1379,7 @@ export default {
|
|||
.catch((errors) => {
|
||||
for (let error of errors.errors) {
|
||||
for (let metadatum of Object.keys(error)){
|
||||
eventBusItemMetadata.errors.push({
|
||||
this.errors.push({
|
||||
metadatum_id: metadatum,
|
||||
errors: error[metadatum]
|
||||
});
|
||||
|
@ -1472,7 +1462,7 @@ export default {
|
|||
.catch((errors) => {
|
||||
for (let error of errors.errors) {
|
||||
for (let metadatum of Object.keys(error)){
|
||||
eventBusItemMetadata.errors.push({
|
||||
this.errors.push({
|
||||
metadatum_id: metadatum,
|
||||
errors: error[metadatum]
|
||||
});
|
||||
|
@ -1500,7 +1490,7 @@ export default {
|
|||
.catch((errors) => {
|
||||
for (let error of errors.errors) {
|
||||
for (let metadatum of Object.keys(error)){
|
||||
eventBusItemMetadata.errors.push({
|
||||
this.errors.push({
|
||||
metadatum_id: metadatum,
|
||||
errors: error[metadatum]
|
||||
});
|
||||
|
@ -1575,7 +1565,7 @@ export default {
|
|||
.catch((errors) => {
|
||||
for (let error of errors.errors) {
|
||||
for (let metadatum of Object.keys(error)){
|
||||
eventBusItemMetadata.errors.push({ metadatum_id: metadatum, errors: error[metadatum]});
|
||||
this.errors.push({ metadatum_id: metadatum, errors: error[metadatum]});
|
||||
}
|
||||
}
|
||||
this.formErrorMessage = errors.error_message;
|
||||
|
@ -1646,13 +1636,13 @@ export default {
|
|||
},
|
||||
onChangeCollapse(event, index) {
|
||||
if (event && !this.metadataCollapses[index] && this.itemMetadata[index].metadatum && this.itemMetadata[index].metadatum['metadata_type'] === "Tainacan\\Metadata_Types\\GeoCoordinate")
|
||||
eventBusItemMetadata.$emit('itemEditionFormResize');
|
||||
this.$emitter.emit('itemEditionFormResize');
|
||||
|
||||
this.metadataCollapses.splice(index, 1, event);
|
||||
},
|
||||
toggleMetadataSectionCollapse(sectionIndex) {
|
||||
if (!this.isMetadataNavigation)
|
||||
Object.assign( this.metadataSectionCollapses, { [sectionIndex]: (this.errorMessage ? true : !this.metadataSectionCollapses[sectionIndex]) });
|
||||
Object.assign( this.metadataSectionCollapses, { [sectionIndex]: (this.formErrorMessage ? true : !this.metadataSectionCollapses[sectionIndex]) });
|
||||
},
|
||||
onDeletePermanently() {
|
||||
this.$buefy.modal.open({
|
||||
|
@ -1786,7 +1776,7 @@ export default {
|
|||
},
|
||||
handleWindowResize: _.debounce( function() {
|
||||
nextTick(() => {
|
||||
eventBusItemMetadata.$emit('itemEditionFormResize');
|
||||
this.$emitter.emit('itemEditionFormResize');
|
||||
if (window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth)
|
||||
this.isMobileScreen = (window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth) <= 768;
|
||||
});
|
||||
|
@ -1796,14 +1786,14 @@ export default {
|
|||
const isPreviouslyFocusedOnCompoundMetadatum = previouslyFocusedMetadatum.metadatum && previouslyFocusedMetadatum.metadatum.metadata_type === 'Tainacan\\Metadata_Types\\Compound';
|
||||
|
||||
if (isPreviouslyFocusedOnCompoundMetadatum || this.isCurrentlyFocusedOnCompoundMetadatum)
|
||||
eventBusItemMetadata.$emit('focusPreviousChildMetadatum');
|
||||
this.$emitter.emit('focusPreviousChildMetadatum');
|
||||
|
||||
if ( !this.isCurrentlyFocusedOnCompoundMetadatum || (this.isCurrentlyFocusedOnCompoundMetadatum && this.isOnFirstMetadatumOfCompoundNavigation) )
|
||||
this.setMetadatumFocus({ index: this.focusedMetadatum - 1, scrollIntoView: true });
|
||||
},
|
||||
focusNextMetadatum() {
|
||||
if (this.isCurrentlyFocusedOnCompoundMetadatum && !this.isOnLastMetadatumOfCompoundNavigation)
|
||||
eventBusItemMetadata.$emit('focusNextChildMetadatum');
|
||||
this.$emitter.emit('focusNextChildMetadatum');
|
||||
|
||||
if ( !this.isCurrentlyFocusedOnCompoundMetadatum || (this.isCurrentlyFocusedOnCompoundMetadatum && this.isOnLastMetadatumOfCompoundNavigation) )
|
||||
this.setMetadatumFocus({ index: this.focusedMetadatum + 1, scrollIntoView: true });
|
||||
|
|
|
@ -188,7 +188,7 @@ import ItemCreationStatusDialog from '../other/item-creation-status-dialog.vue';
|
|||
export default {
|
||||
props: {
|
||||
status: String,
|
||||
collectionId: Number,
|
||||
collectionId: Number|String,
|
||||
isOnSequenceEdit: Boolean,
|
||||
isCurrentItemOnSequenceEdit: Boolean,
|
||||
hasNextItemOnSequenceEdit: Boolean,
|
||||
|
@ -206,13 +206,13 @@ export default {
|
|||
'onDiscard',
|
||||
],
|
||||
mounted() {
|
||||
this.$parent.$emitter.on('toggleItemEditionFooterDropdown', () => {
|
||||
this.$emitter.on('toggleItemEditionFooterDropdown', () => {
|
||||
if (this.$refs && this.$refs['item-edition-footer-dropdown'])
|
||||
this.$refs['item-edition-footer-dropdown'].toggle();
|
||||
});
|
||||
},
|
||||
beforeUnmount() {
|
||||
this.$parent.$emitter.off('toggleItemEditionFooterDropdown');
|
||||
this.$emitter.off('toggleItemEditionFooterDropdown');
|
||||
},
|
||||
methods: {
|
||||
openItemCreationStatusDialog() {
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
|
||||
</div>
|
||||
<div
|
||||
v-if="!isLoading && !$adminOptions.hideItemEditionThumbnail"
|
||||
v-if="!$adminOptions.hideItemEditionThumbnail"
|
||||
class="section-box section-thumbnail">
|
||||
<div class="thumbnail-field">
|
||||
<file-item
|
||||
|
|
|
@ -244,7 +244,7 @@
|
|||
</footer>
|
||||
</form>
|
||||
|
||||
<div v-if="!isLoading && (($route.name == 'TaxonomyCreationForm' && !$userCaps.hasCapability('tnc_rep_edit_taxonomies')) || ($route.name == 'TaxonomyEditionForm' && taxonomy && taxonomy.current_user_can_edit != undefined && !taxonomy.current_user_can_edit))">
|
||||
<div v-if="!isLoadingTaxonomy && (($route.name == 'TaxonomyCreationForm' && !$userCaps.hasCapability('tnc_rep_edit_taxonomies')) || ($route.name == 'TaxonomyEditionForm' && taxonomy && taxonomy.current_user_can_edit != undefined && !taxonomy.current_user_can_edit))">
|
||||
<section class="section">
|
||||
<div class="content has-text-grey has-text-centered">
|
||||
<p>
|
||||
|
|
|
@ -169,9 +169,8 @@
|
|||
// excludeDocumentId: this.form.document,
|
||||
// excludeThumbnailId: this.item.thumbnail_id
|
||||
})
|
||||
.then((response) => {
|
||||
.then(() => {
|
||||
this.isLoading = false;
|
||||
this.totalAttachments = response.total;
|
||||
})
|
||||
.catch((error) => {
|
||||
this.isLoading = false;
|
||||
|
|
|
@ -68,8 +68,8 @@
|
|||
<complete-roles-list
|
||||
v-if="capability.roles"
|
||||
:complete-roles-list="getCompleteRolesList(capability.roles, capability.roles_inherited)">
|
||||
<td
|
||||
slot-scope="props"
|
||||
<template #props>
|
||||
<td
|
||||
class="table-creation column-small-width"
|
||||
:label="$i18n.get('label_associated_roles')"
|
||||
:aria-label="$i18n.get('label_associated_roles') + ': ' + props['complete-roles-list']">
|
||||
|
@ -85,7 +85,8 @@
|
|||
placement: 'auto-start'
|
||||
}"
|
||||
v-html="props['complete-roles-list']"/>
|
||||
</td>
|
||||
</td>
|
||||
</template>
|
||||
</complete-roles-list>
|
||||
<!-- Actions -->
|
||||
<td
|
||||
|
@ -121,6 +122,7 @@
|
|||
|
||||
// Auxiliary component for avoinding multiple calls to getCompleteRolesList
|
||||
const CompleteRolesList = {
|
||||
inheritAttrs: false,
|
||||
render() {
|
||||
return !!this.$slots.default && typeof this.$slots.default == 'function' ? this.$slots.default(this.$attrs) : '';
|
||||
}
|
||||
|
@ -132,7 +134,7 @@
|
|||
},
|
||||
props: {
|
||||
isLoading: false,
|
||||
capabilities: Array
|
||||
capabilities: Object
|
||||
},
|
||||
methods: {
|
||||
openCapabilitiyEditModal(capabilityKey) {
|
||||
|
|
|
@ -605,8 +605,8 @@ export default {
|
|||
mounted() {
|
||||
this.cleanMetadataSections();
|
||||
|
||||
this.$eventBusMetadataList.on('addMetadatumViaButton', this.addMetadatumViaButton);
|
||||
this.$eventBusMetadataList.on('addMetadataSectionViaButton', this.addMetadataSectionViaButton);
|
||||
this.$emitter.on('addMetadatumViaButton', this.addMetadatumViaButton);
|
||||
this.$emitter.on('addMetadataSectionViaButton', this.addMetadataSectionViaButton);
|
||||
|
||||
this.collectionId = this.$route.params.collectionId;
|
||||
this.isLoadingMetadataSections = true;
|
||||
|
@ -624,8 +624,8 @@ export default {
|
|||
if (this.metadataSearchCancel != undefined)
|
||||
this.metadataSearchCancel.cancel('Metadata search Canceled.');
|
||||
|
||||
this.$eventBusMetadataList.off('addMetadatumViaButton', this.addMetadatumViaButton);
|
||||
this.$eventBusMetadataList.off('addMetadataSectionViaButton', this.addMetadataSectionViaButton);
|
||||
this.$emitter.off('addMetadatumViaButton', this.addMetadatumViaButton);
|
||||
this.$emitter.off('addMetadataSectionViaButton', this.addMetadataSectionViaButton);
|
||||
},
|
||||
methods: {
|
||||
...mapActions('metadata', [
|
||||
|
|
|
@ -192,10 +192,10 @@ export default {
|
|||
'getMetadatumTypes'
|
||||
]),
|
||||
addMetadatumViaButton(metadatumType) {
|
||||
this.$eventBusMetadataList.emit('addMetadatumViaButton', metadatumType);
|
||||
this.$emitter.emit('addMetadatumViaButton', metadatumType);
|
||||
},
|
||||
addMetadataSectionViaButton() {
|
||||
this.$eventBusMetadataList.emit('addMetadataSectionViaButton');
|
||||
this.$emitter.emit('addMetadataSectionViaButton');
|
||||
},
|
||||
getPreviewTemplateContent(metadatum) {
|
||||
return `<div class="metadata-type-preview tainacan-form">
|
||||
|
|
|
@ -346,7 +346,7 @@ export default {
|
|||
mounted() {
|
||||
this.cleanMetadata();
|
||||
this.loadMetadata();
|
||||
this.$eventBusMetadataList.on('addMetadatumViaButton', this.addMetadatumViaButton);
|
||||
this.$emitter.on('addMetadatumViaButton', this.addMetadatumViaButton);
|
||||
},
|
||||
beforeUnmount() {
|
||||
// Cancels previous Request
|
||||
|
|
|
@ -321,12 +321,12 @@ export default {
|
|||
},
|
||||
created() {
|
||||
this.fetchTerms();
|
||||
this.$parent.$emitter.on('deleteSelectedTerms', this.deleteSelectedTerms);
|
||||
this.$parent.$emitter.on('updateSelectedTermsParent', this.updateSelectedTermsParent);
|
||||
this.$emitter.on('deleteSelectedTerms', this.deleteSelectedTerms);
|
||||
this.$emitter.on('updateSelectedTermsParent', this.updateSelectedTermsParent);
|
||||
},
|
||||
beforeUnmount() {
|
||||
this.$parent.$emitter.off('deleteSelectedTerms', this.deleteSelectedTerms);
|
||||
this.$parent.$emitter.off('updateSelectedTermsParent', this.updateSelectedTermsParent);
|
||||
this.$emitter.off('deleteSelectedTerms', this.deleteSelectedTerms);
|
||||
this.$emitter.off('updateSelectedTermsParent', this.updateSelectedTermsParent);
|
||||
},
|
||||
methods: {
|
||||
...mapActions('taxonomy', [
|
||||
|
|
|
@ -115,7 +115,7 @@
|
|||
|
||||
<script>
|
||||
import { nextTick } from 'vue';
|
||||
import { eventBusItemMetadata } from '../../../js/event-bus-item-metadata';
|
||||
import { mapActions } from 'vuex';
|
||||
|
||||
export default {
|
||||
props: {
|
||||
|
@ -181,16 +181,19 @@
|
|||
}
|
||||
},
|
||||
created() {
|
||||
eventBusItemMetadata.$emitter.on('hasRemovedItemMetadataGroup', this.laterUpdateIsRemovingGroup);
|
||||
eventBusItemMetadata.$emitter.on('focusPreviousChildMetadatum', this.focusPreviousChildMetadatum);
|
||||
eventBusItemMetadata.$emitter.on('focusNextChildMetadatum', this.focusNextChildMetadatum);
|
||||
this.$emitter.on('hasRemovedItemMetadataGroup', this.laterUpdateIsRemovingGroup);
|
||||
this.$emitter.on('focusPreviousChildMetadatum', this.focusPreviousChildMetadatum);
|
||||
this.$emitter.on('focusNextChildMetadatum', this.focusNextChildMetadatum);
|
||||
},
|
||||
beforeUnmount() {
|
||||
eventBusItemMetadata.$emitter.off('hasRemovedItemMetadataGroup', this.laterUpdateIsRemovingGroup);
|
||||
eventBusItemMetadata.$emitter.off('focusPreviousChildMetadatum', this.focusPreviousChildMetadatum);
|
||||
eventBusItemMetadata.$emitter.off('focusNextChildMetadatum', this.focusNextChildMetadatum);
|
||||
this.$emitter.off('hasRemovedItemMetadataGroup', this.laterUpdateIsRemovingGroup);
|
||||
this.$emitter.off('focusPreviousChildMetadatum', this.focusPreviousChildMetadatum);
|
||||
this.$emitter.off('focusNextChildMetadatum', this.focusNextChildMetadatum);
|
||||
},
|
||||
methods: {
|
||||
...mapActions('item', [
|
||||
'fetchCompoundFirstParentMetaId'
|
||||
]),
|
||||
createChildMetadataGroups() {
|
||||
let currentChildItemMetadataGroups = [];
|
||||
|
||||
|
@ -280,9 +283,9 @@
|
|||
if (this.itemMetadatum.item && this.itemMetadatum.item.id) {
|
||||
|
||||
// Sends value to api so we can obtain the parent_meta_id
|
||||
eventBusItemMetadata.fetchCompoundFirstParentMetaId({
|
||||
itemId: this.itemMetadatum.item.id,
|
||||
metadatumId: this.itemMetadatum.metadatum.id
|
||||
this.fetchCompoundFirstParentMetaId({
|
||||
item_id: this.itemMetadatum.item.id,
|
||||
metadatum_id: this.itemMetadatum.metadatum.id
|
||||
}).then((parentMetaId) => {
|
||||
|
||||
// Create a new placeholder parent_meta_id group here.
|
||||
|
@ -352,7 +355,7 @@
|
|||
|
||||
if (this.itemMetadatum.value && this.itemMetadatum.value[groupIndex] && this.itemMetadatum.value[groupIndex][0]) {
|
||||
this.isRemovingGroup = true;
|
||||
eventBusItemMetadata.$emit('removeCompoundGroup', {
|
||||
this.$emitter.emit('removeCompoundGroup', {
|
||||
itemId: this.itemMetadatum.item.id,
|
||||
metadatumId: this.itemMetadatum.metadatum.id,
|
||||
parentMetaId: this.itemMetadatum.item.id ? this.itemMetadatum.value[groupIndex][0].parent_meta_id : groupIndex
|
||||
|
@ -386,8 +389,8 @@
|
|||
|
||||
// This keeps the navigation going on when no child input exists
|
||||
if (this.childItemMetadataGroups.length === 0) {
|
||||
eventBusItemMetadata.$emit('isOnFirstMetadatumOfCompoundNavigation', true);
|
||||
eventBusItemMetadata.$emit('isOnLastMetadatumOfCompoundNavigation', true);
|
||||
this.$emitter.emit('isOnFirstMetadatumOfCompoundNavigation', true);
|
||||
this.$emitter.emit('isOnLastMetadatumOfCompoundNavigation', true);
|
||||
}
|
||||
},
|
||||
focusNextChildMetadatum() {
|
||||
|
@ -401,13 +404,13 @@
|
|||
|
||||
// This keeps the navigation going on when no child input exists
|
||||
if (this.childItemMetadataGroups.length === 0) {
|
||||
eventBusItemMetadata.$emit('isOnFirstMetadatumOfCompoundNavigation', true);
|
||||
eventBusItemMetadata.$emit('isOnLastMetadatumOfCompoundNavigation', true);
|
||||
this.$emitter.emit('isOnFirstMetadatumOfCompoundNavigation', true);
|
||||
this.$emitter.emit('isOnLastMetadatumOfCompoundNavigation', true);
|
||||
}
|
||||
},
|
||||
informItemEditionFormOfChildNavigation() {
|
||||
eventBusItemMetadata.$emit('isOnFirstMetadatumOfCompoundNavigation', this.focusedGroupMetadatum === 0 && this.focusedChildMetadatum === 0);
|
||||
eventBusItemMetadata.$emit('isOnLastMetadatumOfCompoundNavigation', (this.focusedGroupMetadatum === this.childItemMetadataGroups.length - 1) && (this.focusedChildMetadatum === this.childItemMetadataGroups[this.focusedGroupMetadatum].length - 1) );
|
||||
this.$emitter.emit('isOnFirstMetadatumOfCompoundNavigation', this.focusedGroupMetadatum === 0 && this.focusedChildMetadatum === 0);
|
||||
this.$emitter.emit('isOnLastMetadatumOfCompoundNavigation', (this.focusedGroupMetadatum === this.childItemMetadataGroups.length - 1) && (this.focusedChildMetadatum === this.childItemMetadataGroups[this.focusedGroupMetadatum].length - 1) );
|
||||
},
|
||||
setMetadatumChildFocus({ groupIndex = 0, childIndex = 0, scrollIntoView = false }) {
|
||||
const previousGroupIndex = this.focusedGroupMetadatum;
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
<b-input
|
||||
:id="'tainacan-item-metadatum_id-' + itemMetadatum.metadatum.id + (itemMetadatum.parent_meta_id ? ('_parent_meta_id-' + itemMetadatum.parent_meta_id) : '')"
|
||||
:disabled="disabled"
|
||||
:custom-class="{ 'is-danger': isInvalidDate && dateValue }"
|
||||
:custom-class="isInvalidDate && dateValue ? 'is-danger' : ''"
|
||||
type="text"
|
||||
v-imask="dateMask"
|
||||
v-model="dateValue"
|
||||
|
|
|
@ -93,8 +93,6 @@
|
|||
import iconUrl from 'leaflet/dist/images/marker-icon.png';
|
||||
import iconRetinaUrl from 'leaflet/dist/images/marker-icon-2x.png';
|
||||
import shadowUrl from 'leaflet/dist/images/marker-shadow.png';
|
||||
|
||||
import { eventBusItemMetadata } from '../../../js/event-bus-item-metadata';
|
||||
|
||||
delete Icon.Default.prototype._getIconUrl;
|
||||
Icon.Default.mergeOptions({
|
||||
|
@ -202,7 +200,7 @@
|
|||
// We need to pass mapComponentRef here instead of creating it inside the function
|
||||
// otherwise the listener would conflict when multiple geo metadata are inserted.
|
||||
const mapComponentRef = 'map--' + this.itemMetadatumIdentifier;
|
||||
eventBusItemMetadata.$emitter.on('itemEditionFormResize', () => this.handleWindowResize(mapComponentRef));
|
||||
this.$emitter.on('itemEditionFormResize', () => this.handleWindowResize(mapComponentRef));
|
||||
},
|
||||
mounted() {
|
||||
nextTick(() => {
|
||||
|
@ -212,7 +210,7 @@
|
|||
},
|
||||
beforeUnmount() {
|
||||
const mapComponentRef = 'map--' + this.itemMetadatumIdentifier;
|
||||
eventBusItemMetadata.$emitter.off('itemEditionFormResize', () => this.handleWindowResize(mapComponentRef));
|
||||
this.$emitter.off('itemEditionFormResize', () => this.handleWindowResize(mapComponentRef));
|
||||
},
|
||||
methods: {
|
||||
onUpdateFromLatitudeInput: _.debounce( function($event) {
|
||||
|
|
|
@ -14,8 +14,6 @@
|
|||
:model-value="selected"
|
||||
@update:model-value="onInput"
|
||||
@blur="onBlur"
|
||||
@add="onAdd"
|
||||
@remove="onRemove"
|
||||
:data="options"
|
||||
:maxtags="maxtags != undefined ? maxtags : (itemMetadatum.metadatum.multiple == 'yes' || allowNew === true ? (maxMultipleValues !== undefined ? maxMultipleValues : null) : '1')"
|
||||
autocomplete
|
||||
|
|
|
@ -62,6 +62,7 @@
|
|||
:item-metadatum="itemMetadatum"
|
||||
@input="changeValue"
|
||||
@blur="performValueChange"
|
||||
:disabled="false"
|
||||
:metadata-name-filter-string="metadataNameFilterString"
|
||||
:hide-collapses="hideCollapses"
|
||||
:hide-metadata-types="hideMetadataTypes"
|
||||
|
@ -85,6 +86,7 @@
|
|||
:item-metadatum="itemMetadatum"
|
||||
@input="changeValue"
|
||||
@blur="performValueChange"
|
||||
:disabled="false"
|
||||
:metadata-name-filter-string="metadataNameFilterString"
|
||||
:hide-collapses="hideCollapses"
|
||||
:hide-metadata-types="hideMetadataTypes"
|
||||
|
@ -139,6 +141,7 @@
|
|||
:item-metadatum="itemMetadatum"
|
||||
@input="changeValue"
|
||||
@blur="performValueChange"
|
||||
:disabled="false"
|
||||
:is-last-metadatum="isLastMetadatum"
|
||||
:hide-collapses="hideCollapses"
|
||||
:hide-metadata-types="hideMetadataTypes"
|
||||
|
@ -156,7 +159,6 @@
|
|||
|
||||
<script>
|
||||
import { nextTick } from 'vue';
|
||||
import { eventBusItemMetadata } from '../../js/event-bus-item-metadata';
|
||||
|
||||
export default {
|
||||
name: 'TainacanFormItem',
|
||||
|
@ -218,7 +220,7 @@
|
|||
},
|
||||
created() {
|
||||
this.setInitialValues();
|
||||
eventBusItemMetadata.$emitter.on('updateErrorMessageOf#' + (this.itemMetadatum.parent_meta_id ? this.itemMetadatum.metadatum.id + '-' + this.itemMetadatum.parent_meta_id : this.itemMetadatum.metadatum.id), (errors) => {
|
||||
this.$emitter.on('updateErrorMessageOf#' + (this.itemMetadatum.parent_meta_id ? this.itemMetadatum.metadatum.id + '-' + this.itemMetadatum.parent_meta_id : this.itemMetadatum.metadatum.id), (errors) => {
|
||||
let updatedErrorMessage = '';
|
||||
if (errors && errors.errors && this.itemMetadatum && this.itemMetadatum.metadatum && (this.itemMetadatum.parent_meta_id ? (this.itemMetadatum.parent_meta_id == errors.parent_meta_id && this.itemMetadatum.metadatum.id == errors.metadatum_id) : this.itemMetadatum.metadatum.id == errors.metadatum_id)) {
|
||||
for (let error of errors.errors) {
|
||||
|
@ -231,7 +233,7 @@
|
|||
},
|
||||
beforeUnmount() {
|
||||
if (this.itemMetadatum && this.itemMetadatum.metadatum) {
|
||||
eventBusItemMetadata.$emitter.off('updateErrorMessageOf#' + (this.itemMetadatum.parent_meta_id ? this.itemMetadatum.metadatum.id + '-' + this.itemMetadatum.parent_meta_id : this.itemMetadatum.metadatum.id));
|
||||
this.$emitter.off('updateErrorMessageOf#' + (this.itemMetadatum.parent_meta_id ? this.itemMetadatum.metadatum.id + '-' + this.itemMetadatum.parent_meta_id : this.itemMetadatum.metadatum.id));
|
||||
}
|
||||
},
|
||||
mounted () {
|
||||
|
@ -314,7 +316,7 @@
|
|||
}
|
||||
|
||||
// If none is the case, the value is update request is sent to the API
|
||||
eventBusItemMetadata.$emit('input', {
|
||||
this.$emit('input', {
|
||||
itemId: this.itemMetadatum.item.id,
|
||||
metadatumId: this.itemMetadatum.metadatum.id,
|
||||
values: this.values ? this.values : '',
|
||||
|
|
|
@ -130,12 +130,12 @@
|
|||
}
|
||||
},
|
||||
created(){
|
||||
this.$root.$emitter.on('openProcessesPopup', () => {
|
||||
this.$emitter.on('openProcessesPopup', () => {
|
||||
this.showProcesses = true;
|
||||
});
|
||||
},
|
||||
beforeUnmount() {
|
||||
this.$root.$emitter.off('openProcessesPopup');
|
||||
this.$emitter.off('openProcessesPopup');
|
||||
},
|
||||
methods: {
|
||||
updateSearch() {
|
||||
|
|
|
@ -99,10 +99,10 @@ export default {
|
|||
document.title = this.$route.meta.title;
|
||||
this.pageTitle = document.title;
|
||||
|
||||
this.$root.$emitter.on('onCollectionBreadCrumbUpdate', this.collectionBreadCrumbUpdate);
|
||||
this.$emitter.on('onCollectionBreadCrumbUpdate', this.collectionBreadCrumbUpdate);
|
||||
},
|
||||
beforeUnmount() {
|
||||
this.$root.$emitter.on('onCollectionBreadCrumbUpdate', this.collectionBreadCrumbUpdate);
|
||||
this.$emitter.on('onCollectionBreadCrumbUpdate', this.collectionBreadCrumbUpdate);
|
||||
},
|
||||
methods: {
|
||||
...mapGetters('collection', [
|
||||
|
|
|
@ -402,7 +402,7 @@
|
|||
else
|
||||
this.isCheckboxListLoading = true;
|
||||
|
||||
this.$parent.$emitter.on('updateTaxonomyInputs', ($event) => {
|
||||
this.$emitter.on('updateTaxonomyInputs', ($event) => {
|
||||
if ($event.taxonomyId == this.taxonomy_id && $event.metadatumId == this.metadatumId) {
|
||||
this.finderColumns = [];
|
||||
this.optionName = '';
|
||||
|
|
|
@ -408,7 +408,7 @@
|
|||
|
||||
this.expandResultsSection = this.shouldBeginWithListExpanded;
|
||||
|
||||
this.$parent.$emitter.on('updateTaxonomyInputs', ($event) => {
|
||||
this.$emitter.on('updateTaxonomyInputs', ($event) => {
|
||||
if ($event.taxonomyId == this.taxonomy_id && $event.metadatumId == this.metadatumId) {
|
||||
this.finderColumns = [];
|
||||
this.optionName = '';
|
||||
|
|
|
@ -135,7 +135,6 @@
|
|||
watch: {
|
||||
filterTags: {
|
||||
handler() {
|
||||
console.log(this.swiper)
|
||||
if (typeof this.swiper.update == 'function')
|
||||
this.swiper.update();
|
||||
},
|
||||
|
|
|
@ -115,9 +115,6 @@ export default (element) => {
|
|||
const emitter = mitt();
|
||||
app.config.globalProperties.$emitter = emitter;
|
||||
|
||||
const eventBusMetadataList = mitt();
|
||||
app.config.globalProperties.$eventBusMetadataList = emitter;
|
||||
|
||||
/* Registers Extra Vue Plugins passed to the window.tainacan_extra_plugins */
|
||||
if (typeof window.tainacan_extra_plugins != "undefined") {
|
||||
for (let [extraVuePluginName, extraVuePluginObject] of Object.entries(window.tainacan_extra_plugins))
|
||||
|
@ -240,7 +237,6 @@ export default (element) => {
|
|||
app.component('tainacan-title', TainacanTitle);
|
||||
|
||||
// Event bus are needed to facilate comunication between child-parent-child components
|
||||
app.use(eventBusMetadataList);
|
||||
app.use(eventBusSearch);
|
||||
|
||||
// Changing title of pages
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
import { createApp } from 'vue';
|
||||
import store from './store/store'
|
||||
import mitt from 'mitt';
|
||||
import { mapActions } from 'vuex';
|
||||
|
||||
const emitter = mitt();
|
||||
|
||||
export const eventBusItemMetadata = createApp({
|
||||
data: () => {
|
||||
export const itemMetadataMixin = {
|
||||
created() {
|
||||
this.$emitter.on('removeCompoundGroup', this.removeItemMetadataGroup);
|
||||
},
|
||||
beforeDestroy() {
|
||||
this.$emitter.off('removeCompoundGroup', this.removeItemMetadataGroup);
|
||||
},
|
||||
data () {
|
||||
return {
|
||||
errors : [],
|
||||
conditionalSections: {}
|
||||
|
@ -14,65 +16,50 @@ export const eventBusItemMetadata = createApp({
|
|||
watch: {
|
||||
errors: {
|
||||
handler() {
|
||||
this.$emit('hasErrorsOnForm', this.errors.length > 0 && this.errors[0].errors && this.errors[0].errors.length);
|
||||
this.hasErrorsOnForm( this.errors.length > 0 && this.errors[0].errors && this.errors[0].errors.length );
|
||||
|
||||
if (this.errors.length > 0 && this.errors[0].errors && this.errors[0].errors.length) {
|
||||
for (let error of this.errors)
|
||||
this.$emit('updateErrorMessageOf#' + (error.metadatum_id + (error.parent_meta_id ? '-' + error.parent_meta_id : '')), error);
|
||||
this.$emitter.on('updateErrorMessageOf#' + (error.metadatum_id + (error.parent_meta_id ? '-' + error.parent_meta_id : '')), error);
|
||||
}
|
||||
},
|
||||
deep: true
|
||||
}
|
||||
},
|
||||
emits: [
|
||||
'input',
|
||||
'itemEditionFormResize',
|
||||
'focusPreviousChildMetadatum',
|
||||
'focusNextChildMetadatum',
|
||||
'removeCompoundGroup',
|
||||
'isOnLastMetadatumOfCompoundNavigation',
|
||||
'isOnFirstMetadatumOfCompoundNavigation',
|
||||
'hasErrorsOnForm',
|
||||
'updateErrorMessageOf#',
|
||||
'hasRemovedItemMetadataGroup',
|
||||
'isUpdatingValue'
|
||||
],
|
||||
created() {
|
||||
this.$emitter.on('input', this.updateValue);
|
||||
this.$emitter.on('removeCompoundGroup', this.removeItemMetadataGroup);
|
||||
},
|
||||
beforeUpdate() {
|
||||
this.$emitter.off('input', this.updateValue);
|
||||
this.$emitter.on('removeCompoundGroup', this.removeItemMetadataGroup);
|
||||
},
|
||||
methods : {
|
||||
updateValue({ itemId, metadatumId, values, parentMetaId, parentId }){
|
||||
methods: {
|
||||
...mapActions('item', [
|
||||
'updateItemMetadatum',
|
||||
'updateItemSubmissionMetadatum',
|
||||
'deleteItemMetadataGroup',
|
||||
'deleteGroupFromItemSubmissionMetadatum'
|
||||
]),
|
||||
updateItemMetadataValue({ itemId, metadatumId, values, parentMetaId, parentId }){
|
||||
|
||||
if (itemId) {
|
||||
|
||||
this.$emit('isUpdatingValue', true);
|
||||
this.isUpdatingValues = true;;
|
||||
|
||||
if (values.length > 0 && values[0] && values[0].value) {
|
||||
let onlyValues = values.map((aValueObject) => aValueObject.value);
|
||||
values = onlyValues;
|
||||
}
|
||||
|
||||
this.$store.dispatch('item/updateItemMetadatum', {
|
||||
this.updateItemMetadatum({
|
||||
item_id: itemId,
|
||||
metadatum_id: metadatumId,
|
||||
values: Array.isArray(values[0]) ? values[0] : values,
|
||||
parent_meta_id: parentMetaId ? parentMetaId : null
|
||||
})
|
||||
.then(() => {
|
||||
this.$emit('isUpdatingValue', false);
|
||||
this.isUpdatingValues = false;
|
||||
let index = this.errors.findIndex( errorItem => errorItem.metadatum_id == metadatumId && (parentMetaId ? errorItem.parent_meta_id == parentMetaId : true ));
|
||||
if (index >= 0)
|
||||
this.errors.splice( index, 1);
|
||||
|
||||
this.$emit('updateErrorMessageOf#' + (parentMetaId ? metadatumId + '-' + parentMetaId : metadatumId), this.errors[index]);
|
||||
this.$emitter.emit('updateErrorMessageOf#' + (parentMetaId ? metadatumId + '-' + parentMetaId : metadatumId), this.errors[index]);
|
||||
})
|
||||
.catch(({ error_message, error, item_metadata }) => {
|
||||
this.$emit('isUpdatingValue', false);
|
||||
this.isUpdatingValues = false;;
|
||||
let index = this.errors.findIndex( errorItem => errorItem.metadatum_id == metadatumId && (parentMetaId ? errorItem.parent_meta_id == parentMetaId : true ));
|
||||
let messages = [];
|
||||
|
||||
|
@ -81,10 +68,10 @@ export const eventBusItemMetadata = createApp({
|
|||
|
||||
if ( index >= 0) {
|
||||
Object.assign( this.errors, { [index]: { metadatum_id: metadatumId, parent_meta_id: parentMetaId, errors: messages } });
|
||||
this.$emit('updateErrorMessageOf#' + (parentMetaId ? metadatumId + '-' + parentMetaId : metadatumId), this.errors[index]);
|
||||
this.$emitter.emit('updateErrorMessageOf#' + (parentMetaId ? metadatumId + '-' + parentMetaId : metadatumId), this.errors[index]);
|
||||
} else {
|
||||
this.errors.push( { metadatum_id: metadatumId, parent_meta_id: parentMetaId, errors: messages } );
|
||||
this.$emit('updateErrorMessageOf#' + (parentMetaId ? metadatumId + '-' + parentMetaId : metadatumId), this.errors[0]);
|
||||
this.$emitter.emit('updateErrorMessageOf#' + (parentMetaId ? metadatumId + '-' + parentMetaId : metadatumId), this.errors[0]);
|
||||
}
|
||||
|
||||
});
|
||||
|
@ -97,7 +84,7 @@ export const eventBusItemMetadata = createApp({
|
|||
values = JSON.parse(JSON.stringify(onlyValues));
|
||||
}
|
||||
|
||||
this.$store.dispatch('item/updateItemSubmissionMetadatum', {
|
||||
this.updateItemSubmissionMetadatum({
|
||||
metadatum_id: metadatumId,
|
||||
values: Array.isArray(values[0]) ? values[0] : values,
|
||||
child_group_index: parentMetaId,
|
||||
|
@ -107,7 +94,7 @@ export const eventBusItemMetadata = createApp({
|
|||
// In the item submission, we don't want to block submission or clear errors before a re-submission is performed,
|
||||
// as the validation depends on a single server-side request. Thus, we do not update error arary here.
|
||||
|
||||
this.$emit('isUpdatingValue', false);
|
||||
this.isUpdatingValues = false;;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -123,42 +110,37 @@ export const eventBusItemMetadata = createApp({
|
|||
}
|
||||
this.conditionalSections = updatedConditionalSections;
|
||||
},
|
||||
clearAllErrors() {
|
||||
this.errors = [];
|
||||
},
|
||||
removeItemMetadataGroup({ itemId, metadatumId, parentMetaId, parentMetadatum }) {
|
||||
|
||||
this.$emit('isUpdatingValue', true);
|
||||
this.isUpdatingValues = true;;
|
||||
|
||||
if (itemId && metadatumId && parentMetaId) {
|
||||
|
||||
this.$store.dispatch('item/deleteItemMetadataGroup', {
|
||||
this.deleteItemMetadataGroup({
|
||||
item_id: itemId,
|
||||
metadatum_id: metadatumId,
|
||||
parent_meta_id: parentMetaId
|
||||
})
|
||||
.then((res) => {
|
||||
this.$emit('hasRemovedItemMetadataGroup', res);
|
||||
this.$emit('isUpdatingValue', false);
|
||||
this.$emitter.emit('hasRemovedItemMetadataGroup', res);
|
||||
this.isUpdatingValues = false;
|
||||
})
|
||||
.catch(() => this.$emit('isUpdatingValue', false));
|
||||
.catch(() => this.isUpdatingValues = false);
|
||||
|
||||
// Item sbmission logic
|
||||
} else if (!itemId) {
|
||||
|
||||
this.$store.dispatch('item/deleteGroupFromItemSubmissionMetadatum', {
|
||||
this.deleteGroupFromItemSubmissionMetadatum({
|
||||
metadatum_id: metadatumId,
|
||||
child_group_index: parentMetaId
|
||||
});
|
||||
|
||||
this.$emit('hasRemovedItemMetadataGroup', true);
|
||||
this.$emit('isUpdatingValue', false);
|
||||
this.$emitter.emit('hasRemovedItemMetadataGroup', true);
|
||||
this.isUpdatingValues = false;
|
||||
}
|
||||
},
|
||||
clearAllErrors() {
|
||||
this.errors = [];
|
||||
},
|
||||
fetchCompoundFirstParentMetaId({ itemId, metadatumId }) {
|
||||
return this.$store.dispatch('item/fetchCompoundFirstParentMetaId', { item_id: itemId, metadatum_id: metadatumId });
|
||||
}
|
||||
}
|
||||
});
|
||||
eventBusItemMetadata.config.globalProperties.$emitter = emitter;
|
||||
eventBusItemMetadata.use(store);
|
||||
}
|
|
@ -291,7 +291,7 @@ export const fetchAttachments = ({ commit }, { page, attachmentsPerPage, itemId,
|
|||
let total = res.headers['x-wp-total'];
|
||||
|
||||
commit('setAttachments', attachments);
|
||||
commit('setTotalAttachments', total);
|
||||
commit('setTotalAttachments', isNaN(total) ? 0 : Number(total));
|
||||
|
||||
resolve( {
|
||||
attachments: attachments,
|
||||
|
|
|
@ -135,7 +135,6 @@ export const removePostIn = ( state ) => {
|
|||
};
|
||||
|
||||
export const setTotalItems = ( state, total ) => {
|
||||
console.log(total)
|
||||
state.totalItems = total;
|
||||
};
|
||||
|
||||
|
|
|
@ -1023,7 +1023,7 @@
|
|||
this.openAdvancedSearch = this.$route.query.advancedSearch;
|
||||
}
|
||||
|
||||
this.$root.$emitter.on('openAdvancedSearch', (openAdvancedSearch) => {
|
||||
this.$emitter.on('openAdvancedSearch', (openAdvancedSearch) => {
|
||||
this.openAdvancedSearch = openAdvancedSearch;
|
||||
});
|
||||
|
||||
|
@ -1551,7 +1551,7 @@
|
|||
// Window
|
||||
window.removeEventListener('resize', this.hideFiltersOnMobile);
|
||||
// $root
|
||||
this.$root.$emitter.off('openAdvancedSearch');
|
||||
this.$emitter.off('openAdvancedSearch');
|
||||
// $eventBusSearch
|
||||
this.$eventBusSearchEmitter.off('isLoadingItems');
|
||||
this.$eventBusSearchEmitter.off('hasFiltered');
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
v-if="$userCaps.hasCapability('tnc_rep_edit_taxonomies')"
|
||||
class="header-item">
|
||||
<router-link
|
||||
tag="button"
|
||||
:to="{ path: $routerHelper.getNewTaxonomyPath() }"
|
||||
custom
|
||||
v-slot="{ navigate }">
|
||||
|
|
|
@ -930,7 +930,7 @@
|
|||
this.openAdvancedSearch = this.$route.query.advancedSearch;
|
||||
}
|
||||
|
||||
this.$root.$emitter.on('openAdvancedSearch', (openAdvancedSearch) => {
|
||||
this.$emitter.on('openAdvancedSearch', (openAdvancedSearch) => {
|
||||
this.openAdvancedSearch = openAdvancedSearch;
|
||||
});
|
||||
}
|
||||
|
@ -1467,7 +1467,7 @@
|
|||
window.removeEventListener('resize', this.hideFiltersOnMobile);
|
||||
// $root
|
||||
if (!this.hideAdvancedSearch)
|
||||
this.$root.$emitter.off('openAdvancedSearch');
|
||||
this.$emitter.off('openAdvancedSearch');
|
||||
// $eventBusSearch
|
||||
this.$eventBusSearchEmitter.off('isLoadingItems');
|
||||
this.$eventBusSearchEmitter.off('hasFiltered');
|
||||
|
|
|
@ -6,7 +6,7 @@ import PhotoSwipeLightbox from 'photoswipe/lightbox';
|
|||
import PhotoSwipe from 'photoswipe';
|
||||
import 'photoswipe/dist/photoswipe.css';
|
||||
import Swiper from 'swiper';
|
||||
import { Navigation, A11y, Thumbs } from 'swiper';
|
||||
import { Navigation, A11y, Thumbs } from 'swiper/modules';
|
||||
|
||||
const { __ } = wp.i18n;
|
||||
|
||||
|
|
|
@ -503,6 +503,7 @@
|
|||
:hide-help-buttons="hideHelpButtons"
|
||||
:help-info-bellow-label="helpInfoBellowLabel"
|
||||
:is-collapsed="metadataCollapses[index]"
|
||||
@input="updateItemMetadataValue"
|
||||
@changeCollapse="onChangeCollapse($event, index)"/>
|
||||
|
||||
<!-- JS-side hook for extra content -->
|
||||
|
@ -553,11 +554,11 @@
|
|||
</div>
|
||||
<div class="form-error-area-messages">
|
||||
<strong>{{ formErrorMessage }}</strong>
|
||||
<template v-if="formErrors.length && formErrors[0].errors && formErrors[0].errors.length">
|
||||
<template v-if="errors.length && errors[0].errors && errors[0].errors.length">
|
||||
<p>{{ $i18n.get('instruction_click_error_to_go_to_metadata') }}</p>
|
||||
<ol>
|
||||
<template
|
||||
v-for="(error, index) of formErrors"
|
||||
v-for="(error, index) of errors"
|
||||
:key="index">
|
||||
<li v-if="error.errors.length">
|
||||
<a
|
||||
|
@ -745,12 +746,12 @@
|
|||
|
||||
<script>
|
||||
import { mapActions, mapGetters } from 'vuex';
|
||||
import { eventBusItemMetadata } from '../../../../admin/js/event-bus-item-metadata';
|
||||
import { formHooks } from '../../../../admin/js/mixins';
|
||||
import { itemMetadataMixin } from '../../../../admin/js/item-metadata-mixin';
|
||||
|
||||
export default {
|
||||
name: 'ItemSubmissionForm',
|
||||
mixins: [ formHooks ],
|
||||
mixins: [ formHooks, itemMetadataMixin ],
|
||||
props: {
|
||||
collectionId: String,
|
||||
hideFileModalButton: Boolean,
|
||||
|
@ -863,27 +864,21 @@ export default {
|
|||
metadataSections() {
|
||||
return this.showSteppedLayout ? this.getMetadataSections().filter(aMetadataSection => !this.isSectionHidden(aMetadataSection.id)) : this.getMetadataSections();
|
||||
},
|
||||
formErrors() {
|
||||
return eventBusItemMetadata && eventBusItemMetadata.errors && eventBusItemMetadata.errors.length ? eventBusItemMetadata.errors : []
|
||||
},
|
||||
hasMoreThanOneDocumentTypeOption() {
|
||||
return [ this.hideFileModalButton, this.hideTextModalButton, this.hideLinkModalButton ].filter((option) => { return option == false }).length > 1;
|
||||
},
|
||||
documentErrorMessage() {
|
||||
const existingError = this.formErrors.find(error => error.metadatum_id == 'document');
|
||||
const existingError = this.errors.find(error => error.metadatum_id == 'document');
|
||||
return existingError ? existingError.errors : '';
|
||||
},
|
||||
attachmentsErrorMessage() {
|
||||
const existingError = this.formErrors.find(error => error['attachments'] || error.metadatum_id == 'attachments');
|
||||
const existingError = this.errors.find(error => error['attachments'] || error.metadatum_id == 'attachments');
|
||||
return existingError ? existingError.errors : '';
|
||||
},
|
||||
thumbnailErrorMessage() {
|
||||
const existingError = this.formErrors.find(error => error.metadatum_id == 'thumbnail');
|
||||
const existingError = this.errors.find(error => error.metadatum_id == 'thumbnail');
|
||||
return existingError ? existingError.errors : '';
|
||||
},
|
||||
conditionalSections() {
|
||||
return eventBusItemMetadata && eventBusItemMetadata.conditionalSections ? eventBusItemMetadata.conditionalSections : [];
|
||||
},
|
||||
}
|
||||
},
|
||||
created() {
|
||||
|
||||
|
@ -901,24 +896,13 @@ export default {
|
|||
// Initialize clear data from store
|
||||
this.clearItemSubmission();
|
||||
|
||||
eventBusItemMetadata.clearAllErrors();
|
||||
this.clearAllErrors();
|
||||
this.formErrorMessage = '';
|
||||
this.form.collection_id = this.collectionId;
|
||||
|
||||
// CREATING NEW ITEM SUBMISSION
|
||||
this.createNewItem();
|
||||
|
||||
eventBusItemMetadata.$emitter.on('hasErrorsOnForm', (hasErrors) => {
|
||||
if (hasErrors) {
|
||||
if (Array.isArray(this.formErrors)) {
|
||||
for (let i = 0; i < this.metadataSectionCollapses.length; i++)
|
||||
Object.assign(this.metadataSectionCollapses, { [i]: true });
|
||||
}
|
||||
this.formErrorMessage = this.formErrorMessage ? this.formErrorMessage : this.$i18n.get('info_errors_in_form');
|
||||
this.loadMetadataElements();
|
||||
} else
|
||||
this.formErrorMessage = '';
|
||||
});
|
||||
})
|
||||
.catch(() => {
|
||||
this.collecionAllowsItemSubmission = false;
|
||||
|
@ -938,12 +922,12 @@ export default {
|
|||
* Creates the conditional metadata set to later watch values
|
||||
* of certain metadata that control sections visibility.
|
||||
*/
|
||||
eventBusItemMetadata.conditionalSections = {};
|
||||
this.conditionalSections = {};
|
||||
for (let metadataSection of metadataSections) {
|
||||
if ( metadataSection.is_conditional_section == 'yes') {
|
||||
const conditionalSectionId = Object.keys(metadataSection.conditional_section_rules);
|
||||
if ( conditionalSectionId.length ) {
|
||||
eventBusItemMetadata.conditionalSections[metadataSection.id] = {
|
||||
this.conditionalSections[metadataSection.id] = {
|
||||
sectionId: metadataSection.id,
|
||||
metadatumId: conditionalSectionId[0],
|
||||
metadatumValues: metadataSection.conditional_section_rules[conditionalSectionId[0]],
|
||||
|
@ -967,9 +951,6 @@ export default {
|
|||
else if (this.hideFileModalButton && this.hideTextModalButton && !this.hideLinkModalButton)
|
||||
this.form.document_type = 'url';
|
||||
},
|
||||
beforeUnmount () {
|
||||
eventBusItemMetadata.$emitter.off('hasErrorsOnForm');
|
||||
},
|
||||
methods: {
|
||||
...mapActions('item', [
|
||||
'setItemSubmission',
|
||||
|
@ -1028,7 +1009,7 @@ export default {
|
|||
this.setItemSubmission(Object.assign(this.itemSubmission, data));
|
||||
|
||||
// Clear errors so we don't have them duplicated from api
|
||||
eventBusItemMetadata.errors = [];
|
||||
this.errors = [];
|
||||
|
||||
this.submitItemSubmission({
|
||||
itemSubmission: this.itemSubmission,
|
||||
|
@ -1052,7 +1033,7 @@ export default {
|
|||
if (errors.errors) {
|
||||
for (let error of errors.errors) {
|
||||
for (let metadatum of Object.keys(error)) {
|
||||
eventBusItemMetadata.errors.push({
|
||||
this.errors.push({
|
||||
metadatum_id: metadatum,
|
||||
errors: error[metadatum]
|
||||
});
|
||||
|
@ -1071,7 +1052,7 @@ export default {
|
|||
if (errors.errors) {
|
||||
for (let error of errors.errors) {
|
||||
for (let metadatum of Object.keys(error)) {
|
||||
eventBusItemMetadata.errors.push({
|
||||
this.errors.push({
|
||||
metadatum_id: metadatum,
|
||||
errors: error[metadatum]
|
||||
});
|
||||
|
@ -1085,11 +1066,22 @@ export default {
|
|||
this.isUploading = false;
|
||||
});
|
||||
},
|
||||
hasErrorsOnForm(hasErrors) {
|
||||
if (hasErrors) {
|
||||
if (Array.isArray(this.errors)) {
|
||||
for (let i = 0; i < this.metadataSectionCollapses.length; i++)
|
||||
Object.assign(this.metadataSectionCollapses, { [i]: true });
|
||||
}
|
||||
this.formErrorMessage = this.formErrorMessage ? this.formErrorMessage : this.$i18n.get('info_errors_in_form');
|
||||
this.loadMetadataElements();
|
||||
} else
|
||||
this.formErrorMessage = '';
|
||||
},
|
||||
onDiscard() {
|
||||
// Initialize clear data from store
|
||||
this.clearItemSubmission();
|
||||
|
||||
eventBusItemMetadata.clearAllErrors();
|
||||
this.clearAllErrors();
|
||||
this.formErrorMessage = '';
|
||||
this.form.collection_id = this.collectionId;
|
||||
|
||||
|
@ -1099,7 +1091,7 @@ export default {
|
|||
createNewItem() {
|
||||
|
||||
// Clear errors so we don't have them duplicated from api
|
||||
eventBusItemMetadata.errors = [];
|
||||
this.errors = [];
|
||||
|
||||
let data = JSON.parse(JSON.stringify(this.form));
|
||||
|
||||
|
@ -1168,7 +1160,7 @@ export default {
|
|||
},
|
||||
loadMetadataElements() {
|
||||
this.metadataElements = {};
|
||||
this.formErrors.map((error) => {
|
||||
this.errors.map((error) => {
|
||||
this.metadataElements[error.metadatum_id + (error.parent_meta_id ? ('_parent_meta_id-' + error.parent_meta_id) : '')] = document.getElementById('tainacan-item-metadatum_id-' + error.metadatum_id + (error.parent_meta_id ? ('_parent_meta_id-' + error.parent_meta_id) : ''));
|
||||
});
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue