soter/soter/static/app/album/album.controller.js

81 lines
2.6 KiB
JavaScript

(function () {
'use strict';
angular.module('soter')
.controller('AlbumListController', ['$scope', 'albums', AlbumListController])
.controller('AlbumController', ['$scope', '$location', 'album', AlbumController])
.controller('AlbumPicturesController', ['$scope', 'info', 'Upload', AlbumPicturesController]);
function AlbumListController($scope, albums) {
$scope.info = albums;
}
function AlbumController($scope, $location, album) {
$scope.album = album;
$scope.save = function () {
$scope.album.$save(function (u, putResponseHeaders) {
$scope.toasts.push({Type: 'Success', Message: ''});
$location.path('/albums')
}, function (data, status) {
$scope.toasts.push({Type: 'Danger', Message: data.data});
});
};
$scope.delete = function () {
$scope.album.$delete(function (u, putResponseHeaders) {
$scope.toasts.push({Type: 'Success', Message: ''});
$location.path('/albums')
}, function (data, status) {
$scope.toasts.push({Type: 'Danger', Message: data.data});
});
};
$('#txtName').focus();
}
function AlbumPicturesController($scope, info, Upload) {
$scope.info = info;
$scope.upload = function (files) {
if (files && files.length) {
for (var i = 0; i < files.length; i++) {
var file = files[i];
Upload.upload({
url: '/v1/upload',
fields: {'album': info.id},
file: file
}).progress(function (evt) {
var progressPercentage = parseInt(100.0 * evt.loaded / evt.total);
console.log('progress: ' + progressPercentage + '% ' + evt.config.file.name);
}).success(function (data, status, headers, config) {
console.log('file ' + config.file.name + 'uploaded. Response: ' + data);
});
}
}
};
}
})();
var AlbumCtrlResolve = {
album: ['$route', 'Album', function ($route, Album) {
var id = $route.current.params.id;
return Album.get({id: id}).$promise;
}]
};
var AlbumListCtrlResolve = {
albums: ['Album', function (Album) {
return Album.query({}).$promise;
}]
};
var AlbumPicturesCtrlResolve = {
info: ['$route', 'Album', function ($route, Album) {
var id = $route.current.params.id;
return Album.pictures({id: id}).$promise;
}]
};