diff --git a/app/assets/javascripts/controllers/admin/settings.js.erb b/app/assets/javascripts/controllers/admin/settings.js.erb index 3f7fc53a4..3f3720343 100644 --- a/app/assets/javascripts/controllers/admin/settings.js.erb +++ b/app/assets/javascripts/controllers/admin/settings.js.erb @@ -80,7 +80,6 @@ Application.Controllers.controller('SettingsController', ['$scope', '$rootScope' $scope.fablabName = { name: 'fablab_name', value: settingsPromise.fablab_name }; $scope.nameGenre = { name: 'name_genre', value: settingsPromise.name_genre }; $scope.machinesSortBy = { name: 'machines_sort_by', value: settingsPromise.machines_sort_by }; - $scope.trackingId = { name: 'tracking_id', value: settingsPromise.tracking_id } $scope.cguFile = cguFile.custom_asset; $scope.cgvFile = cgvFile.custom_asset; $scope.customLogo = logoFile.custom_asset; diff --git a/app/assets/javascripts/directives/settings/text-setting.js.erb b/app/assets/javascripts/directives/settings/text-setting.js.erb new file mode 100644 index 000000000..fd8d5371d --- /dev/null +++ b/app/assets/javascripts/directives/settings/text-setting.js.erb @@ -0,0 +1,47 @@ +Application.Directives.directive('textSetting', ['Setting', 'growl', '_t', + function (Setting, growl, _t) { + return ({ + restrict: 'E', + scope: { + name: '@', + label: '@', + settings: '=', + classes: '@', + faIcon: '@', + placeholder: '@', + required: '<' + }, + templateUrl: '<%= asset_path "admin/settings/text.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/privacy.html b/app/assets/templates/admin/settings/privacy.html index 233434c6d..cd1884c68 100644 --- a/app/assets/templates/admin/settings/privacy.html +++ b/app/assets/templates/admin/settings/privacy.html @@ -75,15 +75,11 @@