1/** 2 * --------------------------------------------------------------- 3 * Ce fichier est un SECRET COMMERCIAL de Druide informatique inc. 4 * Tout lecteur ou possesseur non autorisé sera poursuivi. 5 * --------------------------------------------------------------- 6 * 7 * @author Philippe Arcand <[email protected]> 8 * @author Philip Frenette Cloutier <[email protected]> 9 * @author Natercia Machado <[email protected]> 10 * @author Marie Goursolas <[email protected]> 11 * @author Aude Robert-Gingras <[email protected]> 12 * @author Melissa Campos <[email protected]> 13 * @copyright 2018 Druide informatique 14 */ 15 16const AVEC_ANIMATION = true; 17const SANS_ANIMATION = false; 18 19const NBPOSTES_FR = "Nombre de postes"; 20const NBPOSTES_EN = "Number of workstations"; 21const NBUTILISATEURS_FR = "Nombre dâutilisateurs"; 22const NBUTILISATEURS_EN = "Number of users"; 23const NBPARTICIPANTS_FR = "Nombre de participants"; 24const NBPARTICIPANTS_EN = "Number of participants"; 25const NBUTILISATEURSAJOUT_FR = "Nombre dâutilisateurs à ajouter"; 26const NBUTILISATEURSAJOUT_EN = "Number of users to add"; 27const NBPOSTESAJOUT_FR = "Nombre de postes à ajouter"; 28const NBPOSTESAJOUT_EN = "Number of workstations to add"; 29const NBPOSTES_MIN = 5; 30const NBPOSTESAJOUT_MIN = 1; 31 32// Respecte la RFC 3986. 33function fixedEncodeURIComponent(str) { 34 return encodeURIComponent(str).replace(/[!'()*]/g, function (c) { 35 return '%' + c.charCodeAt(0).toString(16); 36 }); 37} 38 39$.urlParam = function (name) { 40 // En attendant que IE 11 meurt! https://caniuse.com/#feat=urlsearchparams 41 var results = new RegExp('[\?&]' + name + '=([^&#]*)').exec(window.location.href); 42 if (results == null) { 43 return null; 44 } 45 if (results.length != 2) 46 return null; 47 if (results[1] == "") 48 return null; 49 return decodeURI(results[1]); 50} 51 52$(function () { 53 // Affichage de la bannière de la demande reçue. 54 let paramDemandeRecue = $.urlParam("demande-recue"); 55 if (paramDemandeRecue == '1') { 56 document.querySelector('#_devis').scrollIntoView({}); 57 $(".notice-demande-recu").addClass('actif'); 58 } 59 60 //Suppression des options 'separateur' apparaissant sur Safari 61 $("select[name='data[produit]']").find("option[value^='separateur']").each(function(idx, elem){ 62 $(elem).remove(); 63 }); 64 65 $("#_formation a.bouton").click(function (e) { 66 e.preventDefault(); 67 let params = new URLSearchParams(window.location.search.slice(1)); 68 params.set('demande', 'formation'); 69 history.pushState({}, '', window.location.origin + window.location.pathname + "?" + params.toString()) 70 metsChoixDefaut(); 71 }); 72 73 const formsFields = $('.form-field'); 74 $(formsFields).each(function () { 75 76 if ($(this).find("textarea").length || $(this).find(".h-captcha")) 77 return; 78 79 const clone = $(this).clone().css("display", "block").css("position", "absolute").css("left", "-9999px"); 80 $(this).after(clone); 81 82 const hauteur = clone.outerHeight(); 83 clone.remove(); 84 85 $(this).css('max-height', hauteur); 86 }); 87 88 afficherFormulaireAvecParamsPourProduit(); 89 afficherFormulaireAvecParamsPourTypeDevis(); 90 afficherFormulaireAvecParamsPourLangue(); 91 metsChoixDefaut(); 92 prepareAffichageNumerique(); 93 formulaireAChangerSelonCondition(formsFields, "produit"); 94 formulaireAChangerSelonCondition(formsFields, "demandelicence"); 95 formulaireAChangerSelonCondition(formsFields, "demandeabonnementpro"); 96 formulaireAChangerSelonCondition(formsFields, "demandeabonnement"); 97 formulaireAChangerSelonCondition(formsFields, "demandelicencescolaire"); 98 formulaireAChangerSelonCondition(formsFields, "demandeinfo"); 99 updateFormulaire(SANS_ANIMATION); 100 attacheEvenementAfficheFormulaire(); 101 102 if ($(location).attr('hash') == '#_formulaire') { 103 afficheFormulaire(); 104 } 105 106 if (formulaireContientErreur()) { 107 $('body').css('scroll-behavior', 'auto'); 108 $('html').css('scroll-behavior', 'auto'); 109 afficheFormulaire('instant'); 110 }
111 supprimerEspacesAvantAsterisque(); 112}); 113 114function supprimerEspacesAvantAsterisque() { 115 var labels = document.querySelectorAll("label.inline"); 116 labels.forEach(function(elem){ 117 elem.childNodes.forEach(function(value){ 118 if(value.nodeType === Node.TEXT_NODE) { 119 value.nodeValue = value.nodeValue.trim(); 120 } 121 }); 122 }); 123} 124 125function formulaireAChangerSelonCondition(formsFields, input) { 126 return $('select[name="data['+ input +']"]').change(function () { 127 $(formsFields).addClass('avec-animation'); 128 updateFormulaire(AVEC_ANIMATION); 129 }); 130} 131 132function formulaireContientErreur() { 133 return $("#_formulaire").find(".error").length; 134} 135 136function attacheEvenementAfficheFormulaire() { 137 $('[href="#_formulaire"]').click(function () { 138 $("#_formulaire").addClass('affiche'); 139 afficheFormulaire() 140 return true; 141 }) 142 143 $('._formulaire').click(function () { 144 if (!$("#_formulaire").length) { 145 location.href = location.pathname + "?#_formulaire"; 146 } else { 147 $("#_formulaire").addClass('affiche'); 148 afficheFormulaire() 149 } 150 return true; 151 }) 152} 153 154function contientFormulaireDevis() { 155 return $('#_formulaire').length > 0; 156} 157 158function redirigeVersFormulaireDevis() { 159 const urlCourant = new URL(document.location); 160 const languePage = document.documentElement.lang.toLowerCase(); 161 const urlFr = "/" + languePage + '/organisations/devis'; 162 const urlEn = "/" + languePage + '/organizations/quote'; 163 const urlStr = languePage == 'fr' ? urlFr : urlEn; 164 165 window.location.replace(urlStr + '?' + urlCourant.searchParams.toString()); 166} 167 168function afficheFormulaire(scroll='smooth') { 169 if (!contientFormulaireDevis()) { 170 redirigeVersFormulaireDevis(); 171 } 172 173 $("#_formulaire").addClass('affiche'); 174 if (sessionStorage.getItem('selection')) { 175 $("select[name='data[produit]']").val(sessionStorage.getItem('selection')); 176 sessionStorage.clear(); 177 } 178 let param = $.urlParam("languetraitee"); 179 if (param == null) { 180 var languePage = document.documentElement.lang.toLowerCase(); 181 var langue = ( languePage == 'en' ? "ANGLAIS" : "FRANCAIS" ); 182 $("select[name='data[languetraitee]']").find('option[value=' + langue + ']').prop('selected', true); 183 } 184} 185 186function convertisCleDataACleParam(cleData) { 187 if (cleData == "demandelicence") 188 return "demande"; 189 if (cleData == "demandeabonnement") 190 return "demande"; 191 if (cleData == "demandeabonnementpro") 192 return "demande"; 193 if (cleData == "demandelicencescolaire") 194 return "demande"; 195 return cleData; 196} 197 198function convertisValeurParam(param, cleData) { 199 paramTmp = param.toUpperCase(); 200 if (paramTmp == "NOUVELLELICENCE") { 201 if (cleData == "demandeabonnement" || cleData == "demandeabonnementpro") 202 return "NOUVELABONNEMENT"; 203 } 204 if (paramTmp == "AJOUTPOSTE") { 205 if (cleData == "demandeabonnement" || cleData == "demandeabonnementpro") 206 return "AJOUTUTILSATEUR"; 207 } 208 if (paramTmp == "REABONNEMENT") { 209 if (cleData == "demandeabonnement" || cleData == "demandeabonnementpro") 210 return "REABONNEMENT_WEB"; 211 } 212 return param; 213} 214 215function metsChoixDefaut() { 216 let aUnChoixDefaut = false; 217 $('#main [name^="data["]').each(function () { 218 let cle = $(this).attr('name').split('[')[1].slice(0, -1); 219 if (cle == null) 220 return; 221 let cleParam = convertisCleDataACleParam(cle); 222 let param = $.urlParam(cleParam); 223 if (param == null) 224 return; 225 aUnChoixDefaut = true; 226 param = convertisValeurParam(decodeURIComponent(param), cle); 227 let tag = $(this).prop("tagName"); 228 switch (tag) { 229 case "SELECT": 230 _metsChoixDefautSelect($(this), param); 231 break; 232 case "INPUT": 233 _metsChoixDefautInput($(this), param); 234 break; 235 default: 236 break; 237 } 238 }); 239 240 if (aUnChoixDefaut) 241 afficheFormulaire(); 242} 243 244function _metsChoixDefautSelect(elem, param) { 245 param = param.toUpperCase(); 246 const optionExiste = $(elem).find('option[value="' + param + '"]').length; 247 if (optionExiste) 248 $(elem).val(param); 249} 250 251function _metsChoixDefautInput(elem, param) { 252 $(elem).val(param); 253} 254 255function prepareAffichageNumerique() { 256 $('<div class="nombre-nav"><div class="nombre-bouton nombre-plus">+</div><div class="nombre-bouton nombre-moins">-</div></div>').insertAfter('input[type="number"]'); 257 $('.form-input-wrapper ').each(function () { 258 const spinner = $(this), 259 input = spinner.find('input[type="number"]'), 260 btnUp = spinner.find('.nombre-plus'), 261 btnDown = spinner.find('.nombre-moins'),
262 min = input.attr('min'), 263 max = input.attr('max'); 264 265 if (!$(input).length) 266 return; 267 268 btnUp.click(function () { 269 let oldValue = parseFloat(input.val()); 270 let newVal = oldValue; 271 if (isNaN(oldValue)) { 272 if (min == null) 273 newVal = 0; 274 else 275 newVal = min; 276 } else if (oldValue >= max) { 277 newVal = oldValue; 278 } else { 279 newVal = oldValue + 1; 280 } 281 spinner.find("input").val(newVal); 282 spinner.find("input").trigger("change"); 283 }); 284 285 btnDown.click(function () { 286 let oldValue = parseFloat(input.val()); 287 let newVal = oldValue; 288 if (isNaN(oldValue)) { 289 if (min == null) 290 newVal = 0; 291 else 292 newVal = min; 293 } else if (oldValue <= min) { 294 newVal = oldValue; 295 } else { 296 newVal = oldValue - 1; 297 } 298 spinner.find("input").val(newVal); 299 spinner.find("input").trigger("change"); 300 }); 301 }); 302} 303 304function updateFormulaire(avecAnimation) { 305 _updateFormulaireProduit(avecAnimation); 306} 307 308function _updateFormulaireProduit(avecAnimation) { 309 const delaisAnimation = avecAnimation ? 400 : 0; 310 const langue = $("html").attr("lang"); 311 const afficheProduit = $('select[name="data[produit]"]'); 312 313 let val = $(afficheProduit).find('option:selected').attr('value'); 314 let afficheNbPoste = true; 315 let afficheLangueTraitee = true; 316 let afficheDemandeLicence = true; 317 let afficheDemandeAbonnement = false; 318 let afficheDemandeAbonnementPro = false; 319 let afficheDemandeLicenceScolaire = false; 320 let afficheDemandeInfo = false; 321 let etiquetteNbPoste = langue === "fr" ? NBPOSTES_FR : NBPOSTES_EN; 322 let nbPostesEstRequis = true; 323 let langueTraiteeEstRequis = true; 324 325 switch (val) { 326 case 'ANTIMULTIPOSTE': 327 break; 328 case 'ANTIPRO': 329 afficheDemandeLicence = false; 330 afficheDemandeAbonnementPro = true 331 etiquetteNbPoste = langue === "fr" ? NBUTILISATEURS_FR : NBUTILISATEURS_EN; 332 break; 333 case 'ANTIWEB': 334 afficheDemandeLicence = false; 335 afficheDemandeAbonnement = true; 336 etiquetteNbPoste = langue === "fr" ? NBUTILISATEURS_FR : NBUTILISATEURS_EN; 337 break; 338 case 'LICENCEAB': 339 afficheDemandeLicenceScolaire = true; 340 afficheDemandeLicence = false; 341 break; 342 case 'LICENCEAPRO': 343 afficheDemandeLicenceScolaire = true; 344 afficheDemandeLicence = false; 345 etiquetteNbPoste = langue === "fr" ? NBUTILISATEURS_FR : NBUTILISATEURS_EN; 346 break; 347 case 'INDETERMINE': 348 afficheDemandeLicence = false; 349 afficheDemandeInfo = true; 350 afficheLangueTraitee = false; 351 afficheNbPoste = false; 352 nbPostesEstRequis = false; 353 langueTraiteeEstRequis = false; 354 break; 355 } 356 _updateNbPoste(afficheNbPoste, etiquetteNbPoste, nbPostesEstRequis, delaisAnimation); 357 _updateDemande(afficheDemandeLicence, 'demandelicence'); 358 _updateDemande(afficheDemandeAbonnementPro, 'demandeabonnementpro'); 359 _updateDemande(afficheDemandeAbonnement, 'demandeabonnement'); 360 _updateDemande(afficheDemandeLicenceScolaire, 'demandelicencescolaire'); 361 _updateDemande(afficheDemandeInfo, 'demandeinfo'); 362 _updateLangue(afficheLangueTraitee, langueTraiteeEstRequis); 363 _updateFormulaireDemande(afficheDemandeAbonnementPro, afficheDemandeAbonnement, afficheDemandeLicenceScolaire, afficheDemandeInfo, delaisAnimation); 364} 365 366function _updateDemande(afficheDemande, element) { 367 const input = $(`select[name="data[${element}]"]`); 368 369 var inputContainer = $(input).parents('.form-field'); 370 if (afficheDemande) { 371 $(inputContainer).show(); 372 } else { 373 $(inputContainer).hide(); 374 } 375} 376
377function _updateFormulaireDemande(afficheDemandeAbonnementPro, afficheDemandeAbonnement, afficheDemandeLicenceScolaire, afficheDemandeInfo, delaisAnimation) { 378 const langue = $("html").attr("lang"); 379 let elemDemande = $('select[name="data[demandelicence]"]'); 380 381 if (afficheDemandeAbonnementPro) { 382 elemDemande = $('select[name="data[demandeabonnementpro]"]'); 383 } else if (afficheDemandeAbonnement) { 384 elemDemande = $('select[name="data[demandeabonnement]"]'); 385 } else if (afficheDemandeLicenceScolaire) { 386 elemDemande = $('select[name="data[demandelicencescolaire]"]'); 387 } else if(afficheDemandeInfo) { 388 elemDemande = $('select[name="data[demandeinfo]"]'); 389 } 390 391 let val = $(elemDemande).find('option:selected').attr('value'); 392 let afficheNoSerie = false; 393 let afficheLangue = true; 394 let champEstRequis = false; 395 let nbPostesEstRequis = true; 396 let langueTraiteeEstRequis = true; 397 let etiquetteNbPoste = langue === "fr" ? NBPARTICIPANTS_FR : NBPARTICIPANTS_EN; 398 switch (val) { 399 case 'NOUVELLELICENCE': 400 case 'NOUVELABONNEMENT': 401 case 'INFO': 402 case 'AJOUTUTILSATEUR': 403 case 'REABONNEMENT_WEB': 404 afficheNoSerie = false; 405 champEstRequis = false; 406 if (val == 'AJOUTUTILSATEUR') { 407 afficheNbPostes = false; 408 etiquetteNbPoste = langue === "fr" ? NBUTILISATEURSAJOUT_FR : NBUTILISATEURSAJOUT_EN; 409 _updateNbPoste(false, etiquetteNbPoste, false, delaisAnimation); 410 _updateNbPosteAjout(true, etiquetteNbPoste); 411 } 412 break; 413 case 'AJOUTPOSTE': 414 case 'MAN': 415 afficheNoSerie = true; 416 champEstRequis = true; 417 if (val == 'AJOUTPOSTE') { 418 etiquetteNbPoste = langue === "fr" ? NBPOSTESAJOUT_FR : NBPOSTESAJOUT_EN; 419 _updateNbPoste(false, etiquetteNbPoste, false, delaisAnimation); 420 _updateNbPosteAjout(true, etiquetteNbPoste); 421 } 422 break; 423 case 'REABONNEMENT': 424 case 'MIGRATION': 425 afficheNoSerie = true; 426 champEstRequis = false; 427 nbPostesEstRequis = false; 428 langueTraiteeEstRequis = false; 429 etiquetteNbPoste = langue === "fr" ? NBPOSTES_FR : NBPOSTES_EN; 430 _updateNbPoste(true, etiquetteNbPoste, nbPostesEstRequis, delaisAnimation); 431 _updateLangue(afficheLangue, langueTraiteeEstRequis) 432 break; 433 } 434 _updateNoSerie(afficheNoSerie, champEstRequis, delaisAnimation); 435} 436 437function _updateLangue(afficheLangue, estRequis) { 438 const input = $('select[name="data[languetraitee]"]') 439 const inputContainer = $(input).parents('.form-field'); 440 const label = $(inputContainer).find('label'); 441 442 if (afficheLangue) { 443 changeEtatChampRequis(label, input, estRequis); 444 $(inputContainer).removeClass('disparait'); 445 $(inputContainer).show(); 446 } else { 447 changeEtatChampRequis(label, input, false); 448 $(inputContainer).addClass('disparait'); 449 $(inputContainer).hide(); 450 } 451} 452 453function _updateNbPoste(afficheNbPoste, etiquetteNbPoste, estRequis, delaisAnimation) { 454 const inputNbPoste = $('input[name="data[nbposte]"]'); 455 const inputNbPosteContainer = $(inputNbPoste).parents('.form-field'); 456 const labelNbPoste = $(inputNbPosteContainer).find('label'); 457 458 if (inputNbPosteContainer.find("label").length) { 459 inputNbPosteContainer.find("label").get(0).childNodes[0].nodeValue = etiquetteNbPoste; 460 } 461 462 if (afficheNbPoste) { 463 $(inputNbPosteContainer).removeClass('disparait'); 464 $(inputNbPosteContainer).show(); 465 $(inputNbPoste).attr('data-old', $(inputNbPoste).val()); 466 // Retirer le champ "nbposteajout" 467 const inputNbPosteAjout = $('input[name="data[nbposteajout]"]'); 468 const inputNbPosteAjoutContainer = $(inputNbPosteAjout).parents('.form-field'); 469 $(inputNbPosteAjoutContainer).addClass('disparait'); 470 $(inputNbPosteAjoutContainer).hide(); 471 472 if ($(inputNbPoste).is('[data-old]')) { 473 $(inputNbPoste).val($(inputNbPoste).attr('data-old')); 474 } else { 475 $(inputNbPoste).val(NBPOSTES_MIN); 476 } 477 if (estRequis) { 478 changeEtatChampRequis(labelNbPoste, inputNbPoste, estRequis); 479 $(inputNbPoste).attr('min', NBPOSTES_MIN) 480 if (($('div.notices.error').text()).search('Minimum') >= 0) 481 $(inputNbPosteContainer).addClass('has-errors'); 482 } else { 483 changeEtatChampRequis(labelNbPoste, inputNbPoste, estRequis); 484 $(inputNbPoste).removeAttr('min') 485 if ($(inputNbPosteContainer).hasClass('has-errors') ) 486 $(inputNbPosteContainer).removeClass('has-errors'); 487 } 488 } else { 489 changeEtatChampRequis(labelNbPoste, inputNbPoste, false); 490 $(inputNbPosteContainer).addClass('disparait'); 491 $(inputNbPosteContainer).hide(); 492 } 493} 494 495function _updateNbPosteAjout(afficheNbPoste, etiquetteNbPoste) { 496 const inputNbPoste = $('input[name="data[nbposteajout]"]'); 497 const inputNbPosteContainer = $(inputNbPoste).parents('.form-field'); 498 const labelNbPoste = $(inputNbPosteContainer).find('label'); 499 inputNbPosteContainer.find("label").get(0).childNodes[0].nodeValue = etiquetteNbPoste; 500 if (afficheNbPoste) { 501 changeEtatChampRequis(labelNbPoste, inputNbPoste, true); 502 $(inputNbPosteContainer).removeClass('disparait'); 503 $(inputNbPosteContainer).show(); 504 $(inputNbPoste).attr('data-old', $(inputNbPoste).val()); 505 506 if ($(inputNbPoste).is('[data-old]')) { 507 $(inputNbPoste).val($(inputNbPoste).attr('data-old')); 508 } else { 509 $(inputNbPoste).val(NBPOSTESAJOUT_MIN); 510 } 511 } else { 512 changeEtatChampRequis(labelNbPoste, inputNbPoste, false); 513 $(inputNbPosteContainer).addClass('disparait'); 514 $(inputNbPosteContainer).hide(); 515 } 516} 517
518function _updateNoSerie(afficheNoSerie, estRequis, delaisAnimation) { 519 const input = $('input[name="data[noserie]"]') 520 const inputContainer = $(input).parents('.form-field'); 521 const label = $(inputContainer).find('label'); 522 523 if (afficheNoSerie) { 524 $(inputContainer).removeClass('disparait'); 525 if (estRequis) { 526 changeEtatChampRequis(label, input, estRequis); 527 if (($('div.notices.error').text()).toLowerCase().search('série') >= 0 || ($('div.notices.error').text()).toLowerCase().search('serial') >= 0 ) 528 $(inputContainer).addClass('has-errors'); 529 } else { 530 changeEtatChampRequis(label, input, estRequis); 531 if ($(inputContainer).hasClass('has-errors') ) 532 $(inputContainer).removeClass('has-errors'); 533 } 534 } else { 535 changeEtatChampRequis(label, input, estRequis); 536 $(inputContainer).addClass('disparait'); 537 } 538} 539 540function afficherFormulaireAvecParamsPourProduit() { 541 let sujet = donneParam('demande') ?? donneParam('quote'); 542 543 if (sujet) { 544 let option = null 545 546 switch (sujet) { 547 case 'licence': 548 case 'license': 549 option = 'ANTIMULTIPOSTE'; 550 break; 551 case 'prosubscription': 552 case 'abonnementpro': 553 option = 'ANTIPRO'; 554 break; 555 case 'subscription': 556 case 'abonnementaweb': 557 option = 'ANTIWEB'; 558 break; 559 case 'schoollicense': 560 case 'licencescolaire': 561 option = 'ANTIWEB'; 562 break; 563 default: 564 option = 'INDETERMINE'; 565 } 566 $("[name='data[produit]']").find('option[value="'+ option +'"]').prop('selected', true); 567 afficheFormulaire(); 568 } 569} 570 571function afficherFormulaireAvecParamsPourTypeDevis() { 572 let sujet = donneParam('type'); 573 574 if (sujet) { 575 let option = null 576 577 switch (sujet) { 578 case 'add': 579 case 'ajout': 580 option = 'AJOUTPOSTE'; 581 break; 582 case 'upgrade': 583 case 'man': 584 option = 'MAN'; 585 break; 586 case 'renewal': 587 case 'reabonnement': 588 option = 'REABONNEMENT'; 589 break; 590 default: 591 option = 'NOUVELLELICENCE'; 592 } 593 $("[name='data[demandelicence]']").find('option[value="'+ option +'"]').prop('selected', true); 594 afficheFormulaire(); 595 } 596} 597 598function afficherFormulaireAvecParamsPourLangue() { 599 var languePage = document.documentElement.lang.toLowerCase(); 600 601 if (donneParam('lang')) { 602 languePage = donneParam('lang'); 603 } 604 605 var langue = ( languePage == 'en' ? "ANGLAIS" : "FRANCAIS" ); 606 $("select[name='data[languetraitee]']").find('option[value=' + langue + ']').prop('selected', true); 607} 608 609function changeEtatChampRequis(label, input, estRequis) { 610 if (estRequis) { 611 if ($(label).find('span.required').length == 0) { 612 $("<span class='required'>*</span>").appendTo(label); 613 } 614 $(label).find('.required').show(); 615 $(input).attr("required", true) 616 } else { 617 $(label).find(".required").hide(); 618 $(input).attr("required", false) 619 } 620}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.