'use strict'; /* global angular */ angular.module('Application').controller('AddonsController', ['$scope', '$location', 'Client', function ($scope, $location, Client) { Client.onReady(function () { if (!Client.getUserInfo().admin) $location.path('/'); }); $scope.ready = false; $scope.addons = []; function refresh() { Client.getAddons(function (error, result) { if (error) return Client.error(error); $scope.addons = result.map(function (a) { return { name: a, state: 'active' }; }); $scope.ready = true; }); } $scope.startAddon = function (addonName) { Client.startAddon(addonName, function (error) { if (error) return Client.error(error); refresh(); }); }; $scope.stopAddon = function (addonName) { Client.stopAddon(addonName, function (error) { if (error) return Client.error(error); refresh(); }); }; Client.onReady(refresh); }]);