CreateCommunityStation.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <template>
  2. <div class='modal is-active'>
  3. <div class='modal-background'></div>
  4. <div class='modal-card'>
  5. <header class='modal-card-head'>
  6. <p class='modal-card-title'>Create community station</p>
  7. <button class='delete' @click='toggleModal()'></button>
  8. </header>
  9. <section class='modal-card-body'>
  10. <!-- validation to check if exists http://bulma.io/documentation/elements/form/ -->
  11. <label class='label'>Unique ID (lowercase, a-z, used in the url)</label>
  12. <p class='control'>
  13. <input class='input' type='text' placeholder='Name...' v-model='newCommunity._id'>
  14. </p>
  15. <label class='label'>Display Name</label>
  16. <p class='control'>
  17. <input class='input' type='text' placeholder='Display name...' v-model='newCommunity.displayName'>
  18. </p>
  19. <label class='label'>Description</label>
  20. <p class='control'>
  21. <input class='input' type='text' placeholder='Description...' v-model='newCommunity.description'>
  22. </p>
  23. </section>
  24. <footer class='modal-card-foot'>
  25. <a class='button is-primary' @click='submitModal()'>Create</a>
  26. </footer>
  27. </div>
  28. </div>
  29. </template>
  30. <script>
  31. import { Toast } from 'vue-roaster';
  32. export default {
  33. data() {
  34. return {
  35. newCommunity: {
  36. _id: '',
  37. displayName: '',
  38. description: ''
  39. }
  40. }
  41. },
  42. ready: function () {
  43. let _this = this;
  44. let socketInterval = setInterval(() => {
  45. if (!!_this.$parent.socket) {
  46. _this.socket = _this.$parent.socket;
  47. clearInterval(socketInterval);
  48. }
  49. }, 100);
  50. },
  51. methods: {
  52. toggleModal: function () {
  53. this.$dispatch('toggleModal', 'createCommunityStation');
  54. },
  55. submitModal: function () {
  56. let _this = this;
  57. if (_this.newCommunity._id == '') return Toast.methods.addToast('ID cannot be a blank field', 3000);
  58. if (_this.newCommunity.displayName == '') return Toast.methods.addToast('Display Name cannot be a blank field', 3000);
  59. if (_this.newCommunity.description == '') return Toast.methods.addToast('Description cannot be a blank field', 3000);
  60. this.socket.emit('stations.create', {
  61. _id: _this.newCommunity._id,
  62. type: 'community',
  63. displayName: _this.newCommunity.displayName,
  64. description: _this.newCommunity.description
  65. }, res => {
  66. if (res.status === 'success') Toast.methods.addToast(`You have added the station successfully`, 4000);
  67. else Toast.methods.addToast(res.message, 4000);
  68. });
  69. this.toggleModal();
  70. }
  71. }
  72. }
  73. </script>