CreateCommunityStation.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <template>
  2. <modal title="Create Community Station">
  3. <template v-slot:body>
  4. <!-- validation to check if exists http://bulma.io/documentation/elements/form/ -->
  5. <label class="label">Name (unique lowercase station id)</label>
  6. <p class="control">
  7. <input
  8. class="input"
  9. type="text"
  10. placeholder="Name..."
  11. v-model="newCommunity.name"
  12. autofocus
  13. />
  14. </p>
  15. <label class="label">Display Name</label>
  16. <p class="control">
  17. <input
  18. class="input"
  19. type="text"
  20. placeholder="Display name..."
  21. v-model="newCommunity.displayName"
  22. />
  23. </p>
  24. <label class="label">Description</label>
  25. <p class="control">
  26. <input
  27. class="input"
  28. type="text"
  29. placeholder="Description..."
  30. v-model="newCommunity.description"
  31. @keyup.enter="submitModal()"
  32. />
  33. </p>
  34. </template>
  35. <template v-slot:footer>
  36. <a class="button is-primary" v-on:click="submitModal()">Create</a>
  37. </template>
  38. </modal>
  39. </template>
  40. <script>
  41. import { Toast } from "vue-roaster";
  42. import Modal from "./Modal.vue";
  43. import io from "../../io";
  44. import validation from "../../validation";
  45. export default {
  46. components: { Modal },
  47. data() {
  48. return {
  49. newCommunity: {
  50. name: "",
  51. displayName: "",
  52. description: ""
  53. }
  54. };
  55. },
  56. mounted: function() {
  57. let _this = this;
  58. io.getSocket(socket => {
  59. _this.socket = socket;
  60. });
  61. },
  62. methods: {
  63. submitModal: function() {
  64. const name = this.newCommunity.name;
  65. const displayName = this.newCommunity.displayName;
  66. const description = this.newCommunity.description;
  67. if (!name || !displayName || !description)
  68. return Toast.methods.addToast("Please fill in all fields", 8000);
  69. if (!validation.isLength(name, 2, 16))
  70. return Toast.methods.addToast(
  71. "Name must have between 2 and 16 characters.",
  72. 8000
  73. );
  74. if (!validation.regex.az09_.test(name))
  75. return Toast.methods.addToast(
  76. "Invalid name format. Allowed characters: a-z, 0-9 and _.",
  77. 8000
  78. );
  79. if (!validation.isLength(displayName, 2, 32))
  80. return Toast.methods.addToast(
  81. "Display name must have between 2 and 32 characters.",
  82. 8000
  83. );
  84. if (!validation.regex.azAZ09_.test(displayName))
  85. return Toast.methods.addToast(
  86. "Invalid display name format. Allowed characters: a-z, A-Z, 0-9 and _.",
  87. 8000
  88. );
  89. if (!validation.isLength(description, 2, 200))
  90. return Toast.methods.addToast(
  91. "Description must have between 2 and 200 characters.",
  92. 8000
  93. );
  94. let characters = description.split("");
  95. characters = characters.filter(function(character) {
  96. return character.charCodeAt(0) === 21328;
  97. });
  98. if (characters.length !== 0)
  99. return Toast.methods.addToast(
  100. "Invalid description format. Swastika's are not allowed.",
  101. 8000
  102. );
  103. this.socket.emit(
  104. "stations.create",
  105. {
  106. name: name,
  107. type: "community",
  108. displayName: displayName,
  109. description: description
  110. },
  111. res => {
  112. if (res.status === "success")
  113. Toast.methods.addToast(
  114. `You have added the station successfully`,
  115. 4000
  116. );
  117. else Toast.methods.addToast(res.message, 4000);
  118. }
  119. );
  120. // this.toggleModal();
  121. }
  122. }
  123. };
  124. </script>