User.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <template>
  2. <div id="user">
  3. <md-card>
  4. <md-card-header>
  5. <span class="md-title">User: {{ user.username }}</span>
  6. </md-card-header>
  7. <md-card-content>
  8. <md-input-container>
  9. <label>Email</label>
  10. <md-input v-model="user.email" />
  11. </md-input-container>
  12. <div class="md-body-2">Change password</div>
  13. <md-input-container id="password-input" md-has-password>
  14. <label>New password</label>
  15. <md-input v-model="user.password" type="password" />
  16. </md-input-container>
  17. <md-switch v-if="loggedInUser.isAdmin" v-model="user.isAdmin" class="md-warn">is admin</md-switch>
  18. <br />
  19. <md-button id="save-button" class="md-raised md-primary" @click="save()">Save</md-button>
  20. </md-card-content>
  21. </md-card>
  22. <ibt-snackbar ref="snackbarObj" />
  23. <ibt-dialog ref="dialogObj" />
  24. </div>
  25. </template>
  26. <script>
  27. import IbtDialog from './IbtDialog.vue';
  28. import IbtSnackbar from './IbtSnackbar.vue';
  29. export default {
  30. data () {
  31. return {
  32. user: {email: '', password: null, isAdmin: false},
  33. password: null
  34. }
  35. },
  36. computed: {
  37. loggedInUser() {
  38. return this.$store.state.loggedInUser;
  39. }
  40. },
  41. beforeCreate: function() {
  42. this.usersUrl = this.$resource('users{/id}');
  43. },
  44. mounted: function() {
  45. this.getUser(this.$route.params.id);
  46. },
  47. methods: {
  48. getUser(id) {
  49. this.usersUrl.get({id: id}).then((response) => {
  50. return response.json();
  51. }, (response) => {
  52. this.$refs.dialogObj.show({text: 'unable to get user'});
  53. }).then((data) => {
  54. this.user = data || {};
  55. });
  56. },
  57. save() {
  58. this.usersUrl.update({id: this.user._id}, this.user).then((response) => {
  59. return response.json();
  60. }, (response) => {
  61. this.$refs.dialogObj.show({text: 'unable to save user settings'});
  62. }).then((data) => {
  63. this.user = data;
  64. this.$refs.snackbarObj.show('user saved');
  65. });
  66. }
  67. },
  68. components: { IbtDialog, IbtSnackbar }
  69. }
  70. </script>
  71. <style>
  72. #user {
  73. padding: 10px;
  74. }
  75. #save-button {
  76. margin-top: 40px;
  77. }
  78. </style>