-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.js
129 lines (105 loc) · 3.63 KB
/
config.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
var hash = location.hash.slice(1);
var options;
if (hash) {
options = JSON.parse(decodeURIComponent(hash));
} else {
console.log("You don't appear to be running PebbleJS, that's cool");
options = {};
}
var levels = options.levels || [];
options.levels = levels;
var recipients = options.recipients || [];
options.recipients = recipients;
var telInput = document.getElementById('mynumber');
telInput.value = options.call || '';
telInput.addEventListener('input',function(evt){
options.call = telInput.value;
});
var addLevelButton = document.getElementById('addlevel');
// for ids if recipients are ever per-level
// right now we treat it as a cursor
var recipGlobalCount = 0;
var addRecipButton = document.getElementById('addrecip');
var recipContainer = document.getElementById('recips');
function addRecip() {
var thisRecipIndex = recipGlobalCount++;
var recipPair = document.createElement('div');
var recipLabel = document.createElement('label');
var recipInput = document.createElement('input');
// TODO: use recipGlobalCount if/when stratified
recipInput.id = 'recip-' + thisRecipIndex;
recipients[thisRecipIndex] = recipients[thisRecipIndex] || '';
recipInput.value = recipients[thisRecipIndex];
recipLabel.htmlFor = recipInput.id;
recipInput.type = 'tel';
// TODO: don't actually label like this
recipLabel.textContent = 'Text phone: ';
// add recipient to UI
recipInput.addEventListener('input', function(evt) {
recipients[thisRecipIndex] = recipInput.value;
});
recipPair.className = 'pair card';
recipPair.appendChild(recipLabel);
recipPair.appendChild(recipInput);
recipContainer.insertBefore(recipPair, addRecipButton);
}
addRecipButton.addEventListener('click',function(){
addRecip();
});
addLevelButton.addEventListener('click',function(){
addLevel();
});
var levelCursor = 0;
function getLevelIndex() {
levels[levelCursor] = levels[levelCursor] || {
play: '',
body: ''
};
return levelCursor++;
}
var levelContainer = document.getElementById('levels');
function addLevel() {
var thisLevel = getLevelIndex();
var thisLevelContainer = document.createElement('div');
var bodyPair = document.createElement('div');
var bodyLabel = document.createElement('label');
var bodyInput = document.createElement('input');
bodyInput.id = 'msgbody-' + thisLevel;
bodyInput.value = levels[thisLevel].body || '';
bodyLabel.textContent = 'Text message:';
bodyLabel.htmlFor = bodyInput.id;
bodyInput.addEventListener('input', function(evt) {
levels[thisLevel].body = bodyInput.value;
});
bodyPair.className = 'pair';
bodyPair.appendChild(bodyLabel);
bodyPair.appendChild(bodyInput);
thisLevelContainer.appendChild(bodyPair);
var playPair = document.createElement('div');
var playLabel = document.createElement('label');
var playInput = document.createElement('input');
playInput.id = 'playurl-' + thisLevel;
playInput.value = levels[thisLevel].play || '';
playLabel.textContent = 'Playback URL:';
playLabel.htmlFor = playInput.id;
playInput.addEventListener('input', function(evt) {
levels[thisLevel].play = playInput.value;
});
playPair.className = 'pair';
playPair.appendChild(playLabel);
playPair.appendChild(playInput);
thisLevelContainer.appendChild(playPair);
thisLevelContainer.className = 'card';
levelContainer.insertBefore(thisLevelContainer, addLevelButton);
}
for (var i=0; i<recipients.length; i++) {
addRecip();
}
for (var i=0; i<levels.length; i++) {
addLevel();
}
document.getElementById('save')
.addEventListener('click', function (evt) {
document.location = 'pebblejs://close#' +
encodeURIComponent(JSON.stringify(options));
});