mirror of https://github.com/BTCPrivate/copay.git
Make directive to accept onScan and beforeScan callbacks instead of broadcasting 'dataScanned' event.
This will allow to reuse directive for screens different from 'send'
This commit is contained in:
parent
b673540638
commit
1f4f78bec0
|
@ -15,7 +15,7 @@
|
|||
</section>
|
||||
|
||||
<section class="right-small" ng-show="showCamera">
|
||||
<qr-scanner ng-show="index.isComplete"/>
|
||||
<qr-scanner ng-show="index.isComplete" on-scan="topbar.onQrCodeScanned(data)" before-scan="topbar.openSendScreen()" />
|
||||
</section>
|
||||
|
||||
<section class="middle tab-bar-section">
|
||||
|
|
|
@ -1,6 +1,14 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.controllers').controller('topbarController', function($rootScope, $scope, $timeout, $modal, isCordova, isMobile, go) {
|
||||
angular.module('copayApp.controllers').controller('topbarController', function($rootScope, go) {
|
||||
|
||||
this.onQrCodeScanned = function(data) {
|
||||
$rootScope.$emit('dataScanned', data);
|
||||
};
|
||||
|
||||
this.openSendScreen = function() {
|
||||
go.send();
|
||||
};
|
||||
|
||||
this.goHome = function() {
|
||||
go.walletHome();
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.directives')
|
||||
.directive('qrScanner', ['$rootScope', '$timeout', '$modal', 'isCordova', 'isMobile', 'go',
|
||||
function($rootScope, $timeout, $modal, isCordova, isMobile, go) {
|
||||
.directive('qrScanner', ['$rootScope', '$timeout', '$modal', 'isCordova',
|
||||
function($rootScope, $timeout, $modal, isCordova) {
|
||||
|
||||
var controller = function($scope) {
|
||||
|
||||
|
@ -20,7 +20,7 @@ angular.module('copayApp.directives')
|
|||
|
||||
$timeout(function() {
|
||||
var data = result.text;
|
||||
$rootScope.$emit('dataScanned', data);
|
||||
$scope.onScan({ data: data });
|
||||
}, 1000);
|
||||
},
|
||||
function onError(error) {
|
||||
|
@ -31,11 +31,12 @@ angular.module('copayApp.directives')
|
|||
alert('Scanning error');
|
||||
}
|
||||
);
|
||||
go.send();
|
||||
$scope.beforeScan();
|
||||
}, 100);
|
||||
};
|
||||
|
||||
$scope.modalOpenScanner = function() {
|
||||
var parentScope = $scope;
|
||||
var ModalInstanceCtrl = function($scope, $rootScope, $modalInstance) {
|
||||
// QR code Scanner
|
||||
var video;
|
||||
|
@ -89,7 +90,7 @@ angular.module('copayApp.directives')
|
|||
$scope.init = function() {
|
||||
setScanner();
|
||||
$timeout(function() {
|
||||
go.send();
|
||||
parentScope.beforeScan();
|
||||
canvas = document.getElementById('qr-canvas');
|
||||
context = canvas.getContext('2d');
|
||||
|
||||
|
@ -120,7 +121,7 @@ angular.module('copayApp.directives')
|
|||
keyboard: false
|
||||
});
|
||||
modalInstance.result.then(function(data) {
|
||||
$rootScope.$emit('dataScanned', data);
|
||||
parentScope.onScan({ data: data });
|
||||
});
|
||||
|
||||
};
|
||||
|
@ -137,6 +138,10 @@ angular.module('copayApp.directives')
|
|||
|
||||
return {
|
||||
restrict: 'E',
|
||||
scope: {
|
||||
onScan: "&",
|
||||
beforeScan: "&"
|
||||
},
|
||||
controller: controller,
|
||||
replace: true,
|
||||
template: '<a id="camera-icon" class="p10" ng-click="openScanner()"><i class="icon-scan size-21"></i></a>'
|
||||
|
|
Loading…
Reference in New Issue