Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Cleaned up ajax responses js/css

  • Loading branch information...
commit 7daa59028c85ada73aee90bab707c53a66f961cc 1 parent 6fb4899
@deepwinter deepwinter authored
Showing with 44 additions and 27 deletions.
  1. +44 −27 modules/mopcore/classes/controller/ajax.php
View
71 modules/mopcore/classes/controller/ajax.php
@@ -35,7 +35,6 @@ public function action_data($uri)
);
$this->response->body(json_encode($ajaxResponse));
- // throw $e;
return;
}
$ajaxResponse = array(
@@ -45,42 +44,47 @@ public function action_data($uri)
$this->response->body(json_encode($ajaxResponse));
}
- public function action_html($subRequestUri)
+ public function action_html($uri)
{
- //request to child, just html and js html
- $subRequest = Request::Factory($subRequestUri);
- $html = $subRequest->execute()->body();
- $cssResources = ();
- foreach($this->resources['librarycss'] as $css){
- $cssResources[] = $css;
- }
- foreach($this->resources['css'] as $css){
- $cssResources[] = $css;
- }
+ try {
+ $subRequest = Request::Factory($uri);
+ $html = $subRequest->execute()->data();
+ } catch (Exception $e) {
+ //return HTML from exception
+ $message = $e->getMessage() . $e->getTrace();
+ $ajaxResponse = array(
+ 'returnValue' => FALSE,
+ 'response' => $message
- $jsResources = array();
- foreach($this->resources['libraryjs'] as $js){
- $jsResources[] = $js;
- }
- foreach($this->resources['js'] as $js){
- $jsResources[] = $js;
+ );
+ $this->response->body(json_encode($ajaxResponse));
+ return;
}
+ $html = $subRequest->execute()->body();
+ $cssResources = array();
+ array_push($cssResources, $this->resources['librarycss']);
+ array_push($cssResources, $this->resources['css']);
+
+ $jsResources = array();
+ array_push($jsResources, $this->resources['libraryjs']);
+ array_push($jsResources, $this->resources['js']);
$ajaxResponse = array(
'response'=>array(
- 'html'=>$html,
- 'js'=>$jsResources,
- 'css'=>$cssResources
- )
+ 'html'=>$html,
+ 'js'=>$jsResources,
+ 'css'=>$cssResources
+ ),
+ 'returnValue' => TRUE,
);
$this->response->body(json_encode($ajaxResponse));
}
public function action_compound($uri)
{
- try {
+ try {
$subRequest = Request::Factory($uri);
$requestResponse = $subRequest->execute();
} catch (Exception $e) {
@@ -94,10 +98,23 @@ public function action_compound($uri)
$this->response->body(json_encode($ajaxResponse));
return;
}
- $compoundResponse = array(
- 'data' => $requestResponse->data(),
- 'html' => $requestResponse->body()
- );
+
+
+ $cssResources = array();
+ array_push($cssResources, $this->resources['librarycss']);
+ array_push($cssResources, $this->resources['css']);
+
+ $jsResources = array();
+ array_push($jsResources, $this->resources['libraryjs']);
+ array_push($jsResources, $this->resources['js']);
+
+
+ $compoundResponse = array(
+ 'data' => $requestResponse->data(),
+ 'html' => $requestResponse->body(),
+ 'css' => $cssResources,
+ 'js' => $jsResources,
+ );
$ajaxResponse = array(
'returnValue' => TRUE,
'response'=>$compoundResponse
Please sign in to comment.
Something went wrong with that request. Please try again.