en | fr  | Contact  | Print  | Share

FrameBeurk File

Fmbk/Module/Kom1/_js/moduleKom1.js.php

//FrameBeurk V0.65 Copyright ToolOscope 2016. Licence CeCILL-C.
// Javascript associé au module Kom1


// empêche la propagation de l'évènement pour prévenir une autre bascule
// (pour le cas où le lien data-div est inclus dans un élément portant l'attribut data-basculeCharge)
function kom1_stoppeEvent(ctrl, evt) {
    if (! evt)
        var evt = window.event;
    evt.cancelBubble = true;
    if (evt.stopPropagation)     evt.stopPropagation();
}

//toggle + (ouvre) / - (ferme) la div en paramètre
// ctrl est l'élément de controle (alimenté à this dans l'appel à la fonction)
// DivVue est la div à afficher (soit alimentée en entrée, soit contenue par l'attribut)
function kom1_basculeAffichage(ctrl, evt, DivVue) {
    if (typeof DivVue === "undefined")
        DivVue = ctrl.getAttribute("data-bascule");
    if (document.getElementById(DivVue)) {
        if (document.getElementById(DivVue).style.display == 'none') {
            document.getElementById(DivVue).style.display = '';
            ctrl.className = ctrl.className.replace('expFerme', 'expOuvert');
        } else {
            document.getElementById(DivVue).style.display = 'none';
            ctrl.className = ctrl.className.replace('expOuvert', 'expFerme');
        }
    }
    <?php echo $CONFIG['Module']['Kom1']['Fonctions']['ApresBasculeAffichage']; ?>();        // fonction post-bascule
}

//idem ci-dessus, mais en plus charge la div par Ajax si elle est vide
function kom1_basculeAffichageEtCharge(ctrl, evt) {

    // empêche la propagation de l'évènement pour prévenir une autre éxécution de kom1_basculeAffichageEtCharge()
    if (! evt)
        var evt = window.event;
    kom1_stoppeEvent(ctrl, evt)

    //extraction des paramètres
    eval('clefURL = ' + ctrl.getAttribute('data-basculeCharge'));

    // détermination de la div d'affichage
    var DivVue = ctrl.getAttribute('data-ajax');
    if (! DivVue) {            // si non envoyé, le nom de la div est composé à partir de la clef d'affichage
        DivVue = 'a';
        for (var i in clefURL)
            DivVue += '.' + clefURL[i];
    }
    
    if (document.getElementById(DivVue)) {
        kom1_basculeAffichage(ctrl, evt, DivVue);
    
        if (document.getElementById(DivVue).innerHTML == ''        //si la div est vide 
                || (evt.type == 'dblclick'))                    // ou si c'est un double-click
            beurk_chargeDivAjax(DivVue, clefURL);        // on la charge
            
        if (evt.type == 'dblclick')
            ctrl.className = ctrl.className.replace('expFerme', 'expOuvert');        // force la fleche vers le bas après le double-click (cause non identifiée...)
    } else
            alert('La Div ' + DivVue + " n'existe pas");

    <?php echo $CONFIG['Module']['Kom1']['Fonctions']['ApresBasculeAffichage']; ?>();        // fonction post-bascule
}

//demande de prévisualisation d'une entité standart par Ajax - fonction appelée par amélioration
function kom1_previsualiseEntite(element, evt) {

    if (element.hasAttribute("data-previsu")) {
        tabData = element.getAttribute("data-previsu").split("/");    // extraction des données de la div et du bbcode
        formName = tabData[0];
        IdMaj  = tabData[1];
        
        if (myform = document.forms[formName]) {
            beurk_afficheDiv('previsualise' + IdMaj);
            <?php echo $CONFIG['Module']['Beurk']['Fonctions']['AfficheChargement']; ?>('previsualise' + IdMaj);
            
            //tableau de paramètre à passer en Ajax chargé dans BEURK_PARAMS_FORM
            beurk_formEnParametres(myform, true);
            BEURK_POST_URL = beurk_UrlVue({'ActVue':'previsualise', 'IdVue':IdMaj}, true);
            BEURK_POST_ENCTYPE = 'application/x-www-form-urlencoded';
            beurk_ajaxAllerPOST();
        } else {
            alert(sprintf('<?php echo Beurk_traduit('Echec de la soumission par Ajax : form "%%s" inconnu !''Kom1'); ?>', formName));
        }
    }
}

