Wallet/src/js/services/go.js

95 lines
2 KiB
JavaScript
Raw Normal View History

2014-12-07 12:44:50 -03:00
'use strict';
2015-03-06 12:00:10 -03:00
angular.module('copayApp.services').factory('go', function($window, $rootScope, $location, $state, profileService) {
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;
2015-03-06 12:00:10 -03:00
if (invert) {
2015-03-06 12:00:10 -03:00
if (profileService.profile && !$rootScope.hideNavigation) {
2014-12-18 18:58:35 -03:00
elem.addClass('move-right');
2014-12-08 12:45:12 -03:00
}
2015-03-06 12:00:10 -03:00
} else {
2014-12-08 12:45:12 -03:00
if (leftbarActive) {
hideSidebars();
}
}
};
2014-12-09 16:11:56 -03:00
root.openExternalLink = function(url) {
var ref = window.open(url, '_blank', 'location=no');
};
root.path = function(path) {
2015-03-06 12:00:10 -03:00
$state.transitionTo(path);
2014-12-07 12:44:50 -03:00
hideSidebars();
};
root.swipe = function(invert) {
2014-12-08 12:45:12 -03:00
toggleSidebar(invert);
};
root.walletHome = function() {
2015-03-06 12:00:10 -03:00
var fc = profileService.focusedClient;
2014-12-09 11:52:01 -03:00
2015-03-06 12:00:10 -03:00
if (fc && !fc.isComplete()) {
root.path('copayers');
} else {
2015-03-06 12:00:10 -03:00
root.path('walletHome');
}
};
root.home = function() {
if ($rootScope.iden)
root.walletHome();
else
2015-03-06 12:00:10 -03:00
root.path('signin');
};
2015-03-06 12:00:10 -03:00
root.addWallet = function() {
$state.go('add');
};
root.send = function() {
2015-03-06 12:00:10 -03:00
$state.go('send');
};
root.preferences = function() {
$state.go('preferences');
};
root.reload = function() {
$state.reload();
};
2014-12-10 12:07:26 -03:00
// Global go. This should be in a better place TODO
// We dont do a 'go' directive, to use the benefits of ng-touch with ng-click
2015-03-06 12:00:10 -03:00
$rootScope.go = function(path) {
2014-12-10 12:07:26 -03:00
root.path(path);
};
2015-03-06 12:00:10 -03:00
$rootScope.openExternalLink = function(url) {
2014-12-10 12:07:26 -03:00
root.openExternalLink(url);
};
2014-12-07 12:44:50 -03:00
return root;
});