galleryManage.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. angular.module("robware").controller('galleryManage', ["$scope", "$http", function($scope, $http) {
  2. $scope.albums=[];
  3. var albumActions={};
  4. var moveIndex="Move selected to album";
  5. $scope.contextMenuActions={
  6. "Delete selected":deleteSelected
  7. };
  8. function getSelectedImageIds(){
  9. var images=[];
  10. angular.forEach($scope.selectedAlbum.Images, function(image){
  11. if (image.selected)
  12. images.push(image.ImageId);
  13. });
  14. return images;
  15. }
  16. function updateAlbums(data){
  17. var selectedId=$scope.selectedAlbum.AlbumId;
  18. $scope.albums=data;
  19. angular.forEach($scope.albums, function(album){
  20. if (album.AlbumId===selectedId)
  21. $scope.selectedAlbum=album;
  22. });
  23. }
  24. function deleteSelected(){
  25. var images=getSelectedImageIds();
  26. if (images.length===0 || !confirm("Are you sure you want to delete?"))
  27. return;
  28. var data={
  29. selectedImages:images
  30. };
  31. $http.post("/gallery/deleteimages",data).then(function(response){
  32. updateAlbums(response.data);
  33. });
  34. };
  35. function moveImages(newAlbum){
  36. var images=getSelectedImageIds();
  37. if (images.length===0)
  38. return;
  39. var data={
  40. selectedImages:images,
  41. targetAlbumId:newAlbum.AlbumId
  42. };
  43. $http.post("/gallery/move",data).then(function(response){
  44. updateAlbums(response.data);
  45. });
  46. }
  47. $scope.$watch("albums", function(){
  48. if ($scope.selectedAlbum===undefined)
  49. $scope.selectedAlbum=$scope.albums[0];
  50. albumActions={};
  51. angular.forEach($scope.albums, function(album){
  52. albumActions[album.AlbumTitle]=function(){
  53. moveImages(album);
  54. };
  55. });
  56. $scope.contextMenuActions[moveIndex]=albumActions;
  57. });
  58. $scope.selectImage=function(image){
  59. image.selected=!image.selected;
  60. };
  61. $scope.editAlbum=function(album){
  62. Navigate("/gallery/editablum/"+album.AlbumId);
  63. };
  64. }]);