Merge branch 'ticket-11201-updateAntCreationCategory' into develop

This commit is contained in:
Marion Muszynski 2017-01-04 13:12:40 +01:00
commit 783c2f60f0
3 changed files with 88 additions and 57 deletions

View File

@ -371,11 +371,14 @@ class HelperFormBootstrap{
}
public function inputUploadImage($p = array()) {
if(isset($p['lang']) && $p['lang']) {
//return $this->inputUploadImageL($p);
}
$this->_html .='
<div class="form-group">
'.(isset($p['label'])?'<label class="control-label '.(isset($p['label-class']) ? $p['label-class'] : '').'">'.$p['label'].'</label>':'').'
<div class="'.(isset($p['input-class']) ? $p['input-class'] : '').'">
<div class="input-group image-preview">
<div class="input-group image-preview" id="'.$p['id'].'">
<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;">
@ -389,7 +392,68 @@ class HelperFormBootstrap{
</span>
</div>
</div>
'.(isset($p['help'])?'<p class="help-block">'.$p['help'].'</p>':'').'
</div>';
$this->_js .= '
<script>
$(function() {
$(document).on(\'click\', \'#close-preview_'.$p['id'].'\', function(){
$(\'#'.$p['id'].'\').popover(\'hide\');
$(\'#'.$p['id'].'\').hover(
function () {
$(\'#'.$p['id'].'\').popover(\'show\');
},
function () {
$(\'#'.$p['id'].'\').popover(\'hide\');
}
);
});
var closebtn = $(\'<button/>\', {
type:"button",
text: \'x\',
id: \'close-preview_'.$p['id'].'\',
style: \'font-size: initial;\',
});
closebtn.attr("class","close pull-right");
$(\'#'.$p['id'].'\').popover({
trigger:\'manual\',
html:true,
title: "<strong>Preview</strong>"+$(closebtn)[0].outerHTML,
content: "There\'s no image",
placement:\'bottom\'
});
$(\'#'.$p['id'].' .image-preview-clear\').click(function(){
$(\'#'.$p['id'].'\').attr("data-content","").popover(\'hide\');
$(\'#'.$p['id'].' .image-preview-filename\').val("");
$(\'#'.$p['id'].' .image-preview-clear\').hide();
$(\'#'.$p['id'].' .image-preview-input input:file\').val("");
$("#'.$p['id'].' .image-preview-input-title").text("Ouvrir");
});
// Create the preview image
$("#'.$p['id'].' .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'].' .image-preview-input-title").text("Change");
$("#'.$p['id'].' .image-preview-clear").show();
$("#'.$p['id'].' .image-preview-filename").val(file.name);
img.attr(\'src\', e.target.result);
$("#'.$p['id'].'").attr("data-content",$(img)[0].outerHTML).popover("show");
}
reader.readAsDataURL(file);
});
});
</script>';
}
public function inputSwitch($p = array()) {

View File

@ -1,60 +1,5 @@
$(document).on('click', '#close-preview', function(){
$('.image-preview').popover('hide');
$('.image-preview').hover(
function () {
$('.image-preview').popover('show');
},
function () {
$('.image-preview').popover('hide');
}
);
});
$(function() {
var closebtn = $('<button/>', {
type:"button",
text: 'x',
id: 'close-preview',
style: 'font-size: initial;',
});
closebtn.attr("class","close pull-right");
$('.image-preview').popover({
trigger:'manual',
html:true,
title: "<strong>Preview</strong>"+$(closebtn)[0].outerHTML,
content: "There\'s no image",
placement:'bottom'
});
$('.image-preview-clear').click(function(){
$('.image-preview').attr("data-content","").popover('hide');
$('.image-preview-filename').val("");
$('.image-preview-clear').hide();
$('.image-preview-input input:file').val("");
$(".image-preview-input-title").text("Browse");
});
// Create the preview image
$(".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) {
$(".image-preview-input-title").text("Change");
$(".image-preview-clear").show();
$(".image-preview-filename").val(file.name);
img.attr('src', e.target.result);
$(".image-preview").attr("data-content",$(img)[0].outerHTML).popover("show");
}
reader.readAsDataURL(file);
});
/* Switch */
var elems = Array.prototype.slice.call(document.querySelectorAll('.js-switch'));
elems.forEach(function(html) {

View File

@ -43,6 +43,15 @@ class AdminAntCreationcategories extends AdminTab
if (isset($_FILES['image_thumb']) && $_FILES['image_thumb']['name'] != NULL) {
copy($_FILES['image_thumb']['tmp_name'], _PS_CAT_IMG_DIR_.$category->id.'_thumb_vp.jpg');
}
if (isset($_FILES['image_category']) && $_FILES['image_category']['name'] != NULL) {
copy($_FILES['image_category']['tmp_name'], _PS_CAT_IMG_DIR_.$category->id.'.jpg');
if (file_exists(_PS_CAT_IMG_DIR_.$category->id.'.jpg')) {
$imagesTypes = ImageType::getImagesTypes('categories');
foreach ($imagesTypes AS $k => $imageType) {
imageResize(_PS_CAT_IMG_DIR_.$category->id.'.jpg', _PS_CAT_IMG_DIR_.$category->id.'-'.stripslashes($imageType['name']).'.jpg', (int)($imageType['width']), (int)($imageType['height']));
}
}
}
if(Tools::getValue('subcategories')) {
$subcategories = Tools::getValue('subcategories');
@ -89,6 +98,10 @@ class AdminAntCreationcategories extends AdminTab
}
} elseif(Tools::isSubmit('submitAddSubCategories')) {
if(Tools::getValue('id_parent')) {
$groups = array();
foreach (Group::getGroups((int)($cookie->id_lang)) AS $row){
$groups[] = $row['id_group'];
}
$id_parent = (int) Tools::getValue('id_parent');
$date = date('Y') . '-' . date('m');
if(Tools::getValue('subcategories2')) {
@ -190,6 +203,15 @@ class AdminAntCreationcategories extends AdminTab
'label-class' => 'col-md-2',
'input-class' => 'col-md-6',
'name' => 'image_thumb',
'id' => 'preview_thumb',
),
array(
'type' => 'uploadImage',
'label' => $this->l('Image Latéral : '),
'label-class' => 'col-md-2',
'input-class' => 'col-md-6',
'name' => 'image_category',
'id' => 'preview_category',
),
array(
'type' => 'tag',