Selaa lähdekoodia

TableAjax fix json response

Piotr Labudda 11 vuotta sitten
vanhempi
commit
feb712f29b
1 muutettua tiedostoa jossa 19 lisäystä ja 21 poistoa
  1. 19 21
      SE/se-lib/TableAjax.php

+ 19 - 21
SE/se-lib/TableAjax.php

@@ -2728,11 +2728,11 @@ function hidePopover() {
 				break;
 				break;
 			}
 			}
 			case 'THE_GEOM_REMOVE': {
 			case 'THE_GEOM_REMOVE': {
-				$this->sendAjaxResponseJson('sendTheGeomRemove', $_REQUEST);
+				$this->sendAjaxResponseJson('ajaxTheGeomRemove', $_REQUEST);
 				break;
 				break;
 			}
 			}
 			default:
 			default:
-				$this->sendAjaxData($_REQUEST);
+				$this->sendAjaxResponseJson('ajaxData', $_REQUEST);
 		}
 		}
 	}
 	}
 
 
@@ -4444,13 +4444,9 @@ jQuery(document).ready(function(){
 		exit;
 		exit;
 	}
 	}
 
 
-	private function sendAjaxData($args) {
+	private function ajaxData($args) {
 		$DBG = ('1' == V::get('DBG', '', $_REQUEST));
 		$DBG = ('1' == V::get('DBG', '', $_REQUEST));
 
 
-		header("Content-type: application/json");
-
-		//sleep(1);// TODO: TEST
-
 		$pageSize = V::get('pageSize', 10, $args, 'int');
 		$pageSize = V::get('pageSize', 10, $args, 'int');
 		$page = V::get('page', 0, $args, 'int');
 		$page = V::get('page', 0, $args, 'int');
 		$currSortCol = V::get('currSortCol', '', $args);
 		$currSortCol = V::get('currSortCol', '', $args);
@@ -4532,38 +4528,38 @@ jQuery(document).ready(function(){
 		$ind = 0;
 		$ind = 0;
 		foreach ($visibleCols as $fieldID => $col) {
 		foreach ($visibleCols as $fieldID => $col) {
 			$ind++;
 			$ind++;
-			$jsonData->cols->{$col} = (object)array('index'=>$ind);
+			$columnConfig = (object)array('index'=>$ind);
 			if ($col == 'ID') {
 			if ($col == 'ID') {
 				// /SE/se-dev/index.php?MENU_INIT=USERS2_MARKETING_EDIT&ARG1=EDIT&ARG1_VAL=31105
 				// /SE/se-dev/index.php?MENU_INIT=USERS2_MARKETING_EDIT&ARG1=EDIT&ARG1_VAL=31105
-				$jsonData->cols->{$col}->format = '<a href="#EDIT/{0}">{0}</a>';
-				$jsonData->cols->{$col}->unique = true;
+				$columnConfig->format = '<a href="#EDIT/{0}">{0}</a>';
+				$columnConfig->unique = true;
 			}
 			}
 			else if (in_array($col, array('A_STATUS','A_STATUS_CURRENT','A_SERVICES_STATUS_CURRENT'))) {
 			else if (in_array($col, array('A_STATUS','A_STATUS_CURRENT','A_SERVICES_STATUS_CURRENT'))) {
-				$jsonData->cols->{$col}->format = '<div class="cell-A_STATUS-{0}">{0}</div>';
+				$columnConfig->format = '<div class="cell-A_STATUS-{0}">{0}</div>';
 			}
 			}
 			else if (in_array($col, array('Status'))) {
 			else if (in_array($col, array('Status'))) {
 				// Ahmes problems Status colors
 				// Ahmes problems Status colors
-				$jsonData->cols->{$col}->format = '<div class="cell-Status-{0}">{0}</div>';
+				$columnConfig->format = '<div class="cell-Status-{0}">{0}</div>';
 			}
 			}
 			else if ($this->_dataSource->isGeomField($col)) {
 			else if ($this->_dataSource->isGeomField($col)) {
-				$jsonData->cols->{$col}->type = 'geom';
+				$columnConfig->type = 'geom';
 			}
 			}
 			if ('' !== ($label = $this->_acl->getFieldLabel($fieldID))) {
 			if ('' !== ($label = $this->_acl->getFieldLabel($fieldID))) {
-				$jsonData->cols->{$col}->friendly = $label;
+				$columnConfig->friendly = $label;
 			}
 			}
 			$colType = $this->_acl->getFieldType($col);
 			$colType = $this->_acl->getFieldType($col);
 			if ($colType) {// @see MarkTableAjaxFilterColType
 			if ($colType) {// @see MarkTableAjaxFilterColType
 				if ($colType['type'] == 'date') {
 				if ($colType['type'] == 'date') {
-					//$jsonData->cols->{$col}->type = 'date';// TODO: require datepicker
+					//$columnConfig->type = 'date';// TODO: require datepicker
 				}
 				}
 			} else {// typespecial - no type
 			} else {// typespecial - no type
-				$jsonData->cols->{$col}->type = 'special';
+				$columnConfig->type = 'special';
 			}
 			}
 
 
 			$typeSpecial = Typespecial::getInstance($fieldID, $col);
 			$typeSpecial = Typespecial::getInstance($fieldID, $col);
 			if ($typeSpecial) {
 			if ($typeSpecial) {
 				if($DBG){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">typeSpecial (F.' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($typeSpecial);echo'</pre>';}
 				if($DBG){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">typeSpecial (F.' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($typeSpecial);echo'</pre>';}
-				$jsonData->cols->{$col}->_tsRetId = $typeSpecial->getReturnId();
+				$columnConfig->_tsRetId = $typeSpecial->getReturnId();
 			}
 			}
 
 
 			// @see sendHiddenColsSave
 			// @see sendHiddenColsSave
@@ -4571,10 +4567,12 @@ jQuery(document).ready(function(){
 			if (isset($_SESSION['USER_PROFILE'][$this->_zasobID])) {
 			if (isset($_SESSION['USER_PROFILE'][$this->_zasobID])) {
 				if (isset($_SESSION['USER_PROFILE'][$this->_zasobID][$fieldID])) {
 				if (isset($_SESSION['USER_PROFILE'][$this->_zasobID][$fieldID])) {
 					if ($_SESSION['USER_PROFILE'][$this->_zasobID][$fieldID] != 1) {
 					if ($_SESSION['USER_PROFILE'][$this->_zasobID][$fieldID] != 1) {
-						$jsonData->cols->{$col}->hidden = true;
+						$columnConfig->hidden = true;
 					}
 					}
 				}
 				}
 			}
 			}
+
+			$jsonData->cols->{$col} = $columnConfig;
 		}
 		}
 		$jsonData->rows = array();
 		$jsonData->rows = array();
 		foreach ($items as $vItem) {
 		foreach ($items as $vItem) {
@@ -4595,8 +4593,7 @@ jQuery(document).ready(function(){
 		}
 		}
 //echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">this->_dataSource (F.' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($this->_dataSource);echo'</pre>';
 //echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">this->_dataSource (F.' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($this->_dataSource);echo'</pre>';
 //echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">jsonData (F.' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($jsonData);echo'</pre>';
 //echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">jsonData (F.' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($jsonData);echo'</pre>';
-		echo json_encode($jsonData);
-		exit;
+		return $jsonData;
 	}
 	}
 
 
 	private function fixEmptyValueFromUser($fieldID) {// TODO: moved to TableAcl->fixEmptyValueFromUser
 	private function fixEmptyValueFromUser($fieldID) {// TODO: moved to TableAcl->fixEmptyValueFromUser
@@ -4727,7 +4724,7 @@ jQuery(document).ready(function(){
 
 
 	private function sendAjaxResponseJson($method, $args) {
 	private function sendAjaxResponseJson($method, $args) {
 		try {
 		try {
-			$response = $this->ajaxTheGeomRemove($args);
+			$response = $this->{$method}($args);
 		}
 		}
 		catch (Exception $e) {
 		catch (Exception $e) {
 			$response = new stdClass();
 			$response = new stdClass();
@@ -4742,6 +4739,7 @@ jQuery(document).ready(function(){
 			case 4033: header('HTTP/1.0 403.3 - Write access forbidden'); break;
 			case 4033: header('HTTP/1.0 403.3 - Write access forbidden'); break;
 			default:
 			default:
 		}
 		}
+		header('Content-type: application/json');
 		echo json_encode($response);
 		echo json_encode($response);
 		exit;
 		exit;
 	}
 	}