-function getCaption(title) {
- $('#Bastide_cart .caption').remove()
- return `<div class="caption "><a href="#/closeview" role="button" aria-label="Fermer" aria-keyshortcuts="Escape" class="back"><svg viewBox="0 0 512 512" class="interface-close nav-icon svg-icon" aria-hidden="true"><use xlink:href="#interface-close"></use></svg></a><h2 id="mview-dialog-title">${title}</h2></div>`
+function Cart() {
+ this.init();
}
-$(function () {
- console.log($('meta[name="csrf-token"]'));
- $('#wf-form-login').attr('action', '/landing/login');
- $("#wf-form-login").append('<input type="hidden" name="_token" value="' + $('meta[name="csrf-token"]').attr('content') + '" />');
-
- var mview = `<div id="view"></div>`;
- var registerForm = `<div id="Bastide_cart" data-content="register"><div id="Bastide_auth_form"><form id="Bastide_register_form" class="" data-content="register" action="/fluidbook/signin">
+Cart.prototype = {
+ init: function() {
+ var $this = this
+ var registerForm = `<div id="Bastide_cart" data-content="register"><div id="Bastide_auth_form"><form id="Bastide_register_form" class="" data-content="register" action="/fluidbook/signin">
<div class="form-group">
<div class="form-header">
établissement hospitalier
<button id="register" class="cta" type="submit">Valider</button>
</form></div></div></div>`
- $(document).on("click", "#create-account", function() {
- $("#viewOverlay").addClass("active")
- $("section.main").append(mview)
- $("section.main #view").addClass("active").append(registerForm)
- $("#Bastide_cart").prepend(getCaption('Créer un compte'))
- })
- $(document).on("submit", "#wf-form-login", function(e) {
- e.preventDefault()
- let formData = $(this).serialize()
- var $this = this
- $.ajax({
- url: '/fluidbook/login',
- type: 'POST',
- data: formData,
- success: function(data) {
- window.location.href = window.location.href+'catalogue'
- },
- error: function(xhr, status, error) {
- $(".errors-container").remove()
- $(".error").removeClass("error")
- $("#wf-form-login").addClass("error").prepend('<div class="errors-container"><p>Une erreur est survenue. Verifiez vos identifiants.</p></div>')
+ $(document).on("click", '[data-action]', function () {
+ let title = $(this).data('title')
+ let action = $(this).data('action')
+ $this.openModal(title, $this.getCartContent('register'))
+ $this.updateTitle(title)
+ $this.updateCart(action)
+ $this.updateDataContent()
+ });
+
+ $(document).on("submit", "#wf-form-login", function(e) {
+ e.preventDefault()
+ let formData = $(this).serialize()
+ var $this = this
+ $.ajax({
+ url: '/fluidbook/login',
+ type: 'POST',
+ data: formData,
+ success: function(data) {
+ window.location.href = window.location.href+'catalogue'
+ },
+ error: function(xhr, status, error) {
+ $(".errors-container").remove()
+ $(".error").removeClass("error")
+ $("#wf-form-login").addClass("error").prepend('<div class="errors-container"><p>Une erreur est survenue. Verifiez vos identifiants.</p></div>')
+ }
+ });
+ });
+
+ $(document).on("submit", "#Bastide_register_form", function(e) {
+ e.preventDefault()
+ let formData = $(this).serialize()
+ $this.register(formData)
+ })
+
+ $(document).on("submit", "#Bastide_forgotpass_form", function(e) {
+ e.preventDefault()
+ let formData = $(this).serialize()
+ $this.forgotpass(formData)
+ })
+
+ $(document).on("click", "#send_email_forgotpass", function(e) {
+ e.preventDefault()
+ $this.forgotpass()
+ })
+
+
+ /**
+ *
+ * Close view
+ *
+ */
+ $(document).on("click", "#closeview", function() {
+ $this.closeView()
+ })
+
+ $(document).mouseup(function(e)
+ {
+ var container = $("#Bastide_cart");
+
+ // if the target of the click isn't the container nor a descendant of the container
+ if (!container.is(e.target) && container.has(e.target).length === 0)
+ {
+ $this.closeView()
}
});
- });
+ },
- $(document).on("submit", "#Bastide_register_form", function(e) {
- e.preventDefault()
- var $this = this
- let formData = $(this).serialize()
+ getCaption: function(title) {
+ return `<div class="caption "><a href="" id="closeview" role="button" aria-label="Fermer" aria-keyshortcuts="Escape" class="back"><svg viewBox="0 0 512 512" class="interface-close nav-icon svg-icon" aria-hidden="true"><use xlink:href="#interface-close"></use></svg></a><h2 id="mview-dialog-title">${title}</h2></div>`
+ },
+
+ updateDataContent: function () {
+ let dataContent = $("#Bastide_auth_form").find('[data-content]').data('content')
+ $("#Bastide_cart").attr('data-content',dataContent)
+ },
+
+ updateTitle: function(title = "Connexion") {
+ $("#mview-dialog-title").text(title)
+ },
+
+ openModal: function (title, content) {
+ let $this = this
+ let view = "<div id='view'>"
+ view += `<div id="Bastide_cart" data-content="">
+ ${this.getCaption(title)}
+ <div class="content">
+ ${content}
+ </div>
+ </div>`;
+ view += "</div>";
+ $("section.main").append(view)
+ $("#viewOverlay,#view").addClass("active")
+ },
+
+ getCartContent: function (action = null) {
+ let form = `<div id="Bastide_auth_form" class="container-form">`;
+ switch (action) {
+ case 'register':
+ form += `<form id="Bastide_register_form" class="" data-content="register" action="/fluidbook/signin">
+ <div class="form-group">
+ <div class="form-header">
+ établissement hospitalier
+ </div>
+ <div class="form-controls">
+ <label for="">Nom de l'établissement</label>
+ <input type="text" name="hospital" />
+ </div>
+ <div class="form-controls">
+ <label for="">Numéro de finess de l’établissement</label>
+ <input type="text" name="finess" />
+ </div>
+ </div>
+ <div class="form-group">
+ <div class="form-header">
+ Contact
+ </div>
+ <div class="form-controls">
+ <label for="">Votre nom</label>
+ <input type="text" name="name" />
+ </div>
+ <div class="form-controls">
+ <label for="">Votre prénom</label>
+ <input type="text" name="firstname" />
+ </div>
+ <div class="form-controls">
+ <label for="">Votre fonction</label>
+ <input type="text" name="function" />
+ </div>
+ <div class="form-controls">
+ <label for="">votre Numéro de téléphone</label>
+ <input type="text" name="phone" />
+ </div>
+ <div class="form-controls">
+ <label for="">votre adresse email pro</label>
+ <input type="email" name="email" />
+ </div>
+ <div class="form-controls">
+ <label for="">confirmer votre adresse email PRO</label>
+ <input type="text" name="email_confirmation" />
+ </div>
+ <div class="form-controls">
+ <label for="">définir votre mot de passe</label>
+ <input type="password" name="password" />
+ </div>
+ <div class="form-controls">
+ <label for="">confirmer votre mot de passe</label>
+ <input type="password" name="password_confirmation" />
+ </div>
+ </div>
+ <div class="form-controls condition" data-valid="/images/valid.svg">
+ <input id="condition_field" type="checkbox" name="accept" />
+ <label for="condition_field">Je reconnais avoir été informé que les informations recueillies sur ce
+ formulaire sont enregistrées dans un fichier informatisé traité par Bastide le Confort
+ Médical. Pour plus d’informations je peux consulter la <a href="/charte-de-protection-des-donnees-personnelles.html">charte de protection des
+ données personnelles</a>.
+ </label>
+ </div>
+ <button id="register" class="cta" type="submit">Valider</button>
+ </form>`
+ break;
+ case 'register_ok':
+ form += `<div id="Bastide_notif_form" data-content="register_ok"><p>Votre demande de création de compte sera examinée dans les plus brefs délais.
+ Vous recevrez un email de confirmation dans les 24h (pensez à vérifier votre dossier spam).</p>
+ <p>Nos équipes commerciales se tiennent à votre disposition : <a href="mailto:resah@bastide-medical.fr">
+ resah@bastide-medical.fr</a></p>
+ </div>`
+ break;
+ case 'forgot_pass':
+ form += `<form id="Bastide_forgotpass_form" data-content="forgotpass">
+ <div class="form-controls">
+ <label for="">Adresse email</label>
+ <input type="email" name="email" />
+ </div>
+ <button id="send_email_forgotpass" class="login cta" type="submit">Envoyer</button>
+ </form>`
+ break;
+ case 'forgot_pass_notif':
+ form += `<div id="Bastide_notif_form" data-content="forgot_pass_notif"><p>Vous allez recevoir un email avec un lien vous permettant de redéfinir votre mot de passe.</p>
+ </div>`
+ break;
+ default:
+ form += ``
+ }
+ form += `</div>`;
+ return form;
+ },
+
+ updateCart: function (content = null) {
+ if ($('#Bastide_cart').length > 0) {
+ $('#Bastide_cart .content').html(this.getCartContent(content));
+ }
+ },
+
+ closeView: function() {
+ $("#viewOverlay").removeClass("active")
+ $("#view").remove()
+ },
+ register: function(d) {
+ var $this = this
$.ajax({
url: '/fluidbook/signin',
type: 'POST',
- data: formData,
+ data: d,
success: function(data) {
- $("#Bastide_cart").attr("data-content","").prepend(getCaption('Merci !'))
- $("#Bastide_auth_form").html(`<div id="Bastide_notif_form" data-content="register_ok"><p>Votre demande de création de compte sera examinée dans les plus brefs délais.
- Vous recevrez un email de confirmation dans les 24h (pensez à vérifier votre dossier spam).</p>
- <p>Nos équipes commerciales se tiennent à votre disposition : <a href="mailto:resah@bastide-medical.fr">
- resah@bastide-medical.fr</a></p>
- </div>`)
+ $this.updateTitle('Merci !')
+ $this.updateCart('register_ok')
+ $this.updateDataContent()
},
error: function(xhr, status, error) {
- let errors = JSON.parse(xhr.responseText);
- $("#Bastide_register_form .errors-container").remove()
- $(".error").removeClass("error")
- for(let k in errors['errors']) {
- $("#Bastide_register_form [name="+k+"]").parent().append('<div class="errors-container"></div>')
- $(".errors-container").parent().addClass("error")
- for(let i in errors['errors'][k]) {
- $("#Bastide_register_form [name="+k+"]").parent().find('.errors-container').append(`<div>${errors['errors'][k][i]}</div>`)
- }
- }
+ let errorsMessage = JSON.parse(xhr.responseText);
+ $this.displayErrors(errorsMessage)
}
});
- })
+ },
- $(document).mouseup(function(e)
- {
- var container = $("#Bastide_cart");
+ forgotpass: function(d) {
+ //do action
+ this.updateCart('forgot_pass_notif')
+ this.updateDataContent()
+ },
- // if the target of the click isn't the container nor a descendant of the container
- if (!container.is(e.target) && container.has(e.target).length === 0)
- {
- $("#viewOverlay").removeClass("active")
- $("#view").remove()
+ displayErrors: function(errors) {
+ $("#Bastide_auth_form .errors-container").remove()
+ $(".error").removeClass("error")
+ for(let k in errors['errors']) {
+ $("#Bastide_auth_form [name="+k+"]").parent().append('<div class="errors-container"></div>')
+ $(".errors-container").parent().addClass("error")
+ for(let i in errors['errors'][k]) {
+ $("#Bastide_auth_form [name="+k+"]").parent().find('.errors-container').append(`<div>${errors['errors'][k][i]}</div>`)
+ }
}
- });
+ },
+}
+
+$(function () {
+ $('#wf-form-login').attr('action', '/landing/login');
+ $("#wf-form-login").append('<input type="hidden" name="_token" value="' + $('meta[name="csrf-token"]').attr('content') + '" />');
+ const cart = new Cart();
});