From cec5dc442e5a0631dbb9530c0856782040f78f54 Mon Sep 17 00:00:00 2001 From: Arvind Date: Mon, 7 Jul 2014 20:07:29 +0530 Subject: [PATCH] Fix: Removing unwanted key value pair from annotation before adding to how. Fix issues with collection containing sweets not getting updated after being posted to store. Check if value entered in the input field for url is empty or not. --- swtr/static/js/app.js | 27 ++++++++++++++++++--------- swtr/static/js/swtmaker.js | 5 ++++- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/swtr/static/js/app.js b/swtr/static/js/app.js index a7dda5d..a2ecb4c 100644 --- a/swtr/static/js/app.js +++ b/swtr/static/js/app.js @@ -138,7 +138,9 @@ window.swtr = window.swtr || {}; if(!(swtr.who)) { swtr.who = "Guest"; } - swtr.TxtAnnoSwts.add(new TxtAnnoSwt({how: annotation, + // Removing the highlights key value pair from annotation object. + var tempAnnotation = _.omit(annotation, 'highlights'); + swtr.TxtAnnoSwts.add(new TxtAnnoSwt({how: tempAnnotation, where: pageURL, who: swtr.who})); if($("#show-sweets").attr('disabled')) { @@ -189,13 +191,17 @@ window.swtr = window.swtr || {}; this.loadOverlayBar(); }, loadOverlayBar: function() { - var template = ""; + var template = ""; $(document.body).append(template); }, @@ -206,6 +212,7 @@ window.swtr = window.swtr || {}; showSweets: function(e) { $("#sweet-list-wrapper").show(); swtr.TxtAnnoSwts.each(function(model){ + console.log(model, model.isNew()); var templateStr ='
  • '+ '@<%= who %> #<%= what %> '+ '<%= where.substr(0, 30) + "..." %> '+ @@ -229,7 +236,9 @@ window.swtr = window.swtr || {}; $("#sweet-list").html(''); }, postSweet: function(e) { - swtr.TxtAnnoSwts.post({success: function(data) { + swtr.TxtAnnoSwts.post({success: function(collection, data) { + swtr.TxtAnnoSwts.set(collection); + $("#sweet-list").html(''); alert("Your SWeets are posted!!"); }, error: function(data) { diff --git a/swtr/static/js/swtmaker.js b/swtr/static/js/swtmaker.js index 86c89c3..420dbb8 100644 --- a/swtr/static/js/swtmaker.js +++ b/swtr/static/js/swtmaker.js @@ -197,7 +197,7 @@ this.collection.post({ success: function(collection, response) { console.log(collection, response); - swtr.sweets.update(collection); + swtr.sweets.set(collection); //TODO: move this to a annotation view or something anno.removeAll(); _.each(swtr.sweets.models, function(swt) { @@ -312,6 +312,9 @@ return false; } else { + if(!url) { + return false; + } window.location.href = '/annotate?where=' + url; } }, -- 1.7.10.4