datatable.directory codebase https://datatable.directory/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
datatable.directory/app/View/WidgetFactory.php

117 lines
3.1 KiB

<?php
namespace App\View;
class WidgetFactory
{
private $labelCols = 3, $fieldCols = 8;
/** Configure layout used for future elements */
public function setLayout($labelCols, $fieldCols)
{
$this->labelCols = $labelCols;
$this->fieldCols = $fieldCols;
}
public function help($text)
{
return view('form._help-inner', ['help' => $text]);
}
public function header($hx, $text)
{
return "<div class=\"row\">".
"<h$hx class=\"col-md-$this->fieldCols offset-md-$this->labelCols\">".e($text)."</h$hx>".
"</div>";
}
public function par($text, $extraClasses='', $escape=true)
{
7 years ago
if (false === strpos($extraClasses, 'mb-')) $extraClasses .= ' mb-2';
return
"<div class=\"row\">".
7 years ago
"<p class=\"col-md-$this->fieldCols offset-md-$this->labelCols ".e($extraClasses)."\">".
($escape ? e($text) : $text) .
"</p>".
"</div>";
}
public function labeledPar($label, $text, $extraClasses='', $escape=true)
{
if (false === strpos($extraClasses, 'mb-')) $extraClasses .= ' mb-2';
return
"<div class=\"row\">".
"<label class=\"text-md-right col-form-label col-md-$this->labelCols\">".e($label)."</label>".
"<p class=\"form-control-plaintext col-md-$this->fieldCols".e($extraClasses)."\">".
($escape ? e($text) : $text) .
"</p>".
"</div>";
}
/**
* Convert the given string to a-href if it is a link.
*
* @param $href
* @return string
*/
public function tryLink($href)
{
$href = trim($href);
if (starts_with($href, ['http://', 'https://', 'mailto:', 'ftp://'])) {
$href_e = e($href);
return "<a href=\"".$href_e."\">".$href_e."</a>";
} else {
return $href;
}
}
public function collapsible($text, $thrSize, $maxHeight)
{
return new CollapsibleTextBoxWidget($text, $thrSize, $maxHeight);
}
private function baseWidget($view, $name, $label)
{
return (new Widget($view, $name, $label))->layout($this->labelCols, $this->fieldCols);
}
public function text($name, $label)
{
return $this->baseWidget('input', $name, $label);
}
public function password($name, $label)
{
return $this->baseWidget('input', $name, $label)->type('password');
}
public function number($name, $label)
{
return $this->baseWidget('input', $name, $label)->type('number');
}
public function email($name, $label)
{
return $this->baseWidget('input', $name, $label)->type('email');
}
public function file($name, $label)
{
return $this->baseWidget('input', $name, $label)->type('file');
}
public function checkbox($name, $label)
{
return (new CheckboxWidget('checkbox', $name, $label))
->layout($this->labelCols, $this->fieldCols);
}
public function textarea($name, $label)
{
return $this->baseWidget('textarea', $name, $label)->minHeight('4em');
}
}