/** * Created by ogannon on 23/02/2016. */ jq(document).ready(function($) { drawManual(jq); }); var drawManual = function($) { $('.manual-chart-wrapper').each(function() { var $this = $(this); var templateRoot = "/cstatic/file-assets/events/elections/templates/"; var results = []; var rows = $this.find('.ge-table-manual__row'); var electionStatus = $this.find('.ge-table-manual__countstarted-answer').text().trim().toUpperCase(); var constituenciesCompleted = $this.find('.ge-table-manual__returned-number').text().trim(); var timeStamp = "?rev=" + new Date().getTime(); var showFirstPref = $this.find('.ge-table-manual__showfirstpref-answer').text().trim().toUpperCase() === 'Y'; var showSeats = $this.find('.ge-table-manual__showseats-answer').text().trim().toUpperCase() === 'Y'; var showSummary = $this.find('.ge-table-manual__showsummary-answer').text().trim().toUpperCase() === 'Y'; var totalConstituencies = $this.find(".ge-table-manual__totalconst-number").text().trim(); var totalSeats = $this.find(".ge-table-manual__totalseats-number").text().trim(); var isExitPoll = $this.find(".ge-table-manual__exitpoll-answer").text().trim() === 'Y'; var seatsFilled = 0; rows.each(function () { var $this = $(this); var code = $this.find(".ge-table-manual__code").text().trim(); var firstpreference = parseFloat($this.find(".ge-table-manual__firstpref").text().trim(), 10); isNaN(firstpreference) ? firstpreference = $this.find(".ge-table-manual__firstpref").text().trim() : ''; var seats = parseInt($this.find(".ge-table-manual__seats").text().trim(), 10); isNaN(seats) ? seats = $this.find(".ge-table-manual__seats").text().trim() : seatsFilled += seats; results.push({ party: code.toUpperCase(), firstpreference: firstpreference, seats: seats, colourClass: code.toLowerCase() }); }); if (electionStatus === 'P') { var html = new EJS({url: templateRoot + 'manual-national.ejs' + timeStamp}).render({ isExitPoll: isExitPoll, constituenciesCompleted: constituenciesCompleted, totalConstituencies: totalConstituencies, electionStatus: electionStatus, showFirstPref: showFirstPref, showSeats: showSeats, showSummary: showSummary, results: results, totalSeats: totalSeats }); $this.find(".manual-national").empty().append(html); return; } else { var html = new EJS({url: templateRoot + 'manual-national.ejs' + timeStamp}).render({ isExitPoll: isExitPoll, constituenciesCompleted: constituenciesCompleted, totalConstituencies: totalConstituencies, electionStatus: electionStatus, showFirstPref: showFirstPref, showSeats: showSeats, showSummary: showSummary, results: results, totalSeats: totalSeats }); $this.find(".manual-national").empty().append(html); } if (showSummary) { var turnout = $this.find(".ge-table-manual__turnout-number").text().trim(); var indicatorsHtml = new EJS({url: templateRoot + 'national-indicators.ejs' + timeStamp}).render({ indicators: { seatsFilled: seatsFilled, constituenciesCompleted: constituenciesCompleted, turnout: turnout }, totals: { totalSeats: totalSeats, totalConstituencies: totalConstituencies } }); $this.find(".manual-indicators").empty().append(indicatorsHtml); } }); };