|
|
|
@ -155,6 +155,20 @@ define(function(require){ |
|
|
|
}); |
|
|
|
}, |
|
|
|
|
|
|
|
getKeyTypes: function(data) { |
|
|
|
var types = []; |
|
|
|
|
|
|
|
if (data.hasOwnProperty('feature_keys') && data.feature_keys.iterate > 0) { |
|
|
|
types.push('feature_keys'); |
|
|
|
} |
|
|
|
|
|
|
|
if (data.hasOwnProperty('combo_keys') && data.combo_keys.iterate > 0) { |
|
|
|
types.push('combo_keys'); |
|
|
|
} |
|
|
|
|
|
|
|
return _.isEmpty(types) ? null : types; |
|
|
|
}, |
|
|
|
|
|
|
|
devicesRenderEdit: function(args) { |
|
|
|
var self = this, |
|
|
|
data = args.data, |
|
|
|
@ -166,20 +180,28 @@ define(function(require){ |
|
|
|
self.devicesGetEditData(data, function(dataDevice) { |
|
|
|
if (dataDevice.hasOwnProperty('provision')) { |
|
|
|
self.devicesGetIterator(dataDevice.provision, function(template) { |
|
|
|
if (template.hasOwnProperty('feature_keys') && template.feature_keys.iterate > 0) { |
|
|
|
if (!dataDevice.provision.hasOwnProperty('feature_keys')) { |
|
|
|
dataDevice.provision.feature_keys = {}; |
|
|
|
} |
|
|
|
|
|
|
|
for (var i = 0, len = template.feature_keys.iterate; i < len; i++) { |
|
|
|
if (!dataDevice.provision.feature_keys.hasOwnProperty(i)) { |
|
|
|
dataDevice.provision.feature_keys[i] = { type: 'none' }; |
|
|
|
} |
|
|
|
} |
|
|
|
var keyTypes = self.getKeyTypes(template); |
|
|
|
|
|
|
|
if (keyTypes) { |
|
|
|
self.devicesListUsers({ |
|
|
|
success: function(users) { |
|
|
|
var keyTypes = [ 'none', 'presence', 'parking', 'personal_parking', 'speed_dial' ], |
|
|
|
_.each(keyTypes, function(type, idx) { |
|
|
|
if (!dataDevice.provision.hasOwnProperty(type)) { |
|
|
|
dataDevice.provision[type] = {}; |
|
|
|
} |
|
|
|
|
|
|
|
var i = 0, |
|
|
|
len = template[type].iterate; |
|
|
|
for (; i < len; i++) { |
|
|
|
if (!dataDevice.provision[type].hasOwnProperty(i)) { |
|
|
|
dataDevice.provision[type][i] = { |
|
|
|
type: 'none' |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
var actions = [ 'none', 'presence', 'parking', 'personal_parking', 'speed_dial' ], |
|
|
|
parkingSpots = [], |
|
|
|
extra; |
|
|
|
|
|
|
|
@ -191,28 +213,100 @@ define(function(require){ |
|
|
|
parkingSpots[i] = i + 1; |
|
|
|
} |
|
|
|
|
|
|
|
keyTypes.forEach(function(val, idx, arr) { |
|
|
|
arr[idx] = { id: val, text: self.i18n.active().devices.popupSettings.featureKeys.types[val] }; |
|
|
|
_.each(actions, function(action, idx, list) { |
|
|
|
list[idx] = { |
|
|
|
id: action, |
|
|
|
text: self.i18n.active().devices.popupSettings.keys.types[action] |
|
|
|
}; |
|
|
|
|
|
|
|
if (val !== 'none') { |
|
|
|
arr[idx].info = self.i18n.active().devices.popupSettings.featureKeys.info.types[val]; |
|
|
|
if (action !== 'none') { |
|
|
|
list[idx].info = self.i18n.active().devices.popupSettings.keys.info.types[action]; |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
extra = { |
|
|
|
users: users, |
|
|
|
featureKeys:{ |
|
|
|
provision: { |
|
|
|
users: users, |
|
|
|
parkingSpots: parkingSpots, |
|
|
|
types: keyTypes |
|
|
|
keyActions: actions, |
|
|
|
keys: [] |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
_.each(keyTypes, function(key, idx) { |
|
|
|
var camelCaseKey = self.devicesSnakeToCamel(key); |
|
|
|
|
|
|
|
extra.provision.keys.push({ |
|
|
|
id: key, |
|
|
|
type: camelCaseKey, |
|
|
|
title: self.i18n.active().devices.popupSettings.keys[camelCaseKey].title, |
|
|
|
label: self.i18n.active().devices.popupSettings.keys[camelCaseKey].label, |
|
|
|
data: dataDevice.provision[key] |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
dataDevice.extra = dataDevice.hasOwnProperty('extra') ? $.extend(true, {}, dataDevice.extra, extra) : extra; |
|
|
|
|
|
|
|
self.devicesRenderDevice(dataDevice, callbackSave, callbackDelete); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
// if (template.hasOwnProperty('feature_keys') && template.feature_keys.iterate > 0) {
|
|
|
|
// if (!dataDevice.provision.hasOwnProperty('feature_keys')) {
|
|
|
|
// dataDevice.provision.feature_keys = {};
|
|
|
|
// }
|
|
|
|
|
|
|
|
// for (var i = 0, len = template.feature_keys.iterate; i < len; i++) {
|
|
|
|
// if (!dataDevice.provision.feature_keys.hasOwnProperty(i)) {
|
|
|
|
// dataDevice.provision.feature_keys[i] = { type: 'none' };
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
// self.callApi({
|
|
|
|
// resource: 'user.list',
|
|
|
|
// data: {
|
|
|
|
// accountId: self.accountId
|
|
|
|
// },
|
|
|
|
// success: function(data, status) {
|
|
|
|
// var keyTypes = [ 'none', 'presence', 'parking', 'personal_parking', 'speed_dial' ],
|
|
|
|
// parkingSpots = [],
|
|
|
|
// extra;
|
|
|
|
|
|
|
|
// // Sort user list by last name
|
|
|
|
// data.data.sort(function(a, b) {
|
|
|
|
// return a.last_name.toLowerCase() > b.last_name.toLowerCase() ? 1 : -1;
|
|
|
|
// });
|
|
|
|
|
|
|
|
// // Generate parking spots map
|
|
|
|
// for (var i = 0; i < 10; i++) {
|
|
|
|
// parkingSpots[i] = i + 1;
|
|
|
|
// }
|
|
|
|
|
|
|
|
// keyTypes.forEach(function(val, idx, arr) {
|
|
|
|
// arr[idx] = {
|
|
|
|
// id: val,
|
|
|
|
// text: self.i18n.active().devices.popupSettings.keys.types[val]
|
|
|
|
// };
|
|
|
|
|
|
|
|
// if (val !== 'none') {
|
|
|
|
// arr[idx].info = self.i18n.active().devices.popupSettings.keys.info.types[val];
|
|
|
|
// }
|
|
|
|
// });
|
|
|
|
|
|
|
|
// extra = {
|
|
|
|
// users: data.data,
|
|
|
|
// featureKeys:{
|
|
|
|
// parkingSpots: parkingSpots,
|
|
|
|
// types: keyTypes
|
|
|
|
// }
|
|
|
|
// };
|
|
|
|
|
|
|
|
// dataDevice.extra = dataDevice.hasOwnProperty('extra') ? $.extend(true, {}, dataDevice.extra, extra) : extra;
|
|
|
|
|
|
|
|
// self.devicesRenderDevice(dataDevice, callbackSave, callbackDelete);
|
|
|
|
// }
|
|
|
|
// });
|
|
|
|
// }
|
|
|
|
else { |
|
|
|
self.devicesRenderDevice(dataDevice, callbackSave, callbackDelete); |
|
|
|
} |
|
|
|
@ -275,23 +369,28 @@ define(function(require){ |
|
|
|
}))), |
|
|
|
deviceForm = templateDevice.find('#form_device'); |
|
|
|
|
|
|
|
if (data.hasOwnProperty('provision') && data.provision.hasOwnProperty('feature_keys')) { |
|
|
|
var section = '.tabs-section[data-section="featureKeys"] '; |
|
|
|
if (data.extra.provision.hasOwnProperty('keys')) { |
|
|
|
_.each(data.extra.provision.keys, function(value, idx) { |
|
|
|
var section = '.tabs-section[data-section="' + value.type + '"] '; |
|
|
|
|
|
|
|
_.each(data.provision.feature_keys, function(val, key){ |
|
|
|
var group = '.control-group[data-id="' + key + '"] ', |
|
|
|
value = '.feature-key-value[data-type="' + val.type + '"]'; |
|
|
|
_.each(value.data, function(val, key) { |
|
|
|
var group = '.control-group[data-id="' + key + '"] ', |
|
|
|
value = '.feature-key-value[data-type="' + val.type + '"]'; |
|
|
|
|
|
|
|
templateDevice |
|
|
|
.find(section.concat(group, value)) |
|
|
|
.addClass('active') |
|
|
|
.find('[name="provision.feature_keys[' + key + '].value"]') |
|
|
|
.val(val.value); |
|
|
|
templateDevice |
|
|
|
.find(section.concat(group, value)) |
|
|
|
.addClass('active') |
|
|
|
.find('[name="provision.feature_keys[' + key + '].value"]') |
|
|
|
.val(val.value); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
$.each(templateDevice.find('.feature-key-index'), function(idx, val) { |
|
|
|
$(val).text(parseInt($(val).text(), 10) + 1); |
|
|
|
}); |
|
|
|
templateDevice |
|
|
|
.find('.feature-key-index') |
|
|
|
.each(function(idx, el) { |
|
|
|
$(el) |
|
|
|
.text(parseInt($(el).text(), 10) + 1); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
if ( data.extra.hasE911Numbers ) { |
|
|
|
@ -511,7 +610,7 @@ define(function(require){ |
|
|
|
setTimeout(function() { |
|
|
|
var action = ($this.hasClass('collapsed') ? 'show' : 'hide').concat('Info'); |
|
|
|
|
|
|
|
$this.find('.text').text(self.i18n.active().devices.popupSettings.featureKeys.info.link[action]); |
|
|
|
$this.find('.text').text(self.i18n.active().devices.popupSettings.keys.info.link[action]); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
@ -609,18 +708,29 @@ define(function(require){ |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* form2object sends feature_keys back as an array even if the first key is 1 |
|
|
|
* feature_key needs to be coerced into an object to match the datatype in originalData |
|
|
|
*/ |
|
|
|
if (formData.hasOwnProperty('provision') && formData.provision.hasOwnProperty('feature_keys')) { |
|
|
|
var featureKeys = {}; |
|
|
|
if (formData.hasOwnProperty('provision') && formData.provision.hasOwnProperty('keys')) { |
|
|
|
/** |
|
|
|
* form2object sends keys back as arrays even if the first key is 1 |
|
|
|
* they needs to be coerced into an object to match the datatype in originalData |
|
|
|
*/ |
|
|
|
_.each(formData.provision.keys, function(value, key, list) { |
|
|
|
var keys = {}; |
|
|
|
|
|
|
|
list[key].forEach(function(val, idx) { |
|
|
|
if (val.type !== 'none') { |
|
|
|
keys[idx] = val; |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
formData.provision.feature_keys.forEach(function(val, idx) { |
|
|
|
featureKeys[idx] = val; |
|
|
|
if (_.isEmpty(keys)) { |
|
|
|
delete originalData.provision[key]; |
|
|
|
} |
|
|
|
else { |
|
|
|
originalData.provision[key] = keys; |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
formData.provision.feature_keys = featureKeys; |
|
|
|
delete formData.provision.keys; |
|
|
|
} |
|
|
|
|
|
|
|
var mergedData = $.extend(true, {}, originalData, formData); |
|
|
|
@ -658,19 +768,6 @@ define(function(require){ |
|
|
|
delete mergedData.media.fax.option; |
|
|
|
} |
|
|
|
|
|
|
|
// Remove feature keys that are not defined
|
|
|
|
if (mergedData.hasOwnProperty('provision') && mergedData.provision.hasOwnProperty('feature_keys')) { |
|
|
|
for (var key in mergedData.provision.feature_keys) { |
|
|
|
if (mergedData.provision.feature_keys[key].type === 'none') { |
|
|
|
delete mergedData.provision.feature_keys[key]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (_.isEmpty(mergedData.provision.feature_keys)) { |
|
|
|
delete mergedData.provision.feature_keys; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if(mergedData.hasOwnProperty('caller_id') && mergedData.caller_id.hasOwnProperty('emergency') && mergedData.caller_id.emergency.hasOwnProperty('number') && mergedData.caller_id.emergency.number === '') { |
|
|
|
delete mergedData.caller_id.emergency.number; |
|
|
|
|
|
|
|
@ -942,6 +1039,10 @@ define(function(require){ |
|
|
|
return formattedData; |
|
|
|
}, |
|
|
|
|
|
|
|
devicesSnakeToCamel: function(string) { |
|
|
|
return string.replace(/(\_\w)/g, function (match) { return match[1].toUpperCase(); }); |
|
|
|
}, |
|
|
|
|
|
|
|
/* Utils */ |
|
|
|
devicesDeleteDevice: function(deviceId, callback) { |
|
|
|
var self = this; |
|
|
|
|