CreateCommunityStation.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. export default {
  32. data() {
  33. return {
  34. newCommunity: {
  35. _id: '',
  36. displayName: '',
  37. description: ''
  38. }
  39. }
  40. },
  41. methods: {
  42. toggleModal: function () {
  43. this.$dispatch('toggleModal', 'createCommunityStation');
  44. },
  45. submitModal: function () {
  46. let _this = this;
  47. if (_this.community._id == '') return Toast.methods.addToast('ID cannot be a blank field', 3000);
  48. if (_this.community.displayName == '') return Toast.methods.addToast('Display Name cannot be a blank field', 3000);
  49. if (_this.community.description == '') return Toast.methods.addToast('Description cannot be a blank field', 3000);
  50. this.socket.emit('stations.createCommunity', {
  51. _id: _this.community._id,
  52. displayName: _this.community.displayName,
  53. description: _this.community.description
  54. }, res => {
  55. if (res.status === 'success') Toast.methods.addToast(`You have added the station successfully`, 4000);
  56. else Toast.methods.addToast(res.message, 4000);
  57. });
  58. this.toggleModal();
  59. }
  60. }
  61. }
  62. </script>