2015-07-23 11:48:28 +03:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
angular.module('copayApp.directives')
|
2016-08-25 11:18:10 -03:00
|
|
|
.directive('qrScanner', function($rootScope, $timeout, $ionicModal, gettextCatalog, platformInfo) {
|
|
|
|
|
|
|
|
|
|
var isCordova = platformInfo.isCordova;
|
|
|
|
|
var isWP = platformInfo.isWP;
|
|
|
|
|
var isIOS = platformInfo.isIOS;
|
|
|
|
|
|
|
|
|
|
var controller = function($scope) {
|
|
|
|
|
|
|
|
|
|
var onSuccess = function(result) {
|
|
|
|
|
$timeout(function() {
|
|
|
|
|
window.plugins.spinnerDialog.hide();
|
|
|
|
|
}, 100);
|
|
|
|
|
if (isWP && result.cancelled) return;
|
|
|
|
|
|
|
|
|
|
$timeout(function() {
|
|
|
|
|
var data = isIOS ? result : result.text;
|
|
|
|
|
$scope.onScan({
|
|
|
|
|
data: data
|
|
|
|
|
});
|
|
|
|
|
}, 1000);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var onError = function(error) {
|
|
|
|
|
$timeout(function() {
|
|
|
|
|
window.plugins.spinnerDialog.hide();
|
|
|
|
|
}, 100);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$scope.cordovaOpenScanner = function() {
|
|
|
|
|
window.plugins.spinnerDialog.show(null, gettextCatalog.getString('Preparing camera...'), true);
|
|
|
|
|
$timeout(function() {
|
|
|
|
|
if (isIOS) {
|
|
|
|
|
cloudSky.zBar.scan({}, onSuccess, onError);
|
|
|
|
|
} else {
|
|
|
|
|
cordova.plugins.barcodeScanner.scan(onSuccess, onError);
|
|
|
|
|
}
|
|
|
|
|
if ($scope.beforeScan) {
|
|
|
|
|
$scope.beforeScan();
|
|
|
|
|
}
|
|
|
|
|
}, 100);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$scope.modalOpenScanner = function() {
|
|
|
|
|
$ionicModal.fromTemplateUrl('views/modals/scanner.html', {
|
|
|
|
|
scope: $scope,
|
|
|
|
|
animation: 'slide-in-up'
|
|
|
|
|
}).then(function(modal) {
|
|
|
|
|
$scope.scannerModal = modal;
|
|
|
|
|
$scope.scannerModal.show();
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$scope.openScanner = function() {
|
|
|
|
|
if (isCordova) {
|
|
|
|
|
$scope.cordovaOpenScanner();
|
|
|
|
|
} else {
|
|
|
|
|
$scope.modalOpenScanner();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
$scope.setFn({theScanFn: $scope.openScanner});
|
|
|
|
|
};
|
2016-05-31 16:52:38 -03:00
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
restrict: 'E',
|
|
|
|
|
scope: {
|
|
|
|
|
onScan: "&",
|
2016-08-25 11:18:10 -03:00
|
|
|
setFn: "&",
|
2016-05-31 16:52:38 -03:00
|
|
|
beforeScan: "&"
|
|
|
|
|
},
|
2016-08-25 11:18:10 -03:00
|
|
|
controller: controller,
|
2016-05-31 16:52:38 -03:00
|
|
|
replace: true,
|
2016-08-25 17:40:20 -03:00
|
|
|
template: '<a on-tap="openScanner()"><i class="icon ion-qr-scanner"></i></a>'
|
2016-05-31 16:52:38 -03:00
|
|
|
}
|
|
|
|
|
});
|