From b9d87cd93692aeef934ea20bb8986cb74a589481 Mon Sep 17 00:00:00 2001 From: Abhishek Das Date: Sun, 7 Apr 2013 20:20:20 +0530 Subject: [PATCH] Sync `parent_id` with db; * Update the corresponding query in `server.js` * Add js to focus input of new element created --- README.md | 2 +- public/javascripts/views/task.js | 7 ++++--- server.js | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index c83fd46..d78802b 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ An open-source [Workflowy](http://workflowy.com) clone. ##To-do -* Work on sub-lists. The parent id of the Backbone task model has to be set for it to be saved properly. The template should be modified to have the `children` ul as part of every task. +* ~~Work on sub-lists. The parent id of the Backbone task model has to be set for it to be saved properly. The template should be modified to have the `children` ul as part of every task.~~ * Search & Tags * Themes diff --git a/public/javascripts/views/task.js b/public/javascripts/views/task.js index c9900be..8675263 100644 --- a/public/javascripts/views/task.js +++ b/public/javascripts/views/task.js @@ -56,19 +56,20 @@ var app = app || {}; update: function(e) { if ( e.which === ENTER_KEY ) { - app.Tasks.add({content:''}); + app.Tasks.add({content:'', parent_id: this.model.get('parent_id')}); this.$input.blur(); - this.$el.next('li').find('input').focus(); + this.$el.prev('li').find('input').focus(); } }, close: function() { var value = this.$input.val().trim(); + console.log(this.model); if (value === '') { this.model.destroy(); } else - this.model.save({content: value}); + this.model.save({content: value, parent_id: this.model.get('parent_id')}); this.$el.removeClass('editing'); } diff --git a/server.js b/server.js index 9d6ca36..fa744d5 100644 --- a/server.js +++ b/server.js @@ -36,7 +36,7 @@ app.get('/tasks', function(req,res){ app.post('/tasks', function(req,res){ var timestamp = Math.round((new Date()).getTime()/1000); - client.query("INSERT INTO tasks (content, timestamp) VALUES (?,?)", [req.body.content,timestamp]); + client.query("INSERT INTO tasks (content, timestamp, parent_id) VALUES (?,?,?)", [req.body.content,timestamp,req.body.parent_id]); client.query("SELECT * FROM tasks WHERE content = ?", [req.body.content], function select(err,task){ req.body.id = task[0].id; res.send(req.body);