continuing

This commit is contained in:
Marion Muszynski 2016-12-28 17:16:50 +01:00
parent b6788e7bbd
commit 795aca43a7
3 changed files with 235 additions and 90 deletions

View File

@ -212,6 +212,9 @@ class HelperFormBootstrap{
$this->inputSwitch($input);
break;
case 'textarea':
$this->inputTextarea($input);
break;
case 'rte':
$this->inputRte($input);
break;
case 'file':
@ -368,7 +371,13 @@ class HelperFormBootstrap{
$this->_html .='
<div class="btn-group btn-group-sm" role="group">
'.((isset($p['option_all']) && $p['option_all'])?'<button type="button" class="select_all_for_'.(isset($p['id']) ? $p['id'] : $p['name']).' btn btn-default">Tout</button>':'').'
'.((isset($p['option_clear']) && $p['option_clear'])?'<button type="button" class="clear_for_'.(isset($p['id']) ? $p['id'] : $p['name']).' btn btn-default">Clear</button>':'').'
'.((isset($p['option_clear']) && $p['option_clear'])?'<button type="button" class="clear_for_'.(isset($p['id']) ? $p['id'] : $p['name']).' btn btn-default">Clear</button>':'');
if(isset($p['buttons']) && is_array($p['buttons'])){
foreach ($p['buttons'] as $button) {
$this->_html .='<button type="button" class="'.$button['class'].(isset($p['id']) ? $p['id'] : $p['name']).' btn btn-default">'.$button['label'].'</button>';
}
}
$this->_html .='
</div>';
}
@ -384,8 +393,14 @@ class HelperFormBootstrap{
allowClear: true
});
'.((isset($p['option_all']) && $p['option_all'])?'$(".select_all_for_'.(isset($p['id']) ? $p['id'] : $p['name']).'").on("click", function () { $("#'.(isset($p['id']) ? $p['id'] : $p['name']).'").select2().val(["'.(implode('","',$all_opt)).'"]).trigger("change"); });':'').'
'.((isset($p['option_clear']) && $p['option_clear'])?'$(".clear_for_'.(isset($p['id']) ? $p['id'] : $p['name']).'").on("click", function () { $("#'.(isset($p['id']) ? $p['id'] : $p['name']).'").select2().val(null).trigger("change"); });':'').'
});
'.((isset($p['option_clear']) && $p['option_clear'])?'$(".clear_for_'.(isset($p['id']) ? $p['id'] : $p['name']).'").on("click", function () { $("#'.(isset($p['id']) ? $p['id'] : $p['name']).'").select2().val(null).trigger("change"); });':'');
if(isset($p['buttons']) && is_array($p['buttons'])){
foreach ($p['buttons'] as $button) {
$this->_html .='$(".'.$button['class'].(isset($p['id']) ? $p['id'] : $p['name']).'").on("click", function () { $("#'.(isset($p['id']) ? $p['id'] : $p['name']).'").select2().val(['.$button['value'].']).trigger("change"); });';
}
}
$this->_html .='
});
</script>';
} else {
$this->_html .='<script>
@ -457,21 +472,49 @@ class HelperFormBootstrap{
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'] : '').'">'.$p['label'].' </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 .= $this->displayFlags($p['languages'], $defaultLanguage, $p['id_langs'], $p['name'],true,false,$p['link_flag_img']);
$this->_html .= '<div class="clearfix"></div>
'.((isset($p['help']) && $p['help']) ? '<span id="helpBlock" class="help-block">'.$p['help'].'</span>' : '').'
</div>
</div>';
}
public function inputTextarea($p = array()){
if (isset($p['lang']) && $p['lang'] === true) {
return $this->inputTextareaL($p);
}
}
public function inputTextareaL($p = array()){
$default_value = (isset($p['default']) ? $p['default'] : '');
$defaultLanguage = $p['default_language'] ? $p['default_language'] : 2;
$this->_html .= '
<div class="form-group">
<label class="control-label '.(isset($p['label-class']) ? $p['label-class'] : '').'">'.$p['label'].' </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>
<textarea class="form-control" rows="3" name="'.$p['name'].'_'.$language['id_lang'].'" id="'.(isset($p['id']) ? $p['id'] : $p['name']).'_'.$language['id_lang'].'" style="display: '.($language['id_lang'] == $defaultLanguage ? 'block' : 'none').';'.(isset($p['css']) ? $p['css'].'"' : '').'">'.str_replace('\r\n', "\n", ($this->_object ? $this->_object->{$p['name']}[(int)$language['id_lang']] : $default_lang)).'</textarea>
</div>';
}
$this->_html .= $this->displayFlags($p['languages'], $defaultLanguage, $p['id_langs'], $p['name'],true,false,$p['link_flag_img']);
$this->_html .= '<div class="clearfix"></div>
</div>
</div>';
}
public function inputBool($p = array()) {
@ -677,4 +720,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/")
{
if (sizeof($languages) == 1)
return false;
$output = '
<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">
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="changeLanguage(\''.$id.'\', '.$ids.', '.$language['id_lang'].', \''.$language['iso_code'].'\');" /> ';
else
$output .= '<img src="'.$link_flag_img.(int)($language['id_lang']).'.jpg" class="pointer" alt="'.$language['name'].'" title="'.$language['name'].'" onclick="changeLanguage(\''.$id.'\', \''.$ids.'\', '.$language['id_lang'].', \''.$language['iso_code'].'\');" /> ';
}
$output .= '</div>';
if ($return)
return $output;
echo $output;
}
}

