diff --git a/client/index.html b/client/index.html index 483d4ea..e5ca894 100755 --- a/client/index.html +++ b/client/index.html @@ -26,7 +26,7 @@
- + @@ -97,7 +97,7 @@ - + diff --git a/client/js/controllers/image/upload.js b/client/js/controllers/image/create.js similarity index 65% rename from client/js/controllers/image/upload.js rename to client/js/controllers/image/create.js index 8d62b50..cd761fd 100644 --- a/client/js/controllers/image/upload.js +++ b/client/js/controllers/image/create.js @@ -3,7 +3,7 @@ * * @param {$scope} $scope The $scope service from angular */ -mainApp.controller('uploadImageCtrl', ['$scope', 'Image', 'Loading', 'Identity', 'upload', function ($scope, Image, Loading, Identity, upload) +mainApp.controller('createImageCtrl', ['$scope', 'Image', 'Loading', 'Identity', 'upload','$rootScope', function ($scope, Image, Loading, Identity, upload, $rootScope) { /*$scope.uploader = new FileUploader({ "token" : Identity.getToken(), @@ -22,11 +22,11 @@ mainApp.controller('uploadImageCtrl', ['$scope', 'Image', 'Loading', 'Identity', */ $scope.doUpload = function () { - /* console.log($('#imageToUpload').prop('files')[0]); - Image.uploadImage($('#imageToUpload').prop('files')[0], function () { - alert("done"); - });*/ - Image.uploadImage("loic",function(){}) + /* console.log($('#imageToUpload').prop('files')[0]); + Image.uploadImage($('#imageToUpload').prop('files')[0], function () { + alert("done"); + });*/ + Image.uploadImage("loic", function () {}) /*$("#drop-area-div").dmUploader({ extraData: { "token" : Identity.getToken(), @@ -59,10 +59,22 @@ mainApp.controller('uploadImageCtrl', ['$scope', 'Image', 'Loading', 'Identity', }; // Manager logout event - $scope.$on('showUploadImageModalEvent', function () { - $scope.token = Identity.getToken(); + $scope.$on('showCreateImageModalEvent', function () { + $scope.token = Identity.getToken(); - $('#uploadImageModal').modal("show"); + $('#createImageModal').modal("show"); }); + var callMeAfterImageCreate = function (response) { + $rootScope.$broadcast("updateImageEvent"); + Loading.stop(); + + } + + $scope.doCreation = function () { + $('#createImageModal').modal("hide"); + Loading.start(); + Image.createImage($scope.name, callMeAfterImageCreate) + }; + }]); diff --git a/client/js/controllers/image/edit.js b/client/js/controllers/image/edit.js index 9bd4975..9fdb392 100644 --- a/client/js/controllers/image/edit.js +++ b/client/js/controllers/image/edit.js @@ -9,7 +9,6 @@ mainApp.controller('editImageCtrl', ['$scope', 'Image', 'Loading', 'Identity', ' $scope.image = image; $scope.axioms = axioms; $('#editImageModal').modal('show'); - console.log(image) }); $scope.data = {}; $scope.data.visibility = "public"; diff --git a/client/js/controllers/image/image.js b/client/js/controllers/image/image.js index 7ce3bb9..b402b52 100755 --- a/client/js/controllers/image/image.js +++ b/client/js/controllers/image/image.js @@ -22,13 +22,29 @@ mainApp.controller('imageCtrl', ['$scope', 'Image', 'Loading', 'Identity', '$roo } } + // Manager logout event + $scope.$on('updateImageEvent', function () { + // If user is login try to retrieve data + if (Identity.isAlreadyLogin()) { + Loading.start(); + Image.getImages(callMeAfterGetImage); + } + }); + $scope.edit = function (image) { $rootScope.$broadcast("editImageEvent", image, Image.getData().axioms); } - $scope.showUploadImageModal = function () { - $rootScope.$broadcast("showUploadImageModalEvent"); + $scope.showCreateImageModal = function () { + $rootScope.$broadcast("showCreateImageModalEvent"); }; + + $scope.deleteImage = function (id) { + Image.deleteImage(id, function () { + $rootScope.$broadcast("updateImageEvent"); + + }) + } }]); diff --git a/client/js/services/Image.js b/client/js/services/Image.js index ef4e0b1..9947869 100644 --- a/client/js/services/Image.js +++ b/client/js/services/Image.js @@ -148,6 +148,23 @@ mainApp.factory('Image', ['$http', 'Identity', function ($http, Identity) { callback() }); }; + var deleteImage = function (id,callback) { + + + var result = $http.post('../server/index.php', + $.param({"token": Identity.getToken(), "task": "image", 'action': 'deleteImage', "id":id})); + + //var result=$http.post('../server/index.php', + // $.param({"token" : Identity.getToken(), "task" : "image", 'action':'uploadImage', 'file_name':form_data, 'id':'6564'})); + + // Wait and handle the response + result.then(function (response) { + callback() + }, function (response) { + alert(response.data) + callback() + }); + }; @@ -160,6 +177,7 @@ mainApp.factory('Image', ['$http', 'Identity', function ($http, Identity) { getImages: getImages, updateImage: updateImage, getData: getData, + deleteImage:deleteImage, createImage: createImage, uploadImage: uploadImage }; diff --git a/client/partials/image/create.html b/client/partials/image/create.html new file mode 100644 index 0000000..ca479e5 --- /dev/null +++ b/client/partials/image/create.html @@ -0,0 +1,33 @@ +