developer.jelix.org is not used any more and exists only for history. Post new tickets on the Github account.
developer.jelix.org n'est plus utilisée, et existe uniquement pour son historique. Postez les nouveaux tickets sur le compte github.

Ticket #30: link_to_remote.diff

File link_to_remote.diff, 3.5 KB (added by julienj, 12 years ago)

Function link_to_remote

  • build/manifests/jelix-lib.mn

     
    548548  block.swf.php
    549549  cfunction.swfbiscuit.php
    550550  block.swfjs.php
     551  function.link_to_remote.php
    551552
    552553cd lib/jelix/plugins/tpl/ltx2pdf
    553554  function.jlocale.php
  • build/config/jelix-test.ini

     
    1 MAIN_TARGET_PATH = _dev
     1MAIN_TARGET_PATH = /home/julien/www/dev_jelix/test/
    22EDITION_NAME =
    33PHP_VERSION_TARGET = 5.2
    44
     
    1717PACKAGE_TAR_GZ =
    1818PACKAGE_ZIP =
    1919
    20 ENABLE_OLD_ACTION_SELECTOR = 1
    21  No newline at end of file
     20ENABLE_OLD_ACTION_SELECTOR = 1
  • lib/jelix/plugins/tpl/html/function.link_to_remote.php

     
     1<?php
     2/**
     3* @package     Jelix
     4* @subpackage  jtpl_plugin
     5* @author      Julien Jacottet
     6* @contributor
     7* @copyright   2008 Julien Jacottet
     8* @link        http://www.jelix.org
     9* @licence     GNU Lesser General Public Licence see LICENCE file or http://www.gnu.org/licenses/lgpl.html
     10*/
     11
     12/**
     13 * function plugin :  Ajax request
     14 *
     15 * it creates a javascript ajax function
     16 * example :
     17 *
     18 * {link_to_remote
     19 *  'Link',    <!-- link label -->
     20 *  'result',    <!-- id dom for ajax result -->
     21 *  'test~default:ajax', array('id'=>'34'),    <!-- jurl request -->
     22 *  array(
     23 *    'position'=>'html',    <!-- html or append or prepend (default html) -->
     24 *    'method'=>'GET',    <!-- GET or POST (default POST) -->
     25 *    'beforeSend'=>'alert("beforeSend")',    <!-- JS script before send (default null) -->
     26 *    'complete'=>'alert("complete")',    <!-- JS script after send  (default null)-->
     27 *    'error'=>'alert("error")',    <!-- JS if error  (default null) -->
     28 * )}
     29 *
     30 * <div id="result"></div>
     31 */
     32
     33function jtpl_function_html_link_to_remote($tpl, $label, $element_id, $action_selector, $action_parameters, $option) {
     34
     35    global $gJCoord,$gJConfig;
     36        static $id_link_to_remote = 0;
     37
     38    // Add js link
     39    $gJCoord->response->addJSLink($gJConfig->urlengine['basePath'].'jelix/jquery/jquery.js');
     40
     41    //Initialise
     42    $id_link_to_remote++;
     43    $url = jUrl::get($action_selector, $action_parameters);
     44    $position = ((array_key_exists("position", $option)) ? $option['position'] : 'html' );
     45    $method = ((array_key_exists("method", $option)) ? $option['method'] : 'GET' );
     46    $beforeSend = ((array_key_exists("beforeSend", $option)) ? $option['beforeSend'] : '' );
     47    $complete = ((array_key_exists("complete", $option)) ? $option['complete'] : '' );
     48    $error = ((array_key_exists("error", $option)) ? $option['error'] : '' );
     49
     50    // Link
     51    echo "<a onclick='link_to_remote_".$id_link_to_remote."();'>".$label."</a>\n";
     52
     53    // Script
     54    echo "
     55    <script>
     56      function link_to_remote_".$id_link_to_remote."() {
     57        $.ajax({
     58          type: '".$method."',
     59          url: '".$url."',
     60          beforeSend: function(){".$beforeSend.";},
     61          complete: function(){".$complete.";},
     62          error: function(){".$error.";},
     63          success: function(msg){
     64            $('#".$element_id."').".$position."(msg);
     65          }
     66        });
     67      };   
     68    </script>";
     69}
     70?>