diff --git a/submodules/callLogs/callLogs.js b/submodules/callLogs/callLogs.js index 8c5b49c..b628946 100644 --- a/submodules/callLogs/callLogs.js +++ b/submodules/callLogs/callLogs.js @@ -100,7 +100,6 @@ define(function(require){ // toDate: monster.util.dateToGregorian(toDate) // }, // success: function(data, status) { - // console.log('success'); // } // }); }); @@ -306,8 +305,6 @@ define(function(require){ } }); - console.log(result); - result.sort(function(a, b) { return b.timestamp - a.timestamp; }) diff --git a/submodules/devices/devices.js b/submodules/devices/devices.js index 48779af..f5de61c 100644 --- a/submodules/devices/devices.js +++ b/submodules/devices/devices.js @@ -348,12 +348,10 @@ define(function(require){ e.preventDefault(); var number = templateDevice.find('.restriction-matcher-input').val(), matched = false; - console.log(number); templateDevice.find('.restriction-matcher-label').each(function() { var label = $(this), regex = new RegExp(data.extra.restrictions[label.data('restriction')].regex); - console.log(regex) if(regex.test(number)) { label.show(); if(matched) { diff --git a/submodules/users/users.js b/submodules/users/users.js index 4ca82d1..5292ad4 100644 --- a/submodules/users/users.js +++ b/submodules/users/users.js @@ -651,7 +651,7 @@ define(function(require){ }); template.on('click', '#add_extensions', function() { - var nextExtension = (parseInt(existingExtensions[existingExtensions.length - 1]) || 2000) + 1 + '', + var nextExtension = parseInt(self.usersGetNextInt(existingExtensions)) + '', dataTemplate = { recommendedExtension: nextExtension }, @@ -1243,8 +1243,46 @@ define(function(require){ }); }, + /* Helper function that takes an array of number in parameter, sorts it, and returns the first number not in the array, greater than the minVal */ + usersGetNextInt: function(arr) { + var orderedArr = arr, + prevVal = 0, + minVal = 2000, + increment = 1; + + orderedArr.sort(function(a,b) { + var parsedA = parseInt(a), + parsedB = parseInt(b); + + return parsedA > parsedB ? 1 : -1; + }); + + _.each(orderedArr, function(val) { + var curr = parseInt(val); + + /* If we already stored a previous value */ + if(prevVal) { + if(curr - prevVal !== increment) { + return prevVal + increment; + } + } + /* Otherwise, if we didn't, and the current value is greater than the minVal, we return the minVal */ + else if(curr > minVal) { + return minVal; + } + + /* We don't want to return value lower than our min val, so we only store prevVal that are greater than the minVal */ + if(curr >= minVal) { + prevVal = curr; + } + }); + + return (prevVal) ? prevVal + increment : minVal; + }, + usersFormatAddUser: function(data) { - var formattedData = { + var self = this, + formattedData = { sendToSameEmail: true, nextExtension: '', nextVMBox: '', @@ -1263,24 +1301,15 @@ define(function(require){ }); }); - arrayExtensions.sort(function(a, b) { - return parseInt(a) > parseInt(b); - }); - - //Set the Next extension to 2001 if there are no extensions in the system, or to the latest extension + 1 if there are - formattedData.nextExtension = (parseInt(arrayExtensions[arrayExtensions.length - 1] || 2000) + 1) + ''; + formattedData.nextExtension = parseInt(self.usersGetNextInt(arrayExtensions)) + ''; _.each(data.vmboxes, function(vmbox) { formattedData.listVMBoxes[vmbox.mailbox] = vmbox; arrayVMBoxes.push(vmbox.mailbox); }); - arrayVMBoxes.sort(function(a, b) { - return parseInt(a) > parseInt(b); - }); - //Set the VMBox Number to 2001 if there are no VMBox in the system, or to the latest vmbox number + 1 if there are - formattedData.nextVMBox = (parseInt(arrayVMBoxes[arrayVMBoxes.length - 1] || 2000) + 1) + ''; + formattedData.nextVMBox = parseInt(self.usersGetNextInt(arrayVMBoxes)) + ''; return formattedData; }, @@ -2487,7 +2516,7 @@ define(function(require){ name: callerIdName } }, - email: data.extra.differentEmail ? data.extra.email : data.user.userName, + email: data.extra.differentEmail ? data.extra.email : data.user.username, priv_level: 'user', timezone: defaultTimezone }, data.user), diff --git a/views/users-creation.html b/views/users-creation.html index 432d192..288dbef 100644 --- a/views/users-creation.html +++ b/views/users-creation.html @@ -37,7 +37,7 @@