Piotr Labudda 9 gadi atpakaļ
vecāks
revīzija
ed2c812831

+ 91 - 119
SE/se-lib/Route/Budget.php

@@ -5,6 +5,7 @@ Lib::loadClass('ProcesHelper');
 Lib::loadClass('TableAjax');
 Lib::loadClass('UserStorageFactory');
 Lib::loadClass('Response');
+Lib::loadClass('UI');
 
 class Route_Budget extends RouteBase {
 
@@ -24,12 +25,12 @@ class Route_Budget extends RouteBase {
 		$args['year'] = V::get('year', '', $_REQUEST, 'int');
 		$args['_print'] = V::get('_print', '', $_REQUEST, 'int');
 
-		SE_Layout::gora();
-		SE_Layout::menu();
+		UI::gora();
+		UI::menu();
 		if (!$args['_print']) {
 			$this->menu($args['year']);
 		}
-		SE_Layout::dol();
+		UI::dol();
 	}
 
 	public function yearBudgetAction() {
@@ -45,93 +46,74 @@ class Route_Budget extends RouteBase {
 			$groups = $this->getUsedUserGroups();
 		}
 
-		SE_Layout::gora();
-		SE_Layout::menu();
+		UI::gora();
+		UI::menu();
 		if (!$args['_print']) {
 			$this->menu($args['year'], $groups, $args['groups']);
 		}
 
 		if (empty($args['year'])) {
-			?>
-			<div class="alert alert-warning">
-				Nie wybrano roku.
-			</div>
-			<?php
-			SE_Layout::dol();
+			UI::alert('warning', "Nie wybrano roku.");
+			UI::dol();
 			exit;
 		}
 
 		if (!$hasData) {
-			?>
-			<div class="alert alert-warning">
-				Brak danych na wybrany rok.
-			</div>
-			<?php
+			UI::alert('warning', "Brak danych na wybrany rok.");
 			return;
 		}
 		//echo'<pre style="border:1px solid red;overflow:auto;max-height:400px">$costs: ';print_r($costs);echo'</pre>';
 
 		$this->printCostsForYear($args['year'], $args['groups']);
 
-		SE_Layout::dol();
+		UI::dol();
 	}
 
 	public function menu($selectedYear, $groups = array(), $selectedGroups = array()) {
-		//SE_Layout::menu();
+		//UI::menu();
 		$year = ($selectedYear)? $selectedYear : date("Y");
-		?>
-<div class="jumbotron">
-  <div class="container">
-		<form class="form-inline" method="POST">
-			<input type="hidden" name="_task" value="yearBudget" />
-			<label for="year">Zestawienie kosztów projektów. Wybierz rok:</label>
-			<div class="input-group date" id="fldZestYear">
-				<input type="text" name="year" class="form-control" value="" />
-				<span class="input-group-addon"><span class="glyphicon glyphicon-time"></span></span>
-			</div>
-			<?php if (!empty($groups)) : ?>
-			<div style="margin:8px 0">
-				<label for="fltrGroups">Pokaż tylko projekty dostępne dla grup:</label>
-				<select multiple name="fltrGroups[]" size="<?php echo min(5, count($groups) + 1); ?>" class="form-control">
-					<option value=""> [ Wszystkie ] </option>
-					<?php foreach ($groups as $idGroup => $groupLdapName) : ?>
-						<option
-										value="<?php echo $idGroup; ?>"
-										<?php if (in_array($idGroup, $selectedGroups)) { echo 'selected="selected"'; } ?>
-										><?php echo $groupLdapName; ?></option>
-					<?php endforeach; ?>
-				</select>
-			</div>
-			<?php endif; ?>
-			<button type="submit" id="fldZestYearBtn" class="btn btn-primary" autocomplete="off">
-				Pokaż
-			</button>
-		</form>
-		<div style="text-align:right">
-			Edytuj
-			<a href="index.php?_route=Budget&_task=plan&year=<?php echo $year; ?>"
-				 class="btn btn-xs btn-default"
-				 title="Plan budżetu (projects_budget_year_month)">plan budżetu</a>
-			na rok <?php echo $year; ?>
-		</div>
-	</div>
-</div>
-<script type="text/javascript">
-jQuery(document).ready(function () {
-  jQuery('#fldZestYearBtn').on('click', function () {
-    jQuery(this).text(jQuery(this).text() + '...').attr('disabled', 'disabled');
-		jQuery(this).parent().submit();
-  })
-
-	jQuery("#fldZestYear").datetimepicker({
-		format: "YYYY",
-		defaultDate: new Date(<?php echo $year; ?>, <?php echo intval(date("m")); ?>, 1),
-		// minDate: new Date(2014, 11, 1),
-		// maxDate: "<?php echo date("Y"); ?>"
-	});
-});
-</script>
-		<?php
+		UI::startTag('div', ['class'=>"jumbotron"]);
+		UI::startContainer();
+		UI::startTag('form', ['class'=>"form-inline", 'method'=>"POST"]);
+			UI::emptyTag('input', ['type'=>"hidden", 'name'=>"_task", 'value'=>"yearBudget"]);
+			UI::tag('label', ['for'=>"year"], "Zestawienie kosztów projektów. Wybierz rok:");
+			UI::startTag('div', ['class'=>"input-group date", 'id'=>"fldZestYear"]);
+				UI::emptyTag('input', ['type'=>"text", 'name'=>"year", 'class'=>"form-control", 'value'=>""]);
+				UI::tag('span', ['class'=>"input-group-addon"], "<span class=\"glyphicon glyphicon-time\"></span>");
+			UI::endTag('div');
+
+			if (!empty($groups)) {
+				UI::startTag('div', ['style'=>"margin:8px 0"]);
+					UI::tag('label', ['for'=>"fltrGroups"], "Pokaż tylko projekty dostępne dla grup:");
+					UI::startTag('select', ['multiple'=>"multiple", 'name'=>"fltrGroups[]", 'size'=>min(5, count($groups) + 1), 'class'=>"form-control"]);
+						UI::tag('option', ['value'=>""], " [ Wszystkie ] ");
+						foreach ($groups as $idGroup => $groupLdapName) {
+							if (in_array($idGroup, $selectedGroups)) {
+								UI::tag('option', ['value'=>$idGroup, 'selected'=>"selected"], $groupLdapName);
+							} else {
+								UI::tag('option', ['value'=>$idGroup], $groupLdapName);
+							}
+						}
+					UI::endTag('select');
+				UI::endTag('div');
+			}
+			UI::tag('button', ['type'=>"submit", 'id'=>"fldZestYearBtn", 'class'=>"btn btn-primary", 'autocomplete'=>"off"], "Pokaż");
+
+		UI::endTag('form');
+		UI::startTag('div', ['style'=>"text-align:right"]);
+			echo "Edytuj ";
+			UI::tag('a', ['href'=>"index.php?_route=Budget&_task=plan&year={$year}",
+				'class'=>"btn btn-xs btn-default",
+				'title'=>"Plan budżetu (projects_budget_year_month)"], "plan budżetu");
+			echo "na rok {$year}";
+		UI::endTag('div');
+
+		UI::endContainer();
+		UI::endTag('div');
+		UI::inlineJS(__FILE__ . '.menu.js', [
+			'year' => $year,
+			'month' => intval(date("m"))
+		]);
 	}
 
 	function css() {
@@ -186,7 +168,6 @@ jQuery(document).ready(function () {
 		.row__summary__plan {background-color:#fcf8e3;}
 		.thead_col_month .col_month_remove { opacity:0.2; }
 		.thead_col_month:hover .col_month_remove { opacity:0.6; }
-
 </style>
 		<?php
 	}
@@ -199,32 +180,29 @@ jQuery(document).ready(function () {
 		$this->css();
 		//DBG::_('DBG', '>1', "costs", $this->_costs, __CLASS__, __FUNCTION__, __LINE__);
 
-//echo'<pre>' . json_encode(array_keys($this->_projectPathsOrder)) . '</pre>';
-//echo'<pre>' . json_encode($this->_projectPathsOrder) . '</pre>';
-//echo'<pre>' . json_encode($this->_projectInfo) . '</pre>';
-//echo'<pre>' . json_encode($this->_costs) . '</pre>';
-//echo'<pre>' . json_encode($this->_plan) . '</pre>';
-$projectPathsOrder = array_keys($this->_projectPathsOrder);
-foreach ($projectPathsOrder as $key => $value) {
-	$projectPathsOrder[$key] = "" . $value;
-}
-?>
-<div id="widget-budget"></div>
-<script src="stuff/vendors.js"></script>
-<script src="stuff/bundle.se_route_budget.js?v=2.1"></script>
-<script>
-jQuery("#widget-budget").Budget({
-	year: '<?php echo $year; ?>',
-	today: '<?php echo date('Y-m-d'); ?>',
-	projectPathsOrder: <?php echo json_encode($projectPathsOrder); ?>,
-	projectPathsMap: <?php echo json_encode($this->_projectPathsOrder); ?>,
-	projectInfo: <?php echo json_encode($this->_projectInfo); ?>,
-	costs: <?php echo json_encode($this->_costs); ?>,
-	plan: <?php echo json_encode($this->_plan); ?>,
-	dbg: false
-});
-</script>
-<?php
+		//echo'<pre>' . json_encode(array_keys($this->_projectPathsOrder)) . '</pre>';
+		//echo'<pre>' . json_encode($this->_projectPathsOrder) . '</pre>';
+		//echo'<pre>' . json_encode($this->_projectInfo) . '</pre>';
+		//echo'<pre>' . json_encode($this->_costs) . '</pre>';
+		//echo'<pre>' . json_encode($this->_plan) . '</pre>';
+		$projectPathsOrder = array_keys($this->_projectPathsOrder);
+		foreach ($projectPathsOrder as $key => $value) {
+			$projectPathsOrder[$key] = "" . $value;
+		}
+
+		UI::tag('div', ['id' => "widget-budget"]);
+		UI::tag('script', ['src'=>"stuff/vendors.js"]);
+		UI::tag('script', ['src'=>"stuff/bundle.se_route_budget.js?v=2.1"]);
+		UI::inlineJS(__FILE__ . '.yearBudget.js', [
+			'year' => $year,
+			'today' => date('Y-m-d'),
+			'projectPathsOrder' => $projectPathsOrder,
+			'projectPathsMap' => $this->_projectPathsOrder,
+			'projectInfo' => $this->_projectInfo,
+			'costs' => $this->_costs,
+			'plan' => $this->_plan,
+			'dbg' => false,
+		]);
 	}
 
 	public function getCost($idProject, $month) {
@@ -302,7 +280,7 @@ jQuery("#widget-budget").Budget({
 	}
 
 	public function getCostsCategoryDBGAction() {// TODO: RMME
-		SE_Layout::gora();
+		UI::gora();
 		$year = V::get('year', 0, $_GET, 'int');
 		if ($year <= 0) throw new Exception("Year not set!");
 		$costsCat = $this->_fetchCostsCategoryByYear($year);
@@ -491,6 +469,8 @@ jQuery("#widget-budget").Budget({
 		$this->_projectInfo[0]->path = "0";
 		$this->_projectInfo[0]->M_DIST_DESC = "Wszystkie projekty";
 		$this->_projectInfo[0]->hasAccess = $hasAccessForAllProjects;
+
+		// TODO: fetch every missing parent project by path
 	}
 
 	public function hasAccessToProject($idProject) {
@@ -771,8 +751,8 @@ END
 	}
 
 	public function planAction() {
-		SE_Layout::gora();
-		SE_Layout::menu();
+		UI::gora();
+		UI::menu();
 
 		$args = array();
 		$args['year'] = V::get('year', '', $_REQUEST, 'int');
@@ -783,22 +763,16 @@ END
 		$this->menu($args['year']);
 
 		if ($args['year'] > 0) {
-			?>
-<div class="container">
-	<a class="btn btn-xs btn-default" href="#">Utwórz plan na kolejny rok na podstawie danych z <?php echo $args['year']; ?> roku</a>
-</div>
-<?php
+			UI::startContainer();
+			UI::tag('a', ['class'=>"btn btn-xs btn-default", 'href'=>"#"], "Utwórz plan na kolejny rok na podstawie danych z {$args['year']} roku");
+			UI::endContainer();
 		}
 
 		$zasobObj = ProcesHelper::getZasobTableInfoByUri('default_db/projects_budget_year_month');
 		if (!$zasobObj) {
-			?>
-<div class="alert alert-danger">
-	Zasob Tabela Plan budżetu (projects_budget_year_month) nie istnieje
-</div>
-<?php
+			UI::alert('danger', "Zasob Tabela Plan budżetu (projects_budget_year_month) nie istnieje");
 			// TODO: btn utwórz
-			SE_Layout::dol();
+			UI::dol();
 			return;
 		}
 
@@ -806,12 +780,8 @@ END
 		$userAcl->fetchGroups();
 
 		if (!$userAcl->hasTableAcl($zasobObj->ID)) {
-			?>
-<div class="alert alert-danger">
-	Brak uprawnień do tabeli Plan budżetu (projects_budget_year_month)
-</div>
-<?php
-			SE_Layout::dol();
+			UI::alert('danger', "Brak uprawnień do tabeli Plan budżetu (projects_budget_year_month)");
+			UI::dol();
 			return;
 		}
 
@@ -837,7 +807,9 @@ END
 			}
 		}
 
+		$syncUrl = Request::getPathUri() . 'index.php?_route=ViewTableAjax&namespace=' . $tblAcl->getNamespace();
 		$tbl = new TableAjax($tblAcl);
+		$tbl->setSyncUrl($syncUrl);
 		$tblLabel = array();
 		if (!empty($zasobObj->DESC_PL)) $tblLabel []= $zasobObj->DESC_PL;
 		if (!empty($zasobObj->OPIS))    $tblLabel []= $zasobObj->OPIS;
@@ -852,7 +824,7 @@ END
 		$tbl->showProcesInit(false);
 		echo $tbl->render();
 
-		SE_Layout::dol();
+		UI::dol();
 	}
 
 }

+ 13 - 0
SE/se-lib/Route/Budget.php.menu.js

@@ -0,0 +1,13 @@
+// @require var year
+// @require var month
+jQuery(document).ready(function () {
+  jQuery('#fldZestYearBtn').on('click', function () {
+    jQuery(this).text(jQuery(this).text() + '...').attr('disabled', 'disabled');
+		jQuery(this).parent().submit();
+  })
+
+	jQuery("#fldZestYear").datetimepicker({
+		format: "YYYY",
+		defaultDate: new Date(year, month, 1),
+	});
+});

+ 19 - 0
SE/se-lib/Route/Budget.php.yearBudget.js

@@ -0,0 +1,19 @@
+// @require var year
+// @require var today
+// @require var projectPathsOrder
+// @require var projectPathsMap
+// @require var projectInfo
+// @require var costs
+// @require var plan
+// @require var dbg
+
+jQuery("#widget-budget").Budget({
+	year: year,
+	today: today,
+	projectPathsOrder: projectPathsOrder,
+	projectPathsMap: projectPathsMap,
+	projectInfo: projectInfo,
+	costs: costs,
+	plan: plan,
+	dbg: dbg
+});