Fix auto complete for tags and others. Adds search.

This commit is contained in:
James Cole 2018-09-23 07:39:04 +02:00
parent 254a46b54c
commit 0bd818956f
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
10 changed files with 331 additions and 154 deletions

View File

@ -184,8 +184,16 @@ span.info-box-text a:hover, span.info-box-number a:hover {
} }
.twitter-typeahead { .twitter-typeahead {
display:block !important; width:100%;
} }
span.twitter-typeahead {
display: inline !important;width:100%;
}
.tt-input {
background-color:#fff !important;
}
.twitter-typeahead .tt-query, .twitter-typeahead .tt-query,
.twitter-typeahead .tt-hint { .twitter-typeahead .tt-hint {

View File

@ -22,6 +22,7 @@
* Do tags auto complete. * Do tags auto complete.
*/ */
function initTagsAC() { function initTagsAC() {
console.log('initTagsAC()');
var tagTags = new Bloodhound({ var tagTags = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('name'), datumTokenizer: Bloodhound.tokenizers.obj.whitespace('name'),
queryTokenizer: Bloodhound.tokenizers.whitespace, queryTokenizer: Bloodhound.tokenizers.whitespace,
@ -32,11 +33,22 @@ function initTagsAC() {
return {name: tagTag}; return {name: tagTag};
}); });
} }
},
remote: {
url: 'json/tags?search=%QUERY',
wildcard: '%QUERY',
filter: function (list) {
return $.map(list, function (name) {
return {name: name};
});
}
} }
}); });
tagTags.initialize(); tagTags.initialize();
$('input[name="tags"]').tagsinput({ $('input[name="tags"]').tagsinput({
typeaheadjs: { typeaheadjs: {
hint: true,
highlight: true,
name: 'tags', name: 'tags',
displayKey: 'name', displayKey: 'name',
valueKey: 'name', valueKey: 'name',
@ -56,8 +68,8 @@ function initExpenseAC() {
* Do destination name (expense accounts) auto complete. * Do destination name (expense accounts) auto complete.
*/ */
function initExpenseACField(fieldName) { function initExpenseACField(fieldName) {
console.log('initExpenseACField("' + fieldName + '")');
if ($('input[name="' + fieldName + '"]').length > 0) { if ($('input[name="' + fieldName + '"]').length > 0) {
console.log('Init expense AC for field "'+fieldName+'"');
var destNames = new Bloodhound({ var destNames = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('name'), datumTokenizer: Bloodhound.tokenizers.obj.whitespace('name'),
queryTokenizer: Bloodhound.tokenizers.whitespace, queryTokenizer: Bloodhound.tokenizers.whitespace,
@ -68,10 +80,19 @@ function initExpenseACField(fieldName) {
return {name: name}; return {name: name};
}); });
} }
},
remote: {
url: 'json/expense-accounts?search=%QUERY',
wildcard: '%QUERY',
filter: function (list) {
return $.map(list, function (name) {
return {name: name};
});
}
} }
}); });
destNames.initialize(); destNames.initialize();
$('input[name="' + fieldName + '"]').typeahead({}, {source: destNames, displayKey: 'name', autoSelect: false}); $('input[name="' + fieldName + '"]').typeahead({hint: true, highlight: true,}, {source: destNames, displayKey: 'name', autoSelect: false});
} }
} }
@ -86,9 +107,8 @@ function initRevenueAC() {
* Do source name (revenue accounts) auto complete. * Do source name (revenue accounts) auto complete.
*/ */
function initRevenueACField(fieldName) { function initRevenueACField(fieldName) {
console.log('initRevenueACField("' + fieldName + '")');
if ($('input[name="' + fieldName + '"]').length > 0) { if ($('input[name="' + fieldName + '"]').length > 0) {
console.log('Init revenue AC for field "'+fieldName+'"');
var sourceNames = new Bloodhound({ var sourceNames = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('name'), datumTokenizer: Bloodhound.tokenizers.obj.whitespace('name'),
queryTokenizer: Bloodhound.tokenizers.whitespace, queryTokenizer: Bloodhound.tokenizers.whitespace,
@ -99,10 +119,19 @@ function initRevenueACField(fieldName) {
return {name: name}; return {name: name};
}); });
} }
},
remote: {
url: 'json/revenue-accounts?search=%QUERY',
wildcard: '%QUERY',
filter: function (list) {
return $.map(list, function (name) {
return {name: name};
});
}
} }
}); });
sourceNames.initialize(); sourceNames.initialize();
$('input[name="' + fieldName + '"]').typeahead({}, {source: sourceNames, displayKey: 'name', autoSelect: false}); $('input[name="' + fieldName + '"]').typeahead({hint: true, highlight: true,}, {source: sourceNames, displayKey: 'name', autoSelect: false});
} }
} }
@ -120,8 +149,17 @@ function initCategoryAC() {
return {name: name}; return {name: name};
}); });
} }
},
remote: {
url: 'json/categories?search=%QUERY',
wildcard: '%QUERY',
filter: function (list) {
return $.map(list, function (name) {
return {name: name};
});
}
} }
}); });
categories.initialize(); categories.initialize();
$('input[name="category"]').typeahead({}, {source: categories, displayKey: 'name', autoSelect: false}); $('input[name="category"]').typeahead({hint: true, highlight: true,}, {source: categories, displayKey: 'name', autoSelect: false});
} }

