Wallet/js/services/go.js

91 lines
2 KiB
JavaScript
Raw Normal View History

2014-12-07 12:44:50 -03:00
'use strict';
angular.module('copayApp.services').factory('go', function($window, $rootScope, $location) {
2014-12-07 12:44:50 -03:00
var root = {};
var hideSidebars = function() {
2014-12-07 14:12:58 -03:00
if (typeof document === 'undefined')
return;
2014-12-07 12:44:50 -03:00
// hack to hide sidebars and use ng-click (no href=)
var win = angular.element($window);
2014-12-07 14:12:58 -03:00
var elem = angular.element(document.querySelector('#off-canvas-wrap'))
2014-12-07 12:44:50 -03:00
elem.removeClass('move-right');
elem.removeClass('move-left');
};
2014-12-08 12:45:12 -03:00
var toggleSidebar = function(invert) {
if (typeof document === 'undefined')
return;
2014-12-08 12:45:12 -03:00
var elem = angular.element(document.querySelector('#off-canvas-wrap'));
var leftbarActive = angular.element(document.getElementsByClassName('move-right')).length;
var rightbarActive = angular.element(document.getElementsByClassName('move-left')).length;
if (invert) {
2014-12-08 12:45:12 -03:00
if (rightbarActive) {
hideSidebars();
}
else {
elem.addClass('move-right');
}
}
2014-12-08 12:45:12 -03:00
else {
if (leftbarActive) {
hideSidebars();
}
else {
elem.addClass('move-left');
}
}
};
2014-12-09 16:11:56 -03:00
root.openExternalLink = function(url) {
var ref = window.open(url, '_blank', 'location=no');
};
root.path = function(path) {
2014-12-07 12:44:50 -03:00
var parts = path.split('#');
$location.path(parts[0]);
if (parts[1])
$location.hash(parts[1]);
hideSidebars();
};
root.swipe = function(invert) {
2014-12-08 12:45:12 -03:00
toggleSidebar(invert);
};
root.walletHome = function() {
var w = $rootScope.wallet;
preconditions.checkState(w);
$rootScope.starting = false;
2014-12-09 11:52:01 -03:00
if (!w.isComplete()) {
root.path('copayers');
} else {
if ($rootScope.pendingPayment) {
root.path('selectWalletForPayment');
} else {
root.path('homeWallet');
}
}
};
root.home = function() {
2014-12-09 11:52:01 -03:00
console.log('[go.js.48:home:]'); //TODO
if ($rootScope.iden)
root.walletHome();
else
root.path('/');
};
root.send = function() {
2014-12-09 11:52:01 -03:00
console.log('[go.js.58]'); //TODO
$location.path('send');
};
2014-12-07 12:44:50 -03:00
return root;
});