// Generated by CoffeeScript 1.8.0
(function() {
  angular.module('ajenti.power', ['core']);

  angular.module('ajenti.power').run(function(customization) {
    customization.plugins.power = {};
    customization.plugins.power.hideBatteries = false;
    return customization.plugins.power.hideAdapters = false;
  });

}).call(this);

// Generated by CoffeeScript 1.8.0
(function() {
  angular.module('core').config(function($routeProvider) {
    return $routeProvider.when('/view/power', {
      templateUrl: '/power:resources/partial/index.html',
      controller: 'PowerIndexController'
    });
  });

}).call(this);

// Generated by CoffeeScript 1.8.0
(function() {
  angular.module('ajenti.power').controller('PowerIndexController', function($scope, $interval, notify, pageTitle, power, messagebox, gettext) {
    pageTitle.set(gettext('Power management'));
    power.getUptime().then(function(uptime) {
      var int;
      $scope.uptime = uptime;
      int = $interval(function() {
        return $scope.uptime += 1;
      }, 1000);
      return $scope.$on('$destroy', function() {
        return $interval.cancel(int);
      });
    });
    power.getBatteries().then(function(batteries) {
      return $scope.batteries = batteries;
    });
    power.getAdapters().then(function(adapters) {
      return $scope.adapters = adapters;
    });
    $scope.poweroff = function() {
      return messagebox.show({
        title: gettext('Warning'),
        text: gettext('Machine will become unreachable. Continue?'),
        positive: gettext('Shutdown'),
        negative: gettext('Cancel')
      }).then(function() {
        return power.poweroff().then(function() {
          return messagebox.show({
            progress: true,
            text: 'System is shutting down'
          });
        });
      });
    };
    $scope.reboot = function() {
      return messagebox.show({
        title: gettext('Warning'),
        text: gettext('Machine may become unreachable. Continue?'),
        positive: gettext('Reboot'),
        negative: gettext('Cancel')
      }).then(function() {
        return power.reboot().then(function() {
          return messagebox.show({
            progress: true,
            text: gettext('System is rebooting. We will try to reconnect with it.')
          });
        });
      });
    };
    $scope.suspend = function() {
      return messagebox.show({
        title: gettext('Warning'),
        text: gettext('Machine will become unreachable. Continue?'),
        positive: gettext('Suspend'),
        negative: gettext('Cancel')
      }).then(function() {
        return power.suspend().then(function() {
          return messagebox.show({
            progress: true,
            text: gettext('System is suspending')
          });
        });
      });
    };
    return $scope.hibernate = function() {
      return messagebox.show({
        title: gettext('Warning'),
        text: gettext('Machine will become unreachable. Continue?'),
        positive: gettext('Hibernate'),
        negative: gettext('Cancel')
      }).then(function() {
        return power.hibernate().then(function() {
          return messagebox.show({
            progress: true,
            text: gettext('System is hibernating')
          });
        });
      });
    };
  });

}).call(this);

// Generated by CoffeeScript 1.8.0
(function() {
  angular.module('ajenti.power').controller('PowerWidgetController', function($scope, services) {
    return $scope.$on('widget-update', function($event, id, data) {
      if (id !== $scope.widget.id) {
        return;
      }
      $scope.batteries = data.batteries;
      return $scope.adapters = data.adapters;
    });
  });

}).call(this);

// Generated by CoffeeScript 1.8.0
(function() {
  angular.module('ajenti.power').service('power', function($http, $q, tasks) {
    this.getUptime = function() {
      var q;
      q = $q.defer();
      $http.get("/api/power/uptime").success(function(data) {
        return q.resolve(data);
      }).error(function(err) {
        return q.reject(err);
      });
      return q.promise;
    };
    this.getBatteries = function() {
      var q;
      q = $q.defer();
      $http.get("/api/power/batteries").success(function(data) {
        return q.resolve(data);
      }).error(function(err) {
        return q.reject(err);
      });
      return q.promise;
    };
    this.getAdapters = function() {
      var q;
      q = $q.defer();
      $http.get("/api/power/adapters").success(function(data) {
        return q.resolve(data);
      }).error(function(err) {
        return q.reject(err);
      });
      return q.promise;
    };
    this.poweroff = function() {
      var q;
      q = $q.defer();
      $http.get("/api/power/poweroff").success(function(data) {
        return q.resolve(data);
      }).error(function(err) {
        return q.reject(err);
      });
      return q.promise;
    };
    this.reboot = function() {
      var q;
      q = $q.defer();
      $http.get("/api/power/reboot").success(function(data) {
        return q.resolve(data);
      }).error(function(err) {
        return q.reject(err);
      });
      return q.promise;
    };
    this.suspend = function() {
      var q;
      q = $q.defer();
      $http.get("/api/power/suspend").success(function(data) {
        return q.resolve(data);
      }).error(function(err) {
        return q.reject(err);
      });
      return q.promise;
    };
    this.hibernate = function() {
      var q;
      q = $q.defer();
      $http.get("/api/power/hibernate").success(function(data) {
        return q.resolve(data);
      }).error(function(err) {
        return q.reject(err);
      });
      return q.promise;
    };
    return this;
  });

}).call(this);

