00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 class AjaxView extends PageViewBase {
00012
00013
00014
00015 public function __construct($page_data) {
00016 parent::__construct($page_data, '');
00017 }
00018
00019
00020
00021
00022
00023
00024
00025
00026 protected function render_content(&$rendered_content, $policy) {
00027 $data = array();
00028 $is_error = true;
00029 switch ($this->page_data->status_code) {
00030 case ControllerBase::ACCESS_DENIED:
00031 $data['error'] = tr('Access denied', 'core');
00032 break;
00033 case ControllerBase::NOT_FOUND:
00034 $data['error'] = tr('Page not found', 'core');
00035 break;
00036 case ControllerBase::INTERNAL_ERROR:
00037 $data['error'] = tr('Server error', 'core');
00038 break;
00039 default:
00040 if ($this->page_data->status instanceof Status && $this->page_data->status->is_error()) {
00041 $is_error = true;
00042 $data['error'] = $this->page_data->status->to_string(Status::OUTPUT_PLAIN);
00043 }
00044 else {
00045 $is_error = false;
00046 $data['result'] = $this->page_data->ajax_data;
00047 }
00048 break;
00049 }
00050 $data['is_error'] = $is_error;
00051 $rendered_content = ConverterFactory::encode($data, CONVERTER_JSON);
00052 }
00053
00054 protected function after_render(&$rendered_content, $policy) {
00055
00056 }
00057
00058
00059
00060
00061
00062
00063 protected function assign_default_vars($policy) {
00064
00065 }
00066
00067
00068
00069
00070
00071
00072 protected function should_cache() {
00073 return false;
00074 }
00075
00076
00077
00078
00079
00080
00081
00082
00083 protected function render_postprocess(&$rendered_content, $policy) {
00084 $this->send_status();
00085
00086 if (!Common::flag_is_set($policy, self::CONTENT_ONLY)) {
00087 header('Cache-Control: maxage=3600');
00088 header('Pragma: public');
00089
00090 header('Content-Type: application/json');
00091 }
00092 }
00093 }
00094 ?>