var nestene = angular.module('nestene', ['JSONedit']); nestene.controller('AutonsController', function($scope, $http, $timeout) { $scope.autons=[]; $scope.getAutons = function() { var autonsPromise = $http.get("autons.json"); autonsPromise.success(function(data, status, headers, config) { $scope.autons = data; }); autonsPromise.error(function(data, status, headers, config) { $.bootstrapGrowl("getting autons failed!", { type: 'danger' }); }); } $scope.intervalFunction = function() { $timeout(function() { $scope.getAutons(); $scope.intervalFunction(); }, 1000); }; $scope.intervalFunction(); }); nestene.controller('CreateAutonFormController', function($scope,$http) { $scope.autonType = ''; $scope.createAuton = function() { var postPromise = $http.post("autons",{auton_type: $scope.autonType}); postPromise.success(function(data, status, headers, config) { $.bootstrapGrowl("Created "+data['auton_id'], { type: 'success' }); }); postPromise.error(function(data, status, headers, config) { $.bootstrapGrowl("Could not create Auton: "+data['message'], { type: 'error' }); }); }; }); nestene.controller('CredentialsController', function($scope,$http) { $scope.credentials={}; $scope.loaded = false; $scope.loadCredentials = function() { var getPromise = $http.get("credentials"); getPromise.success(function(data, status, headers, config) { $scope.credentials = data; $scope.loaded = true; }); getPromise.error(function(data, status, headers, config) { $.bootstrapGrowl("getting credentials failed!", { type: 'danger' }); }); } $scope.loadCredentials(); $scope.storeCredentials = function() { var postPromise = $http.post("credentials",$scope.credentials); postPromise.success(function(data, status, headers, config) { $.bootstrapGrowl("Credentials saved", { type: 'success' }); }); postPromise.error(function(data, status, headers, config) { $.bootstrapGrowl("Could not save credentials", { type: 'danger' }); }); }; });