EditUser.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <template>
  2. <div>
  3. <modal title='Edit User'>
  4. <div slot='body'>
  5. <p class="control has-addons">
  6. <input class='input is-expanded' type='text' placeholder='Username' v-model='editing.username' autofocus>
  7. <a class="button is-info" @click='updateUsername()'>Update Username</a>
  8. </p>
  9. <p class="control has-addons">
  10. <input class='input is-expanded' type='text' placeholder='Username' v-model='editing.email' autofocus>
  11. <a class="button is-info" @click='updateEmail()'>Update Email Address</a>
  12. </p>
  13. <p class="control has-addons">
  14. <span class="select">
  15. <select v-model="editing.role">
  16. <option>default</option>
  17. <option>admin</option>
  18. </select>
  19. </span>
  20. <a class="button is-info" @click='updateRole()'>Update Role</a>
  21. </p>
  22. </div>
  23. <div slot='footer'>
  24. <!--button class='button is-warning'>
  25. <span>&nbsp;Send Verification Email</span>
  26. </button>
  27. <button class='button is-warning'>
  28. <span>&nbsp;Send Password Reset Email</span>
  29. </button-->
  30. <button class='button is-danger' @click='$parent.toggleModal()'>
  31. <span>&nbsp;Close</span>
  32. </button>
  33. </div>
  34. </modal>
  35. </div>
  36. </template>
  37. <script>
  38. import io from '../../io';
  39. import { Toast } from 'vue-roaster';
  40. import Modal from './Modal.vue';
  41. export default {
  42. components: { Modal },
  43. data() {
  44. return {
  45. editing: {}
  46. }
  47. },
  48. methods: {
  49. updateUsername: function () {
  50. this.socket.emit(`users.updateUsername`, this.editing._id, this.editing.username, res => {
  51. Toast.methods.addToast(res.message, 4000);
  52. });
  53. },
  54. updateEmail: function () {
  55. this.socket.emit(`users.updateEmail`, this.editing._id, this.editing.email, res => {
  56. Toast.methods.addToast(res.message, 4000);
  57. });
  58. },
  59. updateRole: function () {
  60. let _this = this;
  61. this.socket.emit(`users.updateRole`, this.editing._id, this.editing.role, res => {
  62. Toast.methods.addToast(res.message, 4000);
  63. if (
  64. res.status === 'success' &&
  65. _this.editing.role === 'default' &&
  66. _this.editing._id === _this.$parent.$parent.$parent.userId
  67. ) location.reload();
  68. });
  69. }
  70. },
  71. ready: function () {
  72. let _this = this;
  73. io.getSocket(socket => _this.socket = socket );
  74. },
  75. events: {
  76. closeModal: function () {
  77. this.$parent.modals.editUser = false;
  78. },
  79. editUser: function (user) {
  80. this.editing = {
  81. _id: user._id,
  82. username: user.username,
  83. email: user.email.address,
  84. role: user.role
  85. };
  86. this.$parent.toggleModal();
  87. }
  88. }
  89. }
  90. </script>
  91. <style type='scss' scoped>
  92. .save-changes { color: #fff; }
  93. .tag:not(:last-child) { margin-right: 5px; }
  94. .select:after { border-color: #029ce3; }
  95. </style>