Przeglądaj źródła

Budget: select sub projects, show only selected

Piotr Labudda 11 lat temu
rodzic
commit
c8d427b91c
1 zmienionych plików z 57 dodań i 9 usunięć
  1. 57 9
      SE/superedit-BUDGET_ANALYTICS.php

+ 57 - 9
SE/superedit-BUDGET_ANALYTICS.php

@@ -89,6 +89,14 @@ jQuery(document).ready(function () {
 		.zestawienie-kosztow-tbl .nr { color:#7A7A7A; }
 		.zestawienie-kosztow-tbl thead th { border:1px solid #7EC5FF; }
 		.zestawienie-kosztow-tbl tbody tr:hover td { background:#cafbfd; }
+		.row-selected td {background-color:#d8fded;}
+		.showOnlySelected tr { display:none; }
+		.showOnlySelected tr.row-selected { display:table-row; }
+
+		.cost { padding:0 2px; min-width:30px; text-align:right; }
+		.cost-only_child { color:#777; }
+		.cost-only_self { color:red; }
+		.cost-self_and_child { color:orange; }
 
 		/* print table background colors */
 		table td, table th { -webkit-print-color-adjust:exact; }
@@ -97,11 +105,6 @@ jQuery(document).ready(function () {
 		td    { page-break-inside:avoid; page-break-after:auto; position:relative; }
 		thead { display:table-header-group }
 		tfoot { display:table-footer-group }
-
-		.cost { padding:0 2px; min-width:30px; text-align:right; }
-		.cost-only_child { color:#777; }
-		.cost-only_self { color:red; }
-		.cost-self_and_child { color:orange; }
 	</style>
 		<?php
 	}
@@ -114,13 +117,17 @@ jQuery(document).ready(function () {
 		$this->css();
 		//echo'<pre style="width:600px;border:1px solid red;max-height:300px;overflow:auto;">';print_r($costs);echo'</pre>';
 ?>
+<div class="container">
 	<div style="float:right;color:#aaa;"><?php echo date("Y-m-d"); ?></div>
 	<h1>Zestawienie kosztów projektów na rok <?php echo $year; ?></h1>
 	<table cellspacing="0" cellpadding="0" border="0" id="zestawienie-kosztow-projektow" class="zestawienie-kosztow-tbl">
 	<thead>
 		<tr>
-			<td colspan="3" style="text-align:right">
-				miesiąc
+			<td colspan="3" class="p2">
+				<span class="pull-left">
+					<input type="checkbox" onclick="return showHideAll(this);"/> pokaż tylko zaznaczone
+				</span>
+				<span class="pull-right">miesiąc</span>
 			</td>
 			<?php foreach ($months as $month) { ?>
 				<th class="c"><?php echo $month; ?></th>
@@ -131,10 +138,14 @@ jQuery(document).ready(function () {
 	<?php $t = 1; ?>
 	<?php foreach ($projOrder as $projPath => $projId) : ?>
 		<?php $projectInfo = $costs[$projId]; ?>
-		<tr class="row-<?php echo ($t = 1 - $t); ?>">
+		<tr class="row-<?php echo ($t = 1 - $t); ?>"
+				data-projId="<?php echo $projectInfo->ID_PROJECT; ?>"
+				data-path="<?php echo $projectInfo->path; ?>">
+			<td class="p2 r nr">
+				<input type="checkbox" name="selectedProject" onclick="return selectProject(this);" value="<?php echo $projectInfo->ID_PROJECT; ?>" />
+			</td>
 			<td class="p2 l nr"><?php echo $projectInfo->path; ?></td>
 			<td class="p2" style="max-width:300px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;" title="<?php echo $projectInfo->M_DIST_DESC; ?>"><?php echo $projectInfo->M_DIST_DESC; ?></td>
-			<td class="p2 r nr"><input type="checkbox" name="selectedProject" value="<?php echo $projectInfo->ID_PROJECT; ?>" /></td>
 			<?php foreach ($months as $month) : ?>
 				<?php if (array_key_exists($month, $projectInfo->costsByMonth)) : ?>
 					<?php $vCost = V::get($month, '', $projectInfo->costsByMonth); ?>
@@ -156,10 +167,47 @@ jQuery(document).ready(function () {
 	<?php endforeach; ?>
 	</tbody>
 	</table>
+</div>
 <script>
 	jQuery(document).ready(function(){
 		jQuery('.ttip').tooltip();
 	});
+
+	function selectProject(n) {
+		var $n = jQuery(n);
+		var $p = $n.parent().parent();
+		if (n.checked) {
+			$p.addClass('row-selected');
+		} else {
+			$p.removeClass('row-selected');
+		}
+		markSubProjects($p, $p.data('path'), n.checked);
+
+		function markSubProjects($p, path, checked) {
+			var $nextRow = $p.next('tr'),
+					nextPath = $nextRow.data('path'),
+					nextCheckbox = $nextRow.find('input[type="checkbox"]').get(0);
+			if (0 !== nextPath.indexOf(path)) {
+				return;
+			}
+			if (checked) {
+				$nextRow.addClass('row-selected');
+			} else {
+				$nextRow.removeClass('row-selected');
+			}
+			nextCheckbox.checked = checked;
+			markSubProjects($nextRow, path, checked);
+		}
+	}
+
+	function showHideAll(n) {
+		if (n.checked) {
+			jQuery('#zestawienie-kosztow-projektow').find('tbody').addClass('showOnlySelected');
+		} else {
+			jQuery('#zestawienie-kosztow-projektow').find('tbody').removeClass('showOnlySelected');
+		}
+	}
+
 </script>
 <?php
 	}