GlobalSettings.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <template>
  2. <div id="settings">
  3. <md-card>
  4. <md-card-header>
  5. <span class="md-title">Settings</span>
  6. </md-card-header>
  7. <md-card-content v-if="loggedInUser.isAdmin">
  8. <md-switch v-model="shownSettings.protectUnregistered" class="md-warn">protect unregistered attendees (only admins can modify or delete)</md-switch>
  9. <br />
  10. <md-switch v-model="shownSettings.protectGroupNotes" class="md-warn">protect group notes</md-switch>
  11. <br />
  12. <md-switch v-model="shownSettings.protectGroupName" class="md-warn">protect group name</md-switch>
  13. <br />
  14. <md-switch v-model="shownSettings.protectDayNotes" class="md-warn">protect day notes</md-switch>
  15. <br />
  16. <md-button id="save-button" class="md-raised md-primary" @click="save()">Save</md-button>
  17. </md-card-content>
  18. <md-card-content v-else>
  19. Only admin are allowed to change global settings.
  20. </md-card-content>
  21. </md-card>
  22. <ibt-dialog ref="dialogObj" />
  23. <ibt-snackbar ref="snackbarObj" />
  24. </div>
  25. </template>
  26. <script>
  27. import IbtDialog from './IbtDialog.vue';
  28. import IbtSnackbar from './IbtSnackbar.vue';
  29. export default {
  30. computed: {
  31. loggedInUser() {
  32. return this.$store.state.loggedInUser;
  33. },
  34. shownSettings() {
  35. return this.$store.state.settings || {};
  36. }
  37. },
  38. beforeCreate: function() {
  39. this.settingsUrl = this.$resource('settings');
  40. },
  41. mounted: function() {
  42. this.fetchSettings();
  43. },
  44. methods: {
  45. fetchSettings() {
  46. // XXX: duplicated code from App.vue; move this login
  47. // near the store.
  48. this.settingsUrl.get().then((response) => {
  49. return response.json();
  50. }, (response) => {
  51. this.$refs.dialogObj.show({text: 'unable to fetch settings'});
  52. }).then((json) => {
  53. if (!json || json.error) {
  54. this.$refs.dialogObj.show({text: 'unable to fetch settings: ' + (json && json.message) || ''});
  55. } else {
  56. this.$store.commit('updateSettings', json);
  57. }
  58. });
  59. },
  60. save() {
  61. this.settingsUrl.save(this.shownSettings).then((response) => {
  62. return response.json();
  63. }, (response) => {
  64. this.$refs.dialogObj.show({text: 'unable to update settings'});
  65. }).then((json) => {
  66. if (!json || json.error) {
  67. this.$refs.dialogObj.show({text: 'unable to update settings: ' + (json && json.message) || ''});
  68. } else {
  69. this.fetchSettings();
  70. this.$refs.snackbarObj.show('settings saved');
  71. }
  72. });
  73. }
  74. },
  75. components: { IbtDialog, IbtSnackbar }
  76. }
  77. </script>
  78. <style>
  79. #settings {
  80. padding: 10px;
  81. }
  82. #save-button {
  83. margin-top: 40px;
  84. }
  85. </style>