Two smaller bugs [0000023],[0000026]
[fa-stable.git] / includes / ajax.inc
index ab57b30b8a36acee153e2f027f752dce56c629ab..135ee03df2dc91cd46d75d79d63a0d22f91adee3 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,29 @@ 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) {
-                 if ($com['why'] !== true && !isset($this->triggers[$com['why']]))
+// 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]);
-
+//                     display_error('unset '.$com['t']);
+                 }
+                 else
+                 if($com['n'] == 'up' && $com['t'] == '_page_body') {
+                         $cmds = array($com);
+                         foreach( $this->aCommands as $k=> $cmd) {
+                               if ($cmd['n'] == 'fc') {        // save focus
+                                       $cmds[] = $cmd; break;
+                               }
+                         }
+                         $this->aCommands = $cmds;
+                         break;
+                 }
                }
-
+//             display_error('Activate:'.htmlentities(print_r($this->triggers, true)));
+//             display_error('Commands :'.htmlentities(print_r($this->aCommands, true)));
            $GLOBALS['_RESULT'] = $this->aCommands;
 //         exit();
        }