CreateCommunityStation.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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' autofocus>
  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' @keyup.enter="submitModal()">
  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. import io from '../../io';
  33. export default {
  34. data() {
  35. return {
  36. newCommunity: {
  37. _id: '',
  38. displayName: '',
  39. description: ''
  40. }
  41. }
  42. },
  43. ready: function () {
  44. let _this = this;
  45. io.getSocket((socket) => {
  46. _this.socket = socket;
  47. });
  48. },
  49. methods: {
  50. toggleModal: function () {
  51. this.$dispatch('toggleModal', 'createCommunityStation');
  52. },
  53. submitModal: function () {
  54. let _this = this;
  55. if (_this.newCommunity._id == '') return Toast.methods.addToast('ID cannot be a blank field', 3000);
  56. if (_this.newCommunity.displayName == '') return Toast.methods.addToast('Display Name cannot be a blank field', 3000);
  57. if (_this.newCommunity.description == '') return Toast.methods.addToast('Description cannot be a blank field', 3000);
  58. this.socket.emit('stations.create', {
  59. _id: _this.newCommunity._id,
  60. type: 'community',
  61. displayName: _this.newCommunity.displayName,
  62. description: _this.newCommunity.description
  63. }, res => {
  64. if (res.status === 'success') Toast.methods.addToast(`You have added the station successfully`, 4000);
  65. else Toast.methods.addToast(res.message, 4000);
  66. });
  67. this.toggleModal();
  68. }
  69. },
  70. events: {
  71. closeModal: function() {
  72. this.$dispatch('toggleModal', 'createCommunityStation');
  73. }
  74. }
  75. }
  76. </script>