summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLoic GUEGAN <loic@Manzerbredes.home>2016-04-27 17:03:29 +0200
committerLoic GUEGAN <loic@Manzerbredes.home>2016-04-27 17:03:29 +0200
commit9a93133272efc239368252bbf4e0eee1791fd911 (patch)
treeb6e1a94cd103bf5c33e3e735d72f463cfe56950b
parent3c72415dcda4ca43a2adf9a0254d51cc6ce196c3 (diff)
parent1cdc04c5f10d57e56a049481d53c3f1006229fcb (diff)
Merge branch 'loic-image-edition' into loic
-rwxr-xr-xclient/index.html3
-rw-r--r--client/js/controllers/image/edit.js24
-rwxr-xr-xclient/js/controllers/image/image.js7
-rw-r--r--client/js/services/Image.js27
-rw-r--r--client/partials/image/edit.html46
-rw-r--r--client/partials/image/image.html57
-rw-r--r--client/partials/image/upload.html5
7 files changed, 138 insertions, 31 deletions
diff --git a/client/index.html b/client/index.html
index 43659d0..d04955c 100755
--- a/client/index.html
+++ b/client/index.html
@@ -26,6 +26,7 @@
<div ng-include="'./partials/home/machineDetails.html'"></div>
<div ng-include="'./partials/loading.html'"></div>
<div ng-include="'./partials/image/upload.html'"></div>
+ <div ng-include="'./partials/image/edit.html'"></div>
<!-- MAIN GRID -->
@@ -95,6 +96,8 @@
<script src="./js/controllers/network/network.js"></script>
<script src="./js/controllers/image/image.js"></script>
<script src="./js/controllers/image/upload.js"></script>
+ <script src="./js/controllers/image/edit.js"></script>
+
<!-- Includes and dependencies for jointJS -->
diff --git a/client/js/controllers/image/edit.js b/client/js/controllers/image/edit.js
new file mode 100644
index 0000000..9bd4975
--- /dev/null
+++ b/client/js/controllers/image/edit.js
@@ -0,0 +1,24 @@
+/**
+ * The image controller
+ *
+ * @param {$scope} $scope The $scope service from angular
+ */
+mainApp.controller('editImageCtrl', ['$scope', 'Image', 'Loading', 'Identity', 'upload', function ($scope, Image, Loading, Identity, upload)
+ {
+ $scope.$on('editImageEvent', function (eventName, image, axioms) {
+ $scope.image = image;
+ $scope.axioms = axioms;
+ $('#editImageModal').modal('show');
+ console.log(image)
+ });
+ $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(){});
+
+ };
+ }]);
diff --git a/client/js/controllers/image/image.js b/client/js/controllers/image/image.js
index 28aeb55..d5034d3 100755
--- a/client/js/controllers/image/image.js
+++ b/client/js/controllers/image/image.js
@@ -3,7 +3,7 @@
*
* @param {$scope} $scope The $scope service from angular
*/
-mainApp.controller('imageCtrl', ['$scope', 'Image', 'Loading', 'Identity', function ($scope, Image, Loading, Identity)
+mainApp.controller('imageCtrl', ['$scope', 'Image', 'Loading', 'Identity','$rootScope', function ($scope, Image, Loading, Identity, $rootScope)
{
// Update view
var callMeAfterGetImage = function () {
@@ -20,4 +20,9 @@ mainApp.controller('imageCtrl', ['$scope', 'Image', 'Loading', 'Identity', funct
callMeAfterGetImage();
}
}
+
+ $scope.edit=function(image){
+ $rootScope.$broadcast("editImageEvent", image, Image.getData().axioms);
+
+ }
}]);
diff --git a/client/js/services/Image.js b/client/js/services/Image.js
index 795f85e..90f3a48 100644
--- a/client/js/services/Image.js
+++ b/client/js/services/Image.js
@@ -4,7 +4,9 @@ mainApp.factory('Image', ['$http', 'Identity', function ($http, Identity) {
// Data object
var data = {};
data.images = null; // Images
-
+ data.axioms = {};
+ data.axioms.protected = [true, false];
+ data.axioms.visibility = ["public", "private"];
/**
* Parse uploadImage anwser
* @param {type} response
@@ -54,6 +56,28 @@ mainApp.factory('Image', ['$http', 'Identity', function ($http, Identity) {
};
/**
+ * Update image
+ * @param {type} image
+ * @param {type} callback
+ * @returns {undefined}
+ */
+ var updateImage = function (image, callback) {
+ var result = $http.post('../server/index.php',
+ $.param({"token": Identity.getToken(), "task": "image", 'action': 'updateImage', 'id': image.id, 'opt': image}));
+
+ // Wait and handle the response
+ result.then(function (response) {
+ callback();
+ }, function (response) {
+ alert(response)
+ });
+
+
+ };
+
+
+
+ /**
* Upload an image
* @param {type} fileToUpload
* @param {type} callback
@@ -106,6 +130,7 @@ mainApp.factory('Image', ['$http', 'Identity', function ($http, Identity) {
// Return services objects
return {
getImages: getImages,
+ updateImage: updateImage,
getData: getData,
uploadImage: uploadImage
};
diff --git a/client/partials/image/edit.html b/client/partials/image/edit.html
new file mode 100644
index 0000000..4420f52
--- /dev/null
+++ b/client/partials/image/edit.html
@@ -0,0 +1,46 @@
+<div class="modal fade" id="editImageModal" ng-controller="editImageCtrl">
+ <div class="modal-dialog">
+ <div class="modal-content"></div>
+ </div>
+ <div class="modal-dialog">
+ <div class="modal-content">
+ <div class="modal-header">
+ <!--<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>-->
+ <h4 class="modal-title">Edit Image</h4>
+
+ </div>
+
+ <div class="modal-body">
+
+ <form class="form-horizontal" role="form">
+ <div class="form-group">
+ <label class="control-label col-sm-2">Name</label>
+ <div class="col-sm-20">
+ <input type="text" value="{{ image.name}}" />
+ </div>
+
+ </div>
+ <fieldset class="form-group">
+ <label class="control-label col-sm-2">Visibility</label>
+ <select class="col-sm-20" id="visibilitySelected" ng-model="data.visibility">
+ <option ng-repeat="visibility in axioms.visibility" ng-selected="image.visibility == visibility">{{ visibility}}</option>
+ </select>
+ </fieldset>
+ <fieldset class="form-group">
+ <label class="control-label col-sm-2">Protected</label>
+ <select class="col-sm-20" id="protectedSelected" ng-model="data.protected">
+ <option ng-repeat="protected in axioms.protected" ng-selected="image.protected == protected">{{ protected}}</option>
+ </select>
+ </fieldset>
+
+ </form>
+ <div class="modal-footer">
+ <!--<a href="#" data-dismiss="modal" class="btn btn-default">Close</a>-->
+
+ <a class="btn btn-lg btn-primary btn-block" ng-click="applyEdition(image)" >Apply</a>
+ </div>
+ </div>
+
+ </div>
+ </div>
+</div>
diff --git a/client/partials/image/image.html b/client/partials/image/image.html
index 886a11d..9c17c2f 100644
--- a/client/partials/image/image.html
+++ b/client/partials/image/image.html
@@ -6,33 +6,36 @@
</div>
<div class="panel-body">
-
- <div class="btn-group btn-group-md" role="group" aria-label="...">
- <button type="button" class="btn btn-default" data-toggle="modal" data-target="#uploadImageModal"">Upload</button>
- <button type="button" class="btn btn-default">Download</button>
- </div>
- <p></p>
- <table class="table table-hover">
- <thead>
- <tr>
- <th>Name</th>
- <th>Size</th>
- <th>Action</th>
- </tr>
- </thead>
- <tbody>
- <tr ng-repeat="image in images">
- <td>{{ image.name }}</td>
- <td>{{ (image.size / 1048576).toFixed(2) }} MB</td>
- <td><button type="button" class="btn btn-danger">Remove</button></td>
- </tr>
-
- </tbody>
- </table>
-
-
-
-
+
+ <div class="btn-group btn-group-md" role="group" aria-label="...">
+ <button type="button" class="btn btn-default" data-toggle="modal" data-target="#uploadImageModal">Upload</button>
+ <button type="button" class="btn btn-default">Download</button>
+ </div>
+ <p></p>
+ <table class="table table-hover">
+ <thead>
+ <tr>
+ <th>Name</th>
+ <th>Size</th>
+ <th>Action</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr ng-repeat="image in images">
+ <td>{{ image.name}}</td>
+ <td>{{ (image.size / 1048576).toFixed(2)}} MB</td>
+ <td>
+ <button type="button" class="btn btn-primary" ng-click="edit(image)">Edit</button>
+ <button type="button" class="btn btn-danger">Remove</button>
+ </td>
+ </tr>
+
+ </tbody>
+ </table>
+
+
+
+
</div>
</div>
diff --git a/client/partials/image/upload.html b/client/partials/image/upload.html
index 01c54b2..641646b 100644
--- a/client/partials/image/upload.html
+++ b/client/partials/image/upload.html
@@ -16,11 +16,12 @@
<input type="hidden" name="task" value="image" />
<input type="hidden" name="token" value="{{ token }}" />
<input type="hidden" name="action" value="uploadImage" />
- <input type="hidden" name="id" value="2564" />
+ <input type="hidden" name="id" value="60ed9403-419e-4ea8-933f-dd1750d97360" />
+ <input type="hidden" name="file_name" value="bob.iso" />
<input name="file" type="file" />
<input type="submit" value="Upload" />
</form>
-
+
<div class="modal-footer">
<!--<a href="#" data-dismiss="modal" class="btn btn-default">Close</a>-->