2020-08-11 04:16:43 +00:00
|
|
|
<template lang="html">
|
2020-10-21 16:26:00 +00:00
|
|
|
<b-dropdown-item-button
|
|
|
|
v-b-modal="modalId"
|
|
|
|
:variant="nightMode ? 'light' : null"
|
|
|
|
>
|
2020-12-15 23:07:17 +00:00
|
|
|
<i class="fas fa-pencil-alt fa-fw" aria-hidden></i>
|
2020-10-05 18:42:04 +00:00
|
|
|
{{ $t('board.list.renameList') }}
|
2020-08-11 04:16:43 +00:00
|
|
|
|
|
|
|
<b-modal
|
|
|
|
:id="modalId"
|
2020-10-14 00:08:56 +00:00
|
|
|
:header-bg-variant="nightMode ? 'dark' : null"
|
|
|
|
:header-text-variant="nightMode ? 'white' : null"
|
|
|
|
:body-bg-variant="nightMode ? 'dark' : null"
|
|
|
|
:body-text-variant="nightMode ? 'white' : null"
|
|
|
|
:footer-bg-variant="nightMode ? 'dark' : null"
|
|
|
|
:footer-text-variant="nightMode ? 'white' : null"
|
2020-10-14 21:48:27 +00:00
|
|
|
footer-class="d-flex justify-content-between"
|
2020-08-24 17:22:01 +00:00
|
|
|
@show="getListName"
|
2020-08-11 04:16:43 +00:00
|
|
|
>
|
2020-10-14 00:35:40 +00:00
|
|
|
<template v-slot:modal-header="{ close }">
|
|
|
|
<modal-header
|
|
|
|
:title="$t('board.list.renameList')"
|
2020-10-14 21:48:27 +00:00
|
|
|
@close="close"
|
|
|
|
/>
|
2020-10-14 00:35:40 +00:00
|
|
|
</template>
|
|
|
|
|
2020-08-11 04:16:43 +00:00
|
|
|
<form ref="renameListForm" @submit.stop.prevent="submit">
|
|
|
|
<b-form-input
|
|
|
|
ref="listNameField"
|
|
|
|
autofocus
|
2020-08-11 23:39:11 +00:00
|
|
|
v-model.trim="listName"
|
2020-10-05 18:42:04 +00:00
|
|
|
:placeholder="$t('board.list.renameListPlaceholder')"
|
2020-08-11 04:16:43 +00:00
|
|
|
required
|
|
|
|
/>
|
2020-08-11 23:39:11 +00:00
|
|
|
|
|
|
|
<b-alert
|
|
|
|
class="mt-3 mb-0"
|
|
|
|
:show="isDuplicate"
|
|
|
|
variant="warning"
|
|
|
|
>
|
2020-10-05 18:42:04 +00:00
|
|
|
{{ $t('board.list.duplicateWarning') }}
|
2020-08-11 23:39:11 +00:00
|
|
|
</b-alert>
|
2020-08-11 04:16:43 +00:00
|
|
|
</form>
|
|
|
|
|
|
|
|
<template v-slot:modal-footer="{ cancel }">
|
2020-10-14 21:48:27 +00:00
|
|
|
<b-button
|
|
|
|
variant="light"
|
|
|
|
@click="cancel"
|
|
|
|
>
|
2020-10-05 18:42:04 +00:00
|
|
|
{{ $t('global.cancel') }}
|
2020-08-11 04:16:43 +00:00
|
|
|
</b-button>
|
|
|
|
|
|
|
|
<b-button
|
|
|
|
variant="primary"
|
2020-08-11 23:39:11 +00:00
|
|
|
:disabled="saving || !dirtied || isDuplicate"
|
2020-08-11 04:16:43 +00:00
|
|
|
@click="submit"
|
|
|
|
>
|
|
|
|
<b-spinner small v-if="saving" />
|
2020-10-05 18:42:04 +00:00
|
|
|
<span v-else>{{ $t('global.save') }}</span>
|
2020-08-11 04:16:43 +00:00
|
|
|
</b-button>
|
|
|
|
</template>
|
|
|
|
</b-modal>
|
|
|
|
</b-dropdown-item-button>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2020-10-14 00:08:56 +00:00
|
|
|
import { mapState, mapGetters } from 'vuex';
|
2020-08-11 04:16:43 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
props: {
|
2020-08-21 07:43:30 +00:00
|
|
|
listIndex: Number,
|
|
|
|
list: Object,
|
2020-08-11 04:16:43 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
listName: null,
|
|
|
|
saving: false,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
computed: {
|
2020-08-21 07:43:30 +00:00
|
|
|
...mapState(['board']),
|
2020-10-14 00:08:56 +00:00
|
|
|
...mapGetters(['nightMode']),
|
2020-08-11 04:16:43 +00:00
|
|
|
|
|
|
|
modalId() {
|
|
|
|
return `rename-list-${this.listIndex}`;
|
|
|
|
},
|
2020-08-11 23:39:11 +00:00
|
|
|
|
|
|
|
dirtied() {
|
2020-08-21 07:43:30 +00:00
|
|
|
const { name } = this.list;
|
2020-08-11 23:39:11 +00:00
|
|
|
|
|
|
|
return this.listName && name !== this.listName;
|
|
|
|
},
|
|
|
|
|
|
|
|
existingListNames() {
|
2020-08-21 07:43:30 +00:00
|
|
|
const { board, list } = this;
|
2020-08-11 23:39:11 +00:00
|
|
|
|
2020-08-21 07:43:30 +00:00
|
|
|
return board.lists.map(({ name }) => name.toLowerCase())
|
|
|
|
.filter(name => name !== list.name.toLowerCase());
|
2020-08-11 23:39:11 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
isDuplicate() {
|
|
|
|
return this.listName && this.existingListNames.includes(this.listName.toLowerCase());
|
|
|
|
},
|
2020-08-11 04:16:43 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
getListName() {
|
2020-08-21 07:43:30 +00:00
|
|
|
const { name } = this.list;
|
2020-08-11 04:16:43 +00:00
|
|
|
|
|
|
|
this.listName = name;
|
|
|
|
},
|
|
|
|
|
|
|
|
submit(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
if (this.$refs.renameListForm.checkValidity()) {
|
|
|
|
this.save();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
async save() {
|
2020-08-21 07:43:30 +00:00
|
|
|
const { listIndex, listName } = this;
|
2020-08-11 04:16:43 +00:00
|
|
|
|
2020-08-21 07:43:30 +00:00
|
|
|
this.saving = true;
|
2020-08-11 04:16:43 +00:00
|
|
|
|
2020-08-21 07:43:30 +00:00
|
|
|
this.$store.commit('RENAME_LIST', { listIndex, listName });
|
2020-08-11 04:16:43 +00:00
|
|
|
|
2020-08-21 07:43:30 +00:00
|
|
|
await this.$store.dispatch('SAVE_BOARD')
|
2020-08-11 04:16:43 +00:00
|
|
|
.catch(() => {
|
|
|
|
this.saving = false;
|
|
|
|
|
|
|
|
this.$bvToast.toast('There was an error renaming list', {
|
|
|
|
title: 'Error',
|
|
|
|
variant: 'danger',
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
this.saving = false;
|
|
|
|
|
|
|
|
this.$bvToast.toast('List renamed', {
|
|
|
|
title: 'Saved',
|
|
|
|
variant: 'success',
|
|
|
|
});
|
|
|
|
|
|
|
|
this.$bvModal.hide(this.modalId);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|