2016-03-21 06:47:01 +01:00
/ * *
* The image controller
*
* @ param { $scope } $scope The $scope service from angular
* /
2016-05-06 14:24:15 +02:00
mainApp . controller ( 'createImageCtrl' , [ '$scope' , 'Image' , 'Loading' , 'Identity' , 'upload' , '$rootScope' , function ( $scope , Image , Loading , Identity , upload , $rootScope )
2016-04-17 18:50:05 +02:00
{
2016-03-21 06:47:01 +01:00
/ * $ s c o p e . u p l o a d e r = n e w F i l e U p l o a d e r ( {
2016-04-17 18:50:05 +02:00
"token" : Identity . getToken ( ) ,
"task" : "image" ,
'action' : 'uploadImage' ,
'id' : '6564'
} ) ;
$scope . uploader . url = '../server/index.php'
$scope . uploader . alias = 'file_name'
$scope . uploader . formData = {
"token" : Identity . getToken ( ) ,
"task" : "image" ,
'action' : 'uploadImage' ,
'id' : '6564'
}
* /
2016-03-21 06:47:01 +01:00
2016-04-17 18:50:05 +02:00
$scope . doUpload = function ( ) {
2016-05-06 14:24:15 +02:00
/ * c o n s o l e . l o g ( $ ( ' # i m a g e T o U p l o a d ' ) . p r o p ( ' f i l e s ' ) [ 0 ] ) ;
Image . uploadImage ( $ ( '#imageToUpload' ) . prop ( 'files' ) [ 0 ] , function ( ) {
alert ( "done" ) ;
} ) ; * /
Image . uploadImage ( "loic" , function ( ) { } )
2016-04-17 18:50:05 +02:00
/ * $ ( " # d r o p - a r e a - d i v " ) . d m U p l o a d e r ( {
extraData : {
"token" : Identity . getToken ( ) ,
"task" : "image" ,
'action' : 'uploadImage' ,
'id' : '6564' } ,
url : "../server/index.php"
} ) ;
* /
/ * u p l o a d ( {
url : '../server/index.php' ,
method : 'POST' ,
data : {
"token" : Identity . getToken ( ) ,
"task" : "image" ,
'action' : 'uploadImage' ,
'id' : '6564' ,
"file_name" : $scope . myFile , // a jqLite type="file" element, upload() will extract all the files from the input and put them into the FormData object before sending.
}
} ) . then (
function ( response ) {
console . log ( response . data ) ; // will output whatever you choose to return from the server on a successful upload
} ,
function ( response ) {
console . error ( response ) ; // Will return if status code is above 200 and lower than 300, same as $http
}
) ; * /
} ;
2016-05-06 14:06:56 +02:00
// Manager logout event
2016-05-06 14:24:15 +02:00
$scope . $on ( 'showCreateImageModalEvent' , function ( ) {
$scope . token = Identity . getToken ( ) ;
2016-05-06 14:06:56 +02:00
2016-05-06 14:24:15 +02:00
$ ( '#createImageModal' ) . modal ( "show" ) ;
2016-05-06 14:06:56 +02:00
} ) ;
2016-04-17 18:50:05 +02:00
2016-05-06 14:24:15 +02:00
var callMeAfterImageCreate = function ( response ) {
$rootScope . $broadcast ( "updateImageEvent" ) ;
Loading . stop ( ) ;
}
$scope . doCreation = function ( ) {
$ ( '#createImageModal' ) . modal ( "hide" ) ;
Loading . start ( ) ;
Image . createImage ( $scope . name , callMeAfterImageCreate )
} ;
2016-04-17 18:50:05 +02:00
} ] ) ;