openmedialibrary/static/js/Preferences.js

41 lines
1.1 KiB
JavaScript
Raw Normal View History

2014-05-04 17:26:43 +00:00
'use strict';
oml.Preferences = (function() {
var that = {};
that.set = function() {
var args = Ox.isObject(arguments[0])
? args
: Ox.makeObject([arguments[0], arguments[1]]),
set = {},
preferences = oml.user.preferences,
previousPreferences = Ox.clone(preferences, true);
Ox.forEach(args, function(value, key) {
if (!Ox.isEqual(preferences[key], value)) {
preferences[key] = value;
set[key] = value;
}
});
if (Ox.len(set)) {
oml.api.setPreferences(set);
Ox.forEach(set, function(value, key) {
Ox.forEach(oml.$ui, function($element) {
if (Ox.UI.isElement($element)) {
$element.triggerEvent('oml_' + key.toLowerCase(), {
value: value,
previousValue: previousPreferences[key]
});
}
});
});
}
};
return that;
}());