copay/src/js/services/go.js

104 lines
2.4 KiB
JavaScript
Raw Normal View History

2014-12-07 07:44:50 -08:00
'use strict';
angular.module('copayApp.services').factory('go', function($window, $rootScope, $location, $state, $timeout, $log, profileService, nodeWebkit) {
2014-12-07 07:44:50 -08:00
var root = {};
var hideSidebars = function() {
2014-12-07 09:12:58 -08:00
if (typeof document === 'undefined')
return;
2015-04-29 08:42:08 -07:00
var elem = document.getElementById('off-canvas-wrap');
elem.className = 'off-canvas-wrap';
2014-12-07 07:44:50 -08:00
};
2014-12-08 07:45:12 -08:00
var toggleSidebar = function(invert) {
if (typeof document === 'undefined')
return;
2015-04-29 08:42:08 -07:00
var elem = document.getElementById('off-canvas-wrap');
var leftbarActive = elem.className.indexOf('move-right') >= 0;
2015-03-06 07:00:10 -08:00
if (invert) {
2015-03-06 07:00:10 -08:00
if (profileService.profile && !$rootScope.hideNavigation) {
2015-04-29 08:42:08 -07:00
elem.className = 'off-canvas-wrap move-right';
2014-12-08 07:45:12 -08:00
}
2015-03-06 07:00:10 -08:00
} else {
2014-12-08 07:45:12 -08:00
if (leftbarActive) {
hideSidebars();
}
}
};
root.openExternalLink = function(url, target) {
2015-05-28 06:52:33 -07:00
if (nodeWebkit.isDefined()) {
nodeWebkit.openExternalLink(url);
2015-11-24 12:16:52 -08:00
} else {
target = target || '_blank';
var ref = window.open(url, target, 'location=no');
2015-05-28 06:52:33 -07:00
}
2014-12-09 11:11:56 -08:00
};
root.path = function(path, cb) {
$state.transitionTo(path)
.then(function() {
if (cb) return cb();
2015-05-18 08:43:15 -07:00
}, function() {
if (cb) return cb('animation in progress');
});
2014-12-07 07:44:50 -08:00
hideSidebars();
};
root.swipe = function(invert) {
2014-12-08 07:45:12 -08:00
toggleSidebar(invert);
};
root.walletHome = function() {
2015-03-06 07:00:10 -08:00
var fc = profileService.focusedClient;
if (fc && !fc.isComplete()) {
$log.debug("Wallet not complete at startup... redirecting")
root.path('copayers');
} else {
2015-11-30 13:57:18 -08:00
root.path('walletHome', function() {
$rootScope.$emit('Local/SetTab', 'walletHome', true);
});
}
};
2015-04-23 11:19:30 -07:00
root.send = function() {
root.path('walletHome', function() {
$rootScope.$emit('Local/SetTab', 'send');
});
2015-04-23 11:19:30 -07:00
};
2015-03-06 07:00:10 -08:00
root.addWallet = function() {
$state.go('add');
};
2015-03-06 07:00:10 -08:00
root.preferences = function() {
$state.go('preferences');
};
root.preferencesGlobal = function() {
$state.go('preferencesGlobal');
};
2015-03-06 07:00:10 -08:00
root.reload = function() {
$state.reload();
};
2014-12-10 07:07:26 -08:00
// Global go. This should be in a better place TODO
2016-01-16 15:04:01 -08:00
// We don't do a 'go' directive, to use the benefits of ng-touch with ng-click
2015-03-06 07:00:10 -08:00
$rootScope.go = function(path) {
2014-12-10 07:07:26 -08:00
root.path(path);
};
$rootScope.openExternalLink = function(url, target) {
root.openExternalLink(url, target);
2014-12-10 07:07:26 -08:00
};
2014-12-07 07:44:50 -08:00
return root;
});