View File

@ -176,9 +176,12 @@ function toggleLanguageFlags(elt)
// Kept for retrocompatibility only (out of AdminProducts & AdminCategories)
function changeLanguage(field, fieldsString, id_language_new, iso_code)
{
console.log(field);
console.log(fieldsString);
var fields = fieldsString.split('¤');
for (var i = 0; i < fields.length; ++i)
{
console.log(fields[i] + '_' + id_language);
getE(fields[i] + '_' + id_language).style.display = 'none';
getE(fields[i] + '_' + id_language_new).style.display = 'block';
getE('language_current_' + fields[i]).src = '../img/l/' + id_language_new + '.jpg';

View File

@ -795,47 +795,85 @@ class AdminPrivateSalesSales extends AdminTab {
// </div>';
// if(Configuration::get('PRIVATESALES_CARRIERFENCE')) {
$carriers = Db::getInstance()->ExecuteS('
SELECT c.`id_carrier`, IF(c.`name` = "0", "'.Configuration::get('PS_SHOP_NAME').'", c.`name`) AS `name`'.($this->cursale !== NULL? ', (
SELECT IFNULL(p.`id_sale`, NULL) FROM `'._DB_PREFIX_.'privatesale_carrier` p WHERE c.`id_carrier` = p.`id_carrier` AND p.`id_sale` = '.$this->cursale->id.'
) AS `id_sale`': '').'
FROM `'._DB_PREFIX_.'carrier` c
WHERE c.`deleted` != 1
');
$carriers = Db::getInstance()->ExecuteS('
SELECT c.`id_carrier`, IF(c.`name` = "0", "'.Configuration::get('PS_SHOP_NAME').'", c.`name`) AS `name`'.($this->cursale !== NULL? ', (
SELECT IFNULL(p.`id_sale`, NULL) FROM `'._DB_PREFIX_.'privatesale_carrier` p WHERE c.`id_carrier` = p.`id_carrier` AND p.`id_sale` = '.$this->cursale->id.'
) AS `id_sale`': '').'
FROM `'._DB_PREFIX_.'carrier` c
WHERE c.`deleted` != 1
');
$carriers_default = array(22, 87, 88, 89); // prod
// $carriers_default = array(22, 46, 47, 48); // dev
$carriers_default = array(22, 87, 88, 89); // prod
$carriers_default = array(22, 39, 40, 45); // local
// $carriers_default = array(22, 46, 47, 48); // dev
echo '<label>'.$this->l('Carriers:').'</label>
<div class="margin-form">
<div id="carriers" style="float: left;">
<select id="m_carriers" name="m_groups[]" multiple="multiple" size="5">
<option value=""></option>
<optgroup label="'.$this->l('Select one or more carriers:').'">';
if( Tools::getIsset('edit')) {
foreach($carriers as $carrier) {
echo '<option value="'.$carrier['id_carrier'].'"'.(isset($carrier['id_sale']) && $carrier['id_sale'] !== NULL?' selected="selected"':'').'>'.$carrier['name'].'</option>';
}
} else{
foreach($carriers as $carrier) {
echo '<option value="'.$carrier['id_carrier'].'"'.(in_array($carrier['id_carrier'], $carriers_default) ? ' selected="selected"':'').'>'.$carrier['name'].'</option>';
}
}
echo '
</optgroup>
</select>
</div>
<script type="text/javascript">
$(document).ready(function() {
$("#m_carriers").multiSelect({
selectAllText: "'.$this->l('Select all').'",
noneSelected: "&nbsp;",
oneOrMoreSelected: "*"
});
});
</script>
<div class="clear"></div>
</div>';
$id_carrier_options = array();
foreach ($carriers as $carrier) {
$id_carrier_options[$carrier['id_carrier']] = array(
'label' => $carrier['name'],
'value' => $carrier['id_carrier']
);
if(Tools::getIsset('edit') && (isset($carrier['id_sale']) && $carrier['id_sale'] !== NULL)) {
$id_carrier_options[$carrier['id_carrier']]['selected'] = true;
} elseif (!Tools::getIsset('edit') && in_array($carrier['id_carrier'], $carriers_default)) {
$id_carrier_options[$carrier['id_carrier']]['selected'] = true;
}
}
// Carriers
$input = array(
'type' => 'select2',
'label' => $this->l('Carriers :'),
'label-class' => 'text-left',
'select-class' => 'text-left',
'name' => 'm_carriers[]',
'id' => 'm_carriers',
'option_all' => true,
'option_clear' => true,
'options' => $id_carrier_options,
'multiple' => true,
'placeholder' => $this->l('Select one or more carriers...'),
'required' => true,
'buttons' => array(
array(
'label' => 'Default',
'value' => '"'.implode('","',$carriers_default).'"',
'class' => 'defaut_for_',
),
),
);
echo $helperForm->generateInput($input);
echo '<div class="clearfix"></div>';
// echo '<label>'.$this->l('Carriers:').'</label>
// <div class="margin-form">
// <div id="carriers" style="float: left;">
// <select id="m_carriers" name="m_groups[]" multiple="multiple" size="5">
// <option value=""></option>
// <optgroup label="'.$this->l('Select one or more carriers:').'">';
// if( Tools::getIsset('edit')) {
// foreach($carriers as $carrier) {
// echo '<option value="'.$carrier['id_carrier'].'"'.(isset($carrier['id_sale']) && $carrier['id_sale'] !== NULL?' selected="selected"':'').'>'.$carrier['name'].'</option>';
// }
// } else{
// foreach($carriers as $carrier) {
// echo '<option value="'.$carrier['id_carrier'].'"'.(in_array($carrier['id_carrier'], $carriers_default) ? ' selected="selected"':'').'>'.$carrier['name'].'</option>';
// }
// }
// echo '
// </optgroup>
// </select>
// </div>
// <script type="text/javascript">
// $(document).ready(function() {
// $("#m_carriers").multiSelect({
// selectAllText: "'.$this->l('Select all').'",
// noneSelected: "&nbsp;",
// oneOrMoreSelected: "*"
// });
// });
// </script>
// <div class="clear"></div>
// </div>';
// echo '<label>'.$this->l('Livraison seulement en France :').'</label>
// <div class="margin-form">
@ -856,59 +894,97 @@ class AdminPrivateSalesSales extends AdminTab {
// </div>
// </div>';
echo '<label>'.$this->l('Description:').'</label>
<div class="margin-form">';
foreach($this->_languages as $language) {
echo '<div id="description_'.$language['id_lang'].'" style="display: '.($language['id_lang'] == $this->_defaultFormLanguage ? 'block' : 'none').'; float: left;">
<textarea style="width: 500px; height: 150px;" name="description_'.$language['id_lang'].'">';
if($this->cursale !== NULL) {
echo htmlentities($this->cursale->description[$language['id_lang']]);
// echo htmlentities(utf8_decode($this->cursale->description[$language['id_lang']]));
}
echo '</textarea>
</div>';
}
$this->displayFlags($this->_languages, $this->_defaultFormLanguage, $divLangName, 'description');
echo '<div class="clear"></div>
</div>';
// Description
$input = array(
'type' => 'textarea',
'label' => $this->l('Description:'),
'lang' => true,
'name' => 'description',
'id' => 'description',
'required' => true,
'languages' => $this->_languages,
'id_langs' => $divLangName,
'link_flag_img' => '../img/l/',
'default' => ($this->cursale !== NULL?$this->cursale->description:'')
);
echo $helperForm->generateInput($input);
echo '<div class="clearfix"></div>';
echo '<label>'.$this->l('Video:').'</label>
<div class="margin-form">';
foreach($this->_languages as $language) {
echo '<div id="video_'.$language['id_lang'].'" style="display: '.($language['id_lang'] == $this->_defaultFormLanguage ? 'block' : 'none').'; float: left;">
<input type="text" name="video_'.$language['id_lang'].'"'.($this->cursale !== NULL? ' value="'.htmlentities($this->cursale->video[$language['id_lang']]).'"': '').' />';
echo '</div>';
}
$this->displayFlags($this->_languages, $this->_defaultFormLanguage, $divLangName, 'video');
echo '<div class="clear"></div>
<p>'.$this->l('Youtube full URL').'</p>
</div>';
// echo '<label>'.$this->l('Description:').'</label>
// <div class="margin-form">';
// foreach($this->_languages as $language) {
// echo '<div id="description_'.$language['id_lang'].'" style="display: '.($language['id_lang'] == $this->_defaultFormLanguage ? 'block' : 'none').'; float: left;">
// <textarea style="width: 500px; height: 150px;" name="description_'.$language['id_lang'].'">';
// if($this->cursale !== NULL) {
// echo htmlentities($this->cursale->description[$language['id_lang']]);
// // echo htmlentities(utf8_decode($this->cursale->description[$language['id_lang']]));
// }
// echo '</textarea>
// </div>';
// }
// $this->displayFlags($this->_languages, $this->_defaultFormLanguage, $divLangName, 'description');
// echo '<div class="clear"></div>
// </div>';
// Video
$input = array(
'type' => 'text',
'label' => $this->l('Video:'),
'lang' => true,
'name' => 'video',
'id' => 'video',
'required' => true,
'languages' => $this->_languages,
'id_langs' => $divLangName,
'link_flag_img' => '../img/l/',
'default' => ($this->cursale !== NULL?$this->cursale->video:'')
);
echo $helperForm->generateInput($input);
echo '<div class="clearfix"></div>';
// echo '<label>'.$this->l('Video:').'</label>
// <div class="margin-form">';
// foreach($this->_languages as $language) {
// echo '<div id="video_'.$language['id_lang'].'" style="display: '.($language['id_lang'] == $this->_defaultFormLanguage ? 'block' : 'none').'; float: left;">
// <input type="text" name="video_'.$language['id_lang'].'"'.($this->cursale !== NULL? ' value="'.htmlentities($this->cursale->video[$language['id_lang']]).'"': '').' />';
// echo '</div>';
// }
// $this->displayFlags($this->_languages, $this->_defaultFormLanguage, $divLangName, 'video');
// echo '<div class="clear"></div>
// <p>'.$this->l('Youtube full URL').'</p>
// </div>';
Module::hookExec('privatesales_edit', array('sale' => $this->cursale));
echo '</div>
<div class="col-sm-5 col-sm-offset-2" style="background:#eee;padding:20px; border-radius:7px;">
<h4 class="text-center"><span class="anticon anticon-images"></span> Images</h4>';
foreach($this->imagelist as $k => $v) {
echo '<label>'.$v[0].'</label>
<div class="margin-form">';
<div class="">';
foreach($this->_languages as $language) {
echo '<div id="img_'.$k.'_'.$language['id_lang'].'" style="display: '.($language['id_lang'] == $this->_defaultFormLanguage ? 'block' : 'none').'; float: left;">
<input type="file" name="img_'.$k.'_'.$language['id_lang'].'" />
<p>'.$this->l('Size:').' '.$v[1].'</p>';
<p class="help-block">'.$this->l('Size:').' '.$v[1].'</p>';
if($this->cursale !== NULL && file_exists(_PS_ROOT_DIR_.'/modules/privatesales/img/'.$this->cursale->id.'/'.$k.'_'.$language['id_lang'].'.jpg')) {
echo '<p><a href="'.__PS_BASE_URI__.'modules/privatesales/img/'.$this->cursale->id.'/'.$k.'_'.$language['id_lang'].'.jpg" onclick="window.open(this.href); return false;"> '.$this->l('Preview').'</a></p>';
}
echo '
</div>';
}
$this->displayFlags($this->_languages, $this->_defaultFormLanguage, $divLangName, 'img_'.$k);
$helperForm->displayFlags($this->_languages, $this->_defaultFormLanguage, $divLangName, 'img_'.$k);
echo '<div class="clear"></div>
</div>';
}
Module::hookExec('privatesales_edit', array('sale' => $this->cursale));
echo '<br class="clear" />
<div class="margin-form">
echo '</div>
<div class="clear"></div>
<div class="ln_solid-small"></div>
<div class="text-center">
<input type="hidden" name="id_sale" value="'.($this->cursale !== NULL? $this->cursale->id: '').'" />
<input type="submit" class="button" '.($this->cursale !== NULL ? 'disabled=disabled': '').' name="submitSaleAdd" value="'.$this->l('Add this sale').'" />
<input type="submit" class="button'.($this->cursale !== NULL? '': ' disable"').'" name="submitSaleUpdate" value="'.$this->l('Edit this sale').'"'.($this->cursale !== NULL? '': ' disabled="disabled"').' id="submitSaleUpdate" />
<input type="submit" class="btn btn-primary" '.($this->cursale !== NULL ? 'disabled=disabled': '').' name="submitSaleAdd" value="'.$this->l('Add this sale').'" />
<input type="submit" class="btn btn-primary'.($this->cursale !== NULL? '': ' disable"').'" name="submitSaleUpdate" value="'.$this->l('Edit this sale').'"'.($this->cursale !== NULL? '': ' disabled="disabled"').' id="submitSaleUpdate" />
</div>';
echo '</form>