Last active
October 1, 2016 15:59
-
-
Save 2JN/31bbe6589c450b1df5eadc025d4da06e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import angular from 'angular'; | |
import angularMeteor from 'angular-meteor'; | |
import uiRouter from 'angular-ui-router'; | |
import { Meteor } from 'meteor/meteor'; | |
import template from './nuevoEmpleado.html'; | |
import { Empleados } from '../../../api/empleados'; | |
class NuevoEmpleadoCtrl { | |
constructor($scope) { | |
$scope.viewModel(this); | |
this.empleado = {}; | |
this.subscribe('users', () => { | |
return [Meteor.userId()]; | |
}); | |
this.helpers({ | |
usuario() { | |
return Meteor.user(); | |
} | |
}); | |
} | |
ingresar() { | |
Empleados.insert(this.empleado); | |
this.reset(); | |
} | |
reset() { | |
this.empleado = {} | |
} | |
} | |
const name = 'nuevoEmpleado'; | |
export default angular.module(name, [ | |
angularMeteor, | |
uiRouter | |
]) | |
.component(name, { | |
templateUrl: template, | |
controllerAs: name, | |
controller: NuevoEmpleadoCtrl | |
}) | |
.config(config); | |
function config($stateProvider) { | |
'ngInject'; | |
$stateProvider.state('agregarEmpleado', { | |
url: '/agregar-empleado', | |
template: '<nuevo-empleado></nuevo-empleado>', | |
resolve: { | |
adminUser: ($q) => { | |
/** | |
*TODO: Implementar auntenticacion por rutas | |
*/ | |
var deferred = $q.defer(); | |
Meteor.autorun(function() { | |
if(!Meteor.logginIn()) { | |
if(Meteor.user() == null) { | |
deferred.reject(); | |
} else { | |
deferred.resolve(Meteor.user()); | |
} | |
} | |
}); | |
return deferred.promise; | |
} | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment