playlists_ctrl.ts 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. /** @ngInject */
  8. constructor(private $scope, private $location, private backendSrv) {
  9. backendSrv.get('/api/playlists')
  10. .then((result) => {
  11. this.playlists = result;
  12. });
  13. }
  14. removePlaylistConfirmed(playlist) {
  15. _.remove(this.playlists, { id: playlist.id });
  16. this.backendSrv.delete('/api/playlists/' + playlist.id)
  17. .then(() => {
  18. this.$scope.appEvent('alert-success', ['Playlist deleted', '']);
  19. }, () => {
  20. this.$scope.appEvent('alert-error', ['Unable to delete playlist', '']);
  21. this.playlists.push(playlist);
  22. });
  23. }
  24. removePlaylist(playlist) {
  25. this.$scope.appEvent('confirm-modal', {
  26. title: 'Delete',
  27. text: 'Are you sure you want to delete playlist ' + playlist.name + '?',
  28. yesText: "Delete",
  29. icon: "fa-trash",
  30. onConfirm: () => {
  31. this.removePlaylistConfirmed(playlist);
  32. }
  33. });
  34. }
  35. }
  36. coreModule.controller('PlaylistsCtrl', PlaylistsCtrl);