diff --git a/fec/fec/static/js/modules/typeahead.js b/fec/fec/static/js/modules/typeahead.js index 22151fce8c..017f31fa20 100644 --- a/fec/fec/static/js/modules/typeahead.js +++ b/fec/fec/static/js/modules/typeahead.js @@ -58,6 +58,20 @@ function formatAuditCandidate(result) { }; } +function formatCaseRegulatoryCitation(result) { + return { + citation: result.citation_text, + type: 'caseRegulatoryCitation' + }; +} + +function formatCaseStatutoryCitation(result) { + return { + citation: result.citation_text, + type: 'caseStatutoryCitation' + }; +} + function getUrl(resource) { return URI(window.API_LOCATION) .path([window.API_VERSION, 'names', resource, ''].join('/')) @@ -68,6 +82,16 @@ function getUrl(resource) { .readable(); } +function getCitationUrl(citationType) { + return URI(window.API_LOCATION) + .path([window.API_VERSION, 'legal', 'citation', citationType, ''].join('/')) + .query({ + wildcard: '%QUERY', + api_key: window.API_KEY_PUBLIC + }) + .readable(); +} + var engineOpts = { datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'), queryTokenizer: Bloodhound.tokenizers.whitespace, @@ -118,6 +142,28 @@ var auditCandidateEngine = createEngine({ } }); +// Uses seperate resource path: /legal/citation/regulation/[query_string]/ +var caseRegulatoryEngine = createEngine({ + remote: { + url: getCitationUrl('regulation'), + wildcard: '%QUERY', + transform: function(response) { + return _.map(response.results, formatCaseRegulatoryCitation); + } + } +}); + +// Uses seperate resource path: /legal/citation/statute/[query_string]/ +var caseStatutoryEngine = createEngine({ + remote: { + url: getCitationUrl('statute'), + wildcard: '%QUERY', + transform: function(response) { + return _.map(response.results, formatCaseStatutoryCitation); + } + } +}); + var candidateDataset = { name: 'candidate', display: 'name', @@ -187,6 +233,39 @@ var auditCandidateDataset = { } }; +var caseRegulatoryCitationDataset = { + name: 'caseRegulatoryCitation', + display: 'regulatory', + limit: 10, + source: caseRegulatoryEngine, + templates: { + header: 'Select a citation:', + pending: + 'Loading citations…', + notFound: Handlebars.compile(''), // This has to be empty to not show anything + suggestion: Handlebars.compile( + '{{ citation }}' + ) + } +}; + +var caseStatutoryCitationDataset = { + name: 'caseStatutoryCitation', + display: 'statutory', + limit: 10, + source: caseStatutoryEngine, + templates: { + header: 'Select a citation:', + pending: + 'Loading citations…', + notFound: Handlebars.compile(''), // This has to be empty to not show anything + suggestion: Handlebars.compile( + '{{ citation }}' + ) + } +}; + + /* This is a fake dataset for showing an empty option with the query * when clicked, this will load the receipts page, * filtered to contributions from this person @@ -239,6 +318,8 @@ var datasets = { committees: committeeDataset, auditCandidates: auditCandidateDataset, auditCommittees: auditCommitteeDataset, + caseRegulatoryCitation: caseRegulatoryCitationDataset, + caseStatutoryCitation: caseStatutoryCitationDataset, allData: [candidateDataset, committeeDataset], all: [candidateDataset, committeeDataset, individualDataset, siteDataset] }; diff --git a/fec/legal/templates/legal-search-results-murs.jinja b/fec/legal/templates/legal-search-results-murs.jinja index 899ee5a3d6..fd8edaa647 100644 --- a/fec/legal/templates/legal-search-results-murs.jinja +++ b/fec/legal/templates/legal-search-results-murs.jinja @@ -1,5 +1,6 @@ {% extends "layouts/legal-doc-search-results.jinja" %} {% import 'macros/legal.jinja' as legal %} +{% import 'macros/filters/typeahead-filter.jinja' as typeahead %} {% set document_type_display_name = 'Closed Matters Under Review' %} {% block header %} @@ -15,6 +16,18 @@ + {# Python API call without suggestions #} +