playlists_ctrl.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. ///<reference path="../../headers/common.d.ts" />
  2. import angular from 'angular';
  3. import _ from 'lodash';
  4. import coreModule from '../../core/core_module';
  5. export class PlaylistsCtrl {
  6. playlists: any;
  7. navModel: any;
  8. /** @ngInject */
  9. constructor(private $scope, private $location, private backendSrv, private navModelSrv) {
  10. this.navModel = navModelSrv.getPlaylistsNav(0);
  11. backendSrv.get('/api/playlists').then(result => {
  12. this.playlists = result;
  13. });
  14. }
  15. removePlaylistConfirmed(playlist) {
  16. _.remove(this.playlists, { id: playlist.id });
  17. this.backendSrv.delete('/api/playlists/' + playlist.id)
  18. .then(() => {
  19. this.$scope.appEvent('alert-success', ['Playlist deleted', '']);
  20. }, () => {
  21. this.$scope.appEvent('alert-error', ['Unable to delete playlist', '']);
  22. this.playlists.push(playlist);
  23. });
  24. }
  25. removePlaylist(playlist) {
  26. this.$scope.appEvent('confirm-modal', {
  27. title: 'Delete',
  28. text: 'Are you sure you want to delete playlist ' + playlist.name + '?',
  29. yesText: "Delete",
  30. icon: "fa-trash",
  31. onConfirm: () => {
  32. this.removePlaylistConfirmed(playlist);
  33. }
  34. });
  35. }
  36. }
  37. coreModule.controller('PlaylistsCtrl', PlaylistsCtrl);