TT#40256 User wants to remove speed dial config

Change-Id: I18090be6cc718e219a3a9cc145198dd4883d5dba
changes/20/22620/2
raxelsen 7 years ago
parent 6117c5f6fe
commit 6c303ccc55

@ -1,5 +1,6 @@
import _ from 'lodash'
import Vue from 'vue';
import { getFieldList } from './common'
export function getSpeedDials(id) {
@ -34,3 +35,21 @@ export function getUnassignedSlots(id) {
});
});
}
export function unassignSpeedDialSlot(options) {
return new Promise((resolve, reject) => {
let updatedAssignedSlots = _.without(options.slots, options.slot);
let headers = {
'Content-Type': 'application/json-patch+json'
};
Vue.http.patch('api/speeddials/' + options.id, [{
op: 'replace',
path: '/speeddials',
value: updatedAssignedSlots
}], { headers: headers }).then(() => {
resolve();
}).catch((err) => {
reject(err.body.message);
});
});
}

@ -36,7 +36,7 @@
icon="delete"
color="negative"
slot="right"
@click="deleteAssignment(index)"
@click="unassignSlot(assigned)"
/>
</q-item-tile>
</q-item-side>
@ -56,6 +56,7 @@
import {
startLoading,
stopLoading,
showToast,
showGlobalError
} from '../../helpers/ui'
import CscPage from '../CscPage'
@ -66,7 +67,8 @@
QItemTile,
QItemSide,
QChip,
QBtn
QBtn,
Dialog
} from 'quasar-framework'
export default {
@ -87,12 +89,32 @@
...mapGetters('speedDial', [
'assignedSlots',
'speedDialLoadingState',
'speedDialLoadingError'
'speedDialLoadingError',
'unassignSlotState',
'unassignSlotError',
'lastUnassignedSlot'
])
},
methods: {
deleteAssignment(index) {
console.log('deleteAssignment(), index', index);
unassignSlot(slot) {
let self = this;
let store = this.$store;
Dialog.create({
title: self.$t('speedDial.removeDialogTitle'),
message: self.$t('speedDial.removeDialogText', {
slot: slot.slot
}),
buttons: [
self.$t('buttons.cancel'),
{
label: self.$t('buttons.remove'),
color: 'negative',
handler () {
store.dispatch('speedDial/unassignSpeedDialSlot', slot)
}
}
]
});
}
},
watch: {
@ -107,6 +129,21 @@
else if (state === 'succeeded') {
stopLoading();
}
},
unassignSlotState(state) {
if (state === 'requesting') {
startLoading();
}
else if (state === 'failed') {
stopLoading();
showGlobalError(this.unassignSlotError);
}
else if (state === 'succeeded') {
stopLoading();
showToast(this.$t('speedDial.unassignSlotSuccessMessage', {
slot: this.lastUnassignedSlot
}));
}
}
}
}

@ -368,6 +368,10 @@
"whenIDial": "When I dial {slot} ...",
"ring": "ring",
"loadSpeedDialErrorMessage": "An error occured while trying to load the speed dials. Please try again.",
"noResultsMessage": "No speed dials found"
"noResultsMessage": "No speed dials found",
"removeDialogTitle": "Remove speed dial",
"removeDialogText": "You are about to remove the speed dial {slot}",
"unassignSlotErrorMessage": "An error occured while trying to unassign the speed dial slot. Please try again.",
"unassignSlotSuccessMessage": "Unassigned slot {slot}"
}
}

@ -3,7 +3,8 @@
import { i18n } from '../i18n';
import { RequestState } from './common'
import {
getSpeedDials
getSpeedDials,
unassignSpeedDialSlot
} from '../api/speed-dial';
export default {
@ -12,7 +13,10 @@ export default {
assignedSlots: [],
slotOptions: [],
speedDialLoadingState: RequestState.initiated,
speedDialError: null
speedDialError: null,
unassignSlotState: RequestState.initiated,
unassignSlotError: null,
lastUnassignedSlot: null
},
getters: {
reminderLoadingState(state) {
@ -32,6 +36,15 @@ export default {
},
speedDialLoadingError(state) {
return state.speedDialLoadingError || i18n.t('speedDial.loadSpeedDialErrorMessage');
},
unassignSlotState(state) {
return state.unassignSlotState;
},
unassignSlotError(state) {
return state.unassignSlotError || i18n.t('speedDial.unassignSlotErrorMessage');
},
lastUnassignedSlot(state) {
return state.lastUnassignedSlot;
}
},
mutations: {
@ -47,6 +60,19 @@ export default {
speedDialFailed(state, error) {
state.speedDialLoadingState = RequestState.failed;
state.speedDialLoadingError = error;
},
unassignSlotRequesting(state) {
state.unassignSlotState = RequestState.requesting;
state.unassignSlotError = null;
},
unassignSlotSucceeded(state, last) {
state.lastUnassignedSlot = last;
state.unassignSlotState = RequestState.succeeded;
state.unassignSlotError = null;
},
unassignSlotFailed(state, error) {
state.unassignSlotState = RequestState.failed;
state.unassignSlotError = error;
}
},
actions: {
@ -57,6 +83,19 @@ export default {
}).catch((error) => {
context.commit('speedDialFailed', error);
});
},
unassignSpeedDialSlot(context, slot) {
context.commit('unassignSlotRequesting');
unassignSpeedDialSlot({
slots: context.state.assignedSlots,
slot: slot,
id: context.getters.subscriberId
}).then(() => {
context.commit('unassignSlotSucceeded', slot.slot);
context.dispatch('loadSpeedDials');
}).catch((error) => {
context.commit('unassignSlotFailed', error);
});
}
}
};

Loading…
Cancel
Save