X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;f=includes%2Fajax.inc;h=a89b55876f83eb355257f2bed324b54ad1452959;hb=a67b9dfc9f6932d5fe64ae21758f86bdb9250df2;hp=ab57b30b8a36acee153e2f027f752dce56c629ab;hpb=1a19006ad043cc6e8462a5c9f9b583b25de268cf;p=fa-stable.git diff --git a/includes/ajax.inc b/includes/ajax.inc index ab57b30b..a89b5587 100644 --- a/includes/ajax.inc +++ b/includes/ajax.inc @@ -1,4 +1,14 @@ . +***********************************************************************/ require_once($path_to_root. "/includes/JsHttpRequest.php"); class Ajax extends JsHttpRequest { @@ -6,18 +16,18 @@ class Ajax extends JsHttpRequest { var $aCommands = array(); var $triggers = array(); - function Ajax() + function __construct() { - $this->JsHttpRequest($_SESSION['language']->encoding); + parent::__construct(@$_SESSION['language']->encoding); } // // This function is used in ctrl routines to activate // update of ajaxified html element selected by given name/id. // function activate($trigname) { -// if (in_ajax()) -// display_error('Activate '. $trigger); + if (in_ajax()) { $this->triggers[$trigname] = true; + } } // // Javascript clientside redirection. @@ -25,11 +35,17 @@ class Ajax extends JsHttpRequest { // function redirect($url) { if(in_ajax()) { - $this->_addCommand(true, array('n'=>'rd'),$url); - $this->run(); + $this->_addCommand(true, array('n'=>'rd'), absolute_url($url)); + $this->run(); } } // + // Popup window (target=_blank) + // + function popup($url) { + $this->_addCommand(true, array('n'=>'pu'), absolute_url($url)); + } + // // Adds an executable Javascript code. // function addScript($trigger, $sJS) @@ -70,42 +86,49 @@ class Ajax extends JsHttpRequest { return $this; } // + // Set current focus. + // + function addFocus($trigger, $sTarget) + { + $this->_addCommand($trigger, array('n'=>'fc'),$sTarget); + return $this; + } + // // Internal procedure adding command to response. // function _addCommand($trigger, $aAttributes, $mData) { - if ($this->isActive() && ($trigger !== false)) { -// display_error('adding '.$trigger.':'.htmlentities($mData)); + if ($this->isActive() && ($trigger !== false)) { - $aAttributes['why'] = $trigger; - $aAttributes['data'] = $mData; - $this->aCommands[] = $aAttributes; - } + $aAttributes['why'] = $trigger; + $aAttributes['data'] = $mData; + $this->aCommands[] = $aAttributes; + } } - /* - * Register binds function with ajax call parameter - - function register($trigger, $function) + + function run() { - if (isset($_REQUEST[$trigger])) { - $function(&$this); - } - } - */ - function run() { - if (!$this->isActive()) return; -// $this->addScript(true, "setFocus('".$_POST['_focus']."');"); - + // remove not active commands foreach ($this->aCommands as $idx => $com) { - if ($com['why'] !== true && !isset($this->triggers[$com['why']])) - unset($this->aCommands[$idx]); - +// If we should reload whole page content ignore all commands but the update. +// This is page repost equivalent, although header and footer are not reloaded. + if ($com['why'] !== true && !isset($this->triggers[$com['why']])) { + unset($this->aCommands[$idx]); + } + elseif($com['n'] == 'up' && $com['t'] == '_page_body') { + $cmds = array($com); + foreach( $this->aCommands as $k=> $cmd) { + if ($cmd['n'] == 'fc' || $cmd['n'] == 'js') { // save focus + $cmds[] = $cmd; //break; + } + } + $this->aCommands = $cmds; + break; + } } - $GLOBALS['_RESULT'] = $this->aCommands; -// exit(); } } @@ -114,4 +137,10 @@ function in_ajax() { return $Ajax->isActive(); } -?> +// Returns absolute path of relative $url. To be used in ajax calls +// for proper redirection from any referer page. +// +function absolute_url($url) +{ + return strpos($url, '..')===0 ? dirname($_SERVER['PHP_SELF']).'/'.$url : $url; +}