var React = require("react/addons"), UserRegistration = require('../../models/userRegistration'), RibicaValidationMixin = require('../../components/shared/mixins/ribicaValidationMixin'), UserStore = require('../../stores/userStore'), NavigationActions = require('../../actions/navigationActions'), UserActions = require('../../actions/userActions'), ValidationUtils = require('../../utils/validation'); var Register = React.createClass({ mixins: [React.addons.LinkedStateMixin, RibicaValidationMixin], getInitialState: function() { return { myBabyDetailsVisible: false, firstName: '', lastName: '', email: '', password: '', passwordConfirmation: '', errors: {}, registration: UserStore.getRegistrationState() }; }, myBabyChange: function() { this.setState({ myBabyDetailsVisible: true }); }, renderMonthSelector: function() { var months = ['Januar', 'Februar', 'Mart', 'April', 'Maj', 'Juni', 'Juli','August','Septembar', 'Oktobar','Novembar','Decembar']; var monthsSelect = []; for(var i = 0; i < months.length; i++) { monthsSelect.push() } return () }, renderYearSelector: function() { var currentYear = (new Date().getFullYear()); var years = []; years.push() for(var i = 0; i < 12; i++) { years.push() } return () }, renderDaySelector: function() { var days = []; days.push() for(var i = 1; i <= 31; i++) { days.push() } return () }, renderBabyDetails: function() { if (!this.state.myBabyDetailsVisible) { return (
) } return (
Djevojčica Dječak Jos ne znamo
{this.renderDaySelector()} {this.renderMonthSelector()} {this.renderYearSelector()}
) }, validations: { firstName: function(value) { if (!ValidationUtils.isValidRequired(value)) { return ["Ime je obavezno."]; } }, password: function(value, callback) { if(!ValidationUtils.isValidRequired(value)) { return ["Šifra je obavezna."]; } if (value.length < 6) { return ["Šifra mora sadržavati minimalno 6 karaktera."] } if (callback) { callback([], ["passwordConfirmation"]); } }, passwordConfirmation: function(value) { if (this.getState().password !== value) { return ["Šifre se ne podudaraju."]; } }, lastName : function(value) { if (!ValidationUtils.isValidRequired(value)) { return ["Prezime je obavezno."]; } }, _emailTimeoutId: null, email: function(value, callback) { if (ValidationUtils.isValidEmail(value)) { //clearTimeout(this._emailTimeoutId); //this._emailTimeoutId = setTimeout(function(){ //// TODO: check if email exists //if (value === 'edin@edin.com') { //if(callback) { //var errors= ['Email is already taken']; //callback(errors); //} //} else { //if(callback) { //callback([]); //} //} //}.bind(this), 1000); } else { return ['Neispravna email adresa.']; } } }, renderErrorMessage: function(message){ return (
{message}
) }, componentDidMount: function() { UserStore.addChangeListener(this.onUserStoreChange); }, componentWillUnmount: function() { UserStore.removeChangeListener(this.onUserStoreChange); }, onUserStoreChange: function() { this.setState({ registration: UserStore.getRegistrationState() }); }, register: function(e) { if(this.validate()) { var user = new UserRegistration({ first_name: this.state.firstName, last_name: this.state.lastName, email: this.state.email, password: this.state.password, password_confirmation: this.state.passwordConfirmation }); UserActions.registerUser(user); } e.preventDefault(); }, successContinue: function(e) { NavigationActions.goToHome(); e.preventDefault(); }, renderRegistrationState: function() { var rs = this.state.registration; if (!rs.performed) { return (
) } else if(rs.performed && !rs.success){ return (
Desila se pogreška pri registraciji. Detalji greške su: {rs.error.responseJSON}
) } else if (rs.performed && rs.success) { return (
Uspješno ste se registrovali na Ribicu. Kliknite ovdje za nastavak.
) } }, render : function() { var cx = React.addons.classSet; var regSuccess = this.state.registration.performed && this.state.registration.success; var classes = cx({ 'hide': regSuccess }); return (
Registracija {this.renderRegistrationState()}
{this.getValidationMessages('firstName').map(this.renderErrorMessage)}
{this.getValidationMessages('lastName').map(this.renderErrorMessage)}
{this.getValidationMessages('email').map(this.renderErrorMessage)}
{this.getValidationMessages('password').map(this.renderErrorMessage)}
{this.getValidationMessages('passwordConfirmation').map(this.renderErrorMessage)}
Vec rođena Na putu
{this.renderBabyDetails()}
); } }) module.exports = Register;