diff --git a/app/assets/javascripts/controllers/admin/settings.js.erb b/app/assets/javascripts/controllers/admin/settings.js.erb index 406bdf42a..2c11d0d31 100644 --- a/app/assets/javascripts/controllers/admin/settings.js.erb +++ b/app/assets/javascripts/controllers/admin/settings.js.erb @@ -55,9 +55,7 @@ Application.Controllers.controller('SettingsController', ['$scope', '$uibModal', $scope.twitterSetting = { name: 'twitter_name', value: settingsPromise.twitter_name }; $scope.aboutTitleSetting = { name: 'about_title', value: settingsPromise.about_title }; $scope.aboutBodySetting = { name: 'about_body', value: settingsPromise.about_body }; - $scope.privacyBodySetting = { name: 'privacy_body', value: settingsPromise.privacy_body }; $scope.privacyDpoSetting = { name: 'privacy_dpo', value: settingsPromise.privacy_dpo }; - $scope.privacyDraftSetting = { name: 'privacy_draft', value: privacyDraftsPromise.setting.value }; $scope.aboutContactsSetting = { name: 'about_contacts', value: settingsPromise.about_contacts }; $scope.homeBlogpostSetting = { name: 'home_blogpost', value: settingsPromise.home_blogpost }; $scope.machineExplicationsAlert = { name: 'machine_explications_alert', value: settingsPromise.machine_explications_alert }; @@ -125,8 +123,11 @@ Application.Controllers.controller('SettingsController', ['$scope', '$uibModal', value: (settingsPromise.display_name_enable === 'true') }; - // binding to the privacy policy revision select - $scope.policyVersion = null; + // By default, we display the currently published privacy policy + $scope.privacyPolicy = { + version: null, + bodyTemp: settingsPromise.privacy_body + }; /** * For use with 'ng-class', returns the CSS class name for the uploads previews. @@ -170,20 +171,33 @@ Application.Controllers.controller('SettingsController', ['$scope', '$uibModal', ); }; + /** + * The privacy policy has its own special save function because updating the policy must notify all users + */ $scope.savePrivacyPolicy = function () { // open modal const modalInstance = $uibModal.open({ templateUrl: '<%= asset_path "admin/settings/save_policy.html" %>', - controller: 'SavePolicyController' + controller: 'SavePolicyController', + resolve: { + saveCb () { return $scope.save; }, + privacyPolicy () { return $scope.privacyPolicy; } + } }); - // once done, update the invoice model and inform the admin - return modalInstance.result.then(function (res) { - $scope.invoices.unshift(res.avoir); - return Invoice.get({ id: invoice.id }, function (data) { - invoice.has_avoir = data.has_avoir; - return growl.success(_t('invoices.refund_invoice_successfully_created')); - }); + // once done, update the client data + modalInstance.result.then(function (type) { + Setting.get({ name: 'privacy_draft', history: true }, function (data) { + // reset history + $scope.privacyDraftsHistory = []; + data.setting.history.forEach(function (draft) { + $scope.privacyDraftsHistory.push({ id: draft.id, name: _t('settings.privacy.draft_from_USER_DATE', { USER: draft.user, DATE: draft.created_at }), content: draft.value }); + }); + if (type === 'privacy_draft') { + // FIXME + $scope.privacyPolicy.version = data.setting.history[data.setting.history.length - 1].id; + } + }) }); }; @@ -242,7 +256,12 @@ Application.Controllers.controller('SettingsController', ['$scope', '$uibModal', * Change the revision of the displayed privacy policy, from drafts history */ $scope.handlePolicyRevisionChange = function () { - $scope.privacyDraftSetting.value = $scope.privacyDraftsHistory[$scope.policyVersion].content; + for (const draft of $scope.privacyDraftsHistory) { + if (draft.id == $scope.privacyPolicy.version) { + $scope.privacyPolicy.bodyTemp = draft.content; + break; + } + } }; /* PRIVATE SCOPE */ @@ -288,7 +307,7 @@ Application.Controllers.controller('SettingsController', ['$scope', '$uibModal', } privacyDraftsPromise.setting.history.forEach(function (draft) { - $scope.privacyDraftsHistory.push({ id: draft.id, name: _t('settings.privacy.draft_from_USER_DATE', { USER: draft.user, DATE: draft.created_at }), content: draft.value }); + $scope.privacyDraftsHistory.push({ id: draft.id, name: _t('settings.privacy.draft_from_USER_DATE', { USER: draft.user.name, DATE: moment(draft.created_at).format('L LT') }), content: draft.value }); }); }; @@ -302,17 +321,30 @@ Application.Controllers.controller('SettingsController', ['$scope', '$uibModal', /** * Controller used in the invoice refunding modal window */ -Application.Controllers.controller('AvoirModalController', ['$scope', '$uibModalInstance', 'growl', '_t', - function ($scope, $uibModalInstance, growl, _t) { +Application.Controllers.controller('SavePolicyController', ['$scope', '$uibModalInstance', 'saveCb', 'privacyPolicy', + function ($scope, $uibModalInstance, saveCb, privacyPolicy) { /* PUBLIC SCOPE */ + + /** + * Save as draft the current text + */ $scope.save = function () { - + saveCb({ name: 'privacy_draft', value: privacyPolicy.bodyTemp }); + $uibModalInstance.close('privacy_draft'); }; + + /** + * Publish the current text as the new privacy policy + */ $scope.publish = function () { - + saveCb({ name: 'privacy_body', value: privacyPolicy.bodyTemp }); + $uibModalInstance.close('privacy_body'); }; + /** + * Cancel the saving, dismiss the modal window + */ $scope.cancel = function () { - + $uibModalInstance.dismiss('cancel'); }; } ]); diff --git a/app/assets/templates/admin/settings/privacy.html b/app/assets/templates/admin/settings/privacy.html index afea388d3..0392f86cd 100644 --- a/app/assets/templates/admin/settings/privacy.html +++ b/app/assets/templates/admin/settings/privacy.html @@ -3,10 +3,10 @@
- -
diff --git a/config/locales/app.admin.en.yml b/config/locales/app.admin.en.yml index 628df300b..7477aa085 100644 --- a/config/locales/app.admin.en.yml +++ b/config/locales/app.admin.en.yml @@ -688,6 +688,7 @@ en: about_title: "\"About\" page title" about_body: "\"About\" page content" about_contacts: "\"About\" page contacts" + privacy_draft: "privacy policy draft" privacy_body: "privacy policy" privacy_dpo: "data protection officer address" booking_window_start: "opening time" diff --git a/config/locales/app.admin.es.yml b/config/locales/app.admin.es.yml index d59ea4085..951b24611 100644 --- a/config/locales/app.admin.es.yml +++ b/config/locales/app.admin.es.yml @@ -688,6 +688,7 @@ es: about_title: "Título de la página \"Acerca de\"" about_body: "Contenido de la página \"Acerca de\"" about_contacts: "Página contactos\"Acerca de\"" + privacy_draft: "privacy policy draft" # translation_missing privacy_body: "privacy policy" # translation_missing privacy_dpo: "data protection officer address" # translation_missing booking_window_start: "hora de apertura" diff --git a/config/locales/app.admin.fr.yml b/config/locales/app.admin.fr.yml index 3cb7ee2b4..be9f4b49e 100644 --- a/config/locales/app.admin.fr.yml +++ b/config/locales/app.admin.fr.yml @@ -688,6 +688,7 @@ fr: about_title: "titre de la page \"À propos\"" about_body: "corps de la page \"À propos\"" about_contacts: "contacts sur la page \"À propos\"" + privacy_draft: "brouillon de la politique de confidentialité" privacy_body: "la politique de confidentialité" privacy_dpo: "l'adresse du délégué à la protection des données" booking_window_start: "l'heure d'ouverture" diff --git a/config/locales/app.admin.pt.yml b/config/locales/app.admin.pt.yml index b75cc6b84..be40e72b8 100755 --- a/config/locales/app.admin.pt.yml +++ b/config/locales/app.admin.pt.yml @@ -688,6 +688,7 @@ pt: about_title: "\"Sobre\" título da página" about_body: "\"Sobre\" conteúdo da página" about_contacts: "\"Sobre\" página de contatos" + privacy_draft: "privacy policy draft" # translation_missing privacy_body: "privacy policy" # translation_missing privacy_dpo: "data protection officer address" # translation_missing booking_window_start: "Horário de abertura"