|
| 1 | +/* |
| 2 | + * jQuery File Upload Plugin Angular JS Example 1.0 |
| 3 | + * https://github.com/blueimp/jQuery-File-Upload |
| 4 | + * |
| 5 | + * Copyright 2013, Sebastian Tschan |
| 6 | + * https://blueimp.net |
| 7 | + * |
| 8 | + * Licensed under the MIT license: |
| 9 | + * http://www.opensource.org/licenses/MIT |
| 10 | + */ |
| 11 | + |
| 12 | +/*global window, angular */ |
| 13 | + |
| 14 | +(function () { |
| 15 | + 'use strict'; |
| 16 | + |
| 17 | + var isOnGitHub = window.location.hostname === 'blueimp.github.com' || |
| 18 | + window.location.hostname === 'blueimp.github.io', |
| 19 | + url = isOnGitHub ? '//jquery-file-upload.appspot.com/' : 'server/php/'; |
| 20 | + |
| 21 | + angular.module('demo', [ |
| 22 | + 'blueimp.fileupload' |
| 23 | + ]) |
| 24 | + .config([ |
| 25 | + '$httpProvider', 'fileUploadProvider', |
| 26 | + function ($httpProvider, fileUploadProvider) { |
| 27 | + if (isOnGitHub) { |
| 28 | + // Demo settings: |
| 29 | + delete $httpProvider.defaults.headers.common['X-Requested-With']; |
| 30 | + angular.extend(fileUploadProvider.defaults, { |
| 31 | + disableImageResize: false, |
| 32 | + maxFileSize: 5000000, |
| 33 | + acceptFileTypes: /(\.|\/)(gif|jpe?g|png)$/i |
| 34 | + }); |
| 35 | + } |
| 36 | + } |
| 37 | + ]) |
| 38 | + |
| 39 | + .controller('DemoFileUploadController', [ |
| 40 | + '$scope', '$http', |
| 41 | + function ($scope, $http) { |
| 42 | + if (!isOnGitHub) { |
| 43 | + $scope.loadingFiles = true; |
| 44 | + $scope.options = { |
| 45 | + url: url |
| 46 | + }; |
| 47 | + $http.get(url) |
| 48 | + .then( |
| 49 | + function (response) { |
| 50 | + $scope.loadingFiles = false; |
| 51 | + $scope.queue = response.data.files; |
| 52 | + }, |
| 53 | + function () { |
| 54 | + $scope.loadingFiles = false; |
| 55 | + } |
| 56 | + ); |
| 57 | + } |
| 58 | + } |
| 59 | + ]) |
| 60 | + |
| 61 | + .controller('FileDestroyController', [ |
| 62 | + '$scope', '$http', |
| 63 | + function ($scope, $http) { |
| 64 | + var file = $scope.file, |
| 65 | + state; |
| 66 | + if (file.url) { |
| 67 | + file.$state = function () { |
| 68 | + return state; |
| 69 | + }; |
| 70 | + file.$destroy = function () { |
| 71 | + state = 'pending'; |
| 72 | + return $http({ |
| 73 | + url: file.delete_url, |
| 74 | + method: file.delete_type |
| 75 | + }).then( |
| 76 | + function () { |
| 77 | + state = 'resolved'; |
| 78 | + $scope.clear(file); |
| 79 | + }, |
| 80 | + function () { |
| 81 | + state = 'rejected'; |
| 82 | + } |
| 83 | + ); |
| 84 | + }; |
| 85 | + } |
| 86 | + } |
| 87 | + ]); |
| 88 | + |
| 89 | +}()); |
0 commit comments