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(""),this.picker_options=[],this.recursively_parse_option_groups(this.select,this.picker),this.picker},t.prototype.recursively_parse_option_groups=function(t,i){var s,l,n,r,c,o,h,a,p,u;for(a=t.children("optgroup"),r=0,o=a.length;o>r;r++)n=a[r],n=jQuery(n),s=jQuery(""),s.append(jQuery("
  • "+n.attr("label")+"
  • ")),i.append(jQuery("
  • ").append(s)),this.recursively_parse_option_groups(n,s);for(p=function(){var i,s,n,r;for(n=t.children("option"),r=[],i=0,s=n.length;s>i;i++)l=n[i],r.push(new e(l,this,this.opts));return r}.call(this),u=[],c=0,h=p.length;h>c;c++)l=p[c],this.picker_options.push(l),l.has_image()&&u.push(i.append(l.node));return u},t.prototype.has_implicit_blanks=function(){var t;return function(){var e,i,s,l;for(s=this.picker_options,l=[],e=0,i=s.length;i>e;e++)t=s[e],t.is_blank()&&!t.has_image()&&l.push(t);return l}.call(this).length>0},t.prototype.selected_values=function(){return this.multiple?this.select.val()||[]:[this.select.val()]},t.prototype.toggle=function(t){var e,s,l;return s=this.selected_values(),l=""+t.value(),this.multiple?n.call(this.selected_values(),l)>=0?(e=this.selected_values(),e.splice(jQuery.inArray(l,s),1),this.select.val([]),this.select.val(e)):null!=this.opts.limit&&this.selected_values().length>=this.opts.limit?null!=this.opts.limit_reached&&this.opts.limit_reached.call(this.select):this.select.val(this.selected_values().concat(l)):this.has_implicit_blanks()&&t.is_selected()?this.select.val(""):this.select.val(l),i(s,this.selected_values())||(this.select.change(),null==this.opts.changed)?void 0:this.opts.changed.call(this.select,s,this.selected_values())},t}(),e=function(){function t(t,e,i){this.picker=e,this.opts=null!=i?i:{},this.clicked=l(this.clicked,this),this.option=jQuery(t),this.create_node()}return t.prototype.destroy=function(){return this.node.find(".thumbnail").unbind()},t.prototype.has_image=function(){return null!=this.option.data("img-src")},t.prototype.is_blank=function(){return!(null!=this.value()&&""!==this.value())},t.prototype.is_selected=function(){var t;return t=this.picker.select.val(),this.picker.multiple?jQuery.inArray(this.value(),t)>=0:this.value()===t},t.prototype.mark_as_selected=function(){return this.node.find(".thumbnail").addClass("selected")},t.prototype.unmark_as_selected=function(){return this.node.find(".thumbnail").removeClass("selected")},t.prototype.value=function(){return this.option.val()},t.prototype.label=function(){return this.option.data("img-label")?this.option.data("img-label"):this.option.text()},t.prototype.clicked=function(){return this.picker.toggle(this),null!=this.opts.clicked&&this.opts.clicked.call(this.picker.select,this),null!=this.opts.selected&&this.is_selected()?this.opts.selected.call(this.picker.select,this):void 0},t.prototype.create_node=function(){var t,e;return this.node=jQuery("
  • "),t=jQuery(""),t.attr("src",this.option.data("img-src")),e=jQuery("
    "),e.click({option:this},function(t){return t.data.option.clicked()}),e.append(t),this.opts.show_label&&e.append(jQuery("

    ").html(this.label())),this.node.append(e),this.node},t}()}).call(this); \ No newline at end of file diff --git a/templates/backOffice/default/brand-edit.html b/templates/backOffice/default/brand-edit.html index 30c930a0c..17a819c1b 100644 --- a/templates/backOffice/default/brand-edit.html +++ b/templates/backOffice/default/brand-edit.html @@ -1,5 +1,11 @@ {extends file="admin-layout.tpl"} +{block name="after-admin-css"} + {stylesheets file='assets/js/image-picker/image-picker.css'} + + {/stylesheets} +{/block} + {block name="no-return-functions"} {$admin_current_location = 'tools'} {/block} @@ -77,6 +83,26 @@

    {admin_form_field form=$form name="visible"} + + {form_field form=$form field='logo_image_id'} +
    + + {admin_form_field_label form=$form name='logo_image_id'} + + + + {if $label_attr.help} + {$label_attr.help} + {/if} +
    + {/form_field} +
    @@ -152,6 +178,9 @@ {javascripts file='assets/js/jquery-ui-1.10.3.custom.min.js'} {/javascripts} + {javascripts file='assets/js/image-picker/image-picker.min.js'} + + {/javascripts} {/block}