فهرست منبع

fixed load more row functions in TableAjax (replace previous if func name match)

Piotr Labudda 10 سال پیش
والد
کامیت
d9e9daee60
1فایلهای تغییر یافته به همراه48 افزوده شده و 11 حذف شده
  1. 48 11
      SE/se-lib/TableAjax.php

+ 48 - 11
SE/se-lib/TableAjax.php

@@ -1040,12 +1040,13 @@ class TableAjax extends ViewAjax {
 					_popoverCell.data('rowid', rowPK);
 					_popoverCell.data('col', 'rowFunctions');
 					_popoverCell.empty();
-					funcListNode = $('<ul class="list-unstyled"></ul>').appendTo(_popoverCell);
+					funcListNode = $('<ul class="list-unstyled popoverRowFunctions"></ul>').appendTo(_popoverCell);
 					moreFunctions.forEach(function(funcName) {
 						var funcItemNode = $('<li></li>').appendTo(funcListNode),
 								funObj = rowFunctions[funcName],
 								funcNode = priv.generateFunctionNode(funObj, rowPK, {ico: true, label: true})
 						;
+						funcNode.addClass('func_name-' + funcName);
 						funcItemNode.append(funcNode);
 					});
 
@@ -1111,7 +1112,11 @@ class TableAjax extends ViewAjax {
 			if ('title' in funObj) funcNode.attr('title', funObj.title);
 
 			if (props.label) {
-				if ('title' in funObj) funcNode.append(' ' + funObj.title);
+				if ('label' in funObj) {
+					funcNode.append(' ' + funObj.label);
+				} else if ('title' in funObj) {
+					funcNode.append(' ' + funObj.title);
+				}
 			}
 
 			return funcNode;
@@ -1132,7 +1137,8 @@ class TableAjax extends ViewAjax {
 			.done(function(data, textStatus, jqXHR){
 				if (data && 'success' === data.type) {
 					var popoverCellContent,
-							rowFunctions = []
+							rowFunctions = [],
+							funcNodesToUpdate = []
 					;
 					if (data.rowFunctions && data.rowFunctions.length > 0) {
 						rowFunctions = data.rowFunctions;
@@ -1140,10 +1146,13 @@ class TableAjax extends ViewAjax {
 					if (rowFunctions.length > 0) {
 						var popoverCellContent = $('<ul class="list-unstyled"></ul>');
 						rowFunctions.forEach(function(funObj) {
-							var funcItemNode = $('<li></li>').appendTo(popoverCellContent),
-									funcNode = priv.generateFunctionNode(funObj, rowPK, {ico: true, label: true})
-							;
-							funcItemNode.append(funcNode);
+							var funcNode = priv.generateFunctionNode(funObj, rowPK, {ico: true, label: true});
+							if (funObj.id) {
+								funcNodesToUpdate.push({id: funObj.id, node: funcNode});
+							} else {
+								var funcItemNode = $('<li></li>').appendTo(popoverCellContent);
+								funcItemNode.append(funcNode);
+							}
 						});
 					} else {
 						popoverCellContent = '<p class="text-muted">Brak dodatkowych funkcji</p>';
@@ -1152,10 +1161,36 @@ class TableAjax extends ViewAjax {
 					if (_popoverCellCurrent) {
 						var popoverNodeId = _popoverCellCurrent.attr('aria-describedby');
 						if (popoverNodeId) {
-							var pooverCntNode = jQuery('#' + popoverNodeId).find('.popoverCellContent');
-							pooverCntNode.empty().append(popoverCellContent);
+							var popoverNode = jQuery('#' + popoverNodeId),
+									popoverCntNode = popoverNode.find('.popoverCellContent'),
+									popoverRowFuncNode = popoverNode.find('.popoverRowFunctions');
+							;
+							{// fix generated row Functions by loaded from ajax call
+								console.log('popoverRowFunctions. popoverRowFuncNode', popoverRowFuncNode);
+								console.log('popoverRowFunctions. funcNodesToUpdate', funcNodesToUpdate);
+								funcNodesToUpdate.forEach(function(funcNodeInfo) {
+									var className = 'func_name-' + funcNodeInfo.id,
+											foundRowFuncNode = null
+									;
+									console.log('popoverRowFunctions. funcNodesToUpdate loop:', funcNodeInfo);
+									popoverRowFuncNode.find('li > a').each(function(ind, n) {
+										var n$ = $(n);
+										console.log('popoverRowFunctions loop(',ind,'):', n, 'data(func_name)', n$.data('func_name'), 'data', n$.data());
+										if (n$.hasClass(className)) {
+											foundRowFuncNode = n$;
+										}
+									});
+									if (foundRowFuncNode) {
+										foundRowFuncNode.replaceWith(funcNodeInfo.node);
+									} else {
+										var funcItemNode = $('<li></li>').appendTo(popoverCellContent);
+										funcItemNode.append(foundRowFuncNode);
+									}
+								});
+							}
+							popoverCntNode.empty().append(popoverCellContent);
 							if (rowFunctions.length <= 0) {
-								pooverCntNode.find('p.text-muted').delay(600).hide(300);
+								popoverCntNode.find('p.text-muted').delay(600).hide(300);
 							}
 						}
 					}
@@ -6016,9 +6051,11 @@ jQuery(document).ready(function(){
 			$msgsList = $msgs->getActiveMessagesForTableRecord($tableName, $id);
 			$totalMsgs = count($msgsList);
 			$rowFunc = new stdClass();
+			$rowFunc->id = 'msgs';
 			$rowFunc->ico = 'glyphicon glyphicon-envelope';
 			$rowFunc->href = 'index.php?_route=TableMsgs&_task=tableRow&idTable=' . $this->_zasobID . '&idRow=' . $id;
-			$rowFunc->title = "Wiadomości <span class=\"badge\">{$totalMsgs}</span>";
+			$rowFunc->title = "Wiadomości ({$totalMsgs})";
+			$rowFunc->label = "Wiadomości <span class=\"badge\">{$totalMsgs}</span>";
 			$response->rowFunctions[] = $rowFunc;
 		}