+ };
+ window.ImageManager = imageManagerService;
+
+ /**
+ * Hide the image manager
+ */
+ $scope.hide = function () {
+ $scope.showing = false;
+ };
+
+ /**
+ * Fetch the list image data from the server.
+ */
+ function fetchData() {
+ var url = '/images/' + $scope.imageType + '/all/' + page;
+ $http.get(url).then((response) => {
+ $scope.images = $scope.images.concat(response.data.images);
+ $scope.hasMore = response.data.hasMore;
+ page++;
+ });
+ }
+ $scope.fetchData = fetchData;
+
+ /**
+ * Save the details of an image.
+ * @param event
+ */
+ $scope.saveImageDetails = function (event) {
+ event.preventDefault();
+ var url = '/images/update/' + $scope.selectedImage.id;
+ $http.put(url, this.selectedImage).then((response) => {
+ events.emit('success', 'Image details updated');
+ }, (response) => {
+ var errors = response.data;
+ var message = '';
+ Object.keys(errors).forEach((key) => {
+ message += errors[key].join('\n');
+ });
+ events.emit('error', message);
+ });
+ };
+
+ /**
+ * Delete an image from system and notify of success.
+ * Checks if it should force delete when an image
+ * has dependant pages.
+ * @param event
+ */
+ $scope.deleteImage = function (event) {
+ event.preventDefault();
+ var force = $scope.dependantPages !== false;
+ var url = '/images/' + $scope.selectedImage.id;
+ if (force) url += '?force=true';
+ $http.delete(url).then((response) => {
+ $scope.images.splice($scope.images.indexOf($scope.selectedImage), 1);
+ $scope.selectedImage = false;
+ events.emit('success', 'Image successfully deleted');
+ }, (response) => {
+ // Pages failure
+ if (response.status === 400) {
+ $scope.dependantPages = response.data;
+ }
+ });
+ };