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
3 changed files with 21 additions and 8 deletions
|
|
@ -15,7 +15,7 @@
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<section class="right-small" ng-show="showCamera">
|
<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>
|
||||||
|
|
||||||
<section class="middle tab-bar-section">
|
<section class="middle tab-bar-section">
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,14 @@
|
||||||
'use strict';
|
'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() {
|
this.goHome = function() {
|
||||||
go.walletHome();
|
go.walletHome();
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('copayApp.directives')
|
angular.module('copayApp.directives')
|
||||||
.directive('qrScanner', ['$rootScope', '$timeout', '$modal', 'isCordova', 'isMobile', 'go',
|
.directive('qrScanner', ['$rootScope', '$timeout', '$modal', 'isCordova',
|
||||||
function($rootScope, $timeout, $modal, isCordova, isMobile, go) {
|
function($rootScope, $timeout, $modal, isCordova) {
|
||||||
|
|
||||||
var controller = function($scope) {
|
var controller = function($scope) {
|
||||||
|
|
||||||
|
|
@ -20,7 +20,7 @@ angular.module('copayApp.directives')
|
||||||
|
|
||||||
$timeout(function() {
|
$timeout(function() {
|
||||||
var data = result.text;
|
var data = result.text;
|
||||||
$rootScope.$emit('dataScanned', data);
|
$scope.onScan({ data: data });
|
||||||
}, 1000);
|
}, 1000);
|
||||||
},
|
},
|
||||||
function onError(error) {
|
function onError(error) {
|
||||||
|
|
@ -31,11 +31,12 @@ angular.module('copayApp.directives')
|
||||||
alert('Scanning error');
|
alert('Scanning error');
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
go.send();
|
$scope.beforeScan();
|
||||||
}, 100);
|
}, 100);
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.modalOpenScanner = function() {
|
$scope.modalOpenScanner = function() {
|
||||||
|
var parentScope = $scope;
|
||||||
var ModalInstanceCtrl = function($scope, $rootScope, $modalInstance) {
|
var ModalInstanceCtrl = function($scope, $rootScope, $modalInstance) {
|
||||||
// QR code Scanner
|
// QR code Scanner
|
||||||
var video;
|
var video;
|
||||||
|
|
@ -89,7 +90,7 @@ angular.module('copayApp.directives')
|
||||||
$scope.init = function() {
|
$scope.init = function() {
|
||||||
setScanner();
|
setScanner();
|
||||||
$timeout(function() {
|
$timeout(function() {
|
||||||
go.send();
|
parentScope.beforeScan();
|
||||||
canvas = document.getElementById('qr-canvas');
|
canvas = document.getElementById('qr-canvas');
|
||||||
context = canvas.getContext('2d');
|
context = canvas.getContext('2d');
|
||||||
|
|
||||||
|
|
@ -120,7 +121,7 @@ angular.module('copayApp.directives')
|
||||||
keyboard: false
|
keyboard: false
|
||||||
});
|
});
|
||||||
modalInstance.result.then(function(data) {
|
modalInstance.result.then(function(data) {
|
||||||
$rootScope.$emit('dataScanned', data);
|
parentScope.onScan({ data: data });
|
||||||
});
|
});
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
@ -137,6 +138,10 @@ angular.module('copayApp.directives')
|
||||||
|
|
||||||
return {
|
return {
|
||||||
restrict: 'E',
|
restrict: 'E',
|
||||||
|
scope: {
|
||||||
|
onScan: "&",
|
||||||
|
beforeScan: "&"
|
||||||
|
},
|
||||||
controller: controller,
|
controller: controller,
|
||||||
replace: true,
|
replace: true,
|
||||||
template: '<a id="camera-icon" class="p10" ng-click="openScanner()"><i class="icon-scan size-21"></i></a>'
|
template: '<a id="camera-icon" class="p10" ng-click="openScanner()"><i class="icon-scan size-21"></i></a>'
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue