Skip to content

Firefly III: a personal finances manager

Fix auto complete for tags and others. Adds search.

James Cole0bd818956f3a
diff --git a/public/css/firefly.css b/public/css/firefly.css
index ec5e8ec00a..8e64155a3c 100644
--- a/public/css/firefly.css
+++ b/public/css/firefly.css
@@ -184,8 +184,16 @@ span.info-box-text a:hover, span.info-box-number a:hover {
}
.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-hint {
diff --git a/public/js/ff/common/autocomplete.js b/public/js/ff/common/autocomplete.js
index 03d6dd890b..ccba2d5028 100644
--- a/public/js/ff/common/autocomplete.js
+++ b/public/js/ff/common/autocomplete.js
@@ -22,6 +22,7 @@
* Do tags auto complete.
*/
function initTagsAC() {
+ console.log('initTagsAC()');
var tagTags = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('name'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
@@ -32,11 +33,22 @@ function initTagsAC() {
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',
@@ -56,8 +68,8 @@ function initExpenseAC() {
* Do destination name (expense accounts) auto complete.
*/
function initExpenseACField(fieldName) {
+ console.log('initExpenseACField("' + fieldName + '")');
if ($('input[name="' + fieldName + '"]').length > 0) {
- console.log('Init expense AC for field "'+fieldName+'"');
var destNames = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('name'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
@@ -68,10 +80,19 @@ function initExpenseACField(fieldName) {
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="' + 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.
*/
function initRevenueACField(fieldName) {
-
+ console.log('initRevenueACField("' + fieldName + '")');
if ($('input[name="' + fieldName + '"]').length > 0) {
- console.log('Init revenue AC for field "'+fieldName+'"');
var sourceNames = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('name'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
@@ -99,10 +119,19 @@ function initRevenueACField(fieldName) {
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="' + 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};
});
}
+ },
+ 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({}, {source: categories, displayKey: 'name', autoSelect: false});
+ $('input[name="category"]').typeahead({hint: true, highlight: true,}, {source: categories, displayKey: 'name', autoSelect: false});
}
\ No newline at end of file
diff --git a/public/js/ff/rules/create-edit.js b/public/js/ff/rules/create-edit.js
index 460100004c..79d6a9b291 100644
--- a/public/js/ff/rules/create-edit.js
+++ b/public/js/ff/rules/create-edit.js
@@ -360,7 +360,7 @@ function updateTriggerInput(selectList) {
* @param URI
*/
function createAutoComplete(input, URI) {
- console.log('Now in createAutoComplete().')
+ console.log('Now in createAutoComplete("' + URI + '").');
input.typeahead('destroy');
var source = new Bloodhound({
@@ -373,10 +373,19 @@ function createAutoComplete(input, URI) {
return {name: name};
});
}
+ },
+ remote: {
+ url: URI + '?search=%QUERY',
+ wildcard: '%QUERY',
+ filter: function (list) {
+ return $.map(list, function (name) {
+ return {name: name};
+ });
+ }
}
});
source.initialize();
- input.typeahead({}, {source: source, displayKey: 'name', autoSelect: false});
+ input.typeahead({hint: true, highlight: true,}, {source: source, displayKey: 'name', autoSelect: false});
}
function testRuleTriggers() {
diff --git a/public/js/ff/transactions/mass/edit-bulk.js b/public/js/ff/transactions/mass/edit-bulk.js
index c4eeba57ff..bcff97c14a 100644
--- a/public/js/ff/transactions/mass/edit-bulk.js
+++ b/public/js/ff/transactions/mass/edit-bulk.js
@@ -22,21 +22,6 @@
$(document).ready(function () {
"use strict";
-
- $.getJSON('json/categories').done(function (data) {
- $('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
- );
- });
+ initTagsAC();
+ initCategoryAC();
});
\ No newline at end of file
diff --git a/public/js/ff/transactions/mass/edit.js b/public/js/ff/transactions/mass/edit.js
index 9f98362fed..e1fa6d17af 100644
--- a/public/js/ff/transactions/mass/edit.js
+++ b/public/js/ff/transactions/mass/edit.js
@@ -25,19 +25,83 @@ $(document).ready(function () {
// destination account names:
if ($('input[name^="destination_name["]').length > 0) {
- $.getJSON('json/expense-accounts').done(function (data) {
- $('input[name^="destination_name["]').typeahead({source: data, autoSelect: false});
- });
+ 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};
+ });
+ }
+ },
+ 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
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) {
- $('input[name^="category["]').typeahead({source: data, autoSelect: false});
- });
+ var categories = new Bloodhound({
+ 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});
+
});
\ No newline at end of file
diff --git a/public/js/ff/transactions/show.js b/public/js/ff/transactions/show.js
index 92ec25999a..74509ba2e0 100644
--- a/public/js/ff/transactions/show.js
+++ b/public/js/ff/transactions/show.js
@@ -32,11 +32,20 @@ $(function () {
return {name: name};
});
}
+ },
+ remote: {
+ url: autoCompleteUri + '?search=%QUERY',
+ wildcard: '%QUERY',
+ filter: function (list) {
+ return $.map(list, function (name) {
+ return {name: name};
+ });
+ }
}
});
transactions.initialize();
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 () {
var current = input.typeahead("getActive");
diff --git a/public/js/ff/transactions/single/common.js b/public/js/ff/transactions/single/common.js
index cf5e4efb27..a9c2dcc386 100644
--- a/public/js/ff/transactions/single/common.js
+++ b/public/js/ff/transactions/single/common.js
@@ -49,81 +49,15 @@ function setCommonAutocomplete() {
console.log('In setCommonAutoComplete()');
// do tags auto complete:
- 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};
- });
- }
- }
- });
- tagTags.initialize();
- $('input[name="tags"]').tagsinput({
- typeaheadjs: {
- name: 'tags',
- displayKey: 'name',
- valueKey: 'name',
- source: tagTags.ttAdapter()
- }
- });
-
+ initTagsAC();
// do destination name (expense accounts):
- if ($('input[name="destination_name"]').length > 0) {
- // 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});
- }
+ initExpenseAC();
// do source name (revenue accounts):
- if ($('input[name="source_name"]').length > 0) {
- // 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});
- }
+ initRevenueAC();
// do categories auto complete:
- var categories = new Bloodhound({
- 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});
+ initCategoryAC();
}
/**
diff --git a/public/js/ff/transactions/single/create.js b/public/js/ff/transactions/single/create.js
index e912a71dbc..9411d1ab2c 100644
--- a/public/js/ff/transactions/single/create.js
+++ b/public/js/ff/transactions/single/create.js
@@ -148,10 +148,19 @@ function updateDescription() {
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('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();
}
diff --git a/public/js/ff/transactions/single/edit.js b/public/js/ff/transactions/single/edit.js
index 30ce29ea8f..47a9a4ea75 100644
--- a/public/js/ff/transactions/single/edit.js
+++ b/public/js/ff/transactions/single/edit.js
@@ -148,9 +148,31 @@ function getAccountId() {
* Set the auto-complete JSON things.
*/
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});
}
/**
diff --git a/public/js/ff/transactions/split/edit.js b/public/js/ff/transactions/split/edit.js
index f3178e0f4e..161040c509 100644
--- a/public/js/ff/transactions/split/edit.js
+++ b/public/js/ff/transactions/split/edit.js
@@ -21,53 +21,152 @@
/** global: originalSum,originalForeignSum, accounting, what, Modernizr, currencySymbol, foreignCurrencySymbol */
-var destAccounts = {};
-var srcAccounts = {};
-var categories = {};
-var descriptions = {};
+var destNames;
+var sourceNames;
+var categories;
+var journalNames;
$(document).ready(function () {
"use strict";
$('.btn-do-split').click(cloneDivRow);
$('.remove-current-split').click(removeDivRow);
- $.getJSON('json/expense-accounts').done(function (data) {
- destAccounts = data;
- $('input[name$="destination_name]"]').typeahead({source: destAccounts, autoSelect: false});
- });
-
- $.getJSON('json/revenue-accounts').done(function (data) {
- srcAccounts = data;
- $('input[name$="source_name]"]').typeahead({source: srcAccounts, autoSelect: false});
- });
-
- $.getJSON('json/categories').done(function (data) {
- categories = data;
- $('input[name$="category_name]"]').typeahead({source: categories, autoSelect: false});
- });
-
- $.getJSON('json/transaction-journals/' + what).done(function (data) {
- descriptions = data;
- $('input[name="journal_description"]').typeahead({source: descriptions, autoSelect: false});
- $('input[name$="transaction_description]"]').typeahead({source: descriptions, autoSelect: false});
- });
-
- $.getJSON('json/tags').done(function (data) {
-
- var opt = {
- typeahead: {
- source: data,
- afterSelect: function () {
- this.$element.val("");
- },
- autoSelect: false
- }
- };
- $('input[name="tags"]').tagsinput(
- opt
- );
- });
-
+ // auto complete destination name (expense accounts):
+ 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};
+ });
+ }
+ },
+ 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});
+
+ // auto complete source name (revenue accounts):
+ 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});
+
+ // auto complete category fields:
+ categories = new Bloodhound({
+ 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});
+
+ // get transaction journal name things:
+ 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="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});
+
+ // 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$="][foreign_amount]"]').on('change', calculateBothSums);
@@ -128,18 +227,18 @@ function cloneDivRow() {
source.find('input[name$="][amount]"]').val("").on('change', calculateBothSums);
source.find('input[name$="][foreign_amount]"]').val("").on('change', calculateBothSums);
- if (destAccounts.length > 0) {
- source.find('input[name$="destination_name]"]').typeahead({source: destAccounts, autoSelect: false});
+ if (destNames) {
+ source.find('input[name$="destination_name]"]').typeahead({hint: true, highlight: true,}, {source: destNames, displayKey: 'name', autoSelect: false});
}
- if (srcAccounts.length > 0) {
- source.find('input[name$="source_name]"]').typeahead({source: srcAccounts, autoSelect: false});
+ if (sourceNames) {
+ source.find('input[name$="source_name]"]').typeahead({hint: true, highlight: true,}, {source: sourceNames, displayKey: 'name', autoSelect: false});
}
- if (categories.length > 0) {
- source.find('input[name$="category_name]"]').typeahead({source: categories, autoSelect: false});
+ if (categories) {
+ source.find('input[name$="category_name]"]').typeahead({hint: true, highlight: true,}, {source: categories, displayKey: 'name', autoSelect: false});
}
- if (descriptions.length > 0) {
- source.find('input[name$="transaction_description]"]').typeahead({source: descriptions, autoSelect: false});
+ if (journalNames) {
+ source.find('input[name$="transaction_description]"]').typeahead({hint: true, highlight: true,}, {source: journalNames, displayKey: 'name', autoSelect: false});
}
$('div.split_row_holder').append(source);