Merge branch 'update-helperform' into develop

This commit is contained in:
Marion Muszynski 2017-01-27 13:09:35 +01:00
commit e49326dd96

View File

@ -166,7 +166,11 @@ class HelperFormBootstrap{
}
public static function generateInput($input) {
echo $this->addInput($input);
$this->addInput($input);
$result = $this->_html;
$this->_html = '';
return $result;
}
public function addJs($js){
@ -214,6 +218,9 @@ class HelperFormBootstrap{
$this->inputSwitch($input);
break;
case 'textarea':
$this->inputTextarea($input);
break;
case 'rte':
$this->inputRte($input);
break;
case 'file':
@ -314,24 +321,24 @@ class HelperFormBootstrap{
}
public function inputSimpleDate($p = array()) {
if($p['period']) {
if(isset($p['period']) && $p['period']) {
$this->_html .='<div class="'.(isset($p['class-from'])?$p['class-from']:'').'">';
}
$this->_html .='
<div class="form-group">
'.(isset($p['label']) && $p['label'] ?'<label class="'.$p['label-class'].'" for="'.(isset($p['id']) ? $p['id'] : $p['name']).'">'.$p['label'].'</label>':'').'
<div class="input-group">
'.(isset($p['label']) && $p['label'] ?'<label class="'.(isset($p['label-class']) && $p['label-class'] ?$p['label-class']:'').'" for="'.(isset($p['id']) ? $p['id'] : $p['name']).'">'.$p['label'].'</label>':'').'
<div class="input-group '.(isset($p['input-class'])?$p['input-class']:'').'">
'.(isset($p['before']) && $p['before'] ?'<div class="input-group-addon">'.$p['before'].'</div>':'').'
<input type="text" class="form-control" value="'.(isset($p['value'])?$p['value']:'').'" name="'.$p['name'].'" id="'.(isset($p['id']) ? $p['id'] : $p['name']).'" placeholder="'.((isset($p['placeholder']) && $p['placeholder'])?$p['placeholder']:'').'">
'.(isset($p['after']) && $p['after'] ?'<div class="input-group-addon">'.$p['after'].'</div>':'').'
</div>
</div>';
if($p['period']) {
if(isset($p['period']) && $p['period']) {
$this->_html .='</div>
<div class="'.(isset($p['class-to'])?$p['class-to']:'').'">
<div class="form-group">
'.(isset($p['label-to']) && $p['label-to'] ?'<label class="'.$p['label-class'].'" for="'.(isset($p['id-to']) ? $p['id-to'] : $p['name-to']).'">'.$p['label-to'].'</label>':'').'
<div class="input-group">
'.(isset($p['label-to']) && $p['label-to'] ?'<label class="'.(isset($p['label-class']) && $p['label-class'] ?$p['label-class']:'').'" for="'.(isset($p['id-to']) ? $p['id-to'] : $p['name-to']).'">'.$p['label-to'].'</label>':'').'
<div class="input-group '.(isset($p['input-to-class'])?$p['input-to-class']:'').'">
'.(isset($p['before-to']) && $p['before-to'] ?'<div class="input-group-addon">'.$p['before-to'].'</div>':'').'
<input type="text" class="form-control" value="'.(isset($p['value-to'])?$p['value-to']:'').'" name="'.$p['name-to'].'" id="'.(isset($p['id-to']) ? $p['id-to'] : $p['name-to']).'" placeholder="'.((isset($p['placeholder-to']) && $p['placeholder-to'])?$p['placeholder-to']:'').'">
'.(isset($p['after-to']) && $p['after-to'] ?'<div class="input-group-addon">'.$p['after-to'].'</div>':'').'
@ -372,7 +379,7 @@ class HelperFormBootstrap{
public function inputUploadImage($p = array()) {
if(isset($p['lang']) && $p['lang']) {
//return $this->inputUploadImageL($p);
return $this->inputUploadImageL($p);
}
$this->_html .='
<div class="form-group">
@ -456,6 +463,105 @@ class HelperFormBootstrap{
</script>';
}
public function inputUploadImageL($p = array()) {
$defaultLanguage = (isset($p['default_language']) && $p['default_language'])? $p['default_language'] : 2;
$this->_html .='
<div class="form-group">
<label class="control-label '.(isset($p['label-class']) ? $p['label-class'] : '').'">
<span class="pull-left">'.$p['label'].'</span>'
.$this->displayFlags($p['languages'], $defaultLanguage, $p['id_langs'], $p['name'],true,false,$p['link_flag_img']).'
<div class="clearfix"></div>
</label>';
//$this->_html .= $this->displayFlags($p['languages'], $defaultLanguage, $p['id_langs'], $p['name'],true,false,$p['link_flag_img'],'table');
//$this->_html .= '
$this->_js .= '
<script>
$(function() {';
foreach ($p['languages'] as $language) {
$this->_html .='
<div class="'.(isset($p['input-class']) ? $p['input-class'] : '').'" style="display: '.($language['id_lang'] == $defaultLanguage ? 'block' : 'none').';" id="'.$p['name'].'_'.$language['id_lang'].'">
<div class="input-group image-preview" id="'.$p['id'].'_'.$language['id_lang'].'">
<input type="text" class="form-control image-preview-filename" disabled="disabled">
<span class="input-group-btn">
<button type="button" class="btn btn-default image-preview-clear" style="display:none;">
<span class="glyphicon glyphicon-remove"></span> Clear
</button>
<div class="btn btn-default image-preview-input">
<span class="glyphicon glyphicon-folder-open"></span>
<span class="image-preview-input-title">Ouvrir</span>
<input type="file" accept="image/png, image/jpeg" name="'.$p['name'].'_'.$language['id_lang'].'"/>
</div>
</span>
</div>';
if(isset($p['url_to_check']) && !empty($p['url_to_check']) && file_exists($p['url_to_check'].$p['name_img'].'_'.$language['id_lang'].'.jpg')) {
$this->_html .='<p><a href="'.$p['url_imgs'].$p['name_img'].'_'.$language['id_lang'].'.jpg" onclick="window.open(this.href); return false;"><span class="anticon anticon-image"></span> Image '.$language['iso_code'].'</a></p>';
}
$this->_html .='</div>';
$this->_js .= '
$(document).on(\'click\', \'#close-preview_'.$p['id'].'_'.$language['id_lang'].'\', function(){
$(\'#'.$p['id'].'_'.$language['id_lang'].'\').popover(\'hide\');
$(\'#'.$p['id'].'_'.$language['id_lang'].'\').hover(
function () {
$(\'#'.$p['id'].'_'.$language['id_lang'].'\').popover(\'show\');
},
function () {
$(\'#'.$p['id'].'_'.$language['id_lang'].'\').popover(\'hide\');
}
);
});
var closebtn = $(\'<button/>\', {
type:"button",
text: \'x\',
id: \'close-preview_'.$p['id'].'_'.$language['id_lang'].'\',
style: \'font-size: initial;\',
});
closebtn.attr("class","close pull-right");
$(\'#'.$p['id'].'_'.$language['id_lang'].'\').popover({
trigger:\'manual\',
html:true,
title: "<strong>Preview</strong>"+$(closebtn)[0].outerHTML,
content: "There\'s no image",
placement:\'bottom\'
});
$(\'#'.$p['id'].'_'.$language['id_lang'].' .image-preview-clear\').click(function(){
$(\'#'.$p['id'].'_'.$language['id_lang'].'\').attr("data-content","").popover(\'hide\');
$(\'#'.$p['id'].'_'.$language['id_lang'].' .image-preview-filename\').val("");
$(\'#'.$p['id'].'_'.$language['id_lang'].' .image-preview-clear\').hide();
$(\'#'.$p['id'].'_'.$language['id_lang'].' .image-preview-input input:file\').val("");
$("#'.$p['id'].'_'.$language['id_lang'].' .image-preview-input-title").text("Browse");
});
// Create the preview image
$("#'.$p['id'].'_'.$language['id_lang'].' .image-preview-input input:file").change(function (){
var img = $(\'<img/>\', {
id: \'dynamic\',
width:250,
height: \'auto\'
});
var file = this.files[0];
var reader = new FileReader();
reader.onload = function (e) {
$("#'.$p['id'].'_'.$language['id_lang'].' .image-preview-input-title").text("Change");
$("#'.$p['id'].'_'.$language['id_lang'].' .image-preview-clear").show();
$("#'.$p['id'].'_'.$language['id_lang'].' .image-preview-filename").val(file.name);
img.attr(\'src\', e.target.result);
$("#'.$p['id'].'_'.$language['id_lang'].'").attr("data-content",$(img)[0].outerHTML).popover("show");
}
reader.readAsDataURL(file);
});';
}
$this->_html .= '<div class="clearfix"></div>
'.((isset($p['help']) && $p['help']) ? '<span id="helpBlock" class="help-block">'.$p['help'].'</span>' : '').'
</div>';
$this->_js.='
});
</script>';
}
public function inputSwitch($p = array()) {
$this->_html .='
<div class="form-group '.(isset($p['class-group'])?$p['class-group']:'').'">
@ -463,46 +569,54 @@ class HelperFormBootstrap{
<div class="'.(isset($p['input-class']) ? $p['input-class'] : '').'">
<div class="checkbox input-switch">
<label>
<input type="checkbox" name="'.$p['name'].'" class="js-switch" '.(isset($p['checked']) && $p['checked']?'checked="checked"':'').' /> '.$p['title'].'
<input type="checkbox" name="'.$p['name'].'" class="js-switch" value="1" '.(isset($p['checked']) && $p['checked']?'checked="checked"':'').' /> '.(isset($p['title'])?$p['title']:'').'
</label>
</div>
</div>
</div>';
//<input type="checkbox" name="'.$p['name'].'" class="js-switch" '.(isset($p['checked']) && $p['checked']?'checked="checked"':'').' /> '.$p['title'].'
}
public function inputText($p = array()){
if (isset($p['lang']) && $p['lang'] === true)
if (isset($p['lang']) && $p['lang'] === true) {
return $this->inputTextL($p);
}
$default_value = (isset($p['default']) ? $p['default'] : '');
$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 text' . (isset($p['class']) && $p['class'] ? ' ' . $p['class'] : '') . '">
<input type="text" ' . $disabled . ' name="'.$p['name'].'" id="'.(isset($p['id']) ? $p['id'] : $p['name']).'" value="'.($this->_object ? $this->_object->{$p['name']} : $default_value ).'"'.(isset($p['css']) ? 'style="'.$p['css'].'"' : '').'/>
' . ((isset($p['required']) && $p['required']) ? '<sup> *</sup>' : '') . '
' . ((isset($p['hint']) && $p['hint']) ? '<p class="hint">'.$p['hint'].'</p>' : '') . '
' . ((isset($p['help']) && $p['help']) ? '<p class="help">'.$p['help'].'</p>' : '') . '
$this->_html .= '
<div class="form-group '.(isset($p['class-group'])?$p['class-group']:'').'">
<label class="control-label '.(isset($p['label-class']) ? $p['label-class'] : '').'">'.$p['label']. ((isset($p['required']) && $p['required']) ? '<sup> *</sup>' : '') . '</label>
<div class="'.(isset($p['input-class']) ? $p['input-class'] : '').'">
<input type="text" class="form-control" ' . $disabled . ' name="'.$p['name'].'" id="'.(isset($p['id']) ? $p['id'] : $p['name']).'" value="'.($this->_object ? $this->_object->{$p['name']} : $default_value ).'"'.(isset($p['css']) ? 'style="'.$p['css'].'"' : '').'/>
' . ((isset($p['help']) && $p['help']) ? '<span id="helpBlock" class="help-block">'.$p['help'].'</span>' : '') . '
' . ((isset($p['html']) && $p['html']) ? $p['html'] : '') . '
</div>';
</div>
</div>';
}
public function inputTextL($p = array()){
$default_value = (isset($p['default']) ? $p['default'] : '');
$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){
$default_lang = (is_array($p['default'])) ? $p['default'][(int)$language['id_lang']] : $default_value;
$this->_html .= '
<div class="lang_'.$language['id_lang'].'" style="display: '.($language['id_lang'] == $this->_defaultFormLanguage ? 'block' : 'none').'; float: left;">
<input type="text" name="'.$p['name'].'_'.$language['id_lang'].'" id="'.(isset($p['id']) ? $p['id'] : $p['name']).'_'.$language['id_lang'].'" value="'.($this->_object ? $this->_object->{$p['name']}[(int)$language['id_lang']] : $default_lang).'"' . (isset($p['css']) ? 'style="'.$p['css'].'"' : '') . '>
' . ((isset($p['required']) && $p['required']) ? '<sup> *</sup>' : '') . '
' . ((isset($p['hint']) && $p['hint']) ? '<p class="hint">'.$p['hint'].'</p>' : '') . '
' . ((isset($p['html']) && $p['html']) ? $p['html'] : '') . '
</div>';
}
$defaultLanguage = $p['default_language'] ? $p['default_language'] : 2;
$this->_html .= '
<p class="clear"></p>
</div>';
<div class="form-group">
<label class="control-label '.(isset($p['label-class']) ? $p['label-class'] : '').'">
<span class="pull-left">'.$p['label'].'</span>
'.$this->displayFlags($p['languages'], $defaultLanguage, $p['id_langs'], $p['name'],true,false,$p['link_flag_img']).'
<div class="clearfix"></div>
</label>
<div class="'.(isset($p['input-class']) ? $p['input-class'] : '').'">';
foreach ($p['languages'] as $language) {
$default_lang = (is_array($p['default'])) ? $p['default'][(int)$language['id_lang']] : $default_value;
$this->_html .= '
<div id="'.(isset($p['id']) ? $p['id'] : $p['name']).'_'.$language['id_lang'].'" style="display: '.($language['id_lang'] == $defaultLanguage ? 'block' : 'none').';">
<input class="form-control" type="text" name="'.$p['name'].'_'.$language['id_lang'].'" id="'.(isset($p['id']) ? $p['id'] : $p['name']).'_'.$language['id_lang'].'" value="'.($this->_object ? $this->_object->{$p['name']}[(int)$language['id_lang']] : $default_lang).'" />
</div>';
}
$this->_html .= '<div class="clearfix"></div>
'.((isset($p['help']) && $p['help']) ? '<span id="helpBlock" class="help-block">'.$p['help'].'</span>' : '').'
</div>
</div>';
}
public function inputFile($p = array()){
@ -560,21 +674,21 @@ class HelperFormBootstrap{
</div>';
}
public function inputBool($p = array()){
public function inputBool($p = array()) {
$checked = ((isset($p['default']) && $p['default']) ? $p['default'] : false);
if ($this->_object)
$checked = $this->_object->{$p['name']};
$this->_html .= '<label' . (isset($p['class']) && $p['class'] ? ' class="' . $p['class'] . '"' : '') . '>'.$p['label'].'</label>
<div class="margin-form bool' . (isset($p['class']) && $p['class'] ? ' ' . $p['class'] : '') . '">
<div id="'.$p['name'].'" style="float: left;">
<input type="radio" name="'.$p['name'].'" value="1" id="'.$p['name'].'_on"'.($checked ? ' checked="checked"' : '').'/>' . (isset($p['label_on']) && $p['label_on'] ? ' <label class="radio_label" for="'.$p['name'].'_on">'.$p['label_on'].'</label>' : '') . '
<input type="radio" name="'.$p['name'].'" value="0" id="'.$p['name'].'_off"'.($checked ? '' : ' checked="checked"').'/>' . (isset($p['label_off']) && $p['label_off'] ? ' <label class="radio_label" for="'.$p['name'].'_off">'.$p['label_off'].'</label>' : '') . '
</div>
<div class="clear"></div>
' . ((isset($p['hint']) && $p['hint']) ? '<p class="small">'.$p['hint'].'</p>' : '') . '
' . ((isset($p['html']) && $p['html']) ? $p['html'] : '') . '
<div class="clear"></div>
</div>';
$this->_html .= '
<div class="form-group">
<label class="control-label ' . (isset($p['label-class']) && $p['label-class'] ? $p['label-class'] : '') . '">'.$p['label'].' </label>
<div class="' . (isset($p['input-class']) && $p['input-class'] ? $p['input-class'] : '') . '">
<label class="radio-inline" for="'.$p['name'].'_on">
<input type="radio" name="'.$p['name'].'" value="1" id="'.$p['name'].'_on"'.($checked ? ' checked="checked"' : '').' /> '.(isset($p['label_on']) && $p['label_on'] ?$p['label_on']:'').'
</label>
<label class="radio-inline" for="'.$p['name'].'_off">
<input type="radio" name="'.$p['name'].'" value="0" id="'.$p['name'].'_off"'.($checked ? '' : ' checked="checked"').'/> '. (isset($p['label_off']) && $p['label_off'] ?$p['label_off']:'').'
</label>
<div class="clearfix"></div>
</div>
</div>';
}
public function inputCheckbox($p = array()){
@ -717,4 +831,27 @@ class HelperFormBootstrap{
'.$message.'
</div>';
}
public function displayFlags($languages, $default_language, $ids, $id, $return = false, $use_vars_instead_of_ids = false, $link_flag_img = "../img/l/", $display ='block')
{
if (sizeof($languages) == 1)
return false;
$output = '<div class="flags_custom">
<div class="displayed_flag">
<img src="'.$link_flag_img.$default_language.'.jpg" class="pointer" id="language_current_'.$id.'" onclick="toggleLanguageFlags(this);" alt="" />
</div>
<div id="languages_'.$id.'" class="language_flags language_flags_custom">
Choose language:<br />';
foreach ($languages as $language) {
if($use_vars_instead_of_ids)
$output .= '<img src="'.$link_flag_img.(int)($language['id_lang']).'.jpg" class="pointer" alt="'.$language['name'].'" title="'.$language['name'].'" onclick="changeLang(\''.$id.'\', '.$ids.', '.$language['id_lang'].', \''.$language['iso_code'].'\', \''.$display.'\');" /> ';
else
$output .= '<img src="'.$link_flag_img.(int)($language['id_lang']).'.jpg" class="pointer" alt="'.$language['name'].'" title="'.$language['name'].'" onclick="changeLang(\''.$id.'\', \''.$ids.'\', '.$language['id_lang'].', \''.$language['iso_code'].'\', \''.$display.'\');" /> ';
}
$output .= '</div></div>';
if ($return)
return $output;
echo $output;
}
}