Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ea10366

Browse files
committed
Fixes to chapter 04 samples
1 parent 6da0d91 commit ea10366

File tree

3 files changed

+49
-15
lines changed

3 files changed

+49
-15
lines changed

js/prowebapps.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,10 +210,8 @@ PROWEBAPPS = (function() {
210210
} // getAction
211211

212212
function updateViewStack(oldView, newView) {
213-
var shouldPush = false;
214-
215213
// first let's determine if we should push onto the stack
216-
shouldPush = oldView && (
214+
var shouldPush = oldView && (
217215
(viewStack.length === 0) ||
218216
(newView && (viewStack[viewStack.length - 1].id != newView.id))
219217
);

snippets/04/todolist.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
<div id="main" class="view">
1616
<h1>To Do List</h1>
1717
<div class="task" style="display: none;">
18-
<h3>MIT: <span class="task-name">Mow the Lawn</span></h3>
19-
<p class="task-description">Task description goes here</p>
18+
<h3>Task: <span class="task-name"></span></h3>
19+
<p class="task-description"></p>
2020
<p class="task-due">
2121
<label>DUE IN:</label>
22-
<span class="task-daysleft">5 days</span>
22+
<span class="task-daysleft"></span>
2323
</p>
2424
<ul class="task-actions">
2525
<li class="right"><a href="#" class="task-complete">COMPLETE TASK</a></li>
@@ -41,11 +41,11 @@ <h1 class="fancy">Create Task</h1>
4141
<div id="errors"></div>
4242
<form id="taskentry">
4343
<ul>
44-
<li><input type="text" class="required" name="task[name]" id="taskname" placeholder="Task Name" value="Mow the Lawn "/></li>
44+
<li><input type="text" class="required" name="task[name]" id="taskname" placeholder="Task Name" value=""/></li>
4545
<li>
4646
<textarea name="task[description]" id="taskdesc" placeholder="Description" rows="5"></textarea>
4747
</li>
48-
<li><input type="text" class="required date" name="task[due]" id="taskdue" placeholder="Task Due" value="2010-08-23 11:23" /></li>
48+
<li><input type="text" class="required date" name="task[due]" id="taskdue" placeholder="Task Due" value="" /></li>
4949
<li class="naked"><input type="submit" name="Save" /></li>
5050
</ul>
5151
</form>

snippets/04/todolist.js

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,43 @@ TODOLIST = (function() {
178178
});
179179
},
180180

181-
getMostImportantTask
181+
saveTask: function(task, callback) {
182+
db.transaction(function(transaction) {
183+
// if the task id is not assigned, then insert
184+
if (! task.id) {
185+
transaction.executeSql(
186+
"INSERT INTO task(name, description, due) VALUES (?, ?, ?);",
187+
[task.name, task.description, task.due],
188+
function(tx) {
189+
transaction.executeSql(
190+
"SELECT MAX(rowid) AS id from task",
191+
[],
192+
function (tx, results) {
193+
task.id = results.rows.item(0).id;
194+
if (callback) {
195+
callback();
196+
} // if
197+
}
198+
);
199+
}
200+
);
201+
}
202+
// otherwise, update
203+
else {
204+
transaction.executeSql(
205+
"UPDATE task " +
206+
"SET name = ?, description = ?, due = ?, completed = ? " +
207+
"WHERE rowid = ?;",
208+
[task.name, task.description, task.due, task.completed, task.id],
209+
function (tx) {
210+
if (callback) {
211+
callback();
212+
} // if
213+
}
214+
);
215+
} // if..else
216+
});
217+
}
182218
};
183219

184220
return subModule;
@@ -236,23 +272,23 @@ getMostImportantTask
236272
/* view activation handlers */
237273

238274
activateMain: function() {
239-
TODOLIST.Storage.getMostImportantTask(function(mit) {
240-
if (mit) {
275+
TODOLIST.Storage.getMostImportantTask(function(task) {
276+
if (task) {
241277
// the no tasks message may be displayed, so remove it
242278
jQuery("#main .notasks").remove();
243279

244280
// update the task details
245-
showTaskDetails("#main .task", mit);
281+
showTaskDetails("#main .task", task);
246282

247283
// attach a click handler to the complete task button
248284
jQuery("#main .task-complete").unbind().click(function() {
249285
jQuery("#main .task").slideUp();
250286

251287
// mark the task as complete
252-
mit.complete();
288+
task.complete();
253289

254290
// save the task back to storage
255-
TODOLIST.Storage.saveTask(mit, module.activateMain);
291+
TODOLIST.Storage.saveTask(task, module.activateMain);
256292
});
257293
}
258294
else {
@@ -269,7 +305,7 @@ getMostImportantTask
269305

270306
populateTaskList();
271307

272-
// update the task list
308+
// refresh the task list display
273309
jQuery("ul#tasklist li").click(function() {
274310
toggleDetailsDisplay(this);
275311
});

0 commit comments

Comments
 (0)