Procházet zdrojové kódy

Merge branch 'master' of biuro.biall-net.pl:plabudda/se

# By Piotr Labudda
# Via Piotr Labudda
* 'master' of biuro.biall-net.pl:plabudda/se:
  added row functions after edit in TableAjax
a.binder před 9 roky
rodič
revize
75c887193e
1 změnil soubory, kde provedl 118 přidání a 95 odebrání
  1. 118 95
      SE/se-lib/TableAjax.php

+ 118 - 95
SE/se-lib/TableAjax.php

@@ -419,6 +419,34 @@ class TableAjax extends ViewAjax {
 		</div>
 		<script>
 
+var p5UI_TableAjax_generateFunctionNode = function(funObj, rowPK, props) {
+	var defaultsProps = {
+				ico: true,
+				label: false
+			},
+			props = $.extend({}, defaultsProps, props);
+			funcNode = $('<a href="#" style="margin:0 2px;"></a>')
+	;
+	if ('href' in funObj) funcNode.attr('href', funObj.href.f(rowPK));
+	if (props.ico) {
+		if ('ico' in funObj) funcNode.append('<span class="' + funObj.ico + '"></span>');
+	}
+	if ('onclick' in funObj) funcNode.attr('onclick', funObj.onclick.f(rowPK));
+	if ('title' in funObj) funcNode.attr('title', funObj.title);
+	if ('target' in funObj) funcNode.attr('target', funObj.target);
+
+	if (props.label) {
+		if ('label' in funObj) {
+			funcNode.append(' ' + funObj.label);
+		} else if ('title' in funObj) {
+			funcNode.append(' ' + funObj.title);
+		}
+	}
+
+	return funcNode;
+};
+
+
 (function($) {
 	var TableAjaxGeomField = function() {
 		var priv = {}; //private api
@@ -1147,7 +1175,7 @@ class TableAjax extends ViewAjax {
 			moreFunctions = keys.splice(3);
 			keys.forEach(function(key) {
 				var funObj = rowFunctions[key],
-						funcNode = priv.generateFunctionNode(funObj, rowPK, {ico: true, label: false})
+						funcNode = p5UI_TableAjax_generateFunctionNode(funObj, rowPK, {ico: true, label: false})
 				;
 				funcNode.appendTo(cellNode);
 			});
@@ -1185,7 +1213,7 @@ class TableAjax extends ViewAjax {
 					moreFunctions.forEach(function(funcName) {
 						var funcItemNode = $('<li></li>').appendTo(funcListNode),
 								funObj = rowFunctions[funcName],
-								funcNode = priv.generateFunctionNode(funObj, rowPK, {ico: true, label: true})
+								funcNode = p5UI_TableAjax_generateFunctionNode(funObj, rowPK, {ico: true, label: true})
 						;
 						funcNode.addClass('func_name-' + funcName);
 						funcItemNode.append(funcNode);
@@ -1237,33 +1265,6 @@ class TableAjax extends ViewAjax {
 			return;
 		};
 
-		priv.generateFunctionNode = function(funObj, rowPK, props) {
-			var defaultsProps = {
-						ico: true,
-						label: false
-					},
-					props = $.extend({}, defaultsProps, props);
-					funcNode = $('<a href="#" style="margin:0 2px;"></a>')
-			;
-			if ('href' in funObj) funcNode.attr('href', funObj.href.f(rowPK));
-			if (props.ico) {
-				if ('ico' in funObj) funcNode.append('<span class="' + funObj.ico + '"></span>');
-			}
-			if ('onclick' in funObj) funcNode.attr('onclick', funObj.onclick.f(rowPK));
-			if ('title' in funObj) funcNode.attr('title', funObj.title);
-			if ('target' in funObj) funcNode.attr('target', funObj.target);
-
-			if (props.label) {
-				if ('label' in funObj) {
-					funcNode.append(' ' + funObj.label);
-				} else if ('title' in funObj) {
-					funcNode.append(' ' + funObj.title);
-				}
-			}
-
-			return funcNode;
-		};
-
 		priv.ajaxLoadMoreFunctionsCell = function(rowPK) {
 			var dbg = priv.options.debug;
 			if (_popoverCellAjaxXhr) {
@@ -1289,7 +1290,7 @@ class TableAjax extends ViewAjax {
 					if (rowFunctions.length > 0) {
 						var popoverCellContent = $('<ul class="list-unstyled"></ul>');
 						rowFunctions.forEach(function(funObj) {
-							var funcNode = priv.generateFunctionNode(funObj, rowPK, {ico: true, label: true});
+							var funcNode = p5UI_TableAjax_generateFunctionNode(funObj, rowPK, {ico: true, label: true});
 							if (funObj.id) {
 								funcNodesToUpdate.push({id: funObj.id, node: funcNode});
 							} else {
@@ -4079,24 +4080,17 @@ function <?php echo $jsToogleFiltrProcesuFunctionName; ?>(n) {
 		$primaryKeyField = $this->_acl->getPrimaryKeyField();
 		$primaryKey = V::get($primaryKeyField, 0, $args, 'int');
 		$fieldName = V::get('col', '', $_REQUEST);
-		if (empty($primaryKey) || empty($fieldName)) {
-			throw new HttpException("Wrong param id or col!", 400);
-		}
+		if (empty($primaryKey)) throw new HttpException("Wrong param id!", 400);
+		if (empty($fieldName)) throw new HttpException("Wrong param col!", 400);
 
 		$fieldID = $this->_acl->getFieldIdByName($fieldName);
-		if (!$fieldID) {
-			throw new HttpException("Field not exists!", 404);
-		}
+		if (!$fieldID) throw new HttpException("Field not exists!", 404);
 
 		$item = $this->_acl->getItem($primaryKey);
-		if (!$item) {
-			throw new HttpException("Item not exists!", 404);
-		}
+		if (!$item) throw new HttpException("Item not exists!", 404);
 
 		$itemFromUser = $this->_acl->convertObjectFromUserInput($args, $type = 'array_by_id', $prefix = 'f');
-		if (!isset($itemFromUser[$fieldName])) {
-			throw new HttpException("Field not set!", 400);
-		}
+		if (!isset($itemFromUser[$fieldName])) throw new HttpException("Field not set!", 400);
 
 		$itemPatch = array();
 		$itemPatch[$fieldName] = V::get($fieldName, null, $itemFromUser);
@@ -4283,17 +4277,41 @@ jQuery(document).ready(function(){
 			url: 'index-ajax.php?_zasobID=<?php echo $this->_zasobID; ?>&_cls=<?php echo __CLASS__; ?>&_hash=<?php echo $this->_htmlID; ?>&_task=EDIT_SAVE&ID=<?php echo $record->ID; ?>',
 		})
 		.done(function(data, textStatus, jqXHR){
-				var outMsg = notifyAjaxCallback(data);
-				alertCntWrap.removeClass('AjaxTable-loading');
-				//console.log('request finished L.<?php echo __LINE__; ?>');
-				alertCnt.empty();
-				var out = '';
-				out += outMsg;
-				out += '<div class="breadcrumb">' +
-						' <a href="#" onclick="return tableAjaxBackToTable();" class="btn btn-link btn-sm"> <i class="glyphicon glyphicon-arrow-left"></i> Wróć do tabeli <?php echo $this->getLabelHtml(); ?></a>' +
-						' <a href="#EDIT/<?php echo $id; ?>/' + Math.random(1).toString().substr(2) + '" class="btn btn-link btn-sm"> <i class="glyphicon glyphicon-pencil"></i> Edytuj rekord <?php echo $id; ?></a>' +
-					'</div>';
-				jQuery(out).appendTo(alertCnt);
+			var outMsg = notifyAjaxCallback(data);
+			alertCntWrap.removeClass('AjaxTable-loading');
+			//console.log('request finished L.<?php echo __LINE__; ?>');
+			alertCnt.empty();
+			var out = '';
+			out += outMsg;
+			out += '<div class="breadcrumb">' +
+					' <a href="#" onclick="return tableAjaxBackToTable();" class="btn btn-link btn-sm"> <i class="glyphicon glyphicon-arrow-left"></i> Wróć do tabeli <?php echo $this->getLabelHtml(); ?></a>' +
+					' <a href="#EDIT/<?php echo $id; ?>/' + Math.random(1).toString().substr(2) + '" class="btn btn-link btn-sm"> <i class="glyphicon glyphicon-pencil"></i> Edytuj rekord <?php echo $id; ?></a>' +
+				'</div>';
+			jQuery(out).appendTo(alertCnt);
+
+			// add rowFunctions from response
+			if (data && data.rowFunctions && data.primaryKey) {
+				// cellNode = priv.renderCellRowFunctions(data.rowFunctions, data.primaryKey);
+				var rowFunWrapNode = $('<div class="container"></div>').insertAfter(alertCnt);
+				var rowFunListNode = $('<ul></ul>').appendTo(rowFunWrapNode);
+				var rowPK = '<?php echo $id; ?>';
+				var keys = Object.keys(data.rowFunctions),
+						total = keys.length,
+						moreFuncBtnNode,
+						moreFunctions = [],
+						idx
+				;
+				// if (priv.options.debug) console.log('TableAjax::renderCellRowFunctions: rowFunctions', data.rowFunctions);
+				moreFunctions = keys.splice(3);
+				keys.forEach(function(key) {
+					var cellNode = $('<li></li>');
+					var funObj = data.rowFunctions[key],
+							funcNode = p5UI_TableAjax_generateFunctionNode(funObj, rowPK, {ico: true, label: true})
+					;
+					funcNode.appendTo(cellNode);
+					cellNode.appendTo(rowFunListNode);
+				});
+			}
 		})
 		.fail(function(jqXHR){// jqXHR.fail(function( jqXHR, textStatus, errorThrown ) {});
 			if (jqXHR.responseJSON) {
@@ -4357,23 +4375,21 @@ jQuery(document).ready(function(){
 	}
 
 	private function ajaxEditSave($args) {
-		$primaryKeyField = $this->_acl->getPrimaryKeyField();
+		$acl = $this->_acl;
+		$primaryKeyField = $acl->getPrimaryKeyField();
 		$primaryKey = V::get($primaryKeyField, 0, $args, 'int');
-		if (empty($primaryKey)) {
-			throw new HttpException("Wrong param id!", 400);
-		}
+		if (empty($primaryKey)) throw new HttpException("Wrong param id!", 400);
 
-		$item = $this->_acl->getItem($primaryKey);
-		if (!$item) {
-			throw new HttpException("Item not exists!", 404);
-		}
+		$item = $acl->getItem($primaryKey);
+		if (!$item) throw new HttpException("Item not exists!", 404);
 
-		$itemFromUser = $this->_acl->convertObjectFromUserInput($args, $type = 'array_by_id', $prefix = 'f');
+		$itemFromUser = $acl->convertObjectFromUserInput($args, $type = 'array_by_id', $prefix = 'f');
 
 		$response = new stdClass();
+		$response->primaryKey = $primaryKey;
 		try {
 			$itemFromUser[$primaryKeyField] = $primaryKey;
-			$affected = $this->_acl->updateItem($itemFromUser);
+			$affected = $acl->updateItem($itemFromUser);
 
 			if ($affected > 0) {
 				$response->type = 'success';
@@ -4382,13 +4398,17 @@ jQuery(document).ready(function(){
 				$response->type = 'info';
 				$response->msg = "Nie wprowadzono żadnych zmian";
 			}
-			$response->record = $this->_acl->getItem($primaryKey);
+			$response->record = $acl->getItem($primaryKey);
 		}
 		catch (Exception $e) {
 			$response->type = 'error';
 			$response->msg = "Wystąpiły błędy!";
 			$response->msg .= $e->getMessage();
 		}
+
+		$rowFunList = $this->getMoreFunctionsCell(array('primary_key'=>$primaryKey, 'record'=>$response->record));
+		if (!empty($rowFunList)) $response->rowFunctions = $rowFunList;
+
 		return $response;
 	}
 
@@ -6183,15 +6203,15 @@ jQuery(document).ready(function(){
 		return $response;
 	}
 
-	function ajaxMoreFunctionsCell($args) {// ajax task 'MORE_FUNCTIONS_CELL'
-		$id = V::get('ID', 0, $args, 'int');
+	public function getMoreFunctionsCell($args) {
+		$id = V::get('primary_key', 0, $args, 'int');
 		if ($id <= 0) throw new HttpException("404", 404);
+		$record = V::get('record', null, $args);
 
-		$response = new stdClass();
-		$response->type = 'success';
-		$response->msg = 'Funkcje';
-		$response->rowFunctions = [];
-		$tableName = $this->_acl->getName();
+		$rowFunList = array();
+		$acl = $this->_acl;
+		$tableName = $acl->getName();
+		$record = ($record)? $record : $acl->getItem($id);
 
 		if(1){// TODO: fetch $totalMsgs from TableMsgs
 			$msgs = Router::getRoute('Msgs');
@@ -6203,18 +6223,16 @@ jQuery(document).ready(function(){
 			$rowFunc->href = 'index.php?_route=TableMsgs&_task=tableRow&idTable=' . $this->_zasobID . '&idRow=' . $id;
 			$rowFunc->title = "Wiadomości ({$totalMsgs})";
 			$rowFunc->label = "Wiadomości <span class=\"badge\">{$totalMsgs}</span>";
-			$response->rowFunctions[] = $rowFunc;
+			$rowFunList[] = $rowFunc;
 		}
 
-		if ('CRM_PROCES' == $this->_acl->getName()) {// TODO: mv to table gui xml or php class
-			$record = $this->_acl->getItem($id);
-
+		if ('CRM_PROCES' == $acl->getName()) {// TODO: mv to table gui xml or php class
 			// procesy5.php?task=CRM_LISTA_ZASOBOW&filtr_id=22001
 			$rowFunc = new stdClass();
 			$rowFunc->ico = 'glyphicon glyphicon-eye-open';
 			$rowFunc->href = "procesy5.php?task=CRM_PROCES&filtr_id={$id}";
 			$rowFunc->title = "Zobacz na drzewie procesów {{$id}}";
-			$response->rowFunctions[] = $rowFunc;
+			$rowFunList[] = $rowFunc;
 
 			$wskazniki = ProcesHelper::get_wskazniki($id);
 			$connectedZasobyTotal = count($wskazniki);
@@ -6222,32 +6240,30 @@ jQuery(document).ready(function(){
 			$rowFunc->ico = 'glyphicon glyphicon-random';
 			$rowFunc->href = "index.php?MENU_INIT=PROCES_ADD_ZASOB&procesID={$id}";
 			$rowFunc->title = "Powiązane zasoby <span class=\"badge\">{$connectedZasobyTotal}</span>";
-			$response->rowFunctions[] = $rowFunc;
+			$rowFunList[] = $rowFunc;
 		}
 
-		if ('CRM_LISTA_ZASOBOW' == $this->_acl->getName()) {// TODO: mv to table gui xml or php class
-			$record = $this->_acl->getItem($id);
-
+		if ('CRM_LISTA_ZASOBOW' == $acl->getName()) {// TODO: mv to table gui xml or php class
 			// procesy5.php?task=CRM_LISTA_ZASOBOW&filtr_id=22001
 			$rowFunc = new stdClass();
 			$rowFunc->ico = 'glyphicon glyphicon-eye-open';
 			$rowFunc->href = "procesy5.php?task=CRM_LISTA_ZASOBOW&filtr_id={$id}";
 			$rowFunc->title = "Zobacz na drzewie zasobów [{$id}]";
-			$response->rowFunctions[] = $rowFunc;
+			$rowFunList[] = $rowFunc;
 
 			// index.php?MENU_INIT=ZASOB_OBOWIAZKI&id_zasob=22001
 			$rowFunc = new stdClass();
 			$rowFunc->ico = 'glyphicon glyphicon-random';
 			$rowFunc->href = "index.php?MENU_INIT=ZASOB_OBOWIAZKI&id_zasob={$id}";
 			$rowFunc->title = "Powiązane procesy (OB)";
-			$response->rowFunctions[] = $rowFunc;
+			$rowFunList[] = $rowFunc;
 
 			// index.php?MENU_INIT=ZASOB_EXTERNAL_IDS&id_zasob=22001
 			$rowFunc = new stdClass();
 			$rowFunc->ico = 'glyphicon glyphicon-random';
 			$rowFunc->href = "index.php?MENU_INIT=ZASOB_EXTERNAL_IDS&id_zasob={$id}";
 			$rowFunc->title = "Powiązane dane (IDS)";
-			$response->rowFunctions[] = $rowFunc;
+			$rowFunList[] = $rowFunc;
 
 			$groupTypeList = array();
 			$groupTypeList[] = 'STANOWISKO';
@@ -6258,17 +6274,16 @@ jQuery(document).ready(function(){
 				$rowFunc->ico = 'glyphicon glyphicon-retweet';
 				$rowFunc->href = "index.php?_route=Users&_task=syncGroup&idGroup={$id}";
 				$rowFunc->title = "Synchronizuj do LDAP";
-				$response->rowFunctions[] = $rowFunc;
+				$rowFunList[] = $rowFunc;
 			}
 		}
 
-		if ('ADMIN_USERS' == $this->_acl->getName()) {// TODO: mv to table gui xml
-			$record = $this->_acl->getItem($id);
+		if ('ADMIN_USERS' == $acl->getName()) {// TODO: mv to table gui xml
 			$isAllowedoReadUserLogin = false;
-			if ($this->_acl->canReadRecord($record)) {
-				$idFieldUserLogin = $this->_acl->getFieldIdByName('ADM_ACCOUNT');
+			if ($acl->canReadRecord($record)) {
+				$idFieldUserLogin = $acl->getFieldIdByName('ADM_ACCOUNT');
 				if ($idFieldUserLogin) {
-					if ($this->_acl->isAllowed($idFieldUserLogin, 'R', $record)) {
+					if ($acl->isAllowed($idFieldUserLogin, 'R', $record)) {
 						$isAllowedoReadUserLogin = true;
 					}
 				}
@@ -6278,23 +6293,22 @@ jQuery(document).ready(function(){
 				$rowFunc->ico = 'glyphicon glyphicon-user';
 				$rowFunc->href = 'index.php?_route=Users&_task=userGroups&usrLogin=' . $record->ADM_ACCOUNT;
 				$rowFunc->title = "Ustal stanowisko";
-				$response->rowFunctions[] = $rowFunc;
+				$rowFunList[] = $rowFunc;
 
 				$rowFunc = new stdClass();
 				$rowFunc->ico = 'glyphicon glyphicon-retweet';
 				$rowFunc->href = 'index.php?_route=Users&_task=syncUser&usrLogin=' . $record->ADM_ACCOUNT;
 				$rowFunc->title = "Synchronizuj do LDAP";
-				$response->rowFunctions[] = $rowFunc;
+				$rowFunList[] = $rowFunc;
 
 				$rowFunc = new stdClass();
 				$rowFunc->ico = 'glyphicon glyphicon-minus';
 				$rowFunc->href = 'index.php?MENU_INIT=USER_OCENA_PRACOWNIKA&usrLogin=' . $record->ADM_ACCOUNT;
 				$rowFunc->title = "Ocena pracownika";
-				$response->rowFunctions[] = $rowFunc;
+				$rowFunList[] = $rowFunc;
 			}
 		}
 
-		$acl = $this->_acl;
 		if ($urlFunctions = Route_UrlAction::getTableFunctions($acl->getID(), $id, $acl->getName(), User::getLogin())) {
 			foreach ($urlFunctions as $urlFunction) {
 				// TODO: is allowed to view - test by Router::getRoute('UrlAction')->isFunctionAllowedForRecord($routeName = $urlFunction['name'], $acl->getID(), $id);
@@ -6305,7 +6319,6 @@ jQuery(document).ready(function(){
 				$rowFunction['title'] = V::get('title', $urlFunction['label'], $urlFunction);
 				if (!empty($urlFunction['link_target'])) $rowFunction['target'] = $urlFunction['link_target'];
 				if (!empty($urlFunction['cell_id_params'])) {
-					$record = $acl->getItem($id);
 					$urlParams = array();// [ "{$urlParamName}={$paramValue}" ]
 					foreach ($urlFunction['cell_id_params'] as $idField => $urlParamName) {
 						$paramValue = '';
@@ -6318,10 +6331,20 @@ jQuery(document).ready(function(){
 					}
 					if (!empty($urlParams)) $rowFunction['href'] .= "&" . implode("&", $urlParams);
 				}
-				$response->rowFunctions[] = $rowFunction;
+				$rowFunList[] = $rowFunction;
 			}
 		}
+		return $rowFunList;
+	}
+
+	public function ajaxMoreFunctionsCell($args) {// ajax task 'MORE_FUNCTIONS_CELL'
+		$id = V::get('ID', 0, $args, 'int');
+		if ($id <= 0) throw new HttpException("404", 404);
 
+		$response = new stdClass();
+		$response->type = 'success';
+		$response->msg = 'Funkcje';
+		$response->rowFunctions = $this->getMoreFunctionsCell(array('primary_key' => $id));
 		return $response;
 	}