View File

@ -360,7 +360,7 @@ function updateTriggerInput(selectList) {
* @param URI * @param URI
*/ */
function createAutoComplete(input, URI) { function createAutoComplete(input, URI) {
console.log('Now in createAutoComplete().') console.log('Now in createAutoComplete("' + URI + '").');
input.typeahead('destroy'); input.typeahead('destroy');
var source = new Bloodhound({ var source = new Bloodhound({
@ -373,10 +373,19 @@ function createAutoComplete(input, URI) {
return {name: name}; return {name: name};
}); });
} }
},
remote: {
url: URI + '?search=%QUERY',
wildcard: '%QUERY',
filter: function (list) {
return $.map(list, function (name) {
return {name: name};
});
}
} }
}); });
source.initialize(); source.initialize();
input.typeahead({}, {source: source, displayKey: 'name', autoSelect: false}); input.typeahead({hint: true, highlight: true,}, {source: source, displayKey: 'name', autoSelect: false});
} }
function testRuleTriggers() { function testRuleTriggers() {

View File

@ -22,21 +22,6 @@
$(document).ready(function () { $(document).ready(function () {
"use strict"; "use strict";
initTagsAC();
$.getJSON('json/categories').done(function (data) { initCategoryAC();
$('input[name="category"]').typeahead({source: data, autoSelect: false});
});
$.getJSON('json/tags').done(function (data) {
var opt = {
source: data,
afterSelect: function () {
this.$element.val("");
},
autoSelect: false
};
$('input[name="tags"]').tagsinput(
opt
);
});
}); });

View File

@ -25,19 +25,83 @@ $(document).ready(function () {
// destination account names: // destination account names:
if ($('input[name^="destination_name["]').length > 0) { if ($('input[name^="destination_name["]').length > 0) {
$.getJSON('json/expense-accounts').done(function (data) { var destNames = new Bloodhound({
$('input[name^="destination_name["]').typeahead({source: data, autoSelect: false}); datumTokenizer: Bloodhound.tokenizers.obj.whitespace('name'),
}); queryTokenizer: Bloodhound.tokenizers.whitespace,
prefetch: {
url: 'json/expense-accounts',
filter: function (list) {
return $.map(list, function (name) {
return {name: name};
});
}
},
remote: {
url: 'json/expense-accounts?search=%QUERY',
wildcard: '%QUERY',
filter: function (list) {
return $.map(list, function (name) {
return {name: name};
});
}
}
});
destNames.initialize();
$('input[name^="destination_name["]').typeahead({hint: true, highlight: true,}, {source: destNames, displayKey: 'name', autoSelect: false});
} }
// source account name // source account name
if ($('input[name^="source_name["]').length > 0) { if ($('input[name^="source_name["]').length > 0) {
$.getJSON('json/revenue-accounts').done(function (data) {
$('input[name^="source_name["]').typeahead({source: data, autoSelect: false}); var sourceNames = new Bloodhound({
}); datumTokenizer: Bloodhound.tokenizers.obj.whitespace('name'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
prefetch: {
url: 'json/revenue-accounts',
filter: function (list) {
return $.map(list, function (name) {
return {name: name};
});
}
},
remote: {
url: 'json/revenue-accounts?search=%QUERY',
wildcard: '%QUERY',
filter: function (list) {
return $.map(list, function (name) {
return {name: name};
});
}
}
});
sourceNames.initialize();
$('input[name^="source_name["]').typeahead({hint: true, highlight: true,}, {source: sourceNames, displayKey: 'name', autoSelect: false});
} }
$.getJSON('json/categories').done(function (data) { var categories = new Bloodhound({
$('input[name^="category["]').typeahead({source: data, autoSelect: false}); datumTokenizer: Bloodhound.tokenizers.obj.whitespace('name'),
}); queryTokenizer: Bloodhound.tokenizers.whitespace,
prefetch: {
url: 'json/categories',
filter: function (list) {
return $.map(list, function (name) {
return {name: name};
});
}
},
remote: {
url: 'json/categories?search=%QUERY',
wildcard: '%QUERY',
filter: function (list) {
return $.map(list, function (name) {
return {name: name};
});
}
}
});
categories.initialize();
$('input[name^="category["]').typeahead({hint: true, highlight: true,}, {source: categories, displayKey: 'name', autoSelect: false});
}); });

View File

@ -32,11 +32,20 @@ $(function () {
return {name: name}; return {name: name};
}); });
} }
},
remote: {
url: autoCompleteUri + '?search=%QUERY',
wildcard: '%QUERY',
filter: function (list) {
return $.map(list, function (name) {
return {name: name};
});
}
} }
}); });
transactions.initialize(); transactions.initialize();
var input=$("#link_other"); var input=$("#link_other");
input.typeahead({}, {source: transactions, displayKey: 'name', autoSelect: false}); input.typeahead({hint: true, highlight: true,}, {source: transactions, displayKey: 'name', autoSelect: false});
input.change(function () { input.change(function () {
var current = input.typeahead("getActive"); var current = input.typeahead("getActive");

View File

@ -49,81 +49,15 @@ function setCommonAutocomplete() {
console.log('In setCommonAutoComplete()'); console.log('In setCommonAutoComplete()');
// do tags auto complete: // do tags auto complete:
var tagTags = new Bloodhound({ initTagsAC();
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('name'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
prefetch: {
url: 'json/tags',
filter: function (list) {
return $.map(list, function (tagTag) {
return {name: tagTag};
});
}
}
});
tagTags.initialize();
$('input[name="tags"]').tagsinput({
typeaheadjs: {
name: 'tags',
displayKey: 'name',
valueKey: 'name',
source: tagTags.ttAdapter()
}
});
// do destination name (expense accounts): // do destination name (expense accounts):
if ($('input[name="destination_name"]').length > 0) { initExpenseAC();
// do tags auto complete:
var destNames = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('name'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
prefetch: {
url: 'json/expense-accounts',
filter: function (list) {
return $.map(list, function (name) {
return {name: name};
});
}
}
});
destNames.initialize();
$('input[name="destination_name"]').typeahead({}, {source: destNames, displayKey: 'name', autoSelect: false});
}
// do source name (revenue accounts): // do source name (revenue accounts):
if ($('input[name="source_name"]').length > 0) { initRevenueAC();
// do tags auto complete:
var sourceNames = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('name'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
prefetch: {
url: 'json/revenue-accounts',
filter: function (list) {
return $.map(list, function (name) {
return {name: name};
});
}
}
});
sourceNames.initialize();
$('input[name="source_name"]').typeahead({}, {source: sourceNames, displayKey: 'name', autoSelect: false});
}
// do categories auto complete: // do categories auto complete:
var categories = new Bloodhound({ initCategoryAC();
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('name'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
prefetch: {
url: 'json/categories',
filter: function (list) {
return $.map(list, function (name) {
return {name: name};
});
}
}
});
categories.initialize();
$('input[name="category"]').typeahead({}, {source: categories, displayKey: 'name', autoSelect: false});
} }
/** /**

View File

@ -148,10 +148,19 @@ function updateDescription() {
return {name: name}; return {name: name};
}); });
} }
},
remote: {
url: 'json/transaction-journals/' + what + '?search=%QUERY',
wildcard: '%QUERY',
filter: function (list) {
return $.map(list, function (name) {
return {name: name};
});
}
} }
}); });
journalNames.initialize(); journalNames.initialize();
$('input[name="description"]').typeahead('destroy').typeahead({}, {source: journalNames, displayKey: 'name', autoSelect: false}); $('input[name="description"]').typeahead('destroy').typeahead({hint: true, highlight: true,}, {source: journalNames, displayKey: 'name', autoSelect: false});
$('#ffInput_description').focus(); $('#ffInput_description').focus();
} }

View File

@ -148,9 +148,31 @@ function getAccountId() {
* Set the auto-complete JSON things. * Set the auto-complete JSON things.
*/ */
function setAutocompletes() { function setAutocompletes() {
$.getJSON('json/transaction-journals/' + what).done(function (data) {
$('input[name="description"]').typeahead({source: data, autoSelect: false}); // do description auto complete:
}); var journalNames = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('name'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
prefetch: {
url: 'json/transaction-journals/' + what,
filter: function (list) {
return $.map(list, function (name) {
return {name: name};
});
}
},
remote: {
url: 'json/transaction-journals/' + what + '?search=%QUERY',
wildcard: '%QUERY',
filter: function (list) {
return $.map(list, function (name) {
return {name: name};
});
}
}
});
journalNames.initialize();
$('input[name="description"]').typeahead({hint: true, highlight: true,}, {source: journalNames, displayKey: 'name', autoSelect: false});
} }
/** /**

View File

@ -21,53 +21,152 @@
/** global: originalSum,originalForeignSum, accounting, what, Modernizr, currencySymbol, foreignCurrencySymbol */ /** global: originalSum,originalForeignSum, accounting, what, Modernizr, currencySymbol, foreignCurrencySymbol */
var destAccounts = {}; var destNames;
var srcAccounts = {}; var sourceNames;
var categories = {}; var categories;
var descriptions = {}; var journalNames;
$(document).ready(function () { $(document).ready(function () {
"use strict"; "use strict";
$('.btn-do-split').click(cloneDivRow); $('.btn-do-split').click(cloneDivRow);
$('.remove-current-split').click(removeDivRow); $('.remove-current-split').click(removeDivRow);
$.getJSON('json/expense-accounts').done(function (data) { // auto complete destination name (expense accounts):
destAccounts = data; destNames = new Bloodhound({
$('input[name$="destination_name]"]').typeahead({source: destAccounts, autoSelect: false}); datumTokenizer: Bloodhound.tokenizers.obj.whitespace('name'),
}); queryTokenizer: Bloodhound.tokenizers.whitespace,
prefetch: {
url: 'json/expense-accounts',
filter: function (list) {
return $.map(list, function (name) {
return {name: name};
});
}
},
remote: {
url: 'json/expense-accounts?search=%QUERY',
wildcard: '%QUERY',
filter: function (list) {
return $.map(list, function (name) {
return {name: name};
});
}
}
});
destNames.initialize();
$('input[name$="destination_name]"]').typeahead({hint: true, highlight: true,}, {source: destNames, displayKey: 'name', autoSelect: false});
$.getJSON('json/revenue-accounts').done(function (data) { // auto complete source name (revenue accounts):
srcAccounts = data; sourceNames = new Bloodhound({
$('input[name$="source_name]"]').typeahead({source: srcAccounts, autoSelect: false}); datumTokenizer: Bloodhound.tokenizers.obj.whitespace('name'),
}); queryTokenizer: Bloodhound.tokenizers.whitespace,
prefetch: {
url: 'json/revenue-accounts',
filter: function (list) {
return $.map(list, function (name) {
return {name: name};
});
}
},
remote: {
url: 'json/revenue-accounts?search=%QUERY',
wildcard: '%QUERY',
filter: function (list) {
return $.map(list, function (name) {
return {name: name};
});
}
}
});
sourceNames.initialize();
$('input[name$="source_name]"]').typeahead({hint: true, highlight: true,}, {source: sourceNames, displayKey: 'name', autoSelect: false});
$.getJSON('json/categories').done(function (data) { // auto complete category fields:
categories = data; categories = new Bloodhound({
$('input[name$="category_name]"]').typeahead({source: categories, autoSelect: false}); datumTokenizer: Bloodhound.tokenizers.obj.whitespace('name'),
}); queryTokenizer: Bloodhound.tokenizers.whitespace,
prefetch: {
url: 'json/categories',
filter: function (list) {
return $.map(list, function (name) {
return {name: name};
});
}
},
remote: {
url: 'json/categories?search=%QUERY',
wildcard: '%QUERY',
filter: function (list) {
return $.map(list, function (name) {
return {name: name};
});
}
}
});
categories.initialize();
$('input[name$="category_name]"]').typeahead({hint: true, highlight: true,}, {source: categories, displayKey: 'name', autoSelect: false});
$.getJSON('json/transaction-journals/' + what).done(function (data) { // get transaction journal name things:
descriptions = data; journalNames = new Bloodhound({
$('input[name="journal_description"]').typeahead({source: descriptions, autoSelect: false}); datumTokenizer: Bloodhound.tokenizers.obj.whitespace('name'),
$('input[name$="transaction_description]"]').typeahead({source: descriptions, autoSelect: false}); queryTokenizer: Bloodhound.tokenizers.whitespace,
}); prefetch: {
url: 'json/transaction-journals/' + what,
filter: function (list) {
return $.map(list, function (name) {
return {name: name};
});
}
},
remote: {
url: 'json/transaction-journals/' + what + '?search=%QUERY',
wildcard: '%QUERY',
filter: function (list) {
return $.map(list, function (name) {
return {name: name};
});
}
}
});
journalNames.initialize();
$.getJSON('json/tags').done(function (data) { $('input[name="journal_description"]').typeahead({hint: true, highlight: true,}, {source: journalNames, displayKey: 'name', autoSelect: false});
$('input[name$="transaction_description]"]').typeahead({hint: true, highlight: true,}, {source: journalNames, displayKey: 'name', autoSelect: false});
var opt = {
typeahead: {
source: data,
afterSelect: function () {
this.$element.val("");
},
autoSelect: false
}
};
$('input[name="tags"]').tagsinput(
opt
);
});
// get tags:
console.log('initTagsAC()');
var tagTags = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('name'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
prefetch: {
url: 'json/tags',
filter: function (list) {
return $.map(list, function (tagTag) {
return {name: tagTag};
});
}
},
remote: {
url: 'json/tags?search=%QUERY',
wildcard: '%QUERY',
filter: function (list) {
return $.map(list, function (name) {
return {name: name};
});
}
}
});
tagTags.initialize();
$('input[name="tags"]').tagsinput({
typeaheadjs: {
hint: true,
highlight: true,
name: 'tags',
displayKey: 'name',
valueKey: 'name',
source: tagTags.ttAdapter()
}
});
$('input[name$="][amount]"]').on('change', calculateBothSums); $('input[name$="][amount]"]').on('change', calculateBothSums);
$('input[name$="][foreign_amount]"]').on('change', calculateBothSums); $('input[name$="][foreign_amount]"]').on('change', calculateBothSums);
@ -128,18 +227,18 @@ function cloneDivRow() {
source.find('input[name$="][amount]"]').val("").on('change', calculateBothSums); source.find('input[name$="][amount]"]').val("").on('change', calculateBothSums);
source.find('input[name$="][foreign_amount]"]').val("").on('change', calculateBothSums); source.find('input[name$="][foreign_amount]"]').val("").on('change', calculateBothSums);
if (destAccounts.length > 0) { if (destNames) {
source.find('input[name$="destination_name]"]').typeahead({source: destAccounts, autoSelect: false}); source.find('input[name$="destination_name]"]').typeahead({hint: true, highlight: true,}, {source: destNames, displayKey: 'name', autoSelect: false});
} }
if (srcAccounts.length > 0) { if (sourceNames) {
source.find('input[name$="source_name]"]').typeahead({source: srcAccounts, autoSelect: false}); source.find('input[name$="source_name]"]').typeahead({hint: true, highlight: true,}, {source: sourceNames, displayKey: 'name', autoSelect: false});
} }
if (categories.length > 0) { if (categories) {
source.find('input[name$="category_name]"]').typeahead({source: categories, autoSelect: false}); source.find('input[name$="category_name]"]').typeahead({hint: true, highlight: true,}, {source: categories, displayKey: 'name', autoSelect: false});
} }
if (descriptions.length > 0) { if (journalNames) {
source.find('input[name$="transaction_description]"]').typeahead({source: descriptions, autoSelect: false}); source.find('input[name$="transaction_description]"]').typeahead({hint: true, highlight: true,}, {source: journalNames, displayKey: 'name', autoSelect: false});
} }
$('div.split_row_holder').append(source); $('div.split_row_holder').append(source);