Skip to content
This repository has been archived by the owner on Dec 23, 2017. It is now read-only.

Show incumbent officeholders in election search. #549

Merged
merged 2 commits into from
Sep 3, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion static/js/modules/election-lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function formatResult(result, lookup) {
officeName: officeMap[result.office],
electionName: formatName(result),
electionDate: formatElectionDate(result),
url: formatUrl(result),
incumbent: formatIncumbent(result),
color: formatColor(result, lookup)
});
}
Expand All @@ -63,6 +63,17 @@ function formatElectionDate(result) {
.format('MMMM Do, YYYY');
}

function formatIncumbent(result) {
if (result.incumbent_id) {
return {
name: result.incumbent_name,
url: '/candidate/' + result.incumbent_id
};
} else {
return null;
}
}

function formatUrl(result) {
var path = ['/elections', officeMap[result.office].toLowerCase()];
if (['S', 'H'].indexOf(result.office) !== -1) {
Expand Down
7 changes: 5 additions & 2 deletions static/templates/electionResult.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
{{#each this}}
<div class="election-result box">
<h4 style="color: {{this.color}}">{{this.electionName}}</h4>
<div>{{ cycle }} General Election: {{this.electionDate}}</div>
<div><a href="{{this.url}}">View all current candidates &raquo;</a></div>
<div>Next general election: {{this.electionDate}}</div>
{{#if this.incumbent}}
<div>Current officeholder: <a href="{{this.incumbent.url}}">{{this.incumbent.name}}</a></div>
{{/if}}
<div>Current candidates: <a href="{{this.url}}">View all &raquo;</a></div>
</div>
{{/each}}
</div>