diff --git a/app/assets/javascripts/controllers/admin/settings.js.erb b/app/assets/javascripts/controllers/admin/settings.js.erb index 37bea37d3..acbf738d0 100644 --- a/app/assets/javascripts/controllers/admin/settings.js.erb +++ b/app/assets/javascripts/controllers/admin/settings.js.erb @@ -76,7 +76,6 @@ Application.Controllers.controller('SettingsController', ['$scope', '$rootScope' $scope.mainColorSetting = { name: 'main_color', value: settingsPromise.main_color }; $scope.secondColorSetting = { name: 'secondary_color', value: settingsPromise.secondary_color }; $scope.nameGenre = { name: 'name_genre', value: settingsPromise.name_genre }; - $scope.machinesSortBy = { name: 'machines_sort_by', value: settingsPromise.machines_sort_by }; $scope.cguFile = cguFile.custom_asset; $scope.cgvFile = cgvFile.custom_asset; $scope.customLogo = logoFile.custom_asset; diff --git a/app/assets/javascripts/directives/settings/select-setting.js.erb b/app/assets/javascripts/directives/settings/select-setting.js.erb new file mode 100644 index 000000000..9937ad007 --- /dev/null +++ b/app/assets/javascripts/directives/settings/select-setting.js.erb @@ -0,0 +1,50 @@ +Application.Directives.directive('selectSetting', ['Setting', 'growl', '_t', + function (Setting, growl, _t) { + return ({ + restrict: 'E', + scope: { + name: '@', + label: '@', + settings: '=', + classes: '@', + required: '<', + option1: '<', + option2: '<', + option3: '<', + option4: '<', + option5: '<' + }, + templateUrl: '<%= asset_path "admin/settings/select.html" %>', + link ($scope, element, attributes) { + // The setting + $scope.setting = { + name: $scope.name, + value: $scope.settings[$scope.name] + }; + + /** + * 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) { + let { value } = setting; + + Setting.update( + { name: setting.name }, + { 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); + } + ); + }; + } + }); + } +]); diff --git a/app/assets/templates/admin/settings/general.html b/app/assets/templates/admin/settings/general.html index 3bfe18833..fe7a81fb8 100644 --- a/app/assets/templates/admin/settings/general.html +++ b/app/assets/templates/admin/settings/general.html @@ -324,20 +324,15 @@
- {{ 'app.admin.settings.phone_required_info' }} -
+ {{ 'app.admin.settings.phone_required_info' }} +