forked from rotki/rotki
-
Notifications
You must be signed in to change notification settings - Fork 0
/
navigation.js
111 lines (100 loc) · 4.22 KB
/
navigation.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
var settings = require("./settings.js")();
require("./accounting_settings.js")();
require("./taxreport.js")();
function determine_location(url) {
var split = url.split('#');
if (split.length == 1 || split[1] == '') {
return '';
}
return split[1];
}
function save_current_location() {
if (!settings.current_location) {
return; //we are at the start of the program
}
if (settings.current_location == 'index') {
console.log("Saving index ... ");
settings.page_index = $('#page-wrapper').html();
} else if (settings.current_location == 'otctrades') {
console.log("Saving otc trades ... ");
settings.page_otctrades = $('#page-wrapper').html();
} else if (settings.current_location == 'settings') {
console.log("Saving settings ... ");
settings.settings = $('#page-wrapper').html();
} else if (settings.current_location.startsWith('exchange_')) {
let exchange_name = settings.current_location.substring(9);
assert_exchange_exists(exchange_name);
console.log("Saving exchange " + exchange_name);
settings.page_exchange[exchange_name] = $('#page-wrapper').html();
} else if (settings.current_location == 'user_settings') {
console.log("Saving user settings ...");
settings.page_user_settings = $('#page-wrapper').html();
} else if (settings.current_location == 'accounting_settings') {
console.log("Saving accounting settings ...");
settings.page_accounting_settings = $('#page-wrapper').html();
} else if (settings.current_location == 'taxreport') {
console.log("Saving tax report ...");
settings.page_taxreport = $('#page-wrapper').html();
} else {
throw "Invalid link location " + settings.current_location;
}
}
function change_location(target) {
save_current_location();
console.log("Changing location to " + target);
settings.current_location = target;
}
function create_or_reload_page(name, create_callback, always_callback) {
change_location(name);
if (!settings['page_'+name]) {
console.log(`At create/reload ${name} with a null page index`);
create_callback();
} else {
console.log(`At create/reload ${name} with a populated page index`);
$('#page-wrapper').html(settings['page_'+name]);
}
always_callback();
}
function init_navigation() {
$('#side-menu a').click(function(event) {
event.preventDefault();
var target_location = determine_location(this.href);
if (target_location == 'otctrades') {
create_or_reload_page('otctrades', create_otctrades_ui, add_otctrades_listeners);
} else if (target_location == 'index') {
create_or_reload_dashboard();
} else if (target_location == 'taxreport') {
create_or_reload_page('taxreport', create_taxreport_ui, add_taxreport_listeners);
}
// else do nothing -- no link
});
$('#settingsbutton a').click(function(event) {
event.preventDefault();
var target_location = determine_location(this.href);
if (target_location != "settings") {
throw "Invalid link location " + target_location;
}
create_or_reload_page('settings', create_settings_ui, add_settings_listeners);
});
$('#user_settings_button a').click(function(event) {
event.preventDefault();
var target_location = determine_location(this.href);
if (target_location != "user_settings") {
throw "Invalid link location " + target_location;
}
create_or_reload_page('user_settings', create_user_settings, add_user_settings_listeners);
});
$('#accounting_settings_button a').click(function(event) {
event.preventDefault();
var target_location = determine_location(this.href);
if (target_location != "accounting_settings") {
throw "Invalid link location " + target_location;
}
create_or_reload_page('accounting_settings', create_accounting_settings, add_accounting_settings_listeners);
});
}
module.exports = function() {
this.init_navigation = init_navigation;
this.change_location = change_location;
this.determine_location = determine_location;
};