playlists_ctrl.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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).then(
  17. () => {
  18. this.$scope.appEvent("alert-success", ["Playlist deleted", ""]);
  19. },
  20. () => {
  21. this.$scope.appEvent("alert-error", ["Unable to delete playlist", ""]);
  22. this.playlists.push(playlist);
  23. }
  24. );
  25. }
  26. removePlaylist(playlist) {
  27. this.$scope.appEvent("confirm-modal", {
  28. title: "Delete",
  29. text: "Are you sure you want to delete playlist " + playlist.name + "?",
  30. yesText: "Delete",
  31. icon: "fa-trash",
  32. onConfirm: () => {
  33. this.removePlaylistConfirmed(playlist);
  34. }
  35. });
  36. }
  37. }
  38. coreModule.controller("PlaylistsCtrl", PlaylistsCtrl);