// ------------------ insertion des BBcode dans les données des formulaires ------------------------
function kom1_insereDansDonnees(repdeb, repfin, ActMaj, IdMaj) {
  var input = document.forms['form' + ActMaj + IdMaj].elements['donnees' + IdMaj];
  input.focus();
  if(typeof document.selection != 'undefined') {  // Internet explorer
    var range = document.selection.createRange(); //insertion BBcode
    var insText = range.text;
    range.text = repdeb + insText + repfin;

    range = document.selection.createRange();  //ajustement position curseur
    if (insText.length == 0) {
      range.move('character', -repfin.length);
    } else {
      range.moveStart('character', repdeb.length);
      range.moveEnd('character', -repfin.length);
    }
    range.select();
  }
  else if(typeof input.selectionStart != 'undefined') { // Netscape 6 (mozilla)
    var start = input.selectionStart; //insertion BBcode
    var end = input.selectionEnd;
    var insText = input.value.substring(start, end);
    input.value = input.value.substr(0, start) + repdeb + insText + repfin + input.value.substr(end);

    input.selectionStart = start + repdeb.length; //ajustement position curseur
    input.selectionEnd = start + repdeb.length + insText.length;
  }
  else { //autres navigateurs
  alert("<?php echo Beurk_traduit('Navigateur non géré : Saisissez vos BBcodes à la main'); ?>");
  }
}

// permet d'inserer dans la textarea le BBcode choisi dans une selectBox
// fonction appelée en amélioration sur l'évènement OnChange
function kom1_insereBBCode(element, evt) {
    
    if (element.hasAttribute("data-bbcode")) {
        tabData = element.getAttribute("data-bbcode").split("/");    // extraction des données de la div et du bbcode
        ActMaj = tabData[0];
        IdMaj  = tabData[1];
        bbcod = tabData[2];
        opt = '';
        
        if (bbcod == '')        //si pas renseigné, on va chercher la valeur du select
            bbcod = element.options[element.selectedIndex].value;
        else                    //si déjà renseigné, la valeur du select est l'option du bbcode
            opt = element.options[element.selectedIndex].value;
            
        if (bbcod != ' ') {
            if (opt == '') {
                kom1_insereDansDonnees('[' + bbcod + ']', '[/' + bbcod + ']', ActMaj, IdMaj);
            } else {
                kom1_insereDansDonnees('[' + bbcod + '=' + opt + ']', '[/' + bbcod + ']', ActMaj, IdMaj);
            }
            //document.forms['form' + ActMaj + IdMaj].elements[selec].selectedIndex=0;
            element.selectedIndex=0;
        }
    }
}

//decode les htmlentities (utile dans le cas de l'alimentation d'un textarea par ajax)
function kom1_decodeHtmlEntitities(texte) {
    var temp_div = document.createElement('div');
    temp_div.innerHTML = texte;
    return temp_div.firstChild.nodeValue;
}

//------------------------- cueillette de date ----------------------------------------
var CALENDRIER = new Array(); //stockage des années-mois des calendriers de la page

// affichage initial du calendrier - fonction appelée en amélioration
function kom1_afficheCalendrier(element, evt) {

    if (element.hasAttribute("data-calendrier")) {
        tabData = element.getAttribute("data-calendrier").split("/");    // extraction de la div d'affichage du calendrier
        nomDiv = tabData[0];
        
        if (element != CALENDRIER[nomDiv + '_input']) {        // 1er affichage

            // une date déjà saisie dans la balise element
            if (kom1_verifieDate(element.value)) {
                var elems = element.value.split('-');
                var anneeIni = elems[0];
                var moisIni = elems[1];
            } else {
                var dateIni = new Date();
                var anneeIni = dateIni.getFullYear();
                var moisIni = dateIni.getMonth() + 1;    // janvier = 0
            }
            
            CALENDRIER[nomDiv + '_input'] = element;    // stockage de la référence du champ lié au calendrier

            kom1_rafraichitCalendrier(nomDiv, anneeIni, moisIni)
        }
        document.getElementById(nomDiv).style.display = '';
    }
}

// date à vérifier
function kom1_verifieDate(dateSaisie) {
    var elems = dateSaisie.split('-', 3);
    if (elems.length != 3)
        return false;
        
    var myDate = new Date(elems[0], elems[1] - 1, elems[2]);
    if (myDate.getFullYear() == parseInt(elems[0]) && (myDate.getMonth() + 1) == parseInt(elems[1]) && myDate.getDate() == parseInt(elems[2]))
        return true;
 
    return false;
 }

