From b5c4ed7811678c840effecca17be1cce7931d0c4 Mon Sep 17 00:00:00 2001 From: Janusz Dobrowolski Date: Fri, 6 Jun 2008 22:23:44 +0000 Subject: [PATCH] Added setting focus and page body reload via ajax --- includes/ajax.inc | 29 +++++++++++++++++++++-------- includes/main.inc | 3 +++ 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/includes/ajax.inc b/includes/ajax.inc index ab57b30b..5625fc90 100644 --- a/includes/ajax.inc +++ b/includes/ajax.inc @@ -15,9 +15,9 @@ class Ajax extends JsHttpRequest { // 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,8 +25,8 @@ 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'),$url); + $this->run(); } } // @@ -70,6 +70,14 @@ 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) @@ -95,15 +103,20 @@ class Ajax extends JsHttpRequest { function run() { if (!$this->isActive()) return; -// $this->addScript(true, "setFocus('".$_POST['_focus']."');"); - + // remove not active commands foreach ($this->aCommands as $idx => $com) { + // display_error( $idx.':'.var_dump($com)); +// 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['n'] == 'up' && $com['t'] == '_page_body') { + $this->aCommands = array($com); + break; + } + else if ($com['why'] !== true && !isset($this->triggers[$com['why']])) unset($this->aCommands[$idx]); - } - $GLOBALS['_RESULT'] = $this->aCommands; // exit(); } diff --git a/includes/main.inc b/includes/main.inc index a4472e8e..2afb6e62 100644 --- a/includes/main.inc +++ b/includes/main.inc @@ -13,6 +13,7 @@ include_once($path_to_root . "/admin/db/users_db.inc"); include_once($path_to_root . "/includes/ui/ui_view.inc"); + include_once($path_to_root . "/includes/ui/ui_controls.inc"); function page($title, $no_menu=false, $is_index=false, $onload="", $js="") { @@ -25,6 +26,7 @@ page_header($title, $no_menu, $is_index, $onload, $js); error_box(); + div_start('_page_body'); // whole page content for ajax reloading } function end_page($no_menu=false, $is_index=false) @@ -33,6 +35,7 @@ $hide_menu = $no_menu; + div_end(); // _page_body section include($path_to_root . "/includes/page/footer.inc"); $Ajax->run(); -- 2.30.2