Create.vue 2.0 KB

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