This commit is contained in:
Michael RICOIS 2018-02-21 11:22:52 +01:00
parent 0336529ca5
commit 34521b21ec

View File

@ -1,7 +1,7 @@
<?php
class HelperFormBootstrap{
class HelperFormBootstrap
{
public $_forms = array();
public $_debug = false;
@ -21,7 +21,8 @@ class HelperFormBootstrap{
public $_dateTime;
public $_dateTimePicker;
public function __construct(){
public function __construct()
{
$this->_html = '';
$this->_object = NULL;
$this->_css = '';
@ -37,50 +38,76 @@ class HelperFormBootstrap{
$this->_dateTime = false;
}
public function renderStyle() {
$this->_style .= '<style type="text/css">
@import url("'.__PS_BASE_URI__.'adm/helpers/includes/jquery-ui-1.8.20.custom.css");
@import url("'.__PS_BASE_URI__.'adm/helpers/includes/css/bootstrap.min.css");
'.($this->_select2?'@import url("'.__PS_BASE_URI__.'adm/helpers/includes/css/select2.min.css");':'').'
'.($this->_dateTimePicker?'@import url("'.__PS_BASE_URI__.'adm/helpers/includes/css/bootstrap-datetimepicker.min.css");':'').'
'.($this->_inputTag?'@import url("'.__PS_BASE_URI__.'adm/helpers/includes/jquery.tagsinput.min.css");':'').'
'.($this->_inputSwitch?'@import url("'.__PS_BASE_URI__.'adm/helpers/includes/switchery.min.css");':'').'
@import url("'.__PS_BASE_URI__.'adm/helpers/includes/css/custom.css");
' . $this->_css . '
</style>';
public function renderStyle()
{
$this->_style .= '<style type="text/css">';
$this->_style .= '@import url("'.__PS_BASE_URI__.'adm/helpers/includes/jquery-ui-1.8.20.custom.css"); ';
$this->_style .= '@import url("'.__PS_BASE_URI__.'adm/helpers/includes/css/bootstrap.min.css"); ';
if ($this->_select2) {
$this->_style .= '@import url("'.__PS_BASE_URI__.'adm/helpers/includes/css/select2.min.css"); ';
}
if ($this->_dateTimePicker) {
$this->_style .= '@import url("'.__PS_BASE_URI__.'adm/helpers/includes/css/bootstrap-datetimepicker.min.css"); ';
}
if ($this->_inputTag) {
$this->_style .= '@import url("'.__PS_BASE_URI__.'adm/helpers/includes/jquery.tagsinput.min.css"); ';
}
if ($this->_inputSwitch) {
$this->_style .= '@import url("'.__PS_BASE_URI__.'adm/helpers/includes/switchery.min.css"); ';
}
$this->_style .= '@import url("'.__PS_BASE_URI__.'adm/helpers/includes/css/custom.css"); ';
$this->_style .= $this->_css;
$this->_style .= '</style>';
return $this->_style;
}
public function renderScript() {
$this->_script .= '<script type="text/javascript" src="'.__PS_BASE_URI__.'adm/helpers/includes/jquery.min.js"></script>';
public function renderScript()
{
$this->_script .= '<script type="text/javascript" src="'.__PS_BASE_URI__.'adm/helpers/includes/libs/jquery-3.3.1.min.js"></script>';
$this->_script .= '<script type="text/javascript" src="'.__PS_BASE_URI__.'adm/helpers/includes/jquery-ui.min.js"></script>';
$this->_script .= '<script type="text/javascript" src="'.__PS_BASE_URI__.'adm/helpers/includes/js/bootstrap.min.js"></script>';
if ($this->_select2) {
$this->_script .= '<script type="text/javascript" src="'.__PS_BASE_URI__.'adm/helpers/includes/js/select2.full.min.js"></script>';
}
if ($this->_dateTimePicker) {
$this->_script .= '<script type="text/javascript" src="'.__PS_BASE_URI__.'adm/helpers/includes/js/moment-with-locales.min.js"></script>';
$this->_script .= '<script type="text/javascript" src="'.__PS_BASE_URI__.'adm/helpers/includes/js/bootstrap-datetimepicker.min.js"></script>';
}
if ($this->_inputMask) {
$this->_script .= '<script type="text/javascript" src="'.__PS_BASE_URI__.'adm/helpers/includes/jquery.inputmask.bundle.min.js"></script>';
}
if ($this->_inputTag) {
$this->_script .= '<script type="text/javascript" src="'.__PS_BASE_URI__.'adm/helpers/includes/jquery.tagsinput.js"></script>';
}
if ($this->_inputSwitch) {
$this->_script .= '<script type="text/javascript" src="'.__PS_BASE_URI__.'adm/helpers/includes/switchery.min.js"></script>';
}
if ($this->_inputWizard) {
$this->_script .= '<script type="text/javascript" src="'.__PS_BASE_URI__.'adm/helpers/includes/jquery.smartWizard.js"></script>';
}
$this->_script .= '<script type="text/javascript" src="'.__PS_BASE_URI__.'adm/helpers/includes/js/custom.js"></script>';
$this->_script .= $this->_js;
return $this->_script;
}
public function renderForm($display = true, $action = NULL, $method = 'POST', $enctype = 'multipart/form-data'){
public function renderForm($display = true, $action = NULL, $method = 'POST', $enctype = 'multipart/form-data')
{
$this->generateForms();
$form = ($this->_messages ? implode("\n", $this->_messages) : '') . $this->_html;
@ -89,7 +116,8 @@ class HelperFormBootstrap{
return $form;
}
public function generateForms($action = NULL, $method = 'POST', $enctype = 'multipart/form-data'){
public function generateForms($action = NULL, $method = 'POST', $enctype = 'multipart/form-data')
{
if (!$this->_forms || empty($this->_forms))
return;
@ -180,22 +208,26 @@ class HelperFormBootstrap{
}
}
public function generateInput($input) {
public function generateInput($input)
{
$this->addInput($input);
$result = $this->_html;
$this->_html = '';
return $result;
}
public function addJs($js){
public function addJs($js)
{
$this->_js .= $js;
}
public function addCss($css){
public function addCss($css)
{
$this->_css .= $css;
}
public function addInput($input){
public function addInput($input)
{
if (!isset($input['type']))
return false;
$html = (isset($input['html']) && $input['html']) ? $input['html'] : NULL;
@ -266,7 +298,8 @@ class HelperFormBootstrap{
}
}
public function addAction($action){
public function addAction($action)
{
if (!isset($action['type']) || !isset($action['name']))
return false;
$css = (isset($action['css']) && $action['css']) ? $action['css'] : NULL;
@ -292,21 +325,25 @@ class HelperFormBootstrap{
}
}
public function closeSection(){
public function closeSection()
{
$this->_html .= '</div>';
}
public function openFieldset($legend, $id = NULL, $img_src='../img/admin/edit.gif', $css = false){
public function openFieldset($legend, $id = NULL, $img_src='../img/admin/edit.gif', $css = false)
{
$this->_html .= '<fieldset' . ($id ? ' id="' . $id . '"' : '') .' class="space"' . ($css ? ' style="' . $css . '"' : '') .'>
<legend><img src="'.$img_src.'" alt="" title="" /> '.$legend.'</legend>
<div class="fieldset_content">';
}
public function closeFieldset($legend, $img_src='../img/admin/edit.gif'){
public function closeFieldset($legend, $img_src='../img/admin/edit.gif')
{
$this->_html .= '</div></fieldset>';
}
public function inputTextAddon($p = array()) {
public function inputTextAddon($p = array())
{
$this->_html .='
<div class="form-group '.(isset($p['class-group'])?$p['class-group']:'').'">
'.(isset($p['label']) && $p['label'] ?'<label class="control-label '.$p['label-class'].'" for="'.(isset($p['id']) ? $p['id'] : $p['name']).'">'.$p['label'].'</label>':'').'
@ -319,7 +356,8 @@ class HelperFormBootstrap{
</div>';
}
public function inputSimpleText($p = array()) {
public function inputSimpleText($p = array())
{
$this->_html .='
<div class="form-group '.(isset($p['class-group'])?$p['class-group']:'').'">
<label class="control-label '.(isset($p['label-class']) ? $p['label-class'] : '').'" for="'.(isset($p['id']) ? $p['id'] : $p['name']).'">'.$p['label'].'</label>
@ -329,7 +367,8 @@ class HelperFormBootstrap{
</div>';
}
public function inputTag($p = array()) {
public function inputTag($p = array())
{
$this->_html .='
<div class="control-group">
<label class="control-label '.(isset($p['label-class']) ? $p['label-class'] : '').'" for="'.(isset($p['id']) ? $p['id'] : $p['name']).'">'.$p['label'].'</label>
@ -341,7 +380,8 @@ class HelperFormBootstrap{
</div>';
}
public function inputSimpleDate($p = array()) {
public function inputSimpleDate($p = array())
{
if(isset($p['period']) && $p['period']) {
$this->_html .='<div class="'.(isset($p['class-from'])?$p['class-from']:'').'">';
}
@ -371,7 +411,8 @@ class HelperFormBootstrap{
}
}
public function inputSelect2($p = array()) {
public function inputSelect2($p = array())
{
$all_opt = array();
$this->_html .='
<div class="form-group '.(isset($p['class-group'])?$p['class-group']:'').'">
@ -442,7 +483,8 @@ class HelperFormBootstrap{
}
}
public function inputUploadImage($p = array()) {
public function inputUploadImage($p = array())
{
if(isset($p['lang']) && $p['lang']) {
return $this->inputUploadImageL($p);
}
@ -528,7 +570,8 @@ class HelperFormBootstrap{
</script>';
}
public function inputUploadImageL($p = array()) {
public function inputUploadImageL($p = array())
{
$defaultLanguage = (isset($p['default_language']) && $p['default_language'])? $p['default_language'] : 2;
$this->_html .='
<div class="form-group">
@ -638,7 +681,8 @@ class HelperFormBootstrap{
</script>';
}
public function inputSwitch($p = array()) {
public function inputSwitch($p = array())
{
$this->_html .='
<div class="form-group '.(isset($p['class-group'])?$p['class-group']:'').'">
'.(isset($p['label'])?'<label class="control-label '.(isset($p['label-class']) ? $p['label-class'] : '').'">'.$p['label'].'</label>':'').'
@ -652,7 +696,8 @@ class HelperFormBootstrap{
</div>';
}
public function inputText($p = array()){
public function inputText($p = array())
{
if (isset($p['lang']) && $p['lang'] === true) {
return $this->inputTextL($p);
@ -670,7 +715,8 @@ class HelperFormBootstrap{
</div>';
}
public function inputTextL($p = array()){
public function inputTextL($p = array())
{
$default_value = (isset($p['default']) ? $p['default'] : '');
$defaultLanguage = isset($p['default_language']) ? $p['default_language'] : 2;
$this->_html .= '
@ -694,13 +740,15 @@ class HelperFormBootstrap{
</div>';
}
public function inputTextarea($p = array()){
public function inputTextarea($p = array())
{
if (isset($p['lang']) && $p['lang'] === true) {
return $this->inputTextareaL($p);
}
}
public function inputTextareaL($p = array()){
public function inputTextareaL($p = array())
{
$default_value = (isset($p['default']) ? $p['default'] : '');
$defaultLanguage = isset($p['default_language']) ? $p['default_language'] : 2;
$this->_html .= '
@ -723,7 +771,8 @@ class HelperFormBootstrap{
</div>';
}
public function inputFile($p = array()){
public function inputFile($p = array())
{
$this->_html .= '
<div class="form-group ' . (isset($p['class']) && $p['class'] ? ' ' . $p['class'] : '') . '">
<label class="control-label '.(isset($p['label-class']) ? $p['label-class'] : '').'">'.$p['label'].'</label>
@ -737,7 +786,8 @@ class HelperFormBootstrap{
</div>';
}
public function inputSelect($p = array()){
public function inputSelect($p = array())
{
$disabled = ((isset($p['disabled']) && $p['disabled']) ? 'disabled="disabled"' : '');
$this->_html .= '
<div class="form-group ' . (isset($p['class']) && $p['class'] ? ' ' . $p['class'] : '') . '">
@ -760,7 +810,8 @@ class HelperFormBootstrap{
</div>';
}
public function inputSelectStyled($p = array()){
public function inputSelectStyled($p = array())
{
$disabled = ((isset($p['disabled']) && $p['disabled']) ? 'disabled="disabled"' : '');
$this->_html .= '<label' . (isset($p['class']) && $p['class'] ? ' class="' . $p['class'] . '"' : '') . '>'.$p['label'].'</label>
<div class="margin-form' . (isset($p['class']) && $p['class'] ? ' ' . $p['class'] : '') . '">
@ -783,7 +834,8 @@ class HelperFormBootstrap{
</div>';
}
public function inputBool($p = array()) {
public function inputBool($p = array())
{
$checked = ((isset($p['default']) && $p['default']) ? $p['default'] : false);
$this->_html .= '
<div class="form-group">
@ -800,7 +852,8 @@ class HelperFormBootstrap{
</div>';
}
public function inputRadio($p = array()) {
public function inputRadio($p = array())
{
$this->_html .= '
<div class="form-group">
<label class="control-label ' . (isset($p['label-class']) && $p['label-class'] ? $p['label-class'] : '') . '">'.$p['label'].' </label>
@ -815,7 +868,8 @@ class HelperFormBootstrap{
</div>';
}
public function inputCheckbox($p = array()){
public function inputCheckbox($p = array())
{
$checked = ((isset($p['checked']) && $p['checked']) ? $p['checked'] : false);
if ($this->_object) {
$checked = $this->_object->{$p['name']};
@ -831,7 +885,8 @@ class HelperFormBootstrap{
</div>';
}
public function inputDate($p = array()){
public function inputDate($p = array())
{
$this->_dateTime = true;
$default = ((isset($p['default']) && $p['default']) ? $p['default'] : '');
$this->_html .= '<label' . (isset($p['class']) && $p['class'] ? ' class="' . $p['class'] . '"' : '') . '>'.$p['label'].'</label>
@ -845,7 +900,8 @@ class HelperFormBootstrap{
</div>';
}
public function inputRte($p = array()){
public function inputRte($p = array())
{
$this->_html .= '<label' . (isset($p['class']) && $p['class'] ? ' class="' . $p['class'] . '"' : '') . '>'.$p['label'].'</label>
<div class="margin-form translatable rte' . (isset($p['class']) && $p['class'] ? ' ' . $p['class'] : '') . '">';
foreach ($this->_languages AS $language){
@ -862,7 +918,8 @@ class HelperFormBootstrap{
</div>';
}
public function selectCheck($p = array()){
public function selectCheck($p = array())
{
$this->_selectCheck = true;
$size = ((isset($p['size']) && $p['size']) ? (int) $p['size'] : 5);
$this->_html .= '<label' . (isset($p['class']) && $p['class'] ? ' class="' . $p['class'] . '"' : '') . '>'.$p['label'].'</label>
@ -892,14 +949,16 @@ class HelperFormBootstrap{
}
public function inputButtonLink($p = array()){
public function inputButtonLink($p = array())
{
$css = isset($p['css']) && $p['css'] ? $p['css'] : false;
$class = isset($p['css']) && $p['css'] ? $p['css'] : false;
$this->_html .= '
<a '.($css ? 'style="'.$css.'"' : '').' href="'.$p['action'].'" class="button" name="'.$p['name'].'">'.$p['label'].'</a>
';
}
public function inputButton($p = array()){
public function inputButton($p = array())
{
$label = isset($p['label']) && $p['label'] ? $p['label'] : false;
$css = isset($p['css']) && $p['css'] ? $p['css'] : false;
$class = isset($p['class']) && $p['class'] ? $p['class'] : false;
@ -907,7 +966,8 @@ class HelperFormBootstrap{
<button '.($css ? 'style="'.$css.'"' : '').' type="submit" class="btn '.($class ? $class : '').'" name="'.$p['name'].'">'.$p['value'].'</button>
';
}
public function inputSubmit($p = array()){
public function inputSubmit($p = array())
{
$label = isset($p['label']) && $p['label'] ? $p['label'] : false;
$css = isset($p['css']) && $p['css'] ? $p['css'] : false;
$class = isset($p['class']) && $p['class'] ? $p['class'] : false;
@ -924,32 +984,39 @@ class HelperFormBootstrap{
}
}
public function inputHidden($p = array()){
public function inputHidden($p = array())
{
$id = ((isset($p['id']) && $p['id']) ? $p['id'] : $p['name']);
$this->_html .= '
<input type="hidden" id="'.$id.'" name="'.$p['name'].'" value="'.$p['value'].'" />';
}
public function displayError($message){
public function displayError($message)
{
$this->_messages[] = '<div class="error">' . $message . '</div>';
}
public function displayMessage($message){
public function displayMessage($message)
{
return $this->_messages[] = '<div class="message">' . $message . '</div>';
}
public function displayConf($message){
public function displayConf($message)
{
return $this->_messages[] = '<div class="conf">' . $message . '</div>';
}
public static function echoConfirmation($message){
public static function echoConfirmation($message)
{
echo '<div class="alert alert-success" role="alert">
<span class="glyphicon glyphicon-ok-sign" aria-hidden="true"></span>
<span class="sr-only">Success:</span>
'.$message.'
</div>';
}
public static function echoError($message){
public static function echoError($message)
{
echo '<div class="alert alert-danger" role="alert">
<span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span>
<span class="sr-only">Error:</span>
@ -957,17 +1024,22 @@ class HelperFormBootstrap{
</div>';
}
public static function displaySuccess($message){
public static function displaySuccess($message)
{
echo '<div class="col-sm-6 col-sm-offset-3 alert-custom alert-ok" style="margin-bottom: 10px;">
<i class="glyphicon glyphicon-ok"></i> <span class="text-alert">'.$message.'</span>
</div>';
}
public static function displayWarning($message){
public static function displayWarning($message)
{
echo '<div class="col-sm-6 col-sm-offset-3 alert-custom alert-warning" style="margin-bottom: 10px;">
<i class="anticon anticon-notification"></i> <span class="text-alert">'.$message.'</span>
</div>';
}
public static function displayErrors($message){
public static function displayErrors($message)
{
echo '<div class="col-sm-6 col-sm-offset-3 alert-custom alert-error" style="margin-bottom: 10px;">
<i class="anticon anticon-warning"></i> <span class="text-alert">'.$message.'</span>
</div>';