2012-10-03 23:34:27 +02:00
|
|
|
$(function () {
|
2013-04-03 22:30:36 +02:00
|
|
|
// NB: this file is included on multiple pages. In each context,
|
|
|
|
// some of the jQuery selectors below will return empty lists.
|
2017-06-29 16:26:48 +02:00
|
|
|
var password_field = $('#id_password, #id_new_password1');
|
2013-04-03 22:30:36 +02:00
|
|
|
|
2016-12-02 14:06:06 +01:00
|
|
|
$.validator.addMethod('password_strength', function (value) {
|
2017-06-29 16:26:48 +02:00
|
|
|
return common.password_quality(value, undefined, password_field);
|
|
|
|
}, function () {
|
|
|
|
return common.password_warning(password_field.val(), password_field);
|
|
|
|
});
|
2013-04-03 22:30:36 +02:00
|
|
|
|
2013-04-03 20:33:25 +02:00
|
|
|
function highlight(class_to_add) {
|
|
|
|
// Set a class on the enclosing control group.
|
|
|
|
return function (element) {
|
|
|
|
$(element).closest('.control-group')
|
|
|
|
.removeClass('success error')
|
|
|
|
.addClass(class_to_add);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2013-04-08 21:24:44 +02:00
|
|
|
$('#registration, #password_reset').validate({
|
2013-04-03 22:30:36 +02:00
|
|
|
rules: {
|
2013-04-08 21:24:44 +02:00
|
|
|
password: 'password_strength',
|
2017-01-12 00:17:43 +01:00
|
|
|
new_password1: 'password_strength',
|
2013-04-03 22:30:36 +02:00
|
|
|
},
|
2012-10-03 23:43:25 +02:00
|
|
|
errorElement: "p",
|
|
|
|
errorPlacement: function (error, element) {
|
2013-04-03 20:33:25 +02:00
|
|
|
// NB: this is called at most once, when the error element
|
|
|
|
// is created.
|
2017-11-05 06:31:20 +01:00
|
|
|
element.next('.help-inline.alert.alert-error').remove();
|
2017-01-19 19:02:56 +01:00
|
|
|
if (element.next().is('label[for="' + element.attr('id') + '"]')) {
|
2017-11-05 06:31:20 +01:00
|
|
|
error.insertAfter(element.next()).addClass('help-inline alert alert-error');
|
2017-01-19 19:02:56 +01:00
|
|
|
} else {
|
2017-11-05 06:31:20 +01:00
|
|
|
error.insertAfter(element).addClass('help-inline alert alert-error');
|
2017-01-19 19:02:56 +01:00
|
|
|
}
|
2012-10-03 23:43:25 +02:00
|
|
|
},
|
2013-04-03 20:33:25 +02:00
|
|
|
highlight: highlight('error'),
|
2017-01-12 00:17:43 +01:00
|
|
|
unhighlight: highlight('success'),
|
2012-10-03 23:43:25 +02:00
|
|
|
});
|
|
|
|
|
2017-06-29 16:26:48 +02:00
|
|
|
password_field.on('change keyup', function () {
|
2013-04-08 20:39:13 +02:00
|
|
|
// Update the password strength bar even if we aren't validating
|
|
|
|
// the field yet.
|
2017-06-22 22:08:43 +02:00
|
|
|
common.password_quality($(this).val(), $('#pw_strength .bar'), $(this));
|
2013-04-03 22:30:36 +02:00
|
|
|
});
|
|
|
|
|
2013-04-03 18:51:36 +02:00
|
|
|
$("#send_confirm").validate({
|
2017-08-15 21:59:44 +02:00
|
|
|
errorElement: "div",
|
2016-12-02 14:06:06 +01:00
|
|
|
errorPlacement: function (error) {
|
2017-08-15 21:59:44 +02:00
|
|
|
$('.alert-error').empty();
|
|
|
|
error.appendTo(".alert-error")
|
2012-10-04 17:05:34 +02:00
|
|
|
.addClass("text-error");
|
2012-10-03 23:43:25 +02:00
|
|
|
},
|
2013-04-03 19:08:11 +02:00
|
|
|
success: function () {
|
|
|
|
$('#errors').empty();
|
2017-01-12 00:17:43 +01:00
|
|
|
},
|
2012-09-25 22:58:59 +02:00
|
|
|
});
|
2013-07-06 03:38:37 +02:00
|
|
|
|
2017-09-27 20:17:15 +02:00
|
|
|
$(".register-page #email, .login-page-container #id_username").on('focusout keydown', function (e) {
|
|
|
|
// check if it is the "focusout" or if it is a keydown, then check if
|
|
|
|
// the keycode was the one for "enter" (13).
|
|
|
|
if (e.type === "focusout" || e.which === 13) {
|
|
|
|
$(this).val($.trim($(this).val()));
|
|
|
|
}
|
|
|
|
});
|
2017-10-06 03:58:09 +02:00
|
|
|
|
|
|
|
var show_subdomain_section = function (bool) {
|
|
|
|
var action = bool ? "hide" : "show";
|
|
|
|
$("#subdomain_section")[action]();
|
|
|
|
};
|
|
|
|
|
|
|
|
$("#realm_in_root_domain").change(function () {
|
|
|
|
show_subdomain_section($(this).is(":checked"));
|
|
|
|
});
|
2017-12-07 04:26:44 +01:00
|
|
|
|
|
|
|
$("#login_form").validate({
|
|
|
|
errorClass: "text-error",
|
|
|
|
wrapper: "div",
|
|
|
|
submitHandler: function (form) {
|
|
|
|
$("#login_form").find('.loader').css('display', 'inline-block');
|
|
|
|
$("#login_form").find("button .text").hide();
|
|
|
|
|
|
|
|
form.submit();
|
|
|
|
},
|
2018-02-02 02:26:16 +01:00
|
|
|
invalidHandler: function () {
|
|
|
|
// this removes all previous errors that were put on screen
|
|
|
|
// by the server.
|
|
|
|
$("#login_form .alert.alert-error").remove();
|
|
|
|
},
|
2017-12-07 04:26:44 +01:00
|
|
|
});
|
2018-01-25 19:08:40 +01:00
|
|
|
|
|
|
|
function check_subdomain_avilable(subdomain) {
|
|
|
|
var url = "/json/realm/subdomain/" + subdomain;
|
|
|
|
$.get(url, function (response) {
|
|
|
|
if (response.msg !== "available") {
|
|
|
|
$("#id_team_subdomain_error_client").html(response.msg);
|
|
|
|
$("#id_team_subdomain_error_client").show();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
var timer;
|
|
|
|
$('#id_team_subdomain').on("keydown", function () {
|
|
|
|
$('.team_subdomain_error_server').text('').css('display', 'none');
|
|
|
|
$("#id_team_subdomain_error_client").css('display', 'none');
|
|
|
|
clearTimeout(timer);
|
|
|
|
});
|
|
|
|
$('#id_team_subdomain').on("keyup", function () {
|
|
|
|
clearTimeout(timer);
|
|
|
|
timer = setTimeout(check_subdomain_avilable, 250, $('#id_team_subdomain').val());
|
|
|
|
});
|
2012-09-25 22:58:59 +02:00
|
|
|
});
|