-
Notifications
You must be signed in to change notification settings - Fork 1
/
options.js
146 lines (131 loc) · 5.54 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
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
// Alerta Chrome Extension
// Copyright (c) 2014 Andy Botting
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
// This code is based on the Google Mail Checker extension by Google.
//
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
function saveOptions() {
var api_url = document.getElementById('api_url').value;
var api_key = document.getElementById('api_key').value;
var dashboard_url = document.getElementById('dashboard_url').value;
var envs = {
'Production': document.getElementById('env_prod').checked,
'Infrastructure': document.getElementById('env_infra').checked,
'Development': document.getElementById('env_dev').checked
};
var sevs = {
'critical': document.getElementById('sev_critical').checked,
'major': document.getElementById('sev_major').checked,
'minor': document.getElementById('sev_minor').checked,
'warning': document.getElementById('sev_warning').checked,
'indeterminate': document.getElementById('sev_indeterminate').checked,
'informational': document.getElementById('sev_inform').checked,
'debug': document.getElementById('sev_debug').checked,
'security': document.getElementById('sev_auth').checked
};
localStorage['api_url'] = api_url
localStorage['api_key'] = api_key
localStorage['dashboard_url'] = dashboard_url
localStorage['environments'] = JSON.stringify(envs);
localStorage['severities'] = JSON.stringify(sevs);
console.log('localStorage=' + JSON.stringify(localStorage));
// Update status to let user know options were saved.
var status = document.getElementById('status');
status.innerHTML = 'Options Saved.';
setTimeout(function() {
status.innerHTML = '';
}, 2000);
}
// Restores select box state to saved value from localStorage.
function restoreOptions() {
console.log('Restore options');
var api_url = localStorage['api_url'];
if (api_url == null) {
api_url = 'http://api.alerta.io';
}
console.log("API URL: " + api_url);
document.getElementById('api_url').value = api_url;
var api_key = localStorage['api_key'];
if (api_key == null) {
api_key = 'demo-key';
}
console.log("API Key: " + api_key);
document.getElementById('api_key').value = api_key;
var dashboard_url = localStorage['dashboard_url'];
if (dashboard_url == null) {
dashboard_url = 'http://try.alerta.io';
}
console.log("Dashboard URL: " + dashboard_url);
document.getElementById('dashboard_url').value = dashboard_url;
var env_str = localStorage['environments'];
if (env_str == null) {
// Default options if not set
envs = {
'Production': true,
'Infrastructure': true,
'Development': false
};
} else {
console.log(env_str);
envs = JSON.parse(env_str);
}
document.getElementById('env_prod').checked = envs['Production'];
document.getElementById('env_infra').checked = envs['Infrastructure'];
document.getElementById('env_dev').checked = envs['Development'];
var sev_str = localStorage['severities'];
if (sev_str == null) {
// Default options if not set
sevs = {
'critical': true,
'major': true,
'minor': false,
'warning': false,
'indeterminate': false,
'informational': false,
'debug': false,
'security': false,
};
} else {
console.log(sev_str);
sevs = JSON.parse(sev_str);
}
console.log("Severity critical: " + sevs['critical']);
console.log("Severity major: " + sevs['major']);
console.log("Severity minor: " + sevs['minor']);
console.log("Severity warning: " + sevs['warning']);
console.log("Severity indeterminate: " + sevs['indeterminate']);
console.log("Severity informational: " + sevs['informational']);
console.log("Severity debug: " + sevs['debug']);
console.log("Severity security: " + sevs['security']);
document.getElementById('sev_critical').checked = sevs['critical'];
document.getElementById('sev_major').checked = sevs['major'];
document.getElementById('sev_minor').checked = sevs['minor'];
document.getElementById('sev_warning').checked = sevs['warning'];
document.getElementById('sev_indeterminate').checked = sevs['indeterminate'];
document.getElementById('sev_inform').checked = sevs['informational'];
document.getElementById('sev_debug').checked = sevs['debug'];
document.getElementById('sev_auth').checked = sevs['security'];
}
document.addEventListener('DOMContentLoaded', restoreOptions);
document.querySelector('#save').addEventListener('click', saveOptions);