Quellcode durchsuchen

TableAjax fix json response for save hidden cols

Piotr Labudda vor 11 Jahren
Ursprung
Commit
8e1985aa50
1 geänderte Dateien mit 31 neuen und 19 gelöschten Zeilen
  1. 31 19
      SE/se-lib/TableAjax.php

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

@@ -1901,17 +1901,21 @@ class TableAjax extends ViewAjax {
 			});
 
 			$.ajax({
-				url: 'index-ajax.php?_zasobID=<?php echo $this->_zasobID; ?>&_cls=<?php echo __CLASS__; ?>&_hash=<?php echo $this->_htmlID; ?>&_task=HIDDEN_COLS_SAVE',
-				type: 'POST',
-				dataType: 'text',
 				data: reqData,
-				async: true,
-				success: function (data) {
-					//console.log('hidden cols saved');
-				},
-				error: function (err) {
-					console.log('request error: {0}'.f(JSON.stringify(err)));
+				type: "POST",
+				dataType: 'json',
+				// async: true,
+				url: 'index-ajax.php?_zasobID=<?php echo $this->_zasobID; ?>&_cls=<?php echo __CLASS__; ?>&_hash=<?php echo $this->_htmlID; ?>&_task=HIDDEN_COLS_SAVE'
+			})
+			.done(function(data, textStatus, jqXHR){
+				if (data && data.type && data.type == 'info') {
+					jQuery.notify('Nie wprowadzono żadnych zmian', 'info');
+				} else {
+					jQuery.notify('Zapisano ustawienia', 'success');
 				}
+			})
+			.fail(function(){
+				jQuery.notify('Wystąpił błąd podczas zapisywania ustawień', 'error');
 			});
 		};
 
@@ -2751,11 +2755,11 @@ function hidePopover() {
 				break;
 			}
 			case 'HIDDEN_COLS_SAVE': {
-				$this->sendHiddenColsSave($_REQUEST);
+				$this->sendAjaxResponseJson('ajaxHiddenColsSave', $_POST);
 				break;
 			}
 			case 'THE_GEOM_SAVE': {
-				$this->sendAjaxResponseJson('sendTheGeomSave', $_REQUEST);
+				$this->sendAjaxResponseJson('ajaxTheGeomSave', $_REQUEST);
 				break;
 			}
 			case 'THE_GEOM_REMOVE': {
@@ -4600,7 +4604,7 @@ jQuery(document).ready(function(){
 				$columnConfig->_tsRetId = $typeSpecial->getReturnId();
 			}
 
-			// @see sendHiddenColsSave
+			// @see ajaxHiddenColsSave
 			// $_SESSION['USER_PROFILE'][$this->_zasobID][fld_id] => boolean
 			if (isset($_SESSION['USER_PROFILE'][$this->_zasobID])) {
 				if (isset($_SESSION['USER_PROFILE'][$this->_zasobID][$fieldID])) {
@@ -4667,9 +4671,13 @@ jQuery(document).ready(function(){
 	 * set hidden cols in $_SESSION['USER_PROFILE'][$this->_zasobID];
 	 *   $_SESSION['USER_PROFILE'][$this->_zasobID][fld_id] => boolean
 	 */
-	private function sendHiddenColsSave($args) {
-		if (empty($_POST)) {
-			exit;
+	private function ajaxHiddenColsSave($args) {
+			throw new HttpException("Wrong param ID", 404);
+		$response = new stdClass();
+
+		if (empty($args)) {
+			$response->type = 'info';
+			return $response;
 		}
 
 		Lib::loadClass('UserProfile');
@@ -4688,10 +4696,10 @@ jQuery(document).ready(function(){
 		$fields = $this->_acl->getFields();
 		foreach ($fields as $kFldId => $vFld) {
 			$vFldName = $vFld['name'];
-			if (isset($_POST[$vFldName])) {
-				if ($_POST[$vFldName] == 'SHOW') {
+			if (isset($args[$vFldName])) {
+				if ($args[$vFldName] == 'SHOW') {
 					$colVis[$kFldId] = 1;
-				} else if ($_POST[$vFldName] == 'HIDE') {
+				} else if ($args[$vFldName] == 'HIDE') {
 					$colVis[$kFldId] = 0;
 				}
 			}
@@ -4700,9 +4708,12 @@ jQuery(document).ready(function(){
 		$_SESSION['USER_PROFILE'][$this->_zasobID] = $colVis;
 
 		UserProfile::save();
+
+		$response->type = 'success';
+		return $response;
 	}
 
-	private function sendTheGeomSave($args) {
+	private function ajaxTheGeomSave($args) {
 		$id = V::get('ID', 0, $args, 'int');
 		$polygon = V::get('polygon', 0, $args);
 		$geomFieldName = 'the_geom';
@@ -4763,6 +4774,7 @@ jQuery(document).ready(function(){
 		}
 
 		header('Content-type: application/json');
+		if (!$response) $response = new stdClass();
 		echo json_encode($response);
 		exit;
 	}