Added setting focus and page body reload via ajax
authorJanusz Dobrowolski <janusz@frontaccounting.eu>
Fri, 6 Jun 2008 22:23:44 +0000 (22:23 +0000)
committerJanusz Dobrowolski <janusz@frontaccounting.eu>
Fri, 6 Jun 2008 22:23:44 +0000 (22:23 +0000)
includes/ajax.inc
includes/main.inc

index ab57b30b8a36acee153e2f027f752dce56c629ab..5625fc900c3ba1c3bbda674de07d90f70cf26e30 100644 (file)
@@ -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();
        }
index a4472e8ecc40f806d0c5cb1797af0c8278892a92..2afb6e625cb2f62e2002aa67c5b976c8a5a4d39b 100644 (file)
@@ -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();