diff --git a/client/js/controllers/image/edit.js b/client/js/controllers/image/edit.js index 60675be..fd52982 100644 --- a/client/js/controllers/image/edit.js +++ b/client/js/controllers/image/edit.js @@ -3,25 +3,33 @@ * * @param {$scope} $scope The $scope service from angular */ -mainApp.controller('editImageCtrl', ['$scope', 'Image', 'Loading', 'Identity', 'upload', function ($scope, Image, Loading, Identity, upload) +mainApp.controller('editImageCtrl', ['$scope', 'Image', 'Loading', 'Identity', 'upload', '$rootScope', function ($scope, Image, Loading, Identity, upload, $rootScope) { $scope.$on('editImageEvent', function (eventName, image, axioms) { $scope.image = image; + $scope.data = {}; + $scope.data.id = image.id; + + $scope.data.name = image.name; + $scope.data.visibility = image.visibility; + $scope.data.protected = image.protected; + $scope.axioms = axioms; $('#editImageModal').modal('show'); }); $scope.data = {}; - $scope.data.visibility = "public"; - $scope.data.protected = false; - - $scope.applyEdition = function (image) { - image.visibility = $scope.data.visibility; - image.protected = $scope.data.protected; - Image.updateImage(image, function(){}); + + + $scope.applyEdition = function (id) { + Image.updateImage($scope.data, function () { + $rootScope.$broadcast("updateImageEvent"); + $('#editImageModal').modal('hide'); + + }); }; - - $scope.getToken=function(){ + + $scope.getToken = function () { return Identity.getToken(); } }]); diff --git a/client/js/services/Image.js b/client/js/services/Image.js index f72de41..6b69f4a 100644 --- a/client/js/services/Image.js +++ b/client/js/services/Image.js @@ -63,11 +63,15 @@ mainApp.factory('Image', ['$http', 'Identity', function ($http, Identity) { * @returns {undefined} */ var updateImage = function (image, callback) { + console.log(image) + + var result = $http.post('../server/index.php', - $.param({"token": Identity.getToken(), "task": "image", 'action': 'updateImage', 'id': image.id, 'opt': image})); + $.param({"token": Identity.getToken(), "task": "image", 'action': 'updateImage', 'id': image.id, 'opt': {'name': image.name}})); // Wait and handle the response result.then(function (response) { + console.log(response.data.Images) callback(); }, function (response) { alert(response); diff --git a/client/partials/image/edit.html b/client/partials/image/edit.html index c3a7c0c..ce2c7fd 100644 --- a/client/partials/image/edit.html +++ b/client/partials/image/edit.html @@ -16,7 +16,7 @@