-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathoptions.js
73 lines (64 loc) · 2.61 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
/*
* Copyright (c) 2018 Robin Mulloy http://robin.mulloy.ca All rights reserved.
* Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
*/
// defaults
var settings = {
'domain' : 'http://pbx',
'username' : '',
'password' : '',
'dest_cid_name' : 'J. Smith',
'dest_cid_number' : '123-555-1234',
'src' : '1234',
'rec' : 'false',
'ringback' : 'us-ring',
'auto_answer' : 'true'
};
function loadOptions() {
document.querySelector('#save-button').addEventListener('click', saveOptions);
chrome.storage.local.get(settings, function(items) {
document.getElementById('domain').value = items.domain;
document.getElementById('username').value = items.username;
document.getElementById('password').value = items.password;
document.getElementById('dest_cid_name').value = items.dest_cid_name;
document.getElementById('dest_cid_number').value = items.dest_cid_number;
document.getElementById('src').value = items.src;
document.getElementById('auto_answer').value = items.auto_answer;
document.getElementById('rec').value = items.rec;
document.getElementById('ringback').value = items.ringback;
});
updateSelect('auto_answer'); // auto-answer
updateSelect('rec'); // records call
updateSelect('ringback'); // ringback
}
function updateSelect(elemID) {
var elem = document.getElementById(elemID);
for (var i = 0; i < elem.children.length; i++) {
var child = elem.children[i];
if (child.value == ringback) {
child.selected = 'true';
break;
}
}
}
function saveOptions() {
var data = {};
data['domain'] = document.getElementById('domain').value;
data['username'] = document.getElementById('username').value;
data['password'] = document.getElementById('password').value;
data['dest_cid_name'] = document.getElementById('dest_cid_name').value;
data['dest_cid_number'] = document.getElementById('dest_cid_number').value;
data['src'] = document.getElementById('src').value;
data['auto_answer'] = document.getElementById('auto_answer').value;
data['rec'] = document.getElementById('rec').value;
data['ringback'] = document.getElementById('ringback').value;
chrome.storage.local.set(data, function() {
setStatus('Options Saved.');
});
}
function setStatus(message) {
var status = document.getElementById('status');
status.innerHTML = message;
setTimeout(function() {status.innerHTML='';}, 4000);
}
document.addEventListener('DOMContentLoaded', loadOptions);