playlists_ctrl.ts 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. ///<reference path="../../headers/common.d.ts" />
  2. import _ from 'lodash';
  3. import coreModule from '../../core/core_module';
  4. export class PlaylistsCtrl {
  5. playlists: any;
  6. navModel: any;
  7. /** @ngInject */
  8. constructor(private $scope, private backendSrv, navModelSrv) {
  9. this.navModel = navModelSrv.getNav('dashboards', 'playlists', 0);
  10. backendSrv.get('/api/playlists').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);