Per aspera ad astra
Home Les EVENEMENTS
Les EVENEMENTS Imprimer Envoyer

Il y a 3 types : Client / serveur / ajax

Exemples :

SERVER

        <renderlet:BUTTON name="button_del" label="Supprimer" class="submit">
            <onclick params="uid" runat="server" confirm="Voulez-vous supprimer cette pathologie ?" when="after-init-renderlets">
                <userobj>
                    
<![CDATA[
                   
                       $paramurl = t3lib_div::_GET();    
                    $uidcourant = $this->oDataHandler->currentEntryId();// récupère l'uid courant
                    $GLOBALS["TYPO3_DB"]->exec_UPDATEquery( "tx_bdd_pathologies", "uid='" . $uidcourant . "'", array('deleted' => 1));
                    return header('Location: /index.php?id=' . $paramurl['pageretour'] );

                    ]]></php>
                </userobj>
            </onclick>
                 

                <userobj>
                    
<![CDATA[
                        $groups = explode(",", $GLOBALS["TSFE"]->fe_user->user['usergroup']);                        
                        if ((in_array("2", $groups) || in_array("3", $groups)) && $this->oDataHandler->currentEntryId()) {
                            return true;
                        }
                        return false;
                         ]]></php>
                </userobj>
            </process>  
        </renderlet:BUTTON>

CLIENT

En PHP convertit automatiquement en Javascript lors du rendu formidable :

         <renderlet:BOX style="margin-bottom:20px;" name="titrage_2" mode="h3">
            <childs>
                <renderlet:LINK name="recherche_avancee_link" label="> Recherche avancée" url="#ici" >
                    <onclick runat="client" >
                        <userobj>
                            
<![CDATA[/*<?php*/

// permet alternativement de cacher/ afficher des renderlet  à chaque click.
// Tous les majix effect doivent être dans le return sinon ils ne se font pas. Penssez à inclure scriptaculous dans vos meta si vous utilisez des effets


                    return array($this->aORenderlets["cherche"]->aChilds["recherche_avancee"]->majixFx("toggleBlind", array("duration" => 1)),
                    $this->aORenderlets["cherche"]->aChilds["btnSubmit_simple"]->majixFx("toggleBlind", array("duration" => 1)));

                            /*?>*/]]></php>
                           </userobj>
                    </onclick>
                </renderlet:LINK>
            </childs>
        </renderlet:BOX>

Ou directement en javascript. A noter un attribut sympas de tout renderlet confirm="Message de confirmation" qui demandera une validation au moment de la validation via une popup javascript.
            <renderlet:TEXT name="cnum" label="Informations *" >
                <data defaultValue="SIRET : " />
                <onBlur runat="client" > 
                    <userobj>
                            <js><![CDATA[
                               cnum = this.rdt('user.cnum').getValue().strip();
                               if (cnum == '') { this.rdt('user.cnum').setValue('SIRET :'); }
                           ]]></js>
                    </userobj>
                </onBlur>
            </renderlet:TEXT>
AJAX sur un renderlet Un exemple simple

        <renderlet:BOX name="box_step4">
            <childs>
                <renderlet:BOX>
                    <html><![CDATA[
                        
                        <h3>Another nice aspect of majix is that it can also handle <b>ajax events</b></h3>
                        
Click the button below ...

                    ]]></html>
                </renderlet:BOX>

                <renderlet:BUTTON label="Gimme ajax !!" >
                    <onclick runat="ajax">
                        <userobj>
                            
<![CDATA[
                                
                                return array(
                                    $this->aORenderlets["step4_boxchange"]->majixReplaceData(
                                        "<b>The PHP server says: when you clicked this button it was exactly " . strftime("%H:%M:%S") . " at my watch</b>"
                                    ),
                                    $this->aORenderlets["step4_boxexplain"]->majixDisplayBlock(),
                                    $this->aORenderlets["step4_btntimenocache"]->majixDisplayBlock(),
                                    $this->majixScrollTo("step4_btntimenocache")
                                );

                            ]]></php>
                        </userobj>
                    </onclick>
                </renderlet:BUTTON>

                <renderlet:BOX name="step4_boxchange" />
                
                <renderlet:BOX name="step4_boxexplain">
                    <html><![CDATA[
                        
                        
This event has been processed by the PHP server on-demand ( using json over ajax RPC ).
                        
The default config for ajax events is to cache results return by server, so that when the same event is fired again, no ajax request is needed to execute the majix tasks.
                        
Click the same button again: nothing happens, the time don't change
                        
Then click the following button for fresh data at each click.

                    ]]></html>
                </renderlet:BOX>

                <renderlet:BUTTON name="step4_btntimenocache" label="Gimme ajax !! without caching">
                    <onclick runat="ajax" cache="false">
                        <userobj>
                            
<![CDATA[
                                
                                return array(
                                    $this->aORenderlets["step4_boxchange"]->majixReplaceData(
                                        "<b>The PHP server says: when you clicked this button it was exactly " . strftime("%H:%M:%S") . " at my watch</b>"
                                    ),
                                    $this->aORenderlets["step4_gotostep5"]->majixDisplayBlock()
                                );

                            ]]></php>
                        </userobj>
                    </onclick>
                </renderlet:BUTTON>

                <renderlet:BUTTON name="step4_gotostep5" label="Continue with step 5">
                    <onclick runat="client">
                        <userobj>
                            
<![CDATA[
                                
                                return array(
                                    $this->aORenderlets["box_step5"]->majixDisplayBlock(),
                                    $this->aORenderlets["step4_gotostep5"]->majixDisplayNone(),
                                    $this->majixScrollTo("box_step5"),
                                );

                            ]]></php>
                        </userobj>
                    </onclick>
                </renderlet:BUTTON>
            </childs>
        </renderlet:BOX>

