"use strict"; var app = angular.module("coalitionBuilderApp", ["ngAnimate", "ngCookies", "ngResource", "ngRoute", "ngSanitize", "ngTouch", "socialLinks"]).config(["$routeProvider", function(a) { a.when("/", { templateUrl: "views/main.html", controller: "MainCtrl", controllerAs: "main" }).otherwise({ redirectTo: "/" }) }]); app.constant("appConstants", { // source: "/static/general-election/json/coalition-builder.json" source: coalitionBuilderDataUrl }), app.config(["$httpProvider", function(a) { a.defaults.useXDomain = !0, delete a.defaults.headers.common["X-Requested-With"] }]), angular.module("coalitionBuilderApp").controller("MainCtrl", ["$scope", "PartyService", function(a, b) { function c() { e.empty(), f.empty(), g.empty() } function d() { a.graphContent = [], a.coalitionContent = [], a.coalitionLongContent = [], angular.forEach(a.chartData, function(b) { a.graphContent.push(b.chartHTML()), a.coalitionContent.push(b.coalitionHTML()), a.coalitionLongContent.push(b.coalitionLongHTML()) }), c(), e.append(a.graphContent), f.append(a.coalitionContent), g.append(a.coalitionLongContent) } a.maxSeats = coalitionBuilderMaxSeats, a.majority = coalitionBuilderMajority, a.filledSeats = 0, a.displayDialog = !0, a.displayAlertDialog = !1, a.displayShare = !1, a.chartData = []; var e = $(".chart-parent"), f = $(".coalition-parent"), g = $(".coalition-parent-long"), h = function() { a.seatWatcher(), a.seatWatcher = void 0 }, i = function() { a.seatWatcher = a.$watch("filledSeats", function() { a.filledSeats >= a.majority && a.displayDialog ? (a.displayDialog = !1, a.displayShare = !0) : (a.displayDialog = !0, a.displayShare = !1) }) }, j = b.get(); j.then(function(b) { b && (a.parties = b, i()) }), Array.prototype.remove = function(a, b) { var c = this.slice((b || a) + 1 || this.length); return this.length = 0 > a ? this.length + a : a, this.push.apply(this, c) }; var k = function(b) { a.chartData.forEach(function(c, d) { c.partyShortName === b.partyShortName && (b.setSelected(!1), a.chartData.remove(d), b.variableSeats ? (a.filledSeats -= b.initialValue, b.seats === b.initialSeats && (b.initialValue = 0)) : a.filledSeats -= b.seats) }), d() }, l = function(b) { a.chartData.push(b), a.filledSeats += b.seats, b.setSelected(!0), d() }, m = function(b) { a.chartData.push(b), a.filledSeats += b.initialValue, b.setSelected(!0), d() }; a.updateVariableSeats = function(b) { (a.filledSeats != a.maxSeats || a.filledSeats + 1 <= a.maxSeats) && (k(b), b.incrementSeats(), m(b)) }, a.addToGraph = function(b) { a.filledSeats == a.maxSeats || a.filledSeats + b.seats > a.maxSeats || a.filledSeats + b.initialValue > a.maxSeats ? (b.selected || (a.displayAlertDialog = !0), b.variableSeats === !0 && b.selected && b.initialValue < b.seats ? (k(b), b.decrementSeats(), m(b)) : k(b)) : b.variableSeats === !0 && b.selected ? b.initialValue > 1 ? (k(b), b.decrementSeats(), m(b)) : (b.seats = b.initialSeats, k(b)) : b.variableSeats !== !0 || b.selected ? -1 === a.chartData.indexOf(b) ? l(b) : k(b) : 0 === b.initialValue && (b.seats -= 1, b.initialValue += 1, m(b)) }, a.reset = function() { c(), a.chartData = [], a.filledSeats = 0, a.displayDialog = !0, a.displayAlertDialog = !1, a.displayShare = !1, angular.forEach(a.parties, function(a) { a.setSelected(!1), a.variableSeats && (a.initialValue = 0, a.seats = a.initialSeats) }), a.seatWatcher || i() }, a.close = function() { a.displayDialog = !0, h() }, a.closeAlertDialog = function() { a.displayAlertDialog = !1 } }]), angular.module("coalitionBuilderApp").factory("Party", function() { function a(a, b, c, d, e, f) { this.partyName = a, this.partyShortName = b, this.seats = c, this.colour = d, this.selected = e, this.variableSeats = f, this.initialValue = 0, this.initialSeats = c } return a.prototype.incrementSeats = function() { this.seats > 0 && (this.initialValue += 1, this.seats -= 1) }, a.prototype.decrementSeats = function() { this.initialValue > 0 && (this.initialValue -= 1, this.seats += 1) }, a.prototype.setSelected = function(a) { this.selected = a }, a.prototype.calculateWidth = function(a) { var b = 100 * a / 158; return b + "%" }, a.apiResponseTransformer = function(b) { return b = b.parties, angular.isArray(b) ? b.map(a.build) : a.build(b) }, a.build = function(b) { return new a(b.name, b.code, b.seats, b.colour, !1, b.variableSeats) }, a.prototype.chartHTML = function() { return this.variableSeats ? '
  • ' + this.partyName + " " + this.initialValue + "
  • " : '
  • ' + this.partyName + " " + this.seats + "
  • " }, a.prototype.coalitionHTML = function() { return this.variableSeats ? '
    ' + this.initialValue + "" + this.partyShortName + "
    " : '
    ' + this.seats + "" + this.partyShortName + "
    " }, a.prototype.coalitionLongHTML = function() { return this.variableSeats ? '
    ' + this.initialValue + "" + this.partyName + "
    " : '
    ' + this.seats + "" + this.partyName + "
    " }, a }), angular.module("coalitionBuilderApp").factory("dataService", ["$http", "$q", function(a, b) { var c = function(c) { var d = b.defer(); return a.get(c).then(function(a) { d.resolve(a.data) }, function() { return b.reject() }), d.promise }; return { getData: c } }]), angular.module("coalitionBuilderApp").factory("PartyService", ["dataService", "Party", "appConstants", function(a, b, c) { return { get: function() { return a.getData(c.source).then(b.apiResponseTransformer) } } }]), angular.module("coalitionBuilderApp").run(["$templateCache", function(a) { a.put("views/main.html", '
    • {{party.partyShortName|uppercase}}
      {{party.seats}}

    Adding this party would exceed the maximum available seats. Please remove, or select another party to continue building your coalition.

    Congratulations!

    You have formed a new government

      Majority {{majority}}
      {{filledSeats}}
      Restart
        Majority {{majority}}
        {{filledSeats}}
        YOUR COALITION
        Pick your first party to begin
        ') }]);