diff --git a/src/api/call-forward.js b/src/api/call-forward.js index 593ec633..c0a17faa 100644 --- a/src/api/call-forward.js +++ b/src/api/call-forward.js @@ -804,6 +804,18 @@ export function appendTimeToTimeset(options) { }); } + +export function getSourcesetById(id) { + return new Promise((resolve, reject)=>{ + Vue.http.get('api/cfsourcesets/' + id).then((res)=>{ + let sourceset = getJsonBody(res.body); + resolve(sourceset); + }).catch((err) => { + reject(err); + }); + }); +} + export function getSourcesBySourcesetId(id) { return new Promise((resolve, reject)=>{ Vue.http.get('api/cfsourcesets/' + id).then((res)=>{ diff --git a/src/components/pages/NewCallForward/CscCallForwardGroup.vue b/src/components/pages/NewCallForward/CscCallForwardGroup.vue index c46bb1c1..dbd4d96b 100644 --- a/src/components/pages/NewCallForward/CscCallForwardGroup.vue +++ b/src/components/pages/NewCallForward/CscCallForwardGroup.vue @@ -9,16 +9,40 @@
+ {{groupTitle}} + - {{$t('pages.newCallForward.titles.timeoutGroupFromPost')}} + + + {{ $t('pages.newCallForward.conditionBtnLabel') }} + + + + + - {{$t('pages.newCallForward.titles.timeoutGroupFromPost')}} - - - {{$t('pages.newCallForward.titles.timeoutGroupFromPost')}} + {{ $t('pages.newCallForward.fromLabelShort') +'"'+ groupSourceset +'"'}} +
@@ -139,6 +157,7 @@ import CscNewCallForwardDestination from './CscNewCallForwardDestination' import CscNewCallForwardAddDestinationForm from './CscNewCallForwardAddDestinationForm' import CscNewCallForwardAddSourcesetForm from './CscNewCallForwardAddSourcesetForm' + import CscNewCallForwardConditionTypeSelect from './CscNewCallForwardConditionTypeSelect' import CscNewCallForwardDestinationTypeForm from './CscNewCallForwardDestinationTypeForm' export default { name: 'csc-cf-group', @@ -158,6 +177,7 @@ CscNewCallForwardDestination, CscNewCallForwardAddDestinationForm, CscNewCallForwardAddSourcesetForm, + CscNewCallForwardConditionTypeSelect, CscNewCallForwardDestinationTypeForm }, data () { @@ -165,7 +185,9 @@ toggleGroup: true, isEnabled: true, toggleNumberForm: true, - toggleGroupInProgress: false + toggleConditionFromForm: true, + toggleGroupInProgress: false, + sourceSet: null }; }, async mounted(){ @@ -174,7 +196,7 @@ const isGroupEnabled = await this.$store.dispatch('newCallForward/isGroupEnabled', {groupName: this.group.name, id: this.group.id}); this.isEnabled = isGroupEnabled; } - + this.updateSourcesetNames() } catch(err){ console.log(err) @@ -184,7 +206,8 @@ ...mapGetters('newCallForward', [ 'getOwnPhoneTimeout', 'destinationInCreation', - 'groupsCount' + 'groupsCount', + 'getMappings' ]), showAddDestBtn(){ const destinations = this.group.destinations; @@ -216,16 +239,15 @@ } return title; }, - isOnlineFromGroup(){ - return this.group.name.includes('timeout-from') || this.group.name.includes('unconditional-from'); - }, - isOfflineFromGroup(){ - return this.group.name.includes('offline-from'); - }, - isBusyFromGroup(){ - return this.group.name.includes('offline-busy'); + groupSourceset(){ + return this.sourceSet ? this.sourceSet.name : false; } }, + watch: { + group: function () { + this.updateSourcesetNames(); + }, + }, methods: { // we need to generate key because destinations have no id genKey(){ @@ -248,6 +270,14 @@ break; } }, + async showConditionForm(){ + switch(this.$refs.addCondition.action){ + case 'addFromCondition': + this.toggleConditionFromForm = false; + this.$refs.onlineSourceset.open(); + break; + } + }, showDestTypeForm(){ this.toggleNumberForm = true; this.$refs.selectDestinationType.add(); @@ -271,9 +301,29 @@ }); this.toggleGroupInProgress = false; }, - + showConditions(){ + this.$refs.addCondition.add(); + this.$refs.addSourceSet.cancel(); + }, showSourcesetForm(){ this.$refs.addSourceSet.add(); + }, + resetToggleCondition(){ + this.toggleConditionFromForm = true; + }, + async updateSourcesetNames(){ + const mappings = this.getMappings; + const groupMappingId = await this.$store.dispatch('newCallForward/getMappingIdByGroupName', this.group.name); + let groupMapping, sourceSet; + if(mappings[groupMappingId]){ + groupMapping = mappings[groupMappingId].filter(($mapping)=>{ + return $mapping.destinationset_id == this.group.id; + }); + sourceSet = groupMapping[0] ? await this.$store.dispatch('newCallForward/getSourcesetById', groupMapping[0].sourceset_id) : null; + if(sourceSet){ + this.sourceSet = sourceSet + } + } } } } @@ -289,6 +339,10 @@ text-align right .csc-cf-destination-value text-align center + .csc-cf-destination-add-condition + color $primary + cursor pointer + font-size 16px .csc-cf-destination-add-destination padding-left 25px width 250px diff --git a/src/components/pages/NewCallForward/CscNewCallForwardAddSourcesetForm.vue b/src/components/pages/NewCallForward/CscNewCallForwardAddSourcesetForm.vue index 4f52af03..723ae36b 100644 --- a/src/components/pages/NewCallForward/CscNewCallForwardAddSourcesetForm.vue +++ b/src/components/pages/NewCallForward/CscNewCallForwardAddSourcesetForm.vue @@ -102,11 +102,6 @@ minLength: 1 } }, - updated(){ - if(Number.isInteger(this.index)){ - this.destinationIndex = this.index; - } - }, computed: { ...mapGetters('newCallForward', [ 'destinationInCreation' @@ -121,21 +116,28 @@ const forwardGroupId = this.groupId; const forwardGroupName = this.groupName; const forwardGroup = await this.$store.dispatch('newCallForward/getForwardGroupById', forwardGroupId); + if (this.numberError || this.nameError || this.saveDisabled) { showGlobalError(this.$t('validationErrors.generic')); } switch(this.mode){ case 'create': - // 1. create sourceset adding name , source and mode: "whitelist" - sourceSetId = await this.$store.dispatch('newCallForward/createSourceSet', { - name: this.name, - source: this.number - }); - await this.$store.dispatch('newCallForward/addSourcesetToGroup', { - name: forwardGroupName, - id: forwardGroupId, - sourceSetId: sourceSetId - }); + try{ + sourceSetId = await this.$store.dispatch('newCallForward/createSourceSet', { + name: this.name, + source: this.number + }); + await this.$store.dispatch('newCallForward/addSourcesetToGroup', { + name: forwardGroupName, + id: forwardGroupId, + sourceSetId: sourceSetId + }); + await this.$store.dispatch('newCallForward/loadForwardGroups'); + } + catch(err){ + console.log(err) + } + break; case 'edit': @@ -145,10 +147,12 @@ }, cancel() { this.number = ''; + this.name = ''; this.enabled = false; }, add() { this.number = ''; + this.name = ''; this.enabled = true; }, close() { diff --git a/src/components/pages/NewCallForward/CscNewCallForwardConditionTypeSelect.vue b/src/components/pages/NewCallForward/CscNewCallForwardConditionTypeSelect.vue new file mode 100644 index 00000000..f9f5838b --- /dev/null +++ b/src/components/pages/NewCallForward/CscNewCallForwardConditionTypeSelect.vue @@ -0,0 +1,66 @@ + + + + + diff --git a/src/components/pages/NewCallForward/CscNewCallForwardDestinationsetTypeSelect.vue b/src/components/pages/NewCallForward/CscNewCallForwardDestinationsetTypeSelect.vue index 8e9260cd..6bc48a71 100644 --- a/src/components/pages/NewCallForward/CscNewCallForwardDestinationsetTypeSelect.vue +++ b/src/components/pages/NewCallForward/CscNewCallForwardDestinationsetTypeSelect.vue @@ -4,28 +4,24 @@ >
{{ $t('pages.newCallForward.unconditionalLabel') }}
-
{{ $t('pages.newCallForward.unconditionalFromLabel') }} -
+
-->
{{ $t('pages.newCallForward.offlineLabel') }}
{{ $t('pages.newCallForward.busyLabel') }} diff --git a/src/locales/en.json b/src/locales/en.json index 9c4107b6..00835495 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -221,6 +221,7 @@ "primarNumberEnabled": "All calls go to the primary number", "primarNumberDisabled": "No call goes to primary number", "forwardBtnLabel": "Add forwarding", + "conditionBtnLabel": "add condition", "numberLabel": "Number", "voiceMailLabel": "Voicemail", "destinationTimeoutLabel": "Then after ", @@ -232,7 +233,8 @@ "cancelDialogTitle": "Delete from {groupName} forwarding", "cancelDialogText": "You are about to delete {destination} from {groupName} call forwarding", "unconditionalLabel": "If online", - "unconditionalFromLabel": "If online and call from ...", + "fromLabel": "If call from ...", + "fromLabelShort": " and call from ", "offlineLabel": "If offline", "busyLabel": "If busy", "sourcesetName": "List name" diff --git a/src/store/new-call-forward.js b/src/store/new-call-forward.js index d70041f5..b4480702 100644 --- a/src/store/new-call-forward.js +++ b/src/store/new-call-forward.js @@ -9,7 +9,9 @@ import { addNewMapping, updateOwnPhoneTimeout, updateDestinationsetName, - createSourcesetWithSource + createSourcesetWithSource, + getSourcesetById, + // getSourcesets } from '../api/call-forward'; const ForwardGroup = { @@ -190,12 +192,21 @@ export default { const allMappings = context.getters.getMappings; let groupMappings = allMappings[groupMappingId]; - groupMappings.push({ - "destinationset_id": data.groupId, - "sourceset_id": data.sourceSetId || null, - "timeset_id":null - }); - + if(data.replaceMapping){ + for(let mapping of groupMappings){ + if(mapping.destinationset_id === data.groupId){ + mapping.sourceset_id = data.sourceSetId || null; + break; + } + } + } + else{ + groupMappings.push({ + "destinationset_id": data.groupId, + "sourceset_id": data.sourceSetId || null, + "timeset_id":null + }); + } await addNewMapping({ mappings: groupMappings, group: groupMappingId, @@ -558,12 +569,26 @@ export default { }); return sourceSetId; }, - async addSourcesetToGroup(context, data){ - await context.dispatch('editMapping', { - name: data.name, - groupId: data.id, - sourceSetId: data.sourceSetId - }); + async addSourcesetToGroup(context, data){ + try{ + await context.dispatch('editMapping', { + name: data.name, + groupId: data.id, + sourceSetId: data.sourceSetId, + replaceMapping: true + }); + } + catch(err){ + console.log(err) + } + }, + // async getSourcesets(){ + // const sourceSets = await getSourcesets(localStorage.getItem('subscriberId')); + // return sourceSet; + // }, + async getSourcesetById(context, id){ + const sourceSet = await getSourcesetById(id); + return sourceSet; } } };