Piotr Labudda 9 rokov pred
rodič
commit
83095e0ac1
1 zmenil súbory, kde vykonal 58 pridanie a 57 odobranie
  1. 58 57
      SE/se-lib/UI.php

+ 58 - 57
SE/se-lib/UI.php

@@ -98,20 +98,11 @@ class UI {
 			echo "{$type}: {$msg}\n";
 			return;
 		}
-?>
-<div class="alert alert-<?php echo $alertType; ?>">
-	<?php echo $msg; ?>
-</div>
-<?php
+		UI::tag('div', ['class'=>"alert alert-{$alertType}"], $msg, "\n");
 	}
 
-	public static function setTitleJsTag($title) {
-?>
-<script>
-	document.title = '<?php echo $title; ?>';
-</script>
-<?php
-	}
+	public static function setTitleJsTag($title) { self::setTitle($title); }
+	public static function setTitle($title) { self::tag('script', null, "document.title = '{$title}';", "\n"); }
 
 	/**
 	 * $params - Array
@@ -136,67 +127,77 @@ class UI {
 		}
 		// if (empty($cols)) return;
 		$hiddenCols = V::get('hidden_cols', array(), $params);
+
+		$tableAttrs = [ 'class' => "table table-bordered table-hover" ];
 		$html_id = V::get('__html_id', '', $params);
-?>
-	<table class="table table-bordered table-hover" <?php echo ($html_id)? 'id="' . $html_id . '"' : ''; ?>>
-	<?php if ($caption) : ?>
-		<caption><?php echo $caption; ?></caption>
-	<?php endif; ?>
-		<thead>
-			<tr>
-			<?php if ($showLp) : ?>
-				<th style="padding:2px">Lp.</th>
-			<?php endif; ?>
-			<?php foreach ($cols as $colName) : ?>
-				<?php if (in_array($colName, $hiddenCols)) continue; ?>
-				<th style="padding:2px"><?php echo $colName; ?></th>
-			<?php endforeach; ?>
-			</tr>
-		</thead>
-		<tbody>
-		<?php $i = 0; foreach ($rows as $row) : $i++; ?>
-			<tr <?php echo (!empty($row['__js_on_click']))? 'onClick="' . $row['__js_on_click'] . '"' : ''; ?>>
-			<?php if ($showLp) : ?>
-				<td style="padding:2px; color:#ccc"><?php echo $i; ?></td>
-			<?php endif; ?>
-			<?php foreach ($cols as $colName) : ?>
-				<?php if (in_array($colName, $hiddenCols)) continue; ?>
-				<td style="padding:2px"><?php echo V::get($colName, '', $row); ?></td>
-			<?php endforeach; ?>
-			</tr>
-		<?php endforeach; ?>
-		</tbody>
-	</table>
-<?php
+		if ($html_id) $tableAttrs['id'] = $html_id;
+		self::startTag('table', $tableAttrs); echo "\n";
+		if ($caption) { self::tag('caption', null, $caption); echo "\n"; }
+		self::startTag('thead', null); echo "\n";
+		self::startTag('tr', null); echo "\n";
+		if ($showLp) { self::tag('th', [ 'style' => "padding:2px" ], "Lp.");  echo "\n"; }
+		foreach ($cols as $colName) {
+			if (in_array($colName, $hiddenCols)) continue;
+			self::tag('th', [ 'style' => "padding:2px"], $colName); echo "\n";
+		}
+		self::endTag('tr'); echo "\n";
+		self::endTag('thead'); echo "\n";
+		self::startTag('tbody', null); echo "\n";
+		$i = 0;
+		foreach ($rows as $row) {
+			$i++;
+			$trAttrs = array();
+			if (!empty($row['__js_on_click'])) $trAttrs['onClick'] = $row['__js_on_click'];
+			self::startTag('tr', $trAttrs); echo "\n";
+			if ($showLp) { self::tag('th', [ 'style' => "padding:2px; color:#ccc" ], $i); echo "\n"; }
+			foreach ($cols as $colName) {
+				if (in_array($colName, $hiddenCols)) continue;
+				self::tag('td', [ 'style' => "padding:2px" ], V::get($colName, '', $row)); echo "\n";
+			}
+			self::endTag('tr'); echo "\n";
+		}
+		self::endTag('tbody'); echo "\n";
+		self::endTag('table'); echo "\n";
 	}
 
-	public static function startContainer($attrs = array()) {
-		// echo '<div class="container">' . "\n";
-		if (!empty($attrs['class'])) $attrs['class'] .= ' container';
-		$attrs['class'] = ' container';
-		self::startTag('div', $attrs);
+	public static function startContainer($attrs = array()) {// echo '<div class="container">' . "\n";
+		$attrs['class'] = (!empty($attrs['class']))
+			? $attrs['class'] . ' ' . 'container'
+			: 'container';
+		self::startTag('div', $attrs, "\n");
 	}
-	public static function endContainer() { echo '</div>' . "\n"; }
-	public static function startTag($tag, $attrs = array()) {
+	public static function endContainer() { self::endTag('div', "\n"); }
+	public static function startTag($tag, $attrs = array(), $addWhiteSpace = false) {
 		$outAttrs = '';
 		if (is_array($attrs)) {
 			foreach ($attrs as $attrName => $val) $outAttrs .= " {$attrName}=\"{$val}\"";
 		}
-		echo '<' . $tag . $outAttrs . '>';
+		echo '<' . $tag . $outAttrs . '>' . self::whiteSpace($addWhiteSpace);
+	}
+	public static function whiteSpace($addWhiteSpace = false) {
+		return (!$addWhiteSpace)
+			? ''
+			: (true === $addWhiteSpace) ? " " : $addWhiteSpace;
+	}
+	public static function endTag($tag, $addWhiteSpace = false) {
+		echo '</' . $tag . '>' . self::whiteSpace($addWhiteSpace);
 	}
-	public static function endTag($tag) { echo '</' . $tag . '>'; }
-	public static function tag($tag, $attrs = array(), $childrens = array()) {
+	public static function tag($tag, $attrs = array(), $childrens = array(), $addWhiteSpace = false) {
+		$whiteSpace = self::whiteSpace($addWhiteSpace);
 		self::startTag($tag, $attrs);
+		echo $whiteSpace;
 		if (!empty($childrens) && is_array($childrens)) throw new Exception("UI::tag() children as nodes not implemented".json_encode($childrens));
 		if (is_scalar($childrens)) echo $childrens;
+		echo $whiteSpace;
 		self::endTag($tag);
+		echo $whiteSpace;
 	}
-	public static function emptyTag($tag, $attrs = array()) {
+	public static function emptyTag($tag, $attrs = array(), $addWhiteSpace = false) {
 		$outAttrs = '';
 		if (is_array($attrs)) {
 			foreach ($attrs as $attrName => $val) $outAttrs .= " {$attrName}=\"{$val}\"";
 		}
-		echo '<' . $tag . $outAttrs . '/>';
+		echo '<' . $tag . $outAttrs . '/>' . self::whiteSpace($addWhiteSpace);
 	}
 	public static function link($type, $content, $href, $attrs = array()) {
 		$attrs['class'] = V::get('class', '', $attrs);
@@ -215,9 +216,9 @@ class UI {
 
 	}
 
-	public static function price($value) {
+	public static function price($value, $dec = ',') {
 		// TODO: if not number type - string wwith wrong format - try to convert?
-		return number_format($value, 2, ',', ' ');
+		return number_format($value, 2, $dec, ' ');
 	}
 
 }