/** @namespace Defaults
@desc Collection of methods for retrieving default options.
@todo Document defaults objects?
*/
var Defaults =
{
/** @method Defaults.Get
@readonly
@desc Retrieves default value for a specific category and key.
@arg {String} category - Category of option.
@arg {String} key - Key of option.
@returns {Mixed} Default value of option requested.
*/
'Get': function (category, key)
{
var categoryObject = this[category];
if (!categoryObject) { return null; }
return key ? categoryObject[key] : categoryObject;
},
/** @method Defaults.GetCategoryOptions
@readonly
@desc Retrieves default value for a specific category and key.
@arg {String} category - Category of option.
@arg {String} key - Key of option.
@returns {Mixed} Default value of option requested.
*/
'GetCategoryOptions': function (category)
{
return this[category];
},
/** @method Defaults.Extend
@readonly
@desc Retrieve defaults for specific category and overwrite properties with those supplied.
@arg {String} category - Category of options.
@arg {Object} overlay - Properties to overwrite defaults.
@returns {Object} Extended defaults.
*/
'Extend': function (category, overlay)
{
var defaults = this[category],
combinedObject = {};
// copy defaults
if (defaults)
{
for (var key in defaults) { if (defaults.hasOwnProperty(key))
{
combinedObject[key] = defaults[key];
combinedObject['{0}_isDefault'.format(key)] = true;
}}
}
// copy overlay
if (overlay)
{
for (var key in overlay) { if (overlay.hasOwnProperty(key))
{
combinedObject[key] = overlay[key];
combinedObject['{0}_isDefault'.format(key)] = false;
}}
}
return combinedObject;
},
'_global':
{
'privacyMode' : false,
//'hideAvatar' : true, // This was duplicated in Contacts category
'call-notice-duration' : '30',
'call-notice-sound' : 'bottle',
'chat-notice-duration' : '30',
'chat-notice-sound' : 'bottle',
'video-notice-duration' : '30',
'video-notice-sound' : 'bottle',
'voicemail-notice-duration' : '30',
'voicemail-notice-sound' : 'bottle',
'meetup-notice-duration' : '30',
'meetup-notice-sound' : 'bottle',
'faxdelivered-notice-duration': '30',
'faxdelivered-notice-sound' : 'bottle',
'fax-notice-duration' : '30',
'fax-notice-sound' : 'bottle',
'autostartFramework' : false,
'startMinimized' : false,
'startupStarlet' : 'StarScope 2',
'hideCallAlerts' : false
},
'Activity':
{
'inbound' : true,
'outbound' : true,
'voicemail': true,
'fax' : true,
'chat' : true,
'video' : true,
'count' : 99
},
'ChatWindow':
{
'color-in' : '#F1F1F1',
'color-out' : '#E0F1D8',
'font-size' : '14',
'incomingMsgDisplay': 'name'
},
'StarChat':
{
'display': 'full'
},
'FaxList':
{
'display-limit': 99
},
'Dialpad':
{
'collapsedDialpad': false
},
'LocationGroupList':
{
'collapsedDialpad' : false, // TODO - Add handling of Dialpad category in index.js for SS2 Settings....
'advancedOptions' : false,
'showUnregisteredExt' : false,
'activeCallDragDropBlindTransfer': false,
'autoClearFilter' : false,
'expandDefaultExt' : false,
'display' : 'compact',
'sortBy' : 'callerid'
},
'StarFax': {},
'Downloads':
{
'concurrentLimit': 6
},
'Contacts':
{
'hideAvatar' : true,
'onPhoneAvailability' : false, // put in Contacts since that is the widget that uses the setting
'autoUnavailTriggered': false
}
};
/** @namespace Options
@desc Collection of methods for dealing with options.
*/
var Options =
{
/** @method Options.Get
@readonly
@desc Retrieves options by category and key, converts them into an indexed object, and overides defaults.
@arg {String} category - Category of option.
@arg {Boolean} update - Whether to receive future updates.
@arg {String} key - Key of option.
@arg {Function} callback - Function to pass options on initial list and update.
@returns {Object} {@link Bus.ask} promise.
*/
Get: function (category, update, key, callback)
{
var internalCallback = function (packet)
{
var options = Utilities.CategoryKeyValueListFromArray(packet.data, 'categoryName', 'key', 'value');
if (update) // if update, don't overlay defaults
{
callback && callback(options);
return options;
}
if (key) // single key
{
!options[key] && (options[key] = Defaults.Get(category, key)); // get default if no value
callback && callback(options); // fire callback
return options;
}
else // whole category
{
options = Defaults.Extend(category, Utilities.CategoryKeyValueListFromArray(packet.data, 'categoryName', 'key', 'value'))
callback && callback(options);
return options;
}
};
return Bus.ask('options',
{
action : 'list',
subscribe : update,
callback : callback ? internalCallback : false,
category : category,
filter : key
})
.then(internalCallback);
}
};