179 lines
6.9 KiB
JavaScript
179 lines
6.9 KiB
JavaScript
$(function () {
|
|
_signup.init();
|
|
});
|
|
|
|
_signup = {
|
|
recaptchaToken: null,
|
|
|
|
init: function () {
|
|
var self = this;
|
|
|
|
_reCaptcha.onLoad = function () {
|
|
$("#form-signup > #recaptcha").reCaptcha({
|
|
callback: function (token) {
|
|
self.recaptchaToken = token;
|
|
self.submitForm();
|
|
}
|
|
});
|
|
|
|
$("#form-signup").on("submit", function (e) {
|
|
e.preventDefault();
|
|
//self.submitForm();
|
|
$("#form-signup > #recaptcha").reCaptcha("run");
|
|
return false;
|
|
});
|
|
|
|
$("#part_iva, #cod_fisc").change(function () {
|
|
if ($(this).getValue()) {
|
|
if (this.id === "part_iva") {
|
|
$("#cod_fisc").removeAttr("required");
|
|
} else if (this.id === "cod_fisc") {
|
|
$("#part_iva").removeAttr("required");
|
|
}
|
|
} else {
|
|
$("#part_iva").prop("required", true);
|
|
$("#cod_fisc").prop("required", true);
|
|
}
|
|
});
|
|
|
|
$("#cuu_pa, #e_mail_pec").change(function () {
|
|
if ($(this).getValue()) {
|
|
if (this.id === "cuu_pa") {
|
|
$("#e_mail_pec").removeAttr("required");
|
|
} else if (this.id === "e_mail_pec") {
|
|
$("#cuu_pa").removeAttr("required");
|
|
}
|
|
} else {
|
|
$("#cuu_pa").prop("required", true);
|
|
$("#e_mail_pec").prop("required", true);
|
|
}
|
|
});
|
|
|
|
$("#user_name").keyup(_.debounce(
|
|
function () {
|
|
let username = $(this).val();
|
|
|
|
if (username.contains(" ")) {
|
|
username = username.replaceAll(" ", "");
|
|
|
|
$(this).val(username).trigger("keyup");
|
|
|
|
return;
|
|
}
|
|
|
|
const $usernameLoader = $("#username-loader");
|
|
|
|
$usernameLoader.children(".valid").addClass("hidden");
|
|
$usernameLoader.children(".notValid").addClass("hidden");
|
|
$usernameLoader.children(".loading").removeClass("hidden");
|
|
|
|
new Ajax()
|
|
.get("checkValidUsername")
|
|
.data({
|
|
azienda: _login.get_azienda(),
|
|
username
|
|
})
|
|
.execute(res => {
|
|
$usernameLoader.children(".loading").addClass("hidden");
|
|
|
|
if (res.returnId === 1 && res.returnData.valid) {
|
|
$usernameLoader.children(".notValid").addClass("hidden");
|
|
$usernameLoader.children(".valid").removeClass("hidden");
|
|
$(this).closest(".form-group").removeClass("has-error").addClass("has-success");
|
|
$("#form-signup button[type='submit']").attr("disabled", false);
|
|
} else {
|
|
$usernameLoader.children(".valid").addClass("hidden");
|
|
$usernameLoader.children(".notValid").removeClass("hidden");
|
|
$(this).closest(".form-group").addClass("has-error").removeClass("has-success");
|
|
$("#form-signup button[type='submit']").attr("disabled", true);
|
|
}
|
|
|
|
$(this).parent().siblings(".help-block").html(res.returnData.message).removeClass("hidden");
|
|
});
|
|
},
|
|
500
|
|
));
|
|
|
|
const $nazione = $("#nazione");
|
|
|
|
if ($nazione.length > 0) {
|
|
new Ajax()
|
|
.get("getNazioni")
|
|
.data({
|
|
azienda: _login.get_azienda()
|
|
})
|
|
.$toDisable($("#form-signup"))
|
|
.noticeAsModal()
|
|
.execute(ret => {
|
|
const nazioni = ret.returnData;
|
|
|
|
if (nazioni) {
|
|
nazioni.forEach(nazione => {
|
|
const option = new Option(nazione.descrizione, nazione.nazione, false, nazione.nazione === "IT");
|
|
|
|
$nazione.append(option);
|
|
});
|
|
|
|
$nazione.change(function () {
|
|
const $prov = $("#prov");
|
|
|
|
if ($(this).getValue() !== "IT") {
|
|
$prov.removeAttr("data-required");
|
|
$prov.removeAttr("required");
|
|
$prov.val("");
|
|
$prov.parent().hide();
|
|
} else {
|
|
$prov.attr("data-required", "");
|
|
$prov.prop("required", true);
|
|
$prov.parent().show();
|
|
}
|
|
});
|
|
|
|
$nazione.trigger("change");
|
|
}
|
|
});
|
|
}
|
|
};
|
|
},
|
|
|
|
submitForm: function () {
|
|
var self = this;
|
|
var $form = $("#form-signup");
|
|
var formData = _checkForm.checkData($form);
|
|
|
|
if (formData !== false) {
|
|
self.sendRequest(formData);
|
|
} else {
|
|
var toast = new Toast();
|
|
toast.warning("Compila tutti i dati richiesti");
|
|
}
|
|
},
|
|
|
|
sendRequest: function (data) {
|
|
var self = this;
|
|
data.azienda = _login.get_azienda();
|
|
var ajax = new Ajax();
|
|
|
|
const title = "Registrazione Completata";
|
|
const message = "La richiesta di registrazione è stata inoltrata e sarà sottoposta ad opportuna verifica.<br/>Se ritenuta valida, riceverà le credenziali provvisorie all'e-mail indicata.<br/><br/>In caso di mancata ricezione della suddetta comunicazione entro poche ore, si suggerisce di ritentare la procedura oppure di contattare il supporto tecnico.";
|
|
|
|
ajax.post("sign_up")
|
|
.data(data)
|
|
.recaptchaToken(self.recaptchaToken)
|
|
.$button($("#form-signup button[type='submit']"))
|
|
.$toDisable($("#form-signup"))
|
|
.noticeAsModal()
|
|
.onSuccess({
|
|
callback: function () {
|
|
$("#goto_signin").trigger("click");
|
|
|
|
if (_.isFunction(window.notifyRegistrationComplete)) {
|
|
notifyRegistrationComplete(title, message);
|
|
} else {
|
|
new ModalBox().primary(message, title);
|
|
}
|
|
}
|
|
})
|
|
.execute();
|
|
}
|
|
}; |