Example #1
0
 private function startProcessAjax()
 {
     header('Cache-Control: no-cache');
     header('Pragma: no-cache');
     header('Expires: -1');
     $this->_rootComponent->resetDoLater();
     $this->_rootComponent->init();
     $this->_rootComponent->execDoLater();
     $evt = array('type' => GLZ_EVT_START_PROCESS);
     $this->dispatchEvent($evt);
     $ajaxTarget = org_glizy_Request::get('ajaxTarget');
     $targetComponent =& $this->_rootComponent->getComponentById($ajaxTarget);
     if (is_null($targetComponent)) {
         // prima prova a creare i figli in modo ritardato
         // questo è usato nella gestione degli stati
         $this->_rootComponent->deferredChildCreation(true);
         $targetComponent =& $this->_rootComponent->getComponentById($ajaxTarget);
         // se il targetComponent è ancora nullo
         // prova a lanciare il process di tutti i figli
         if (is_null($targetComponent)) {
             $this->_rootComponent->process();
             $targetComponent =& $this->_rootComponent->getComponentById($ajaxTarget);
             if (is_null($targetComponent)) {
                 return false;
             }
         }
     }
     $ajaxMethod = __Request::get('ajaxMethod', 'process_ajax');
     if (method_exists($targetComponent, $ajaxMethod)) {
         org_glizy_Request::remove('pageId');
         org_glizy_Request::remove('ajaxTarget');
         $result = $targetComponent->{$ajaxMethod}();
     } else {
         $result = $this->processAjaxCallController($targetComponent);
     }
     if (!$targetComponent->controllerDirectOutput() && !is_array($result) && !is_object($result)) {
         $result = array('status' => $result === true ? 'success' : 'error');
     }
     if (is_array($result) && isset($result['html'])) {
         header("Content-Type: " . $this->contentType . "; charset=" . __Config::get('CHARSET'));
         echo $result['html'];
     } else {
         header("Content-Type: application/json; charset=utf-8");
         echo json_encode($result);
     }
     return true;
 }