(function () { "use strict"; angular.module("enrDetailsPaneModule") .directive("detailsOfficeRaceVotes", [function () { return { templateUrl: "Scripts/EnrAngular/EnrDetailsPane/detailsOfficeRaceVotes.html", scope: { raceName: "=", candidateList: "=", showRaceName: "=", officeName: "=" }, controller: "detailsOfficeRaceVotesController", restrict: "E" }; }]) .controller("detailsOfficeRaceVotesController", ["$scope", "$filter", "primaryService", "gradientService", "jsonDataFetcher", function ($scope, $filter, primaryService, gradientService, jsonDataFetcher) { $scope.isPrimary = primaryService.getIsPrimary(); var office = $scope.raceName; var list = $scope.candidateList; var count = 0; angular.forEach($scope.candidateList, function (value, key) { if (value.winner == "T") count++; }); if (count > 1) { $scope.numberOfSeats = '(' + count + ' to be elected)'; $scope.padclass = 'padbottom0'; } else { $scope.numberOfSeats = ''; $scope.padclass = ''; } //list.sort(function (a, b) { // // sort by votes descending, then by nameLast // if (a.votes > b.votes) // return -1; // else if (a.votes < b.votes) // return 1; // else if (a.nameLast > b.nameLast) // return 1; // else if (b.nameLast < a.nameLast) // return -1; // else // return 0; //}); $scope.candidateList = list; if ($scope.officeName != undefined) $scope.useGradients = $scope.isPrimary && !gradientService.isOfficeExcludedFromGradients(office); else $scope.useGradients = $scope.isPrimary && !gradientService.isCurOfficeExcludedFromGradients(); if ($scope.isPrimary) $scope.candidateList = $filter('partyCode')($scope.candidateList, primaryService.getSelectedParty());; $scope.isRaceNameVisible = function () { return $scope.showRaceName === true ? "" : "hidden"; } $scope.getSelectedPartyColor = function () { return primaryService.getSelectedPartyColor(); } $scope.getWinners = function (candidate) { if (primaryService.getIsCertified()) { if (candidate.winner == "T") { return 'winner-color-select'; } else { return 'winner-color-deselect'; } } return 'winner-color-deselect'; } }]); }());