From 581622f83de9f28987c39bb4f58d55b219706387 Mon Sep 17 00:00:00 2001 From: Nick Cardin Date: Mon, 10 Oct 2016 23:02:19 -0400 Subject: [PATCH] feat(qr-scanner): update directive to use the new scan view --- src/js/directives/qrScanner.js | 83 +++++++--------------------------- 1 file changed, 17 insertions(+), 66 deletions(-) diff --git a/src/js/directives/qrScanner.js b/src/js/directives/qrScanner.js index 5e199d7c1..0a23819a5 100644 --- a/src/js/directives/qrScanner.js +++ b/src/js/directives/qrScanner.js @@ -1,77 +1,28 @@ 'use strict'; angular.module('copayApp.directives') - .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}); - }; + .directive('qrScanner', function($state, $rootScope, $log) { return { restrict: 'E', scope: { - onScan: "&", - setFn: "&", - beforeScan: "&" + onScan: "&" }, - controller: controller, replace: true, - template: '' + template: '', + link: function(scope, el, attrs) { + + scope.openScanner = function() { + $log.debug('Opening scanner by directive...'); + $state.go('scanner', { passthroughMode: 1 }); + }; + + $rootScope.$on('$ionicView.afterEnter', function() { + if($rootScope.scanResult) { + scope.onScan({ data: $rootScope.scanResult }); + $rootScope.scanResult = null; + } + }); + } } });