1

Interface improvements

This commit is contained in:
Alex Yatskov 2014-09-19 15:08:09 +09:00
parent 26760e135a
commit 0684fe9a69
3 changed files with 23 additions and 23 deletions

View File

@ -71,18 +71,24 @@
} }
function onLearn() { function onLearn() {
var query = { $('#learn').prop('disabled', true);
keyword: $('#keyword').val(),
params: ctx.searchParams
};
$.getJSON('/node/addKeyword', query, function(results) { $('#learnError').slideUp(function() {
if (results.success) { var query = {
$('#learnDlg').modal('hide'); keyword: $('#keyword').val(),
} params: ctx.searchParams
else { };
$('#learnError').fadeIn();
} $.getJSON('/node/addKeyword', query, function(results) {
if (results.success) {
$('#learnDlg').modal('hide');
}
else {
$('#learnError').slideDown(function() {
$('#learn').prop('disabled', false);
});
}
});
}); });
} }
@ -124,6 +130,7 @@
$('#learnDlg').on('show.bs.modal', function() { $('#learnDlg').on('show.bs.modal', function() {
$('#learn').prop('disabled', true); $('#learn').prop('disabled', true);
$('#keyword').val(''); $('#keyword').val('');
$('#learnError').hide();
}); });
$('#learn').click(onLearn); $('#learn').click(onLearn);

View File

@ -87,7 +87,7 @@
</div> </div>
</div> </div>
</div> </div>
<div class="alert alert-danger" id="learnError" style="display: none;">Error learning keyword</div> <div class="alert alert-danger" id="learnError" style="display: none;">Error writing keyword to database</div>
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
<div class="btn-group"> <div class="btn-group">

View File

@ -146,19 +146,12 @@ function loadDb(params) {
} }
function addKeyword(query, callback) { function addKeyword(query, callback) {
if (!query.keyword) {
callback({
keyword: query.keyword,
success: false
});
return;
}
getKeywords(function(keywords) { getKeywords(function(keywords) {
var keyword = query.keyword.toLowerCase();
var features = combine(keywords, query.params); var features = combine(keywords, query.params);
var values = [ var values = [
query.keyword, keyword,
features.food || 0.0, features.food || 0.0,
features.service || 0.0, features.service || 0.0,
features.value || 0.0, features.value || 0.0,
@ -167,7 +160,7 @@ function addKeyword(query, callback) {
connection.query('INSERT INTO keywords VALUES(?, ?, ?, ?, ?)', values, function(err) { connection.query('INSERT INTO keywords VALUES(?, ?, ?, ?, ?)', values, function(err) {
callback({ callback({
keyword: query.keyword, keyword: keyword,
success: err === null success: err === null
}); });
}); });