1

Enable and disable forget button

This commit is contained in:
Alex Yatskov 2014-11-09 12:01:26 +09:00
parent 11d25531a4
commit 16da52d53f
2 changed files with 47 additions and 33 deletions

View File

@ -19,7 +19,8 @@
<div class="panel panel-default">
<div class="panel-heading">
<big>Visualizer</big>
<div class="pull-right">
<div class="btn-group pull-right">
<button class="btn btn-xs btn-default" id="forget">Forget</button>
<button class="btn btn-xs btn-default" id="learn">Learn</button>
</div>
</div>

View File

@ -35,7 +35,7 @@
$.getJSON('/search', _ctx.query, function(results) {
saveSnapshot(results);
outputSnapshot(results);
$('#customized').show();
setCustomized(true);
});
}
@ -60,15 +60,16 @@
$('#searchKeyword').append($('<option></option>', { value: keyword, text: keyword }));
}
search();
$('#searchKeyword,#minScore,#hintSteps,#maxResults').change(function() {
search();
});
onSearch();
$('#searchKeyword,#minScore,#hintSteps,#maxResults').change(onSearch);
$('#historyIndex').on('slideStop', onSelectSnapshot);
$('#learn').click(onLearn);
$('#forget').click(onForget);
});
}
$('#learn').click(function() {
function onLearn() {
var keyword = prompt('Input keyword to learn as (alphanumeric, no spaces)');
if (keyword === null) {
return;
@ -89,11 +90,13 @@
alert('Failed to learn keyword');
}
});
});
});
}
function search() {
function onForget() {
}
function onSearch() {
var keyword = $('#searchKeyword').val();
_ctx.query = {
@ -134,14 +137,14 @@
$.getJSON('/search', _ctx.query, function(results) {
saveSnapshot(results);
outputSnapshot(results);
$('#customized').hide();
setCustomized(false);
});
}
function onSelectSnapshot() {
var index = $('#historyIndex').slider('getValue');
outputSnapshot(_ctx.log[index]);
$('#customized').show();
setCustomized(true);
}
function saveSnapshot(results) {
@ -157,6 +160,16 @@
}
}
function setCustomized(customized) {
$('#forget').prop('disabled', customized);
if (customized) {
$('#customized').show();
}
else {
$('#customized').hide();
}
}
function outputSnapshot(results) {
for (var name in results.columns) {
_ctx.query.features[name] = results.columns[name].value;