Create.vue 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <template>
  2. <modal title="Create Playlist">
  3. <template v-slot:body>
  4. <p class="control is-expanded">
  5. <input
  6. v-model="playlist.displayName"
  7. class="input"
  8. type="text"
  9. placeholder="Playlist Display Name"
  10. autofocus
  11. @keyup.enter="createPlaylist()"
  12. />
  13. </p>
  14. </template>
  15. <template v-slot:footer>
  16. <a class="button is-info" v-on:click="createPlaylist()"
  17. >Create Playlist</a
  18. >
  19. </template>
  20. </modal>
  21. </template>
  22. <script>
  23. import { Toast } from "vue-roaster";
  24. import Modal from "../Modal.vue";
  25. import io from "../../../io";
  26. import validation from "../../../validation";
  27. export default {
  28. components: { Modal },
  29. data() {
  30. return {
  31. playlist: {
  32. displayName: null,
  33. songs: [],
  34. createdBy: this.$parent.$parent.username,
  35. createdAt: Date.now()
  36. }
  37. };
  38. },
  39. mounted: function() {
  40. let _this = this;
  41. io.getSocket(socket => {
  42. _this.socket = socket;
  43. });
  44. },
  45. methods: {
  46. createPlaylist: function() {
  47. const displayName = this.playlist.displayName;
  48. if (!validation.isLength(displayName, 2, 32))
  49. return Toast.methods.addToast(
  50. "Display name must have between 2 and 32 characters.",
  51. 8000
  52. );
  53. if (!validation.regex.azAZ09_.test(displayName))
  54. return Toast.methods.addToast(
  55. "Invalid display name format. Allowed characters: a-z, A-Z, 0-9 and _.",
  56. 8000
  57. );
  58. this.socket.emit("playlists.create", this.playlist, res => {
  59. Toast.methods.addToast(res.message, 3000);
  60. });
  61. this.$parent.modals.createPlaylist = !this.$parent.modals
  62. .createPlaylist;
  63. }
  64. }
  65. };
  66. </script>
  67. <style lang="scss" scoped>
  68. .menu {
  69. padding: 0 20px;
  70. }
  71. .menu-list li {
  72. display: flex;
  73. justify-content: space-between;
  74. }
  75. .menu-list a:hover {
  76. color: #000 !important;
  77. }
  78. li a {
  79. display: flex;
  80. align-items: center;
  81. }
  82. .controls {
  83. display: flex;
  84. a {
  85. display: flex;
  86. align-items: center;
  87. }
  88. }
  89. .table {
  90. margin-bottom: 0;
  91. }
  92. h5 {
  93. padding: 20px 0;
  94. }
  95. </style>