Un exemple un peu plus complexe d'ajax formidable Celui là montre aussi comment gérer une liste dynamique ajax avec un selector.
        <renderlet:SELECTOR defaultWrap="false" name="region" style="height : 200px" class="selector" label="Regions *" activeListable="true" >
            <validators>
                <validator:STANDARD>
                    <required message="Sélectionnez au moins une région pour obtenir la liste des département correspondant. Cette informations est requise." />
                </validator:STANDARD>
            </validators>
            <available>
                <data>
                    <userobj>
                        
<![CDATA[

                            /*$aRow = $this->oDataHandler->getListData();
                            $numregion = $aRow["uid"]; */

                            $result= $GLOBALS["TYPO3_DB"]->exec_SELECTgetRows(
                            "uid as value, region as caption",
                            "tx_bdd_regions",
                            "pid = 63", //AND  tx_bdd_departements.id_region = " . $numregion ,
                            "",
                            "region ASC");
                            
                            return $result;
                            
                        ]]></php>
                    </userobj>
                </data>

                <onChange runat="ajax" params="encapsulation.region" when="before-init-renderlets" >
                    <userobj>
                        
<![CDATA[
                            $aParams = func_get_arg(1);
                            $sText = implode(',', array_merge($aParams["encapsulation.region"]["selected"], $aParams["encapsulation.region"]["available_active"] ));
                            $this->oSandBox->liste_regions = $sText;

                            $aItems = $this->aORenderlets["encapsulation"]->aChilds["departement"]->_getItems();
                            return $this->aORenderlets["encapsulation"]->aChilds["departement"]->majixReplaceData($aItems);

                            //return array($this->aORenderlets["encapsulation"]->aChilds["departement.available"]->majixRepaint());
                        ]]></php>
                    </userobj>
                </onChange>
            </available>

            <buttonRemove type="IMAGE" label="" path="EXT:ameos_formidable/api/base/rdt_selector/res/img/remove.gif" >
                <onClick runat="ajax" params="encapsulation.region" when="before-init-renderlets" >
                    <userobj>
                        
<![CDATA[
                            $aParams = func_get_arg(1);
                            //return $this->majixDebug($aParams["encapsulation.region"]);
                            $sText = implode(',', $aParams["encapsulation.region"]["selected"]);
                            $this->oSandBox->liste_regions = $sText;

                            $aItems = $this->aORenderlets["encapsulation"]->aChilds["departement"]->_getItems();
                            return $this->aORenderlets["encapsulation"]->aChilds["departement"]->majixReplaceData($aItems);

                        ]]></php>
                    </userobj>
                </onClick>
            </buttonRemove>
            
        </renderlet:SELECTOR>


        <renderlet:LISTBOX multiple="true" defaultWrap="false" name="departement" class="selector" label="CTRL + clic pour en sélectionner plusieurs" style="float:left;" activeListable="true" >
            <!--validators>
                <validator:STANDARD>
                    <required message="Veuillez sélectionner au moins un département." />
                </validator:STANDARD>
            </validators-->            
            
                <data>
                    <userobj>
                        
<![CDATA[
                            //$aRow = $this->oDataHandler->getStoredData();
                            //$regions = $aRow["region"];

                            if ($this->oSandBox->liste_regions == "init" ) {
                                $aRow = $this->oDataHandler->getStoredData();
                                $regions = $aRow["region"];
                            } else {
                                $regions = $this->oSandBox->liste_regions;
                            }

                            $regions = explode(",", $regions);
                            
                            $result = array();
                            //debugster($regions);

                            foreach($regions as $une_region) {
                                $res = $GLOBALS["TYPO3_DB"]->exec_SELECTgetRows(
                                "uid as value, CONCAT(' ', numero, ' - ',departement ) as caption, departement",
                                "tx_bdd_departements",
                                "id_region = " . $une_region ,
                                "",
                                "");
                                foreach ($res as $value) {
                                    $result[$value['departement']] = $value;
                                }
                            }

                            sort($result);
                            return $result;
                            
                        ]]></php>
                    </userobj>
                </data>
        
        </renderlet:LISTBOX>

AJAX et récupération de paramètres dans un LISTER

Utilisez params="rowData::nom_de_la_collonne, rowData::col2_truc" pour récupérer les valeurs de colonnes dans la ligne cliquée du lister
                <column type="renderlet:BUTTON" name="btn-del" label="Refuser" listHeader="" class="btn-edit" sort="false">
                    <onclick runat="ajax" params="rowData::uid, rowData::faq" cache="false" confirm="Voulez-vous refuser cette question et ainsi supprimer cette fiche ?" when="after-init-renderlets" >
                        <userobj>
                            
<![CDATA[
                                $data = $this->oMajixEvent->getParams();
                                $uidcourant = $data["uid"];
                                $GLOBALS["TYPO3_DB"]->exec_UPDATEquery( "tx_bdd_faq", "uid='" . $uidcourant . "'", array('deleted' => 1));
                                $this->oDataHandler->refreshStoredData();
                                return array ( $this->aORenderlets["debug"]->majixSetHtml(" Vous venez de refuser la faq " . $data["faq"] . ". Elle ne sera pas publié sur le site."),
                                    $this->aORenderlets["faq"]->majixRepaint());
                            ]]></php>
                        </userobj>
                    </onclick>
                </column>
Mise à jour le Mardi, 19 Octobre 2010 14:25