diff --git a/core/lib/Thelia/Action/Brand.php b/core/lib/Thelia/Action/Brand.php index b362a0ee3..b289541f2 100644 --- a/core/lib/Thelia/Action/Brand.php +++ b/core/lib/Thelia/Action/Brand.php @@ -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()) diff --git a/core/lib/Thelia/Controller/Admin/BrandController.php b/core/lib/Thelia/Controller/Admin/BrandController.php index c41332894..b7229d27e 100644 --- a/core/lib/Thelia/Controller/Admin/BrandController.php +++ b/core/lib/Thelia/Controller/Admin/BrandController.php @@ -80,13 +80,14 @@ class BrandController extends AbstractSeoCrudController // Prepare the data that will hydrate the form $data = [ - 'id' => $object->getId(), - 'locale' => $object->getLocale(), - 'title' => $object->getTitle(), - 'chapo' => $object->getChapo(), - 'description' => $object->getDescription(), - 'postscriptum' => $object->getPostscriptum(), - 'visible' => $object->getVisible() ? true : false + 'id' => $object->getId(), + 'locale' => $object->getLocale(), + 'title' => $object->getTitle(), + 'chapo' => $object->getChapo(), + 'description' => $object->getDescription(), + 'postscriptum' => $object->getPostscriptum(), + '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; diff --git a/core/lib/Thelia/Core/Event/Brand/BrandUpdateEvent.php b/core/lib/Thelia/Core/Event/Brand/BrandUpdateEvent.php index ffd2456d8..7b9398622 100644 --- a/core/lib/Thelia/Core/Event/Brand/BrandUpdateEvent.php +++ b/core/lib/Thelia/Core/Event/Brand/BrandUpdateEvent.php @@ -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; + } } diff --git a/core/lib/Thelia/Core/Template/Loop/Brand.php b/core/lib/Thelia/Core/Template/Loop/Brand.php index 0a9774221..c5fab67af 100644 --- a/core/lib/Thelia/Core/Template/Loop/Brand.php +++ b/core/lib/Thelia/Core/Template/Loop/Brand.php @@ -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); diff --git a/core/lib/Thelia/Core/Template/Smarty/Plugins/AdminUtilities.php b/core/lib/Thelia/Core/Template/Smarty/Plugins/AdminUtilities.php index 0a8fe68e2..ff77aab6e 100644 --- a/core/lib/Thelia/Core/Template/Smarty/Plugins/AdminUtilities.php +++ b/core/lib/Thelia/Core/Template/Smarty/Plugins/AdminUtilities.php @@ -159,15 +159,19 @@ class AdminUtilities extends AbstractSmartyPlugin public function buildFormFieldLabel($params, &$smarty) { - $form = $this->getParam($params, 'form', false); - $field_name = $this->getParam($params, 'name', false); - $label_attr = $this->getParam($params, 'label_attr', array()); + $form = $this->getParam($params, 'form', false); + $field_name = $this->getParam($params, 'name', false); + $label_attr = $this->getParam($params, 'label_attr', false); - return $this->fetchSnippet($smarty, 'forms'.DS.'form-label', array( - 'form' => $form, - 'field_name' => $field_name, - 'label_attr' => $label_attr - )); + $args = [ + 'form' => $form, + 'field_name' => $field_name, + ]; + + if ($label_attr !== false) + $args['label_attr'] = $label_attr; + + return $this->fetchSnippet($smarty, 'forms'.DS.'form-label', $args); } /** diff --git a/core/lib/Thelia/Form/Brand/BrandModificationForm.php b/core/lib/Thelia/Form/Brand/BrandModificationForm.php index fa0ba3015..d30b8ad0d 100644 --- a/core/lib/Thelia/Form/Brand/BrandModificationForm.php +++ b/core/lib/Thelia/Form/Brand/BrandModificationForm.php @@ -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 diff --git a/core/lib/Thelia/Form/ProductModificationForm.php b/core/lib/Thelia/Form/ProductModificationForm.php index 18f79c659..894399d94 100644 --- a/core/lib/Thelia/Form/ProductModificationForm.php +++ b/core/lib/Thelia/Form/ProductModificationForm.php @@ -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."), - ] + ], ]) ; diff --git a/templates/backOffice/default/assets/js/image-picker/image-picker.css b/templates/backOffice/default/assets/js/image-picker/image-picker.css new file mode 100644 index 000000000..14a96e398 --- /dev/null +++ b/templates/backOffice/default/assets/js/image-picker/image-picker.css @@ -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; } diff --git a/templates/backOffice/default/assets/js/image-picker/image-picker.min.js b/templates/backOffice/default/assets/js/image-picker/image-picker.min.js new file mode 100644 index 000000000..c0c731d68 --- /dev/null +++ b/templates/backOffice/default/assets/js/image-picker/image-picker.min.js @@ -0,0 +1,7 @@ +// Image Picker +// by Rodrigo Vera +// +// Version 0.2.4 +// Full source at https://github.com/rvera/image-picker +// MIT License, https://github.com/rvera/image-picker/blob/master/LICENSE +(function(){var t,e,i,s,l=function(t,e){return function(){return t.apply(e,arguments)}},n=[].indexOf||function(t){for(var e=0,i=this.length;i>e;e++)if(e in this&&this[e]===t)return e;return-1};jQuery.fn.extend({imagepicker:function(e){return null==e&&(e={}),this.each(function(){var i;return i=jQuery(this),i.data("picker")&&i.data("picker").destroy(),i.data("picker",new t(this,s(e))),null!=e.initialized?e.initialized.call(i.data("picker")):void 0})}}),s=function(t){var e;return e={hide_select:!0,show_label:!1,initialized:void 0,changed:void 0,clicked:void 0,selected:void 0,limit:void 0,limit_reached:void 0},jQuery.extend(e,t)},i=function(t,e){return 0===jQuery(t).not(e).length&&0===jQuery(e).not(t).length},t=function(){function t(t,e){this.opts=null!=e?e:{},this.sync_picker_with_select=l(this.sync_picker_with_select,this),this.select=jQuery(t),this.multiple="multiple"===this.select.attr("multiple"),null!=this.select.data("limit")&&(this.opts.limit=parseInt(this.select.data("limit"))),this.build_and_append_picker()}return t.prototype.destroy=function(){var t,e,i,s;for(s=this.picker_options,e=0,i=s.length;i>e;e++)t=s[e],t.destroy();return this.picker.remove(),this.select.unbind("change"),this.select.removeData("picker"),this.select.show()},t.prototype.build_and_append_picker=function(){var t=this;return this.opts.hide_select&&this.select.hide(),this.select.change(function(){return t.sync_picker_with_select()}),null!=this.picker&&this.picker.remove(),this.create_picker(),this.select.after(this.picker),this.sync_picker_with_select()},t.prototype.sync_picker_with_select=function(){var t,e,i,s,l;for(s=this.picker_options,l=[],e=0,i=s.length;i>e;e++)t=s[e],t.is_selected()?l.push(t.mark_as_selected()):l.push(t.unmark_as_selected());return l},t.prototype.create_picker=function(){return this.picker=jQuery("