Bläddra i källkod

fixed Typespecial cell function to load typespecial info to cell tooltip

Piotr Labudda 9 år sedan
förälder
incheckning
1800c6a209
2 ändrade filer med 28 tillägg och 43 borttagningar
  1. 27 0
      SE/se-lib/Route/ViewTableAjax.php
  2. 1 43
      SE/se-lib/TableAjax.php

+ 27 - 0
SE/se-lib/Route/ViewTableAjax.php

@@ -308,6 +308,33 @@ class Route_ViewTableAjax extends RouteBase {
 		return $response;
 	}
 
+	public function typeSpecialCellAction() {
+		Response::sendTryCatchJson(array($this, 'typeSpecialCell'), $args = $_REQUEST);
+	}
+	public function typeSpecialCell($args) {
+		$namespace = V::get('namespace', '', $args, 'word');
+		if (!$namespace) throw new HttpException("Bad Request - missing namespace", 400);
+		$acl = Core_AclHelper::getAclByNamespace($namespace);
+		$id = V::get('ID', 0, $args, 'int');
+		$fieldName = V::get('col', '', $args);
+		if ($id <= 0 || empty($fieldName)) throw new HttpException("Bad Request - missing id or col", 400);
+
+		$col = $fieldName;// TODO: RM $col
+
+		$jsonData = new stdClass();
+		$idField = $acl->getFieldIdByName($fieldName);
+		if (!$idField) throw new Exception("Wrong field");
+
+		$item = $acl->getItem($id);
+		if (!$acl->canReadObjectField($fieldName, $item)) throw new Exception("Brak dostępu");
+
+		$typeSpecial = Typespecial::getInstance($idField, $fieldName);
+		if ($typeSpecial) {
+			$jsonData->data = $typeSpecial->getReturnData($acl->getID(), $id, $fieldName, '');
+		}
+		return $jsonData;
+	}
+
 	/**
 	 * @param $_GET['namespace'] = AclNamespace
 	 * @param $_GET['format'] = 'csv' | 'html'

+ 1 - 43
SE/se-lib/TableAjax.php

@@ -3044,7 +3044,7 @@ var p5UI_TableAjax_generateFunctionNode = function(funObj, rowPK, props) {
 
 			_popoverCellAjaxXhr = $.ajax({
 				type: 'GET',
-				url: 'index-ajax.php?_zasobID=<?php echo $this->_zasobID; ?>&_cls=<?php echo __CLASS__; ?>&_hash=<?php echo $this->_htmlID; ?>&_task=TYPESPECIALL_CELL&ID=' + id + '&col=' + col,
+				url: 'index.php?_route=ViewTableAjax&_task=typeSpecialCell&namespace=<?= $acl->getNamespace(); ?>' + '&ID=' + id + '&col=' + col,
 				dataType: 'json',
 				contentType: "application/json; charset=utf-8",
 				data: '',
@@ -4004,16 +4004,6 @@ function <?php echo $jsToogleFiltrProcesuFunctionName; ?>(n) {
 				}
 				break;
 			}
-			case 'TYPESPECIALL_CELL': {
-				$id = V::get('ID', 0, $_REQUEST, 'int');
-				$col = V::get('col', '', $_REQUEST);
-				if ($id > 0 && !empty($col)) {
-					$this->sendTypeSpecialCell($id, $col, $_REQUEST);
-				} else {
-					echo '404';
-				}
-				break;
-			}
 			case 'HIDDEN_COLS_SAVE': {
 				$this->sendAjaxResponseJson('ajaxHiddenColsSave', $_POST);
 				break;
@@ -5732,38 +5722,6 @@ jQuery(document).ready(function(){
 		exit;
 	}
 
-	private function sendTypeSpecialCell($id, $fldName, $args) {
-		$DBG = ('1' == V::get('DBG', '', $_REQUEST));
-
-		header("Content-type: application/json");
-		$jsonData = new stdClass();
-
-		$fldID = $this->_acl->getFieldIdByName($fldName);
-		if($DBG){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">fld('.$fldName.') (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($fldID);echo'</pre>';}
-
-		$item = $this->_acl->getItem($id);
-		if (!$this->_acl->canReadObjectField($fldName, $item)) {
-			$jsonData->msg = 'Brak dostępu';
-			echo json_encode($jsonData);
-			exit;
-		}
-
-		if (!$fldID) {
-			$jsonData->msg = 'Wrong field';
-			echo json_encode($jsonData);
-			exit;
-		}
-
-		$typeSpecial = Typespecial::getInstance($fldID, $fldName);
-		if ($typeSpecial) {
-			$jsonData->data = $typeSpecial->getReturnData($this->_zasobID, $id, $fldName, '');
-			if($DBG){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">specialValuesByIds('.$id.'/'.$fldName.') (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($specialValuesByIds);echo'</pre>';}
-		}
-
-		echo json_encode($jsonData);
-		exit;
-	}
-
 	public function ajaxData($args) {
 		$DBG = ('1' == V::get('DBG', '', $_REQUEST));
 		$acl = $this->_acl;