Create.vue 2.1 KB

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