This repository has been archived by the owner on Jan 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 82
/
options.js
80 lines (73 loc) · 2.18 KB
/
options.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
/**
* Module to load/save options to preferences. Options are represented
* as a dictionary with the following fields:
*
* asana_host_port {String} host and (optional) port of the asana
* server to connect to.
* default_workspace_id {Integer} ID of the workspace that tasks should
* go into by default. The user will be allowed to choose a
* different option when adding a task. This is 0 if no default
* workspace is selected.
*
* They are stored off in browser local storage for the extension as a
* single serialized string, read/written all-or-nothing.
*/
Asana.Options = {
/**
* @param opt_options {dict} Options to use; if unspecified will be loaded.
* @return {String} The URL for the login page.
*/
loginUrl: function(opt_options) {
var options = opt_options || Asana.Options.loadOptions();
return 'https://' + options.asana_host_port + '/';
},
/**
* @param opt_options {dict} Options to use; if unspecified will be loaded.
* @return {String} The URL for the signup page.
*/
signupUrl: function(opt_options) {
return 'http://asana.com/?utm_source=chrome&utm_medium=ext&utm_campaign=ext';
},
/**
* @return {dict} Default options.
*/
defaultOptions: function() {
return {
asana_host_port: "app.asana.com",
default_workspace_id: 0
};
},
/**
* Load the user's preferences synchronously from local storage.
*
* @return {dict} The user's stored options
*/
loadOptions: function() {
var options_json = localStorage.options;
var options;
if (!options_json) {
options = this.defaultOptions();
localStorage.options = JSON.stringify(options);
return options;
} else {
options = JSON.parse(options_json);
return options;
}
},
/**
* Save the user's preferences synchronously to local storage.
* Overwrites all options.
*
* @param options {dict} The user's options.
*/
saveOptions: function(options) {
localStorage.options = JSON.stringify(options);
},
/**
* Reset the user's preferences to the defaults.
*/
resetOptions: function() {
delete localStorage.options;
this.loadOptions();
}
};