function kom1_rafraichitCalendrier(nomDiv, annee, mois) {    // réaffichage suite à modification

    CALENDRIER[nomDiv + '_annee'] = annee;    // stockage
    CALENDRIER[nomDiv + '_mois'] = mois;
    
    var jour1erDuMois = new Date(annee, mois - 1, 1).getDay();
    jour1erDuMois = (jour1erDuMois===0) ? 7 : jour1erDuMois;    //repositionne le dimanche en fin de semaine
    var nbJoursMois = new Date(annee, mois, 0).getDate();        // mois est ici l'indice du mois+1 (et janvier = 0)
//alert (annee + ' ' + mois + ' ' + jour1erDuMois);

    var codeCal = '<table class="calendrier"><tr><td><a class="maj" onClick="kom1_decrementeAnnee(\'' + nomDiv + '\');">&lt;&lt;</a></td><td colspan="5">' + annee + '</td><td><a class="maj" onClick="kom1_incrementeAnnee(\'' + nomDiv + '\')">&gt;&gt;</a></td></tr>'
        + '<tr><td><a class="maj" onClick="kom1_decrementeMois(\'' + nomDiv + '\');">&lt;&lt;</a></td><td colspan="5">' + mois + '</td><td><a class="maj" onClick="kom1_incrementeMois(\'' + nomDiv + '\');">&gt;&gt;</a></td></tr>'
        + '<tr><td><?php echo Beurk_traduit('Lu''Kom1'); ?></td>'
        + '<td><?php echo Beurk_traduit('Ma''Kom1'); ?></td>'
        + '<td><?php echo Beurk_traduit('Me''Kom1'); ?></td>'
        + '<td><?php echo Beurk_traduit('Je''Kom1'); ?></td>'
        + '<td><?php echo Beurk_traduit('Ve''Kom1'); ?></td>'
        + '<td><?php echo Beurk_traduit('Sa''Kom1'); ?></td>'
        + '<td><?php echo Beurk_traduit('Di''Kom1'); ?></td>'
        + '</tr><tr>';
    var col = 1;
    //jours avant le 1er
    for (var jo=1;jo<jour1erDuMois;jo++) {
        codeCal += '<td></td>';
        col++;
    }
    //jours du mois
    moisMM = '00' + mois;
    moisMM = moisMM.substr(moisMM.length - 2);    // au format MM
    
    for (var jo=1;jo<=nbJoursMois;jo++) {
        if (col > 7) {
            codeCal += '</tr><tr>';
            col = 1;
        }
        
        jourJJ = '00' + jo;
        jourJJ = jourJJ.substr(jourJJ.length - 2);    // au format JJ
        codeCal += '<td><a onclick="kom1_cueilleDate(\'' + nomDiv + '\', \'' + annee + '-' + moisMM + '-' + jourJJ + '\')">' + jo + '</a></td>';
        col++;
    }
    //jours après la fin du mois
    for (var jo=col;jo<=7;jo++)
        codeCal += '<td></td>';
    
    codeCal += '</tr></table>';

    document.getElementById(nomDiv).innerHTML = codeCal;
}

function kom1_decrementeAnnee(nomDiv) {
    kom1_rafraichitCalendrier(nomDiv, CALENDRIER[nomDiv + '_annee'] - 1, CALENDRIER[nomDiv + '_mois']);
    CALENDRIER[nomDiv + '_input'].focus();    // redonne le focus à la date saisie
}
function kom1_incrementeAnnee(nomDiv) {
    kom1_rafraichitCalendrier(nomDiv, CALENDRIER[nomDiv + '_annee'] + 1, CALENDRIER[nomDiv + '_mois']);
    CALENDRIER[nomDiv + '_input'].focus();    // redonne le focus à la date saisie
}
function kom1_decrementeMois(nomDiv) {
    annee = CALENDRIER[nomDiv + '_annee'];
    mois = CALENDRIER[nomDiv + '_mois'] - 1;
    if (mois < 1) {
        mois = 12;
        annee--;
    }
    kom1_rafraichitCalendrier(nomDiv, annee, mois);
    CALENDRIER[nomDiv + '_input'].focus();    // redonne le focus à la date saisie
}
function kom1_incrementeMois(nomDiv) {
    annee = CALENDRIER[nomDiv + '_annee'];
    mois = CALENDRIER[nomDiv + '_mois'] + 1;
    if (mois > 12) {
        mois = 1;
        annee++;
    }
    kom1_rafraichitCalendrier(nomDiv, annee, mois);
    CALENDRIER[nomDiv + '_input'].focus();    // redonne le focus à la date saisie
}

function kom1_cueilleDate(nomDiv, dateSelectionnee) {
    champ = CALENDRIER[nomDiv + '_input'];
    champ.value = dateSelectionnee;
    document.getElementById(nomDiv).style.display = 'none';
}

// cache le calendrier si le champ date a perdu le focus : un peu bancal !!!! à revoir...
// fonction appelée en amélioration
function kom1_effaceCalendrier(element, evt) {
    if (element.hasAttribute("data-calendrier")) {
        tabData = element.getAttribute("data-calendrier").split("/");    // extraction de la div d'affichage du calendrier
        nomDiv = tabData[0];

        setTimeout(function() {if (document.activeElement != CALENDRIER[nomDiv + '_input']) document.getElementById(nomDiv).style.display = 'none';}, 500);    // pour éviter que le calendrier ne soit effacé avant que la date ne soit sélectionnée
    }
}



© 2010-2015 by ToolOscope SASU. © 2016-2018 by Arnaud De Rette. All rights reserved