pyc-website
main website for pyc inc.
git clone https://9o.is/git/pyc-website.git
IdVerification.js
(2262B)
1 angular.module("IdVerification", ['Forms', 'ngAlert', 'angularFileUpload'])
2
3 .controller('IdVerificationAlert', ['$scope', '$controller', function($scope, $controller) {
4 $controller('AlertCtrl', {$scope: $scope});
5
6 $scope.$on('alertIdVerification', function(event, alert) {
7 $scope.addAlert(alert);
8 });
9 }])
10
11 .controller('IdVerificationCtrl', ['$scope', '$controller', '$rootScope', '$fileUploader', function($scope, $controller, $rootScope, $fileUploader) {
12 $controller('FormCtrl', {$scope: $scope, $controller: $controller});
13
14 $scope.uploader = $fileUploader.create({
15 scope: $scope,
16 url: '/settings/verification/upload'
17 });
18
19 // file must be an image
20 $scope.uploader.filters.push(function(item) {
21 var type = $scope.uploader.isHTML5 ? item.type : '/' + item.value.slice(item.value.lastIndexOf('.') + 1);
22 type = '|' + type.toLowerCase().slice(type.lastIndexOf('/') + 1) + '|';
23 return '|jpg|png|jpeg|pdf|'.indexOf(type) !== -1;
24 });
25
26 // file must be less than 5 MB (5243000 bytes)
27 $scope.uploader.filters.push(function(item) {
28 return item.size < 5243000;
29 });
30
31 // 1 file max are allowed
32 $scope.uploader.queueLimit = 1;
33
34 // 1 file minimum required before submitting
35 $scope.filesRequired = function() {
36 return $scope.uploader.queue.length < 1;
37 };
38
39 $scope.uploader.bind('whenaddingfilefailed', function () {
40 $rootScope.$broadcast('alertIdVerification', {msg_type: "danger", msg: "Your file could not be added."});
41 });
42
43 $scope.uploader.bind('error', function () {
44 $rootScope.$broadcast('alertIdVerification', {msg_type: "danger", msg: "Your file could not be uploaded. Please try again."});
45 });
46
47 $scope.uploader.bind('success', function () {
48 var success = function(alert) {
49 $rootScope.purchaseLimit = alert.data.purchaseLimit;
50 $rootScope.$broadcast('alertIdVerification', alert);
51 //$state.go($state.$current, null, { reload: true });
52 $scope.uploader.clearQueue();
53 $scope.reset();
54 };
55
56 var failure = function(alert) {
57 $rootScope.$broadcast('alertIdVerification', alert);
58 };
59
60 $scope.submit('IdVerification', 'submit', success, failure);
61 });
62
63 $scope.save = function() {
64 $scope.loading = true;
65 $scope.uploader.uploadAll();
66 };
67 }]);