Skip to content

Instantly share code, notes, and snippets.

@kaumac
Created July 16, 2014 21:25
Show Gist options
  • Save kaumac/02b8617810325da0b133 to your computer and use it in GitHub Desktop.
Save kaumac/02b8617810325da0b133 to your computer and use it in GitHub Desktop.
'use strict';
// The Angular App
angular.module('kiikPanel', [
'ngCookies',
'ngResource',
'ngSanitize',
'Devise',
'ngAnimate',
'ui.router'
])
// Makes Lo-dash / Underscore avaiable at constant level
.constant('_', window._)
// Angular app configuration
.config(['$httpProvider', '$stateProvider', '$urlRouterProvider', 'AuthProvider', function ($httpProvider, $stateProvider, $urlRouterProvider, AuthProvider) {
$httpProvider.defaults.headers.common['X-Requested-With'];
$urlRouterProvider.otherwise('/');
$stateProvider
.state('sign_in', {
url: '/users/sign_in',
templateUrl: 'user/sign_in',
controller: 'LoginController',
noHeader: true
})
.state('recipients', {
url: '/',
templateUrl: '/recipients',
controller: 'RecipientsController',
resolve: {
recipients: function(RecipientsService) {
return RecipientsService.getRecipients();
}
}
})
.state('recipient', {
url: '/recipient/:recipient_id',
templateUrl: '/views/recipient',
controller: 'RecipientController'
})
}])
// Declare event bindings
.run(['$rootScope', '$state', 'Auth', function($rootScope, $state, Auth) {
$rootScope.$on('devise:unauthorized', function(event, xhr, deferred) {
event.preventDefault();
$state.transitionTo("sign_in");
});
$rootScope.$on('devise:logout', function(event, oldCurrentUser) {
event.preventDefault();
$state.transitionTo("sign_in");
});
}])
'use strict';
angular.module('kiikPanel').controller('RecipientsController', ['$scope', 'recipients', function($scope, recipients) {
$scope.recipients = recipients.data;
}]);
'use strict';
angular.module('kiikPanel').factory('RecipientsService', ['$resource', function($resource) {
return $resource('/api/recipients/all', null, {
'getRecipients': { method: 'GET' }
});
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment