riot.tag2('login', ' ', '', '', function(opts) { function getCookie(name) { var cookieValue = null; if (document.cookie && document.cookie !== '') { var cookies = document.cookie.split(';'); for (var i = 0; i < cookies.length; i++) { var cookie = jQuery.trim(cookies[i]); if (cookie.substring(0, name.length + 1) === (name + '=')) { cookieValue = decodeURIComponent(cookie.substring(name.length + 1)); break; } } } return cookieValue; } this.csrftoken = getCookie("csrftoken"); this.showRegister = function(e) { e.preventDefault(); if (this.parent.state == "REGISTER") { this.parent.state = "LOGIN"; riot.update(); } this.parent.state = "REGISTER"; this.parent.update(); }; }); riot.tag2('preise', ' ', '@media (max-width: 991px) { preise img,[data-is="preise"] img{ height:32px; padding:4px 2px; } preise table,[data-is="preise"] table{ background-color:#eee; border:1px solid #ccc; padding:4px; } }', '', function(opts) { this.state = "RENT"; this.showRegisterModal = function(e) { $("#preise-modal").modal("hide"); $("#register-modal").modal("show"); }.bind(this) this.show = function(w) { return function(e) { e.preventDefault(); this.state = w; } }.bind(this) }); riot.tag2('register-login', ' ', '', '', function(opts) { this.state = "REGISTER"; }); riot.tag2('register', ' ', 'register input.is-invalid,[data-is="register"] input.is-invalid{ background-color:#fee; }', '', function(opts) { self.page = "form"; function validateEmail(email) { var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; return re.test(email); } function getCookie(name) { var cookieValue = null; if (document.cookie && document.cookie !== '') { var cookies = document.cookie.split(';'); for (var i = 0; i < cookies.length; i++) { var cookie = jQuery.trim(cookies[i]); if (cookie.substring(0, name.length + 1) === (name + '=')) { cookieValue = decodeURIComponent(cookie.substring(name.length + 1)); break; } } } return cookieValue; } var csrftoken = getCookie("csrftoken"); this.errors = {}; this.inProgress = false; this.validate = function(checkEmpty) { this.errors = {}; if (checkEmpty) { if (!this.refs.email1.value) { this.errors.email1 = "Bitte füllen Sie dieses Feld aus"; } if (!this.refs.email2.value) { this.errors.email2 = "Bitte füllen Sie dieses Feld aus"; } if (!this.refs.password1.value) { this.errors.password1 = "Bitte füllen Sie dieses Feld aus"; } if (!this.refs.password2.value) { this.errors.password2 = "Bitte füllen Sie dieses Feld aus"; } if (!this.refs.phonenumber.value) { this.errors.phonenumber = "Bitte füllen Sie dieses Feld aus"; } } if (this.refs.email1.value && !validateEmail(this.refs.email1.value)) { this.errors.email1 = "Bitte geben Sie eine gültige E-Mail-Adresse ein"; } if (this.refs.email2.value && !validateEmail(this.refs.email2.value)) { this.errors.email2 = "Bitte geben Sie eine gültige E-Mail-Adresse ein"; } if (this.refs.password1.value && this.refs.password1.value.length < 6) { this.errors.password1 = "Das Passwort sollte mind. 6 Zeichen lang sein"; } if (this.refs.email1.value && this.refs.email2.value && this.refs.email1.value != this.refs.email2.value) { this.errors.email2 = "Die beiden E-Mail-Adressen stimmen nicht überein"; } if (this.refs.password1.value && this.refs.password2.value && this.refs.password1.value != this.refs.password2.value) { this.errors.password2 = "Die beiden Passwörter stimmen nicht überein"; } } this.onBlur = function(e) { this.validate(false); }; this.showLogin = function(e) { e.preventDefault(); if (this.parent.state == "LOGIN") { this.parent.state = "REGISTER"; this.parent.update(); } this.parent.state = "LOGIN"; this.parent.update(); }; this.cb = function(data) { if (data != "ok") { if (data.email) { this.errors.email1 = data.email[0]; } if (data.phonenumber) { this.errors.phonenumber = data.phonenumber[0]; } } else { this.page = "thanks"; } window.setTimeout((function() { this.inProgress = false; this.update(); }).bind(this), 1500); this.update(); }; this.submit = function(e) { e.preventDefault(); this.validate(true); this.inProgress = true; if ($.isEmptyObject(this.errors)) { $.post( "/api/register/", { "csrfmiddlewaretoken": csrftoken, email: this.refs.email1.value, password: this.refs.password1.value, phonenumber: this.refs.phonenumber.value, }, $.proxy(this.cb, this) ); } else { this.inProgress = false; } } });