diff --git a/public/built.js b/public/built.js index cfb777e86e0e..5e28b8fb3f18 100644 --- a/public/built.js +++ b/public/built.js @@ -30967,6 +30967,29 @@ function prettyJson(json) { return '' + match + ''; }); } + +function searchData(data, key, fuzzy) { + return function findMatches(q, cb) { + var matches, substringRegex; + if (fuzzy) { + var options = { + keys: [key], + } + var fuse = new Fuse(data, options); + matches = fuse.search(q); + } else { + matches = []; + substrRegex = new RegExp(q, 'i'); + $.each(data, function(i, obj) { + if (substrRegex.test(obj[key])) { + matches.push(obj); + } + }); + } + cb(matches); + } +}; + var NINJA = NINJA || {}; NINJA.TEMPLATES = { diff --git a/public/css/built.css b/public/css/built.css index 8fc151f77508..d4b3a8204e6b 100644 --- a/public/css/built.css +++ b/public/css/built.css @@ -2060,7 +2060,7 @@ See http://bgrins.github.io/spectrum/themes/ for instructions. /*root typeahead class*/ .twitter-typeahead { - display: inherit !important; + /*display: inherit !important;*/ width: 100%; } diff --git a/public/css/typeahead.js-bootstrap.css b/public/css/typeahead.js-bootstrap.css index da8cbf605407..9f4125d18e34 100644 --- a/public/css/typeahead.js-bootstrap.css +++ b/public/css/typeahead.js-bootstrap.css @@ -4,7 +4,7 @@ /*root typeahead class*/ .twitter-typeahead { - display: inherit !important; + /*display: inherit !important;*/ width: 100%; } diff --git a/public/js/script.js b/public/js/script.js index a8201d3c427e..67031a5fe3c9 100644 --- a/public/js/script.js +++ b/public/js/script.js @@ -1074,4 +1074,26 @@ function prettyJson(json) { match = snakeToCamel(match); return '' + match + ''; }); -} \ No newline at end of file +} + +function searchData(data, key, fuzzy) { + return function findMatches(q, cb) { + var matches, substringRegex; + if (fuzzy) { + var options = { + keys: [key], + } + var fuse = new Fuse(data, options); + matches = fuse.search(q); + } else { + matches = []; + substrRegex = new RegExp(q, 'i'); + $.each(data, function(i, obj) { + if (substrRegex.test(obj[key])) { + matches.push(obj); + } + }); + } + cb(matches); + } +}; diff --git a/resources/views/header.blade.php b/resources/views/header.blade.php index 9f9c3aa3ed3b..f541eec53329 100644 --- a/resources/views/header.blade.php +++ b/resources/views/header.blade.php @@ -259,13 +259,11 @@ } function showSearch() { - console.log('showSearch..'); - //$('#search').typeahead('setQuery', ''); + $('#search').typeahead('val', ''); $('#navbar-options').hide(); $('#search-form').show(); if (window.hasOwnProperty('loadedSearchData')) { - console.log('has data'); $('#search').focus(); } else { trackEvent('/activity', '/search'); @@ -275,68 +273,24 @@ $('#search').typeahead({ hint: true, highlight: true, - }, - { + } + @foreach (['clients', 'contacts', 'invoices', 'quotes', 'navigation'] as $type) + ,{ name: 'data', display: 'value', - source: searchData(data['clients']), + source: searchData(data['{{ $type }}'], 'value', true), templates: { - header: ' {{ trans('texts.clients') }}' + header: ' {{ trans("texts.{$type}") }}' } - }, - { - name: 'data', - display: 'value', - source: searchData(data['contacts']), - templates: { - header: ' {{ trans('texts.contacts') }}' - } - }, - { - name: 'data', - display: 'value', - source: searchData(data['invoices']), - templates: { - header: ' {{ trans('texts.contacts') }}' - } - }, - { - name: 'data', - display: 'value', - source: searchData(data['quotes']), - templates: { - header: ' {{ trans('texts.quotes') }}' - } - }, - { - name: 'data', - display: 'value', - source: searchData(data['navigation']), - templates: { - header: ' {{ trans('texts.navigation') }}' - } - }).on('typeahead:selected', function(element, datum, name) { + } + @endforeach + ).on('typeahead:selected', function(element, datum, name) { window.location = datum.url; }).focus(); - - //.typeahead('setQuery', $('#search').val()); }); } } - - function searchData(data) { - return function findMatches(q, cb) { - - var options = { - keys: ['value'], - } - var fuse = new Fuse(data, options); - var matches = fuse.search(q); - - cb(matches); - } - }; - + function hideSearch() { $('#search-form').hide(); $('#navbar-options').show(); diff --git a/resources/views/invoices/edit.blade.php b/resources/views/invoices/edit.blade.php index 548cc41e232c..343620e16af1 100644 --- a/resources/views/invoices/edit.blade.php +++ b/resources/views/invoices/edit.blade.php @@ -209,11 +209,7 @@ $parent.invoice_items().length > 1" class="fa fa-sort"> - {!! Former::text('product_key')->useDatalist($products->toArray(), 'product_key') - ->data_bind("value: product_key, valueUpdate: 'afterkeydown', attr: {name: 'invoice_items[' + \$index() + '][product_key]'}") - ->addClass('datalist') - ->raw() - !!} +