forked from Asana/Chrome-Extension-Example
-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.html
161 lines (142 loc) · 4.58 KB
/
options.html
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
<html>
<head><title>Asana Options</title></head>
<script type="text/javascript" src="asana.js"></script>
<script type="text/javascript" src="options.js"></script>
<script type="text/javascript" src="server_model.js"></script>
<script type="text/javascript" src="api_bridge.js"></script>
<script type="text/javascript" src="jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="jquery-ui-1.8.10.custom.min.js"></script>
<link rel="stylesheet" href="common.css"/>
<link rel="stylesheet" href="options_style.css"/>
<script type="text/javascript">
var init = function() {
fillOptions();
$("#reset_button").click(resetOptions);
};
// Restores select box state to saved value from localStorage.
var fillOptions = function() {
var options = Asana.Options.loadOptions();
$("#asana_host_port_input").val(options.asana_host_port);
fillDomainsInBackground(options);
};
var fillDomainsInBackground = function(opt_options) {
var options = opt_options || Asana.Options.loadOptions();
Asana.ServerModel.workspaces(function(workspaces) {
$("#domains_group").html("");
workspaces.forEach(function(domain) {
$("#domains_group").append(
'<label><input name="default_domain_id" type="radio" id="default_domain_id-' +
domain.id + '" key="' + domain.id + '"/>' + domain.name + '</label><br/>');
});
var default_domain_element = $("#default_domain_id-" + options.default_domain_id);
if (default_domain_element[0]) {
default_domain_element.attr("checked", "checked");
} else {
$("#domains_group").find("input")[0].checked = true;
}
$("#domains_group").find("input").change(onChange);
}, function(error_response) {
$("#domains_group").html(
'<div>Error loading workspaces. Verify the following:<ul>' +
'<li>Asana Host is configured correctly.</li>' +
'<li>You are <a target="_blank" href="' +
Asana.Options.loginUrl() +
'">logged in</a>.</li>' +
'<li>You have access to the Asana API.</li></ul>');
});
};
var onChange = function() {
setSaveEnabled(true);
};
var setSaveEnabled = function(enabled) {
var button = $("#save_button");
if (enabled) {
button.removeClass("disabled");
button.addClass("enabled");
button.click(saveOptions);
} else {
button.removeClass("enabled");
button.addClass("disabled");
button.unbind('click');
}
};
var resetOptions = function() {
Asana.Options.resetOptions();
fillOptions();
setSaveEnabled(false);
};
var saveOptions = function() {
var asana_host_port = $("#asana_host_port_input").val();
var default_domain_input = $("input[@name='default_domain_id']:checked");
Asana.Options.saveOptions({
asana_host_port: asana_host_port,
default_domain_id: default_domain_input
? default_domain_input.attr("key")
: 0
});
setSaveEnabled(false);
$("#status").html("Options saved.");
setTimeout(function() {
$("#status").html("");
}, 3000);
fillDomainsInBackground();
};
</script>
<body onload="init()">
<table id="layout">
<tr><td colspan="3" class="v-spacer"></td></tr>
<tr>
<td class="h-spacer"></td>
<td id="options">
<table class="form">
<tr>
<td class="field-name">Default Workspace:</td>
<td class="field-value">
<div id="domains_group">Loading...</div>
</td>
</tr>
<tr>
<td class="field-name"></td>
<td class="field-notes">
The default workspace where new tasks are added. You can always select
a different workspace when you're creating a task.
</td>
</tr>
<tr><td colspan="2" class="field-spacer"></td></tr>
<tr>
<td class="field-name">Asana Host:</td>
<td class="field-value">
<input id="asana_host_port_input" type="text" oninput="onChange();">
</td>
</tr>
<tr>
<td class="field-name"></td>
<td class="field-notes">
The hostname for the Asana application. You should leave this set to
its default value.
</td>
</tr>
<tr><td colspan="2" class="field-spacer"></td></tr>
<tr>
<td class="field-name"></td>
<td class="field-value">
<div id="save_button" class="button primary-button disabled">
<span class="button-text">Save</span>
</div>
<div id="reset_button" class="button primary-button enabled">
<span class="button-text">Reset</span>
</div>
</td>
</tr>
<tr>
<td class="field-name"></td>
<td class="field-value">
<div id="status"></div>
</td>
</tr>
</table>
</td>
<td class="h-spacer"></td>
</tr></table>
</body>
</html>