﻿'use strict';

angular.module('myApp.upload', ['ngRoute', 'angularFileUpload'])

.config(['$routeProvider', function ($routeProvider) {
        $routeProvider.when('/upload/inline', {
            templateUrl: 'upload/inline.html',
            controller: 'inlineCtrl'
        });
    }])

.controller('inlineCtrl', ['$scope', 'FileUploader', 'inlineService', function ($scope, FileUploader, inlineService) {
        
        inlineService.getQiniuToken().then(function (token) {
            $scope.token = token;
        });
        
        var uploader = $scope.uploader = new FileUploader({
            url: 'http://upload.qiniu.com',
            autoUpload: true
        });
        
        $scope.currentFile = "";
        
        uploader.onWhenAddingFileFailed = function (item /*{File|FileLikeObject}*/, filter, options) {
            console.info('onWhenAddingFileFailed', item, filter, options);
        };
        uploader.onAfterAddingFile = function (fileItem) {
            console.info('onAfterAddingFile', fileItem);
            $scope.currentFile = fileItem.name;
        };
        uploader.onAfterAddingAll = function (addedFileItems) {
            console.info('onAfterAddingAll', addedFileItems);
        };
        uploader.onBeforeUploadItem = function (item) {
            console.info('onBeforeUploadItem', item);
            item.formData.push({ token: $scope.token });
            item.formData.push({ key: item.file.name });
        };
        uploader.onProgressItem = function (fileItem, progress) {
            console.info('onProgressItem', fileItem, progress);
        };
        uploader.onProgressAll = function (progress) {
            console.info('onProgressAll', progress);
        };
        uploader.onSuccessItem = function (fileItem, response, status, headers) {
            console.info('onSuccessItem', fileItem, response, status, headers);
        };
        uploader.onErrorItem = function (fileItem, response, status, headers) {
            console.info('onErrorItem', fileItem, response, status, headers);
        };
        uploader.onCancelItem = function (fileItem, response, status, headers) {
            console.info('onCancelItem', fileItem, response, status, headers);
        };
        uploader.onCompleteItem = function (fileItem, response, status, headers) {
            console.info('onCompleteItem', fileItem, response, status, headers);
            fileItem.url = "http://7xsvf8.com1.z0.glb.clouddn.com/" + response.key;
        };
        uploader.onCompleteAll = function () {
            console.info('onCompleteAll');
        };


    }]);
@@ -724,32 +724,34 @@
        %0A        
+//
 uploader.onWhenA
@@ -829,32 +829,34 @@
 ions) %7B%0A        
+//
     console.info
@@ -906,32 +906,34 @@
 tions);%0A        
+//
 %7D;%0A        uploa
@@ -1094,32 +1094,34 @@
      %7D;%0A        
+//
 uploader.onAfter
@@ -1160,32 +1160,34 @@
 tems) %7B%0A        
+//
     console.info
@@ -1224,32 +1224,34 @@
 Items);%0A        
+//
 %7D;%0A        uploa
@@ -1472,32 +1472,34 @@
      %7D;%0A        
+//
 uploader.onProgr
@@ -1540,32 +1540,34 @@
 ress) %7B%0A        
+//
     console.info
@@ -1606,32 +1606,34 @@
 gress);%0A        
+//
 %7D;%0A        uploa
@@ -1619,32 +1619,34 @@
    //%7D;%0A        
+//
 uploader.onProgr
@@ -1676,32 +1676,34 @@
 ress) %7B%0A        
+//
     console.info
@@ -1731,32 +1731,34 @@
 gress);%0A        
+//
 %7D;%0A        uploa
@@ -1744,32 +1744,34 @@
    //%7D;%0A        
+//
 uploader.onSucce
@@ -1828,32 +1828,34 @@
 ders) %7B%0A        
+//
     console.info
@@ -1910,32 +1910,34 @@
 aders);%0A        
+//
 %7D;%0A        uploa
@@ -1923,32 +1923,34 @@
    //%7D;%0A        
+//
 uploader.onError
@@ -2005,32 +2005,34 @@
 ders) %7B%0A        
+//
     console.info
@@ -2085,32 +2085,34 @@
 aders);%0A        
+//
 %7D;%0A        uploa
@@ -2098,32 +2098,34 @@
    //%7D;%0A        
+//
 uploader.onCance
@@ -2181,32 +2181,34 @@
 ders) %7B%0A        
+//
     console.info
@@ -2262,32 +2262,34 @@
 aders);%0A        
+//
 %7D;%0A        uploa
@@ -2534,32 +2534,34 @@
      %7D;%0A        
+//
 uploader.onCompl
@@ -2583,32 +2583,34 @@
 on () %7B%0A        
+//
     console.info
@@ -2636,16 +2636,18 @@
         
+//
 %7D;%0A%0A%0A   

comment unneccesary code.