diff --git a/.eslintrc b/.eslintrc index 4006a27f2..545c29d9c 100644 --- a/.eslintrc +++ b/.eslintrc @@ -7,7 +7,8 @@ "Application": true, "angular": true, "Fablab": true, - "moment": true, - } + "moment": true + }, + "plugins": ["lint-erb"] } diff --git a/app/assets/javascripts/controllers/admin/settings.js.erb b/app/assets/javascripts/controllers/admin/settings.js.erb index 2a30c975c..cfb8e701d 100644 --- a/app/assets/javascripts/controllers/admin/settings.js.erb +++ b/app/assets/javascripts/controllers/admin/settings.js.erb @@ -54,6 +54,9 @@ Application.Controllers.controller('SettingsController', ['$scope', '$rootScope' // full history of privacy policy drafts $scope.privacyDraftsHistory = []; + // all settings as retrieved from database + $scope.allSettings = settingsPromise; + // various configurable settings $scope.twitterSetting = { name: 'twitter_name', value: settingsPromise.twitter_name }; $scope.linkName = { name: 'link_name', value: settingsPromise.link_name }; diff --git a/app/assets/javascripts/directives/settings/boolean-setting.js b/app/assets/javascripts/directives/settings/boolean-setting.js deleted file mode 100644 index e69de29bb..000000000 diff --git a/app/assets/javascripts/directives/settings/boolean-setting.js.erb b/app/assets/javascripts/directives/settings/boolean-setting.js.erb new file mode 100644 index 000000000..c448d94b2 --- /dev/null +++ b/app/assets/javascripts/directives/settings/boolean-setting.js.erb @@ -0,0 +1,40 @@ +Application.Directives.directive('booleanSetting', ['Setting', 'growl', '_t', + function (Setting, growl, _t) { + return ({ + restrict: 'E', + scope: { + name: '@', + label: '@', + settings: '=' + }, + templateUrl: '<%= asset_path "admin/settings/boolean.html" %>', + link ($scope, element, attributes) { + // The setting + $scope.setting = { + name: $scope.name, + value: ($scope.settings[$scope.name] === 'true') + }; + + /** + * 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) { + const { value } = setting; + + Setting.update( + { name: setting.name }, + { value: value.toString() }, + function () { growl.success(_t('app.admin.settings.customization_of_SETTING_successfully_saved', { SETTING: _t(`app.admin.settings.${setting.name}`) })); }, + 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/javascripts/router.js.erb b/app/assets/javascripts/router.js.erb index fd7743c1b..1772fe61a 100644 --- a/app/assets/javascripts/router.js.erb +++ b/app/assets/javascripts/router.js.erb @@ -1010,7 +1010,7 @@ angular.module('application.router', ['ui.router']) settingsPromise: ['Setting', function (Setting) { return Setting.query({ names: `['twitter_name', 'about_title', 'about_body', 'tracking_id',\ - 'privacy_body', 'privacy_dpo', 'about_contacts', \ + 'privacy_body', 'privacy_dpo', 'about_contacts', 'book_overlapping_slots', \ 'home_blogpost', 'machine_explications_alert', 'training_explications_alert', \ 'training_information_message', 'subscription_explications_alert', 'event_explications_alert', \ 'space_explications_alert', 'booking_window_start', 'booking_window_end', \ diff --git a/app/assets/templates/admin/settings/boolean.html b/app/assets/templates/admin/settings/boolean.html new file mode 100644 index 000000000..ee8f0b2d7 --- /dev/null +++ b/app/assets/templates/admin/settings/boolean.html @@ -0,0 +1,12 @@ +