diff --git a/src/api/pbx-seats.js b/src/api/pbx-seats.js index f265c31d..87591e95 100644 --- a/src/api/pbx-seats.js +++ b/src/api/pbx-seats.js @@ -5,6 +5,7 @@ import { getSubscriberAndPreferences, getSubscribers, setDisplayName, + setWebUsername, setPbxExtension, setPbxWebPassword, setPbxGroupIds, @@ -134,9 +135,10 @@ export function createSeat (seat) { let subscriberId Promise.resolve().then(() => { return createSubscriber({ - username: seat.name.trim().toLowerCase().replace(/\s+/g, '-'), + username: seat.sipUsername.trim(), + display_name: seat.displayName.trim(), + webusername: seat.webUsername.trim(), password: seat.sipPassword ? seat.sipPassword : createId(), - display_name: seat.name, webpassword: seat.webPassword.length > 0 ? seat.webPassword : null, is_pbx_group: false, pbx_extension: seat.extension, @@ -173,12 +175,34 @@ export function removeSeat (id) { /** * @param options * @param options.seatId - * @param options.seatName + * @param options.displayName */ -export function setSeatName (options) { +export function setSeatDisplayName (options) { return new Promise((resolve, reject) => { Promise.resolve().then(() => { - return setDisplayName(options.seatId, options.seatName) + return setDisplayName(options.seatId, options.displayName) + }).then(() => { + return getSubscriberAndPreferences(options.seatId) + }).then((result) => { + resolve({ + seat: result.subscriber, + preferences: result.preferences + }) + }).catch((err) => { + reject(err) + }) + }) +} + +/** + * @param options + * @param options.seatId + * @param options.webUsername + */ +export function setSeatWebUsername (options) { + return new Promise((resolve, reject) => { + Promise.resolve().then(() => { + return setWebUsername(options.seatId, options.webUsername) }).then(() => { return getSubscriberAndPreferences(options.seatId) }).then((result) => { diff --git a/src/api/subscriber.js b/src/api/subscriber.js index 0a16301e..2693d301 100644 --- a/src/api/subscriber.js +++ b/src/api/subscriber.js @@ -297,6 +297,10 @@ export function setDisplayName (id, displayName) { return setField(id, 'display_name', displayName) } +export function setWebUsername (id, webUsername) { + return setField(id, 'webusername', webUsername) +} + export function setPbxExtension (id, pbxExtension) { return setField(id, 'pbx_extension', pbxExtension) } diff --git a/src/components/pages/PbxConfiguration/CscPbxSeatAddForm.vue b/src/components/pages/PbxConfiguration/CscPbxSeatAddForm.vue index 9ec6d060..12d12677 100644 --- a/src/components/pages/PbxConfiguration/CscPbxSeatAddForm.vue +++ b/src/components/pages/PbxConfiguration/CscPbxSeatAddForm.vue @@ -7,17 +7,17 @@ class="col-xs-12 col-lg-3" > - - - -
+
+ + + + + + + + +
{ + return new RegExp(/\s/).test(value) === false + } + }, + webUsername: { required, maxLength: maxLength(64) }, @@ -234,15 +285,48 @@ export default { 'getMinAllowedExtension', 'getMaxAllowedExtension' ]), - seatNameErrorMessage () { - if (!this.$v.data.name.required) { + seatDisplayNameErrorMessage () { + if (!this.$v.data.displayName.required) { + return this.$t('{field} is required', { + field: this.$t('Seat Display Name') + }) + } else if (!this.$v.data.displayName.maxLength) { + return this.$t('{field} must have at most {maxLength} letters', { + field: this.$t('Seat Display Name'), + maxLength: this.$v.data.displayName.$params.maxLength.max + }) + } else { + return '' + } + }, + seatWebUsernameErrorMessage () { + if (!this.$v.data.webUsername.required) { return this.$t('{field} is required', { - field: this.$t('Seat name') + field: this.$t('Seat Web Username') }) - } else if (!this.$v.data.name.maxLength) { + } else if (!this.$v.data.webUsername.maxLength) { return this.$t('{field} must have at most {maxLength} letters', { - field: this.$t('Seat name'), - maxLength: this.$v.data.name.$params.maxLength.max + field: this.$t('Seat Web Username'), + maxLength: this.$v.data.webUsername.$params.maxLength.max + }) + } else { + return '' + } + }, + seatSipUsernameErrorMessage () { + if (!this.$v.data.sipUsername.required) { + return this.$t('SIP Username is required', { + field: this.$t('Seat SIP Username') + }) + } else if (!this.$v.data.sipUsername.maxLength) { + return this.$t('SIP Username must have at most {maxLength} letters', { + field: this.$t('Seat SIP Username'), + maxLength: this.$v.data.sipUsername.$params.maxLength.max + }) + } else if (!this.$v.data.sipUsername.noWhiteSpace) { + return this.$t('SIP Username must not contain any space character', { + field: this.$t('Seat SIP Username'), + maxLength: this.$v.data.sipUsername.$params.maxLength.max }) } else { return '' @@ -291,7 +375,9 @@ export default { methods: { getDefaults () { return { - name: '', + displayName: '', + sipUsername: '', + webUsername: '', extension: '', password: { password: '', @@ -312,7 +398,9 @@ export default { }, save () { this.$emit('save', { - name: this.data.name, + displayName: this.data.displayName, + sipUsername: this.data.sipUsername, + webUsername: this.data.webUsername, extension: this.data.extension, webPassword: this.data.password.password, sipPassword: this.data.sipPassword.password, diff --git a/src/i18n/en.json b/src/i18n/en.json index 5f31df22..d75da262 100644 --- a/src/i18n/en.json +++ b/src/i18n/en.json @@ -53,6 +53,7 @@ "Block outgoing": "Block outgoing", "Busy Greeting": "Busy Greeting", "Busy Lamp Field": "Busy Lamp Field", + "CLI": "CLI", "Call": "Call", "Call Blocking": "Call Blocking", "Call Forwarding": "Call Forwarding", @@ -138,6 +139,7 @@ "Destinations": "Destinations", "Devices": "Devices", "Disable": "Disable", + "Display Name": "Display Name", "Do not ring primary number": "Do not ring primary number", "Download fax": "Download fax", "Download voicemail": "Download voicemail", @@ -362,6 +364,10 @@ "SIP Password": "SIP Password", "SIP Password confirm": "SIP Password confirm", "SIP URI": "SIP URI", + "SIP Username": "SIP Username", + "SIP Username is required": "SIP Username is required", + "SIP Username must have at most {maxLength} letters": "SIP Username must have at most {maxLength} letters", + "SIP Username must not contain any space character": "SIP Username must not contain any space character", "Sa": "Sa", "Same time for selected days": "Same time for selected days", "Saturday": "Saturday", @@ -369,6 +375,10 @@ "Save new password": "Save new password", "Scan to login sip:phone": "Scan to login sip:phone", "Seat": "Seat", + "Seat Display Name": "Seat Display Name", + "Seat SIP Username": "Seat SIP Username", + "Seat Web Username": "Seat Web Username", + "Seat displayName": "Seat displayName", "Seat name": "Seat name", "Seats": "Seats", "Secret Key (empty=disabled)": "Secret Key (empty=disabled)", @@ -463,6 +473,7 @@ "We": "We", "Web Password": "Web Password", "Web Password confirm": "Web Password confirm", + "Web Username": "Web Username", "WebSocket connection to kamailio lb failed with code {code}": "WebSocket connection to kamailio lb failed with code {code}", "Wednesday": "Wednesday", "Weekly": "Weekly", @@ -506,6 +517,7 @@ "busy": "busy", "call from ...": "call from ...", "call not from ...": "call not from ...", + "cli of the seat": "cli of the seat", "condition": "condition", "data error": "data error", "date is": "date is", diff --git a/src/pages/CscPagePbxSeatDetails.vue b/src/pages/CscPagePbxSeatDetails.vue index e17d8c3d..4523f841 100644 --- a/src/pages/CscPagePbxSeatDetails.vue +++ b/src/pages/CscPagePbxSeatDetails.vue @@ -42,21 +42,52 @@ @change-password="changeWebPassword({ password: $event.password })" /> + + + + @@ -72,14 +103,14 @@ @input="$v.changes.extension.$touch" > @@ -227,9 +258,13 @@ import CscInputButtonSave from 'components/form/CscInputButtonSave' import CscInputButtonReset from 'components/form/CscInputButtonReset' import CscChangePasswordDialog from 'src/components/CscChangePasswordDialog' import CscPageSticky from 'src/components/CscPageSticky' -import { between } from 'vuelidate/lib/validators' import { inRange } from 'src/helpers/validation' import numberFilter from '../filters/number' +import { + required, + maxLength, + between +} from 'vuelidate/lib/validators' export default { name: 'CscPagePbxSeatDetails', components: { @@ -254,6 +289,14 @@ export default { isInRange: function (value) { return inRange(value, this.getMinAllowedExtension, this.getMaxAllowedExtension, between) } + }, + displayName: { + required, + maxLength: maxLength(64) + }, + webUsername: { + required, + maxLength: maxLength(64) } } }, @@ -283,8 +326,11 @@ export default { getPrimaryNumber () { return numberFilter(this.seatSelected.primary_number) }, - hasNameChanged () { - return this.changes.name !== this.seatSelected.display_name + hasDisplayNameChanged () { + return this.changes.displayName !== this.seatSelected.display_name + }, + hasWebUsernameChanged () { + return this.changes.webUsername !== this.seatSelected.webusername }, hasExtensionChanged () { return this.changes.extension !== this.seatSelected.pbx_extension @@ -308,6 +354,34 @@ export default { return '' } }, + seatDisplayNameErrorMessage () { + if (!this.$v.changes.displayName.required) { + return this.$t('{field} is required', { + field: this.$t('Seat Display Name') + }) + } else if (!this.$v.changes.displayName.maxLength) { + return this.$t('{field} must have at most {maxLength} letters', { + field: this.$t('Seat Display Name'), + maxLength: this.$v.changes.displayName.$params.maxLength.max + }) + } else { + return '' + } + }, + seatWebUsernameErrorMessage () { + if (!this.$v.changes.webUsername.required) { + return this.$t('{field} is required', { + field: this.$t('Seat Web Username') + }) + } else if (!this.$v.changes.webUsername.maxLength) { + return this.$t('{field} must have at most {maxLength} letters', { + field: this.$t('Seat Web Username'), + maxLength: this.$v.changes.webUsername.$params.maxLength.max + }) + } else { + return '' + } + }, internalSoundSetOptions () { const items = [] if (this.soundSet) { @@ -375,7 +449,8 @@ export default { }, methods: { ...mapActions('pbxSeats', [ - 'setSeatName', + 'setSeatDisplayName', + 'setSeatWebUsername', 'setSeatExtension', 'setSeatNumbers', 'setSeatGroups', @@ -418,7 +493,9 @@ export default { }, getSeatData () { return (this.seatSelected) ? { - name: this.seatSelected.display_name, + displayName: this.seatSelected.display_name, + sipUsername: this.seatSelected.username, + webUsername: this.seatSelected.webusername, extension: this.seatSelected.pbx_extension, aliasNumbers: this.getAliasNumberIds(), webPassword: this.seatSelected.webpassword, @@ -429,8 +506,11 @@ export default { cliNumber: this.getCliNumberId() } : null }, - resetName () { - this.changes.name = this.seatSelected.display_name + resetDisplayName () { + this.changes.displayName = this.seatSelected.display_name + }, + resetWebUsername () { + this.changes.webUsername = this.seatSelected.webusername }, resetExtension () { this.changes.extension = this.seatSelected.pbx_extension @@ -448,10 +528,16 @@ export default { this.changes.soundSet = this.getSoundSetId() }, save () { - if (this.hasNameChanged) { - this.setSeatName({ + if (this.hasDisplayNameChanged) { + this.setSeatDisplayName({ + seatId: this.seatSelected.id, + displayName: this.changes.displayName + }) + } + if (this.hasWebUsernameChanged) { + this.setSeatWebUsername({ seatId: this.seatSelected.id, - seatName: this.changes.name + webUsername: this.changes.webUsername }) } if (this.hasExtensionChanged) { diff --git a/src/store/pbx-seats.js b/src/store/pbx-seats.js index 48a7bc2f..feea24cf 100644 --- a/src/store/pbx-seats.js +++ b/src/store/pbx-seats.js @@ -13,7 +13,8 @@ import { getSeatList, createSeat, removeSeat, - setSeatName, + setSeatDisplayName, + setSeatWebUsername, setSeatExtension, setSeatGroups, setSeatNumbers, @@ -319,14 +320,28 @@ export default { context.commit('seatRemovalFailed', err.message) }) }, - setSeatName (context, options) { + setSeatDisplayName (context, options) { context.commit('seatUpdateRequesting', { seatId: options.seatId, - seatField: i18n.t('Seat name') + seatField: i18n.t('Seat displayName') }) - setSeatName({ + setSeatDisplayName({ seatId: options.seatId, - seatName: options.seatName + displayName: options.displayName + }).then((result) => { + context.commit('seatUpdateSucceeded', result) + }).catch((err) => { + context.commit('seatUpdateFailed', err.message) + }) + }, + setSeatWebUsername (context, options) { + context.commit('seatUpdateRequesting', { + seatId: options.seatId, + seatField: i18n.t('Seat Web Username') + }) + setSeatWebUsername({ + seatId: options.seatId, + webUsername: options.webUsername }).then((result) => { context.commit('seatUpdateSucceeded', result) }).catch((err) => { @@ -457,6 +472,6 @@ export default { context.commit('seatUpdateFailed', err.message) } } - + } }