Skip to content

Commit ab26212

Browse files
now showing scheduled dom changes
1 parent 11254f2 commit ab26212

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

example/server.js

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,22 @@ app.get('/', function(req, res, next){
3939
</head>
4040
<body>
4141
<div class="container">
42-
<h1>Todo Example</h1>
42+
<div class="page-header">
43+
<h1>Todo Example</h1>
44+
</div>
4345
<ul id="lists" class="list-group">
4446
${renderTodos(req.session)}
4547
</ul>
4648
<form action="add">
47-
<input type="text" name="description" />
49+
<div class="form-group">
50+
<label>Description</label><input type="text" name="description" />
51+
</div>
52+
<div class="form-group">
53+
<label>Reminder (seconds)</label><input type="range" name="reminder" max="20" value="0"/>
54+
</div>
4855
<input type="submit" value="Add"/>
4956
</form>
57+
<div id="reminder" style="margin-top: 10px"></div>
5058
</div>
5159
<script src="index.js"></script>
5260
</body>
@@ -111,7 +119,8 @@ const addRoute = function(query, session, cb){
111119
}
112120
const todo = {
113121
id: (new Date).getTime(),
114-
description: query.description
122+
description: query.description,
123+
reminder: query.reminder
115124
}
116125
session.todos.push(todo)
117126
session.save(function(){
@@ -120,10 +129,25 @@ const addRoute = function(query, session, cb){
120129
container: 'lists',
121130
content: '<li class="list-group-item">' + todo.description + ' <button class="pull-right" data-url="/delete?id=' + todo.id + '">Delete</button></li>'
122131
}]
132+
if(todo.reminder !== '0'){
133+
console.log('scheduling reminder')
134+
sendReminder(todo, cb)
135+
}
123136
cb(response)
124137
})
125138
};
126139

140+
const sendReminder = function(todo, cb){
141+
setTimeout(function(){
142+
const reminderResponse = [{
143+
action: 'replace',
144+
container: 'reminder',
145+
content: '<div class="alert alert-info" role="alert" onclick="this.style.display = \'none\';">Reminder for ' + todo.description + '!</div>'
146+
}]
147+
cb(reminderResponse)
148+
}, todo.reminder * 1000)
149+
};
150+
127151
const renderTodos = function(sess){
128152
if(!sess.todos){
129153
return ''

0 commit comments

Comments
 (0)