From 720d80ae64cc2dcd3ca88ca38e40560457b764b9 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Fri, 19 Sep 2014 21:29:51 +0900 Subject: [PATCH] Add ability to forget keywords --- client/application.js | 46 ++++++++++++++++++++++++++++++++++--------- client/index.html | 2 +- 2 files changed, 38 insertions(+), 10 deletions(-) diff --git a/client/application.js b/client/application.js index 47e6b0d..f32d861 100644 --- a/client/application.js +++ b/client/application.js @@ -72,11 +72,13 @@ function onLearn() { $('#learnKeyword').prop('disabled', true); + $('#learnError').slideUp(function() { var query = { keyword: $('#keywordToLearn').val(), params: ctx.searchParams }; + $.getJSON('/node/addKeyword', query, function(results) { if (results.success) { $('#learnDialog').modal('hide'); @@ -90,6 +92,18 @@ }); } + function onForget() { + $('#forgetKeyword').prop('disabled', true); + + var query = { + keyword: $('#keywordToForget').val() + }; + + $.getJSON('/node/removeKeyword', query, function(results) { + $('#forgetDialog').modal('hide'); + }); + } + function outputResults(results, count) { var searchResultCnt = String(results.length); if (results.length < count) { @@ -113,30 +127,44 @@ ready: function() { $('#keywordsToSearch').selectpicker(); + $('#keywordToForget').selectpicker(); $.getJSON('/node/getKeywords', function(keywords) { + $('#searchKeywords').click(onSearch); for (var i = 0, count = keywords.length; i < count; ++i) { $('#keywordsToSearch').append($('', { value: keywords[i], text: keywords[i] })); } + $('#keywordsToSearch').selectpicker('refresh'); + $('#keywordsToSearch').change(function() { + $('#searchKeywords').prop('disabled', !$(this).val()); + }); - $('#learnDialog').on('show.bs.modal', function() { - $('#learnKeyword').prop('disabled', true); - $('#keywordToLearn').val(''); - $('#learnError').hide(); + $('#forgetKeyword').click(onForget); + $('#forgetDialog').on('show.bs.modal', function() { + $.getJSON('/node/getKeywords', function(keywords) { + $('#keywordToForget').empty(); + for (var i = 0, count = keywords.length; i < count; ++i) { + $('#keywordToForget').append($('', { + value: keywords[i], + text: keywords[i] + })); + } + $('#keywordToForget').selectpicker('refresh'); + $('#forgetKeyword').prop('disabled', keywords.length === 0); + }); }); $('#learnKeyword').click(onLearn); $('#keywordToLearn').bind('input', function() { $('#learnKeyword').prop('disabled', !$(this).val()); }); - - $('#searchKeywords').click(onSearch); - $('#keywordsToSearch').selectpicker('refresh'); - $('#keywordsToSearch').change(function() { - $('#searchKeywords').prop('disabled', !$(this).val()); + $('#learnDialog').on('show.bs.modal', function() { + $('#learnKeyword').prop('disabled', true); + $('#keywordToLearn').val(''); + $('#learnError').hide(); }); }); } diff --git a/client/index.html b/client/index.html index 46ea76c..8040e64 100644 --- a/client/index.html +++ b/client/index.html @@ -99,7 +99,7 @@