Added brand logo image selection

This commit is contained in:
Franck Allimant
2014-06-27 21:07:51 +02:00
parent f279131fe6
commit a0aa0bd1c2
10 changed files with 120 additions and 19 deletions

View File

@@ -58,6 +58,7 @@ class Brand extends BaseAction implements EventSubscriberInterface
$brand
->setVisible($event->getVisible())
->setLogoImageId(intval($event->getLogoImageId()) == 0 ? null : $event->getLogoImageId())
->setLocale($event->getLocale())
->setTitle($event->getTitle())
->setDescription($event->getDescription())

View File

@@ -86,7 +86,8 @@ class BrandController extends AbstractSeoCrudController
'chapo' => $object->getChapo(),
'description' => $object->getDescription(),
'postscriptum' => $object->getPostscriptum(),
'visible' => $object->getVisible() ? true : false
'visible' => $object->getVisible() ? true : false,
'logo_image_id' => $object->getLogoImageId()
];
// Setup the object form
@@ -123,12 +124,13 @@ class BrandController extends AbstractSeoCrudController
$brandUpdateEvent = new BrandUpdateEvent($formData['id']);
$brandUpdateEvent
->setLogoImageId($formData['logo_image_id'])
->setVisible($formData['visible'])
->setLocale($formData['locale'])
->setTitle($formData['title'])
->setChapo($formData['chapo'])
->setDescription($formData['description'])
->setPostscriptum($formData['postscriptum'])
->setVisible($formData['visible'])
;
return $brandUpdateEvent;

View File

@@ -24,6 +24,7 @@ class BrandUpdateEvent extends BrandCreateEvent
protected $chapo;
protected $description;
protected $postscriptum;
protected $logo_image_id;
/**
* @param int $brandId
@@ -112,4 +113,22 @@ class BrandUpdateEvent extends BrandCreateEvent
{
return $this->postscriptum;
}
/**
* @param int $logo_image_id
* @return $this
*/
public function setLogoImageId($logo_image_id)
{
$this->logo_image_id = $logo_image_id;
return $this;
}
/**
* @return int
*/
public function getLogoImageId()
{
return $this->logo_image_id;
}
}

View File

@@ -183,6 +183,7 @@ class Brand extends BaseI18nLoop implements PropelSearchLoopInterface, SearchLoo
->set("META_KEYWORDS" , $brand->getVirtualColumn('i18n_META_KEYWORDS'))
->set("POSITION" , $brand->getPosition())
->set("VISIBLE" , $brand->getVisible())
->set("LOGO_IMAGE_ID" , $brand->getLogoImageId())
;
$loopResult->addRow($loopResultRow);

View File

@@ -161,13 +161,17 @@ class AdminUtilities extends AbstractSmartyPlugin
{
$form = $this->getParam($params, 'form', false);
$field_name = $this->getParam($params, 'name', false);
$label_attr = $this->getParam($params, 'label_attr', array());
$label_attr = $this->getParam($params, 'label_attr', false);
return $this->fetchSnippet($smarty, 'forms'.DS.'form-label', array(
$args = [
'form' => $form,
'field_name' => $field_name,
'label_attr' => $label_attr
));
];
if ($label_attr !== false)
$args['label_attr'] = $label_attr;
return $this->fetchSnippet($smarty, 'forms'.DS.'form-label', $args);
}
/**

View File

@@ -53,6 +53,15 @@ class BrandModificationForm extends BrandCreationForm
]
]
)
->add("logo_image_id", "integer", [
'constraints' => [ ],
'required' => false,
'label' => Translator::getInstance()->trans('Select the brand logo'),
'label_attr' => [
'for' => 'mode',
'help' => Translator::getInstance()->trans("Select the brand logo amongst the brand images")
]
])
;
// Add standard description fields, excluding title and locale, which are already defined

View File

@@ -40,10 +40,8 @@ class ProductModificationForm extends ProductCreationForm
'label' => Translator::getInstance()->trans('Brand / Supplier'),
'label_attr' => [
'for' => 'mode',
],
'attr' => [
'help' => Translator::getInstance()->trans("Select the product brand, or supplier."),
]
],
])
;

View File

@@ -0,0 +1,29 @@
ul.thumbnails.image_picker_selector {
overflow: auto;
list-style-image: none;
list-style-position: outside;
list-style-type: none;
padding: 0px;
margin: 0px; }
ul.thumbnails.image_picker_selector ul {
overflow: auto;
list-style-image: none;
list-style-position: outside;
list-style-type: none;
padding: 0px;
margin: 0px; }
ul.thumbnails.image_picker_selector li.group_title {
float: none; }
ul.thumbnails.image_picker_selector li {
margin: 0px 12px 12px 0px;
float: left; }
ul.thumbnails.image_picker_selector li .thumbnail {
padding: 6px;
border: 1px solid #dddddd;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none; }
ul.thumbnails.image_picker_selector li .thumbnail img {
-webkit-user-drag: none; }
ul.thumbnails.image_picker_selector li .thumbnail.selected {
background: #f39922; }

File diff suppressed because one or more lines are too long

View File

@@ -1,5 +1,11 @@
{extends file="admin-layout.tpl"}
{block name="after-admin-css"}
{stylesheets file='assets/js/image-picker/image-picker.css'}
<link rel="stylesheet" href="{$asset_url}">
{/stylesheets}
{/block}
{block name="no-return-functions"}
{$admin_current_location = 'tools'}
{/block}
@@ -77,6 +83,26 @@
<div class="col-md-4">
{admin_form_field form=$form name="visible"}
{form_field form=$form field='logo_image_id'}
<div class="form-group {if $error}has-error{/if}">
{admin_form_field_label form=$form name='logo_image_id'}
<select id="{$label_attr.for}" {if $required}aria-required="true" required{/if} name="{$name}" class="form-control brand-image-selector">
<option value="">{intl l="No logo image"}</option>
{loop name="brand-images" type="image" brand=$ID width="90" height="90" resize_mode="crop"}
<option value="{$ID}" data-img-src="{$IMAGE_URL}" {if $LOGO_IMAGE_ID == $ID}selected="selected"{/if}>{$TITLE}</option>
{/loop}
</select>
{if $label_attr.help}
<span class="help-block">{$label_attr.help}</span>
{/if}
</div>
{/form_field}
</div>
</div>
@@ -152,6 +178,9 @@
{javascripts file='assets/js/jquery-ui-1.10.3.custom.min.js'}
<script src="{$asset_url}"></script>
{/javascripts}
{javascripts file='assets/js/image-picker/image-picker.min.js'}
<script src="{$asset_url}"></script>
{/javascripts}
<script>
$(function() {
// Load active tab
@@ -169,6 +198,8 @@
{if ! empty($current_tab)}
$('.nav-tabs a[href="#{$current_tab}"]').trigger("click");
{/if}
$('.brand-image-selector').imagepicker();
});
</script>
{/block}