1

More cleanup

This commit is contained in:
Alex Yatskov 2014-09-19 20:26:46 +09:00
parent bf3725bcb8
commit eba1774a6e
2 changed files with 11 additions and 13 deletions

View File

@ -27,7 +27,7 @@
} }
function onSearch() { function onSearch() {
var keywords = $('#keywords').val() || []; var keywords = $('#keywordsToSearch').val() || [];
var searchParams = {}; var searchParams = {};
for (var i = 0, count = keywords.length; i < count; ++i) { for (var i = 0, count = keywords.length; i < count; ++i) {
@ -91,8 +91,6 @@
} }
function outputResults(results, count) { function outputResults(results, count) {
$('#results').empty();
var searchResultCnt = String(results.length); var searchResultCnt = String(results.length);
if (results.length < count) { if (results.length < count) {
searchResultCnt += ' of ' + count; searchResultCnt += ' of ' + count;
@ -100,6 +98,7 @@
$('#count').text(searchResultCnt); $('#count').text(searchResultCnt);
var template = Handlebars.compile($('#template').html()); var template = Handlebars.compile($('#template').html());
$('#results').empty();
$('#results').append(template({'results': results})); $('#results').append(template({'results': results}));
} }
@ -113,18 +112,16 @@
}, },
ready: function() { ready: function() {
$('#keywords').selectpicker(); $('#keywordsToSearch').selectpicker();
$.getJSON('/node/getKeywords', function(keywords) { $.getJSON('/node/getKeywords', function(keywords) {
for (var i = 0, count = keywords.length; i < count; ++i) { for (var i = 0, count = keywords.length; i < count; ++i) {
$('#keywords').append($('<option></option>', { $('#keywordsToSearch').append($('<option></option>', {
value: keywords[i], value: keywords[i],
text: keywords[i] text: keywords[i]
})); }));
} }
$('#search').click(onSearch);
$('#learnDialog').on('show.bs.modal', function() { $('#learnDialog').on('show.bs.modal', function() {
$('#learnKeyword').prop('disabled', true); $('#learnKeyword').prop('disabled', true);
$('#keywordToLearn').val(''); $('#keywordToLearn').val('');
@ -136,9 +133,10 @@
$('#learnKeyword').prop('disabled', !$(this).val()); $('#learnKeyword').prop('disabled', !$(this).val());
}); });
$('#keywords').selectpicker('refresh'); $('#searchKeywords').click(onSearch);
$('#keywords').change(function() { $('#keywordsToSearch').selectpicker('refresh');
$('#search').prop('disabled', !$(this).val()); $('#keywordsToSearch').change(function() {
$('#searchKeywords').prop('disabled', !$(this).val());
}); });
}); });
} }

View File

@ -17,9 +17,9 @@
<!-- Query Selector --> <!-- Query Selector -->
<div id="input" class="form-horizontal"> <div id="input" class="form-horizontal">
<div class="form-group"> <div class="form-group">
<label for="keywords" class="col-md-2 control-label">Keywords</label> <label for="keywordsToSearch" class="col-md-2 control-label">Keywords</label>
<div class="col-md-10"> <div class="col-md-10">
<select id="keywords" class="form-control" multiple="multiple" data-max-options="4" data-live-search="data-live-search" name="keywords"></select> <select id="keywordsToSearch" class="form-control" multiple="multiple" data-max-options="4" data-live-search="data-live-search" name="keywordsToSearch"></select>
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
@ -42,7 +42,7 @@
</div> </div>
<div class="form-group"> <div class="form-group">
<div class="col-md-offset-2 col-md-10"> <div class="col-md-offset-2 col-md-10">
<button class="btn btn-primary" id="search" type="button" disabled="disabled"> <button class="btn btn-primary" id="searchKeywords" type="button" disabled="disabled">
<span class="glyphicon glyphicon-search"></span> Search <span class="glyphicon glyphicon-search"></span> Search
</button> </button>
</div> </div>