Semaphore/public/js/routes/users.js
Matej Kramny 0f180756ab Auth page
- Restructuring & co
2016-03-18 22:03:28 +00:00

63 lines
1.6 KiB
JavaScript

app.config(function ($stateProvider, $couchPotatoProvider) {
$stateProvider.state('users', {
url: '/users',
templateUrl: '/view/abstract',
abstract: true
})
.state('users.add', {
url: '/add',
pageTitle: 'Add User',
templateUrl: "/public/html/user/add.html",
controller: 'AddUserCtrl',
resolve: {
dummy: $couchPotatoProvider.resolve(['controllers/user/add'])
}
})
.state('users.list', {
url: '/all',
pageTitle: 'Users',
templateUrl: "/public/html/user/list.html",
controller: 'UsersCtrl',
resolve: {
dummy: $couchPotatoProvider.resolve(['controllers/user/users'])
}
})
.state('user', {
abstract: true,
url: '/user/:user_id',
templateUrl: '/public/html/abstract.html',
controller: ['$scope', 'user', function ($scope, user) {
$scope.user = user;
}],
resolve: {
user: ['User', '$stateParams', '$q', '$state', function (User, $stateParams, $q, $state) {
var deferred = $q.defer();
var user = new User($stateParams.user_id)
user.get()
.success(function (data, status) {
user.data = data;
deferred.resolve(user);
})
.error(function (data, status) {
if (status == 404) {
$state.transitionTo('homepage');
return deferred.reject();
}
});
return deferred.promise;
}]
}
})
.state('user.view', {
url: '/',
controller: 'UserCtrl',
templateUrl: '/public/html/user/view.html',
resolve: {
dummy: $couchPotatoProvider.resolve(['controllers/user/user'])
}
})
});