CreateCommunityStation.vue 2.3 KB

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