ref controllers
This commit is contained in:
parent
dd1981a26c
commit
cc2853e827
4 changed files with 166 additions and 159 deletions
|
|
@ -1,12 +1,13 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('copayApp.controllers').controller('indexController', function($rootScope, $scope, $log, $filter, $timeout, latestReleaseService, bwcService, pushNotificationsService, lodash, go, profileService, configService, rateService, storageService, addressService, gettext, gettextCatalog, amMoment, nodeWebkit, addonManager, bwsError, txFormatService, uxLanguage, glideraService, coinbaseService, platformInfo, addressbookService, walletService) {
|
angular.module('copayApp.controllers').controller('indexController', function($rootScope, $scope, $log, $filter, $timeout, latestReleaseService, bwcService, pushNotificationsService, lodash, go, profileService, configService, rateService, storageService, addressService, gettext, gettextCatalog, amMoment, addonManager, bwsError, txFormatService, uxLanguage, glideraService, coinbaseService, platformInfo, addressbookService, walletService) {
|
||||||
var self = this;
|
var self = this;
|
||||||
var SOFT_CONFIRMATION_LIMIT = 12;
|
var SOFT_CONFIRMATION_LIMIT = 12;
|
||||||
var errors = bwcService.getErrors();
|
var errors = bwcService.getErrors();
|
||||||
var historyUpdateInProgress = {};
|
var historyUpdateInProgress = {};
|
||||||
var isChromeApp = platformInfo.isChromeApp;
|
var isChromeApp = platformInfo.isChromeApp;
|
||||||
var isCordova = platformInfo.isCordova;
|
var isCordova = platformInfo.isCordova;
|
||||||
|
var isNW = platformInfo.isNW;
|
||||||
|
|
||||||
var ret = {};
|
var ret = {};
|
||||||
ret.isCordova = isCordova;
|
ret.isCordova = isCordova;
|
||||||
|
|
@ -48,7 +49,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r
|
||||||
ret.tab = 'walletHome';
|
ret.tab = 'walletHome';
|
||||||
var vanillaScope = ret;
|
var vanillaScope = ret;
|
||||||
|
|
||||||
if (nodeWebkit.isDefined()) {
|
if (isNW) {
|
||||||
latestReleaseService.checkLatestRelease(function(err, newRelease) {
|
latestReleaseService.checkLatestRelease(function(err, newRelease) {
|
||||||
if (err) {
|
if (err) {
|
||||||
$log.warn(err);
|
$log.warn(err);
|
||||||
|
|
@ -741,7 +742,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r
|
||||||
$log.info('CSV generation not available in mobile');
|
$log.info('CSV generation not available in mobile');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var isNode = nodeWebkit.isDefined();
|
var isNode = isNW;
|
||||||
var fc = profileService.focusedClient;
|
var fc = profileService.focusedClient;
|
||||||
var c = fc.credentials;
|
var c = fc.credentials;
|
||||||
if (!fc.isComplete()) return;
|
if (!fc.isComplete()) return;
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('copayApp.controllers').controller('sidebarController',
|
angular.module('copayApp.controllers').controller('sidebarController',
|
||||||
function($rootScope, $timeout, lodash, profileService, configService, go, isMobile, isCordova) {
|
function($rootScope, $timeout, lodash, profileService, configService, go, platformInfo) {
|
||||||
var self = this;
|
var self = this;
|
||||||
self.isWindowsPhoneApp = isMobile.Windows() && isCordova;
|
self.isWindowsPhoneApp = platformInfo.isWP && platformInfo.isCordova;
|
||||||
self.walletSelection = false;
|
self.walletSelection = false;
|
||||||
|
|
||||||
// wallet list change
|
// wallet list change
|
||||||
|
|
|
||||||
|
|
@ -1,174 +1,179 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('copayApp.directives')
|
angular.module('copayApp.directives')
|
||||||
.directive('qrScanner', ['$rootScope', '$timeout', '$modal', 'isCordova', 'gettextCatalog', 'isMobile',
|
.directive('qrScanner', function($rootScope, $timeout, $modal, gettextCatalog, platformInfo) {
|
||||||
function($rootScope, $timeout, $modal, isCordova, gettextCatalog, isMobile) {
|
|
||||||
|
|
||||||
var controller = function($scope) {
|
var isCordova = platformInfo.isCordova;
|
||||||
|
var isWP = platformInfo.isWP;
|
||||||
|
var isIOS = platformInfo.isIOS;
|
||||||
|
|
||||||
var onSuccess = function(result) {
|
var controller = function($scope) {
|
||||||
$timeout(function() {
|
|
||||||
window.plugins.spinnerDialog.hide();
|
|
||||||
window.ignoreMobilePause = false;
|
|
||||||
}, 100);
|
|
||||||
if (isMobile.Windows() && result.cancelled) return;
|
|
||||||
|
|
||||||
$timeout(function() {
|
var onSuccess = function(result) {
|
||||||
var data = isMobile.iOS() ? result : result.text;
|
$timeout(function() {
|
||||||
$scope.onScan({ data: data });
|
window.plugins.spinnerDialog.hide();
|
||||||
}, 1000);
|
window.ignoreMobilePause = false;
|
||||||
};
|
}, 100);
|
||||||
|
if (isWP && result.cancelled) return;
|
||||||
|
|
||||||
var onError = function(error) {
|
$timeout(function() {
|
||||||
$timeout(function() {
|
var data = isiOS ? result : result.text;
|
||||||
window.ignoreMobilePause = false;
|
$scope.onScan({
|
||||||
window.plugins.spinnerDialog.hide();
|
data: data
|
||||||
}, 100);
|
});
|
||||||
};
|
}, 1000);
|
||||||
|
};
|
||||||
|
|
||||||
$scope.cordovaOpenScanner = function() {
|
var onError = function(error) {
|
||||||
window.ignoreMobilePause = true;
|
$timeout(function() {
|
||||||
window.plugins.spinnerDialog.show(null, gettextCatalog.getString('Preparing camera...'), true);
|
window.ignoreMobilePause = false;
|
||||||
$timeout(function() {
|
window.plugins.spinnerDialog.hide();
|
||||||
if (isMobile.iOS()) {
|
}, 100);
|
||||||
cloudSky.zBar.scan({}, onSuccess, onError);
|
};
|
||||||
} else {
|
|
||||||
cordova.plugins.barcodeScanner.scan(onSuccess, onError);
|
$scope.cordovaOpenScanner = function() {
|
||||||
|
window.ignoreMobilePause = true;
|
||||||
|
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() {
|
||||||
|
var parentScope = $scope;
|
||||||
|
var ModalInstanceCtrl = function($scope, $rootScope, $modalInstance) {
|
||||||
|
// QR code Scanner
|
||||||
|
var video;
|
||||||
|
var canvas;
|
||||||
|
var $video;
|
||||||
|
var context;
|
||||||
|
var localMediaStream;
|
||||||
|
var prevResult;
|
||||||
|
|
||||||
|
var _scan = function(evt) {
|
||||||
|
if (localMediaStream) {
|
||||||
|
context.drawImage(video, 0, 0, 300, 225);
|
||||||
|
try {
|
||||||
|
qrcode.decode();
|
||||||
|
} catch (e) {
|
||||||
|
//qrcodeError(e);
|
||||||
}
|
}
|
||||||
if ($scope.beforeScan) {
|
}
|
||||||
$scope.beforeScan();
|
$timeout(_scan, 800);
|
||||||
|
};
|
||||||
|
|
||||||
|
var _scanStop = function() {
|
||||||
|
if (localMediaStream && localMediaStream.active) {
|
||||||
|
var localMediaStreamTrack = localMediaStream.getTracks();
|
||||||
|
for (var i = 0; i < localMediaStreamTrack.length; i++) {
|
||||||
|
localMediaStreamTrack[i].stop();
|
||||||
}
|
}
|
||||||
}, 100);
|
} else {
|
||||||
|
try {
|
||||||
|
localMediaStream.stop();
|
||||||
|
} catch (e) {
|
||||||
|
// Older Chromium not support the STOP function
|
||||||
|
};
|
||||||
|
}
|
||||||
|
localMediaStream = null;
|
||||||
|
video.src = '';
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.modalOpenScanner = function() {
|
qrcode.callback = function(data) {
|
||||||
var parentScope = $scope;
|
if (prevResult != data) {
|
||||||
var ModalInstanceCtrl = function($scope, $rootScope, $modalInstance) {
|
prevResult = data;
|
||||||
// QR code Scanner
|
return;
|
||||||
var video;
|
}
|
||||||
var canvas;
|
_scanStop();
|
||||||
var $video;
|
$modalInstance.close(data);
|
||||||
var context;
|
|
||||||
var localMediaStream;
|
|
||||||
var prevResult;
|
|
||||||
|
|
||||||
var _scan = function(evt) {
|
|
||||||
if (localMediaStream) {
|
|
||||||
context.drawImage(video, 0, 0, 300, 225);
|
|
||||||
try {
|
|
||||||
qrcode.decode();
|
|
||||||
} catch (e) {
|
|
||||||
//qrcodeError(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$timeout(_scan, 800);
|
|
||||||
};
|
|
||||||
|
|
||||||
var _scanStop = function() {
|
|
||||||
if (localMediaStream && localMediaStream.active) {
|
|
||||||
var localMediaStreamTrack = localMediaStream.getTracks();
|
|
||||||
for (var i = 0; i < localMediaStreamTrack.length; i++) {
|
|
||||||
localMediaStreamTrack[i].stop();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
localMediaStream.stop();
|
|
||||||
} catch(e) {
|
|
||||||
// Older Chromium not support the STOP function
|
|
||||||
};
|
|
||||||
}
|
|
||||||
localMediaStream = null;
|
|
||||||
video.src = '';
|
|
||||||
};
|
|
||||||
|
|
||||||
qrcode.callback = function(data) {
|
|
||||||
if (prevResult != data) {
|
|
||||||
prevResult = data;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_scanStop();
|
|
||||||
$modalInstance.close(data);
|
|
||||||
};
|
|
||||||
|
|
||||||
var _successCallback = function(stream) {
|
|
||||||
video.src = (window.URL && window.URL.createObjectURL(stream)) || stream;
|
|
||||||
localMediaStream = stream;
|
|
||||||
video.play();
|
|
||||||
$timeout(_scan, 1000);
|
|
||||||
};
|
|
||||||
|
|
||||||
var _videoError = function(err) {
|
|
||||||
$scope.cancel();
|
|
||||||
};
|
|
||||||
|
|
||||||
var setScanner = function() {
|
|
||||||
navigator.getUserMedia = navigator.getUserMedia ||
|
|
||||||
navigator.webkitGetUserMedia || navigator.mozGetUserMedia ||
|
|
||||||
navigator.msGetUserMedia;
|
|
||||||
window.URL = window.URL || window.webkitURL ||
|
|
||||||
window.mozURL || window.msURL;
|
|
||||||
};
|
|
||||||
|
|
||||||
$scope.init = function() {
|
|
||||||
setScanner();
|
|
||||||
$timeout(function() {
|
|
||||||
if (parentScope.beforeScan) {
|
|
||||||
parentScope.beforeScan();
|
|
||||||
}
|
|
||||||
canvas = document.getElementById('qr-canvas');
|
|
||||||
context = canvas.getContext('2d');
|
|
||||||
|
|
||||||
|
|
||||||
video = document.getElementById('qrcode-scanner-video');
|
|
||||||
$video = angular.element(video);
|
|
||||||
canvas.width = 300;
|
|
||||||
canvas.height = 225;
|
|
||||||
context.clearRect(0, 0, 300, 225);
|
|
||||||
|
|
||||||
navigator.getUserMedia({
|
|
||||||
video: true
|
|
||||||
}, _successCallback, _videoError);
|
|
||||||
}, 500);
|
|
||||||
};
|
|
||||||
|
|
||||||
$scope.cancel = function() {
|
|
||||||
_scanStop();
|
|
||||||
$modalInstance.dismiss('cancel');
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
var modalInstance = $modal.open({
|
|
||||||
templateUrl: 'views/modals/scanner.html',
|
|
||||||
windowClass: 'full',
|
|
||||||
controller: ModalInstanceCtrl,
|
|
||||||
backdrop : 'static',
|
|
||||||
keyboard: false
|
|
||||||
});
|
|
||||||
modalInstance.result.then(function(data) {
|
|
||||||
parentScope.onScan({ data: data });
|
|
||||||
});
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.openScanner = function() {
|
var _successCallback = function(stream) {
|
||||||
if (isCordova) {
|
video.src = (window.URL && window.URL.createObjectURL(stream)) || stream;
|
||||||
$scope.cordovaOpenScanner();
|
localMediaStream = stream;
|
||||||
}
|
video.play();
|
||||||
else {
|
$timeout(_scan, 1000);
|
||||||
$scope.modalOpenScanner();
|
};
|
||||||
}
|
|
||||||
|
var _videoError = function(err) {
|
||||||
|
$scope.cancel();
|
||||||
|
};
|
||||||
|
|
||||||
|
var setScanner = function() {
|
||||||
|
navigator.getUserMedia = navigator.getUserMedia ||
|
||||||
|
navigator.webkitGetUserMedia || navigator.mozGetUserMedia ||
|
||||||
|
navigator.msGetUserMedia;
|
||||||
|
window.URL = window.URL || window.webkitURL ||
|
||||||
|
window.mozURL || window.msURL;
|
||||||
|
};
|
||||||
|
|
||||||
|
$scope.init = function() {
|
||||||
|
setScanner();
|
||||||
|
$timeout(function() {
|
||||||
|
if (parentScope.beforeScan) {
|
||||||
|
parentScope.beforeScan();
|
||||||
|
}
|
||||||
|
canvas = document.getElementById('qr-canvas');
|
||||||
|
context = canvas.getContext('2d');
|
||||||
|
|
||||||
|
|
||||||
|
video = document.getElementById('qrcode-scanner-video');
|
||||||
|
$video = angular.element(video);
|
||||||
|
canvas.width = 300;
|
||||||
|
canvas.height = 225;
|
||||||
|
context.clearRect(0, 0, 300, 225);
|
||||||
|
|
||||||
|
navigator.getUserMedia({
|
||||||
|
video: true
|
||||||
|
}, _successCallback, _videoError);
|
||||||
|
}, 500);
|
||||||
|
};
|
||||||
|
|
||||||
|
$scope.cancel = function() {
|
||||||
|
_scanStop();
|
||||||
|
$modalInstance.dismiss('cancel');
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
return {
|
var modalInstance = $modal.open({
|
||||||
restrict: 'E',
|
templateUrl: 'views/modals/scanner.html',
|
||||||
scope: {
|
windowClass: 'full',
|
||||||
onScan: "&",
|
controller: ModalInstanceCtrl,
|
||||||
beforeScan: "&"
|
backdrop: 'static',
|
||||||
},
|
keyboard: false
|
||||||
controller: controller,
|
});
|
||||||
replace: true,
|
modalInstance.result.then(function(data) {
|
||||||
template: '<a id="camera-icon" class="p10" ng-click="openScanner()"><i class="icon-scan size-21"></i></a>'
|
parentScope.onScan({
|
||||||
|
data: data
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
$scope.openScanner = function() {
|
||||||
|
if (isCordova) {
|
||||||
|
$scope.cordovaOpenScanner();
|
||||||
|
} else {
|
||||||
|
$scope.modalOpenScanner();
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
]);
|
};
|
||||||
|
|
||||||
|
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>'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,8 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('copayApp.services').factory('txStatus', function($modal, lodash, profileService, $timeout, txFormatService, isCordova) {
|
angular.module('copayApp.services').factory('txStatus', function($modal, lodash, profileService, $timeout, txFormatService, platformInfo) {
|
||||||
var root = {};
|
var root = {};
|
||||||
|
var isCordova = platformInfo.isCordova;
|
||||||
|
|
||||||
root.notify = function(txp, cb) {
|
root.notify = function(txp, cb) {
|
||||||
var fc = profileService.focusedClient;
|
var fc = profileService.focusedClient;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue