Enhance Product Drop Down Selector on Invoices #1975

This commit is contained in:
Hillel Coren 2018-05-14 11:58:09 +03:00
parent 2b7b9f83e4
commit a678044b4b
4 changed files with 25 additions and 25 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1158,7 +1158,7 @@ function prettyJson(json) {
}); });
} }
function searchData(data, key, fuzzy) { function searchData(data, key, fuzzy, secondKey) {
return function findMatches(q, cb) { return function findMatches(q, cb) {
var matches, substringRegex; var matches, substringRegex;
if (fuzzy) { if (fuzzy) {
@ -1173,7 +1173,8 @@ function searchData(data, key, fuzzy) {
$.each(data, function(i, obj) { $.each(data, function(i, obj) {
if (substrRegex.test(obj[key])) { if (substrRegex.test(obj[key])) {
matches.push(obj); matches.push(obj);
} } else if (secondKey && substrRegex.test(obj[secondKey]))
matches.push(obj);
}); });
} }
cb(matches); cb(matches);

View File

@ -1039,13 +1039,12 @@ ko.bindingHandlers.productTypeahead = {
display: allBindings.key, display: allBindings.key,
limit: 50, limit: 50,
templates: { templates: {
suggestion: function(item) { return '<div title="' suggestion: function(item) { return '<div title="' + _.escape(item.notes) + '" style="border-bottom: solid 1px #CCC">'
+ _.escape(item.product_key) + ': ' + _.escape(item.product_key) + ': '
+ item.cost + "\n" + roundToTwo(item.cost, true) + "<br/>"
+ item.notes.substring(0, 60) + '">' + _.escape(item.notes.substring(0, 100)) + '</div>' }
+ _.escape(item.product_key) + '</div>' }
}, },
source: searchData(allBindings.items, allBindings.key) source: searchData(allBindings.items, allBindings.key, false, 'notes')
}).on('typeahead:select', function(element, datum, name) { }).on('typeahead:select', function(element, datum, name) {
@if (Auth::user()->account->fill_products) @if (Auth::user()->account->fill_products)
var model = ko.dataFor(this); var model = ko.dataFor(this);