1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-12-04 15:24:23 +01:00
fab-manager/app/assets/javascripts/directives/settings/boolean-setting.js.erb

51 lines
1.6 KiB
Plaintext
Raw Normal View History

Application.Directives.directive('booleanSetting', ['Setting', 'growl', '_t',
function (Setting, growl, _t) {
return ({
restrict: 'E',
scope: {
name: '@',
label: '@',
settings: '=',
yesLabel: '@',
noLabel: '@',
classes: '@'
},
templateUrl: '<%= asset_path "admin/settings/boolean.html" %>',
link ($scope, element, attributes) {
// The setting
$scope.setting = {
name: $scope.name,
value: ($scope.settings[$scope.name] === 'true')
};
// default values for the switch labels
$scope.yesLabel = $scope.yesLabel || 'app.admin.settings.enabled';
$scope.noLabel = $scope.noLabel || 'app.admin.settings.disabled';
/**
* Callback to save the setting value to the database
* @param setting {{value:*, name:string}} note that the value will be stringified
*/
$scope.save = function (setting) {
2020-05-20 15:57:03 +02:00
const value = setting.value.toString();
Setting.update(
{ name: setting.name },
2020-05-20 15:57:03 +02:00
{ value },
function () {
growl.success(_t('app.admin.settings.customization_of_SETTING_successfully_saved', { SETTING: _t(`app.admin.settings.${setting.name}`) }));
$scope.settings[$scope.name] = value;
},
function (error) {
if (error.status === 304) return;
growl.error(_t('app.admin.settings.an_error_occurred_saving_the_setting'));
console.log(error);
}
);
};
}
});
}
]);