From cf9dc6d99944787e971579547aac2db4d1422a05 Mon Sep 17 00:00:00 2001 From: nelsonic Date: Thu, 9 Apr 2015 14:14:48 +0100 Subject: [PATCH] editing timer after its complete. done. https://github.com/ideaq/time/issues/95 --- front/public/js/alpha.js | 46 +++++++++++++++++++++++++++++++++++----- front/views/index.html | 11 ++++++++++ models/timer.js | 1 + 3 files changed, 53 insertions(+), 5 deletions(-) diff --git a/front/public/js/alpha.js b/front/public/js/alpha.js index 4b77f145..25fe46a3 100644 --- a/front/public/js/alpha.js +++ b/front/public/js/alpha.js @@ -189,7 +189,7 @@ $(document).ready(function() { * rendertimers renders your list of past timers in the ui. * centralises all the view rendering. */ - var rendertimers = function() { + var rendertimers = function(edit, id) { // transform the timers Object to an Array so we can SORT it below: var arr = Object.keys(timers).map(function(id) { var timer = timers[id]; @@ -202,15 +202,27 @@ $(document).ready(function() { // Add timer to past-timers list using handlebars var raw_template = $('#timer_list_template').html(); var template = Handlebars.compile(raw_template); + var editor_template_raw = $('#timer_edit_template').html(); + var editor_template = Handlebars.compile(editor_template_raw); var parent = $("#past-timers-list"); var html = ''; - byDate.map(function(i){ + byDate.map(function(i) { var timer = i // timers[i] timer.took = timeformat(timer.elapsed); // repetitive ... - html += template(timer); - console.log(" >>> "+i, timer); + // show edit form if render called with edit true and an id + if(edit && timer.id === id) { + html += editor_template(timer); + } + else { + html += template(timer); + } + // console.log(" >>> "+i, timer); }) parent.html(html); // completely re-write the DOM each time! :-O + // attach a listener event to each timer list entry + arr.map(function(timer){ + editlistener(timer.id); + }); return; } @@ -301,7 +313,6 @@ $(document).ready(function() { } }) - // enter key: http://stackoverflow.com/questions/979662 // $(document).keypress(function(e) { // if(e.which == 13) { @@ -316,6 +327,31 @@ $(document).ready(function() { } + var editlistener = function(id) { + console.log(' - - - - - - edit listener - - - - -'); + var ed = $('#'+id); + ed.click(function(e) { + rendertimers('edit', this.id); + // console.log(e); + console.log(this.id); + // console.log($(this)) + }); + console.log('#'+id+"-save"); + $('#'+id+"-save").click(function(event){ + event.stopImmediatePropagation(); + event.preventDefault(); + console.log(this); + var timer = timers[this.id.replace('-save','')]; + timer.desc = $('#'+id+"-desc").val(); + timer.took = $('#'+id+"-took").val(); + console.log("TIMER EDIT", timer); + timerupsert(timer, function(){ + rendertimers(); + }); + }) + return; + } + var sb = $("#stop"); // stop button sb.click( function() { console.log("#stop Clicked!") diff --git a/front/views/index.html b/front/views/index.html index 608a886e..1d43d8e4 100644 --- a/front/views/index.html +++ b/front/views/index.html @@ -16,6 +16,7 @@
00:00
+ @@ -58,6 +59,16 @@ + + + diff --git a/models/timer.js b/models/timer.js index 8df0e268..64114309 100644 --- a/models/timer.js +++ b/models/timer.js @@ -6,6 +6,7 @@ module.exports = { ct: Joi.forbidden(), // don't allow people to set this! start: Joi.date().iso(), end: Joi.date().iso().optional(), + endtimestamp: Joi.string().optional(), // convenience aid: Joi.string(), session: Joi.string().optional(), id: Joi.string().optional(),