diff --git a/static/js/modules/tables.js b/static/js/modules/tables.js index d24c497af..ef22c0bbe 100644 --- a/static/js/modules/tables.js +++ b/static/js/modules/tables.js @@ -59,7 +59,7 @@ function mapFilters(filters) { var parsedFilters; function buildCycle(datum) { - if (parsedFilters.cycle) { + if (parsedFilters && parsedFilters.cycle) { var cycles = _.intersection( _.map(parsedFilters.cycle, function(cycle) {return parseInt(cycle);}), datum.cycles @@ -130,6 +130,18 @@ function barColumn(formatter) { }; } +function urlColumn(attr, opts) { + return _.extend({ + render: function(data, type, row, meta) { + var anchor = document.createElement('a'); + anchor.textContent = data; + anchor.setAttribute('href', row[attr]); + anchor.setAttribute('target', '_blank'); + return anchor.outerHTML; + } + }, opts); +} + var dateColumn = formattedColumn(helpers.datetime); var currencyColumn = formattedColumn(helpers.currency); var barCurrencyColumn = barColumn(helpers.currency); @@ -441,6 +453,7 @@ module.exports = { candidateColumn: candidateColumn, committeeColumn: committeeColumn, currencyColumn: currencyColumn, + urlColumn: urlColumn, barCurrencyColumn: barCurrencyColumn, dateColumn: dateColumn, modalAfterRender: modalAfterRender, diff --git a/static/js/pages/candidate-single.js b/static/js/pages/candidate-single.js index 9fe405617..572b1201c 100644 --- a/static/js/pages/candidate-single.js +++ b/static/js/pages/candidate-single.js @@ -8,18 +8,7 @@ var tables = require('../modules/tables'); var decoders = require('../modules/decoders'); var columns = [ - { - data: 'document_description', - className: 'all', - orderable: false, - render: function(data, type, row, meta) { - var anchor = document.createElement('a'); - anchor.textContent = data; - anchor.setAttribute('href', row.pdf_url); - anchor.setAttribute('target', '_blank'); - return anchor.outerHTML; - } - }, + tables.urlColumn('pdf_url', {data: 'document_description', className: 'all', orderable: false}), { data: 'amendment_indicator', className: 'min-desktop', diff --git a/static/js/pages/committee-single.js b/static/js/pages/committee-single.js index 0d279979b..d34dae936 100644 --- a/static/js/pages/committee-single.js +++ b/static/js/pages/committee-single.js @@ -132,18 +132,7 @@ var occupationColumns = [ ]; var filingsColumns = [ - { - data: 'document_description', - className: 'all', - orderable: false, - render: function(data, type, row, meta) { - var anchor = document.createElement('a'); - anchor.textContent = data; - anchor.setAttribute('href', row.pdf_url); - anchor.setAttribute('target', '_blank'); - return anchor.outerHTML; - } - }, + tables.urlColumn('pdf_url', {data: 'document_description', className: 'all', orderable: false}), { data: 'amendment_indicator', className: 'min-desktop', @@ -227,12 +216,7 @@ $(document).ready(function() { switch ($table.attr('data-type')) { case 'committee-contributor': path = ['committee', committeeId, 'schedules', 'schedule_a', 'by_contributor'].join('/'); - query = {}; - if (year) { - query.year = year; - } else { - query.cycle = cycle; - } + query = {cycle: cycle}; tables.initTableDeferred($table, null, path, query, committeeColumns, aggregateCallbacks, { dom: tables.simpleDOM, order: [[1, 'desc']], diff --git a/static/js/pages/elections.js b/static/js/pages/elections.js index 812668d91..2412840b0 100644 --- a/static/js/pages/elections.js +++ b/static/js/pages/elections.js @@ -62,18 +62,7 @@ var columns = [ tables.barCurrencyColumn({data: 'total_receipts'}), tables.barCurrencyColumn({data: 'total_disbursements'}), tables.barCurrencyColumn({data: 'cash_on_hand_end_period'}), - { - data: 'pdf_url', - className: 'all', - orderable: false, - render: function(data, type, row, meta) { - var anchor = document.createElement('a'); - anchor.textContent = row.document_description; - anchor.setAttribute('href', data); - anchor.setAttribute('target', '_blank'); - return anchor.outerHTML; - } - }, + tables.urlColumn('pdf_url', {data: 'document_description', className: 'all', orderable: false}) ]; var sizeColumns = [ diff --git a/static/js/pages/filings.js b/static/js/pages/filings.js index 25fa569b2..d49ba1eb1 100644 --- a/static/js/pages/filings.js +++ b/static/js/pages/filings.js @@ -9,18 +9,7 @@ var tables = require('../modules/tables'); var decoders = require('../modules/decoders'); var columns = [ - { - data: 'document_description', - className: 'all', - orderable: false, - render: function(data, type, row, meta) { - var anchor = document.createElement('a'); - anchor.textContent = data; - anchor.setAttribute('href', row.pdf_url); - anchor.setAttribute('target', '_blank'); - return anchor.outerHTML; - } - }, + tables.urlColumn('pdf_url', {data: 'document_description', className: 'all', orderable: false}), { data: 'committee_name', className: 'min-desktop', diff --git a/static/js/pages/landing.js b/static/js/pages/landing.js new file mode 100644 index 000000000..7be58bac7 --- /dev/null +++ b/static/js/pages/landing.js @@ -0,0 +1,38 @@ +'use strict'; + +/* global require, document */ + +var $ = require('jquery'); + +var tables = require('../modules/tables'); + +var columns = [ + tables.urlColumn('pdf_url', {data: 'document_description', className: 'all', orderable: false}), + { + data: 'committee_name', + className: 'min-desktop', + orderable: false, + render: function(data, type, row, meta) { + return tables.buildEntityLink(data, '/committee/' + row.committee_id + tables.buildCycle(row), 'committee'); + }, + }, + { + data: 'candidate_name', + className: 'min-desktop', + orderable: false, + render: function(data, type, row, meta) { + return tables.buildEntityLink(data, '/candidate/' + row.candidate_id + tables.buildCycle(row), 'candidate'); + }, + }, + tables.dateColumn({data: 'receipt_date', className: 'min-tablet', orderable: false}), +]; + +$(document).ready(function() { + var $table = $('#results'); + tables.initTable($table, null, 'filings', {per_page: 10}, columns, tables.offsetCallbacks, { + // Order by receipt date descending + order: [[3, 'desc']], + useFilters: false, + dom: 't' + }); +}); diff --git a/templates/layouts/main.html b/templates/layouts/main.html index a9b52f816..1c47c8cd1 100644 --- a/templates/layouts/main.html +++ b/templates/layouts/main.html @@ -49,7 +49,7 @@ This site is in beta. Learn more.
- Federal Election Commission | United States of America + Federal Election Commission | United States of America
{% endblock %} + +{% block scripts %} + +{% endblock %} \ No newline at end of file