Commit 8d900148 authored by Carsten  Rose's avatar Carsten Rose
Browse files

AbstractBuildForm, BuildFormBootstrap: Botstrap impelemented

parent 7577c035
......@@ -116,7 +116,7 @@ abstract class AbstractBuildForm {
* @throws exceptions\CodeException
* @throws exceptions\DbException
*/
public function elements($recordId, $filter = FORM_ELEMENTS_NATIVE, $feIdContainer=0) {
public function elements($recordId, $filter = FORM_ELEMENTS_NATIVE, $feIdContainer = 0) {
$html = '';
// get current data record
......@@ -169,6 +169,23 @@ abstract class AbstractBuildForm {
return $this->wrap[$item][WRAP_SETUP_START] . $value . $this->wrap[$item][WRAP_SETUP_END];
}
/**
* @param $tag
* @param $value
* @param bool|false $flagOmitEmpty
* @return string
*/
public function wrapTag($tag, $value, $flagOmitEmpty = false) {
if ($flagOmitEmpty && $value === "")
return '';
// <div class="container-fluid"> >> </div>
$arr = explode(' ', $tag);
$closing = '</' . substr($arr[0], 1) . '>';
return $tag . $value . $closing;
}
/**
* @param array $htmlFormElementId
* @param $label
......@@ -798,21 +815,7 @@ abstract class AbstractBuildForm {
* @return mixed
*/
public function buildPill(array $formElement, $htmlFormElementId, $value) {
// save parent processed FE's
$tmpStore = $this->feSpecNative;
$sql = SQL_FORM_ELEMENT;
$this->feSpecNative = $this->db->sql($sql, ROW_REGULAR, [ 'yes', $this->formSpec["id"], 'native,container', $formElement['id'] ]);
HelperFormElement::explodeParameter($this->feSpecNative);
$html = $this->elements($this->store->getVar(SIP_RECORD_ID, STORE_SIP), FORM_ELEMENTS_NATIVE_SUBRECORD);
// restore parent processed FE's
$this->feSpecNative = $tmpStore;
return $html;
return $value;
}
/**
......@@ -828,7 +831,7 @@ abstract class AbstractBuildForm {
// <fieldset>
$html = '<fieldset ' . $this->getAttribute('name', $htmlFormElementId) . '>';
if($formElement['label'] !== '') {
if ($formElement['label'] !== '') {
$html .= '<legend>' . $formElement['label'] . '</legend>';
}
......@@ -836,7 +839,7 @@ abstract class AbstractBuildForm {
// child FE's
$sql = SQL_FORM_ELEMENT;
$this->feSpecNative = $this->db->sql($sql, ROW_REGULAR, [ 'yes', $this->formSpec["id"], 'native,container', $formElement['id'] ]);
$this->feSpecNative = $this->db->sql($sql, ROW_REGULAR, ['yes', $this->formSpec["id"], 'native,container', $formElement['id']]);
HelperFormElement::explodeParameter($this->feSpecNative);
$html .= $this->elements($this->store->getVar(SIP_RECORD_ID, STORE_SIP), FORM_ELEMENTS_NATIVE_SUBRECORD);
......@@ -849,9 +852,8 @@ abstract class AbstractBuildForm {
$this->feSpecNative = $tmpStore;
return $html;
return $html;
}
}
\ No newline at end of file
......@@ -9,9 +9,12 @@
namespace qfq;
use qfq;
use qfq\exceptions\UserException;
require_once(__DIR__ . '/../qfq/Constants.php');
require_once(__DIR__ . '/../qfq/helper/OnArray.php');
require_once(__DIR__ . '/../qfq/AbstractBuildForm.php');
require_once(__DIR__ . '/../qfq/exceptions/UserException.php');
/**
* Class BuildFormBootstrap
......@@ -23,18 +26,21 @@ class BuildFormBootstrap extends AbstractBuildForm {
*
*/
public function fillWrap() {
$this->wrap[WRAP_SETUP_TITLE][WRAP_SETUP_START] = '<h3>';
$this->wrap[WRAP_SETUP_TITLE][WRAP_SETUP_END] = '</h3>';
$this->wrap[WRAP_SETUP_TITLE][WRAP_SETUP_START] = '<div class="row hidden-xs"><div class="col-md-12"><h1>';
$this->wrap[WRAP_SETUP_TITLE][WRAP_SETUP_END] = '</h1></div></div>';
$this->wrap[WRAP_SETUP_ELEMENT][WRAP_SETUP_START] = '<p>';
$this->wrap[WRAP_SETUP_ELEMENT][WRAP_SETUP_END] = '</p>';
$this->wrap[WRAP_SETUP_ELEMENT][WRAP_SETUP_START] = '<div class="form-group">';
$this->wrap[WRAP_SETUP_ELEMENT][WRAP_SETUP_END] = '</div>';
$this->wrap[WRAP_SETUP_LABEL][WRAP_SETUP_START] = '';
$this->wrap[WRAP_SETUP_LABEL][WRAP_SETUP_END] = '';
$this->wrap[WRAP_SETUP_INPUT][WRAP_SETUP_START] = '';
$this->wrap[WRAP_SETUP_INPUT][WRAP_SETUP_END] = '';
$this->wrap[WRAP_SETUP_NOTE][WRAP_SETUP_START] = '';
$this->wrap[WRAP_SETUP_NOTE][WRAP_SETUP_END] = '';
$this->wrap[WRAP_SETUP_LABEL][WRAP_SETUP_START] = '<div class="col-md-2">';
$this->wrap[WRAP_SETUP_LABEL][WRAP_SETUP_END] = '</div>';
$this->wrap[WRAP_SETUP_INPUT][WRAP_SETUP_START] = '<div class="col-md-6">';
$this->wrap[WRAP_SETUP_INPUT][WRAP_SETUP_END] = '</div>';
$this->wrap[WRAP_SETUP_NOTE][WRAP_SETUP_START] = '<div class="col-md-4">';
$this->wrap[WRAP_SETUP_NOTE][WRAP_SETUP_END] = '</div>';
$this->wrap[WRAP_SETUP_SUBRECORD][WRAP_SETUP_START] = '<div class="col-md-12">';
$this->wrap[WRAP_SETUP_SUBRECORD][WRAP_SETUP_END] = '</div>';
$this->wrap[WRAP_SETUP_IN_FIELDSET][WRAP_SETUP_START] = '<p>';
$this->wrap[WRAP_SETUP_IN_FIELDSET][WRAP_SETUP_END] = '</p>';
......@@ -61,23 +67,100 @@ class BuildFormBootstrap extends AbstractBuildForm {
public function head() {
$html = '';
$html .= $this->wrapItem(WRAP_SETUP_TITLE, $this->formSpec['title'], true);
$html .= '<form action="?" method="post" target="_top" accept-charset="UTF-8">';
// $html .= $this->wrapItem(WRAP_SETUP_TITLE, $this->formSpec['title'], true);
// $html .= '<form action="?" method="post" target="_top" accept-charset="UTF-8">';
$html .= '<div class="container-fluid">'; //Whole FORM
$html .= '<div class="row hidden-xs"><div class="col-md-12"><h2>' . $this->formSpec['title'] . '</h2></div></div>'; // Form Title
$pill = $this->buildPillNavigation(OnArray::filter($this->feSpecNative, 'type', 'pill'));
$button = $this->buildButtons();
$html .= $this->wrapTag('<div class="row">', $pill . $button);
$html .= '<form class="form-horizontal" action="?" method="post" target="_top" accept-charset="UTF-8">';
$html .= '<div class="tab-content">';
return $html;
}
/**
* @param $htmlFormElementId
* @param $formElement
* @param $value
* @param $pillArray
* @return string
* @throws UserException
*/
public function wrapElement($htmlFormElementId, $formElement, $value) {
private function buildPillNavigation($pillArray) {
$html = '';
$pillButton = '';
$pillDropdown = '';
if ($pillArray == null)
return '';
$maxVisiblePill = (isset($this->formSpec['maxVisiblePill']) && $this->formSpec['maxVisiblePill'] !== '') ? $this->formSpec['maxVisiblePill'] : 1000;
// Iterate over all 'pill'
$ii = 0;
$active = 'class="active"';
foreach ($pillArray as $formElement) {
$ii++;
if ($formElement['name'] === '' || $formElement['label'] === '') {
$this->store->setVar(SYSTEM_FORM_ELEMENT, $formElement['name'] . ' / ' . $formElement['id'], STORE_SYSTEM);
$this->store->setVar(SYSTEM_FORM_ELEMENT_COLUMN, 'name, label', STORE_SYSTEM);
throw new UserException("Field 'name' and/or 'label' are empty", ERROR_NAME_LABEL_EMPTY);
}
$a = '<a href="#' . $this->createAnker($formElement['id']) . '" data-toggle="tab">' . $formElement['name'] . '</a>';
if ($ii <= $maxVisiblePill) {
$pillButton .= '<li role="presentation" ' . $active . '>' . $a . '</li>';
} else {
$pillDropdown .= '<li>' . $a . '</li>';
}
$active = '';
}
// Pill Dropdown necessary?
if ($ii > $maxVisiblePill) {
$html = $this->wrapTag('<ul class="dropdown-menu">', $pillDropdown, true);
$html .= '<a class="dropdown-toggle" data-toggle="dropdown" href="#" role="button">more <span class="caret"></span></a>';
}
$html = $this->wrapTag('<ul id="myTabs" class="nav nav-pills" role="tablist">', $pillButton . $html);
$html = $this->wrapTag('<div class="col-md-10">', $html);
return $html;
}
/**
* Create an identifier for the pill navigation menu
*
* @param $id
* @return string
*/
private function createAnker($id) {
return $this->formSpec['name'] . '_' . $id;
}
private function buildButtons() {
$html = <<<BUTTONS
<div class="col-md-2 ">
<div class="btn-toolbar pull-right" role="toolbar">
<div class="btn-group" role="group">
<button type="button" class="btn btn-default navbar-btn"><span class="glyphicon glyphicon-ok"></span></button>
<button type="button" class="btn btn-default navbar-btn"><span class="glyphicon glyphicon-remove"></span></button>
</div>
<div class="btn-group" role="group">
<button type="button" class="btn btn-default navbar-btn"><span class="glyphicon glyphicon-trash"></span></button>
</div>
<div class="btn-group" role="group">
<button type="button" class="btn btn-default navbar-btn"><span class="glyphicon glyphicon-plus"></span></button>
</div>
</div>
</div>
BUTTONS;
return $html;
}
......@@ -87,13 +170,91 @@ class BuildFormBootstrap extends AbstractBuildForm {
public function tail() {
$html = '';
$sip = $this->store->getVar(CLIENT_SIP, STORE_CLIENT);
$sipName = CLIENT_SIP;
$html .= $this->buildHidden(array(), $sipName, $sip);
// $sip = $this->store->getVar(CLIENT_SIP, STORE_CLIENT);
// $sipName = CLIENT_SIP;
// $html .= $this->buildHidden(array(), $sipName, $sip);
// TODO: bootstrap. See BuildFormTable.tail()
$html .= '</div> <!--class="tab-content" -->'; // <div class="tab-content">
$html .= '</form>'; // <form class="form-horizontal" ...
$html .= '</div>'; // <div class="container-fluid">
return $html;
}
/**
* @param $htmlFormElementId
* @param $formElement
* @param $value
* @return string
*/
public function wrapElement($htmlFormElementId, $formElement, $value) {
$html = '';
// Construct Marshaller Name
$buildElementFunctionName = 'build' . $this->buildElementFunctionName[$formElement['type']];
if ($formElement['type'] === 'subrecord') {
// subrecord in render='table' are outside the table
$html .= $this->wrapItem(WRAP_SETUP_ELEMENT, $this->wrapItem(WRAP_SETUP_SUBRECORD, $formElement['label']));
$html .= $this->wrapItem(WRAP_SETUP_ELEMENT, $this->wrapItem(WRAP_SETUP_SUBRECORD, $this->$buildElementFunctionName($formElement, $htmlFormElementId, $value)));
$html .= $this->wrapItem(WRAP_SETUP_ELEMENT, $this->wrapItem(WRAP_SETUP_SUBRECORD, $formElement['note']));
} else {
if ($formElement['nestedInFieldSet'] === 'no') {
$html .= $this->wrap[WRAP_SETUP_ELEMENT][WRAP_SETUP_START];
$htmlElement = $this->$buildElementFunctionName($formElement, $htmlFormElementId, $value);
if ($formElement['type'] == 'pill') {
$html = '<div role="tabpanel" class="tab-pane active" id="' . $this->createAnker($formElement['id']) . '">';
$html .= $htmlElement;
$html .= '</div>';
} else {
$html .= $this->wrapItem(WRAP_SETUP_LABEL, $this->buildLabel($htmlFormElementId, $formElement['label']));
$html .= $this->wrapItem(WRAP_SETUP_INPUT, $htmlElement);
}
$html .= $this->wrapItem(WRAP_SETUP_NOTE, $formElement['note']);
$html .= $this->wrap[WRAP_SETUP_ELEMENT][WRAP_SETUP_END];
} else {
$html .= $this->wrapItem(WRAP_SETUP_IN_FIELDSET, $this->buildLabel($htmlFormElementId, $formElement['label']));
$html .= $this->wrapItem(WRAP_SETUP_IN_FIELDSET, $this->$buildElementFunctionName($formElement, $htmlFormElementId, $value));
if ($formElement['note'] !== '')
$html .= $this->wrapItem(WRAP_SETUP_IN_FIELDSET, $formElement['note']);
}
}
return $html;
}
/**
* @param array $formElement
* @param $htmlFormElementId
* @param $value
* @return mixed
*/
public function buildPill(array $formElement, $htmlFormElementId, $value) {
// save parent processed FE's
$tmpStore = $this->feSpecNative;
// $html = '<div role="tabpanel" class="tab-pane active" id="' . $this->createAnker($formElement['id']) .'">';
// child FE's
$sql = SQL_FORM_ELEMENT;
$this->feSpecNative = $this->db->sql($sql, ROW_REGULAR, ['yes', $this->formSpec["id"], 'native,container', $formElement['id']]);
HelperFormElement::explodeParameter($this->feSpecNative);
$html = $this->elements($this->store->getVar(SIP_RECORD_ID, STORE_SIP), FORM_ELEMENTS_NATIVE_SUBRECORD);
// $html .= '</div>';
// restore parent processed FE's
$this->feSpecNative = $tmpStore;
return $html;
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment