1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
/**
* The image controller
*
* @param {$scope} $scope The $scope service from angular
*/
mainApp.controller('editImageCtrl', ['$scope', 'Image', 'Loading', 'Identity', 'upload', '$rootScope', function ($scope, Image, Loading, Identity, upload, $rootScope)
{
$scope.$on('editImageEvent', function (eventName, image, axioms) {
var list = $("#upload_button");
$.each(list, function(){$(this).detach();});
$scope.image = image;
$scope.data = {};
$scope.data.id = image.id;
if (image.protected) {
$scope.data.protected = "true";
} else {
$scope.data.protected = "false";
}
$scope.data.name = image.name;
$scope.data.visibility = image.visibility;
$scope.axioms = axioms;
$('#progress .bar').css(
'width',
'0%'
);
if(image.status != "queued"){
$("#fileupload").css('display','none');
$("#fileupload").val('');
$("#progress").css('display', 'none');
}else{
$("#fileupload").val('');
$("#fileupload").css('display','block');
$("#progress").css('display', 'block');
$("#fileupload").fileupload({
replaceFileInput: false,
formData: {task: "image", token: Identity.getToken(), action: "uploadImage", id: $scope.data.id},
/* ... */
progressall: function (e, data) {
var progress = parseInt(data.loaded / data.total * 100, 10);
$('#progress_text').html(progress+'%');
$('#progress .bar').css(
'width',
progress + '%'
);
},
add: function (e, data) {
data.process();
var list = $("#upload_button");
$.each(list, function(){$(this).detach();});
data.context = $('<button id="upload_button"/>').text('Upload')
.click(function () {
$(this).detach();
data.submit();
});
console.log("test");
$("#fileupload").after(data.context);
},
});
}
$('#editImageModal').modal('show');
});
$scope.applyEdition = function (id) {
Image.updateImage($scope.data, function () {
$rootScope.$broadcast("updateImageEvent");
$('#editImageModal').modal('hide');
});
};
$scope.getToken = function () {
return Identity.getToken();
}
}]);
|