Ejemplo n.º 1
0
 protected function _prepareMassaction()
 {
     $this->setMassactionIdField('entity_id');
     $this->getMassactionBlock()->setFormFieldName('slider');
     $this->getMassactionBlock()->addItem('delete', ['label' => __('Delete'), 'url' => $this->getUrl('bannerslideradmin/*/massDelete'), 'confirm' => __('Are you sure?')]);
     $statuses = Status::getAvailableStatuses();
     array_unshift($statuses, ['label' => '', 'value' => '']);
     $this->getMassactionBlock()->addItem('status', ['label' => __('Change status'), 'url' => $this->getUrl('bannerslideradmin/*/massStatus', ['_current' => true]), 'additional' => ['visibility' => ['name' => 'status', 'type' => 'select', 'class' => 'required-entry', 'label' => __('Status'), 'values' => $statuses]]]);
     return $this;
 }
Ejemplo n.º 2
0
 protected function _prepareColumns()
 {
     $this->addColumn('in_banner', ['header_css_class' => 'a-center', 'type' => 'checkbox', 'name' => 'in_banner', 'align' => 'center', 'index' => 'banner_id', 'values' => $this->_getSelectedBanners()]);
     $this->addColumn('banner_id', ['header' => __('Banner ID'), 'type' => 'number', 'index' => 'banner_id', 'header_css_class' => 'col-id', 'column_css_class' => 'col-id']);
     $this->addColumn('banner_name', ['header' => __('Name'), 'index' => 'banner_name', 'class' => 'xxx', 'width' => '50px']);
     $this->addColumn('image', ['header' => __('Image'), 'filter' => false, 'class' => 'xxx', 'width' => '50px', 'renderer' => 'Tuna\\BannerSlider\\Block\\Adminhtml\\Banner\\Helper\\Renderer\\Image']);
     $this->addColumn('title', ['header' => __('Slider'), 'index' => 'title', 'class' => 'xxx', 'width' => '50px']);
     $this->addColumn('start_time', ['header' => __('Starting time'), 'type' => 'datetime', 'index' => 'start_time', 'class' => 'xxx', 'width' => '50px', 'timezone' => true]);
     $this->addColumn('end_time', ['header' => __('Ending time'), 'type' => 'datetime', 'index' => 'end_time', 'class' => 'xxx', 'width' => '50px', 'timezone' => true]);
     $this->addColumn('status', ['header' => __('Status'), 'index' => 'status', 'type' => 'options', 'filter_index' => 'main_table.status', 'options' => Status::getAvailableStatuses()]);
     $this->addColumn('edit', ['header' => __('Edit'), 'filter' => false, 'sortable' => false, 'index' => 'stores', 'header_css_class' => 'col-action', 'column_css_class' => 'col-action', 'renderer' => 'Tuna\\BannerSlider\\Block\\Adminhtml\\Slider\\Edit\\Tab\\Helper\\Renderer\\EditBanner']);
     $this->addColumn('order_banner_slider', ['header' => __('Order'), 'name' => 'order_banner_slider', 'index' => 'order_banner_slider', 'class' => 'xxx', 'width' => '50px', 'editable' => true]);
     return parent::_prepareColumns();
 }
Ejemplo n.º 3
0
 protected function _prepareForm()
 {
     $slider = $this->_coreRegistry->registry('slider');
     //get registry from controller registered
     $isElementDisabled = true;
     $form = $this->_formFactory->create();
     $form->setHtmlIdPrefix('slider_');
     //set id prefix for form
     $fieldset = $form->addFieldset('base_fieldset', ['legend' => __('Slider Information'), 'class' => 'fieldset-wide']);
     if ($slider->getId()) {
         $fieldset->addField('slider_id', 'hidden', ['name' => 'slider_id']);
     }
     $fieldset->addField('title', 'text', ['name' => 'title', 'label' => __('Title'), 'title' => __('Title'), 'required' => true, 'class' => 'required-entry']);
     $fieldMaps = [];
     $fieldMaps['show_title'] = $fieldset->addField('show_title', 'select', ['label' => __('Show Title'), 'title' => __('Show Title'), 'name' => 'show_title', 'options' => Status::getAvailableStatuses(), 'disabled' => false]);
     $fieldMaps['status'] = $fieldset->addField('status', 'select', ['label' => __('Slider Status'), 'title' => __('Slider Status'), 'name' => 'status', 'options' => Status::getAvailableStatuses(), 'disabled' => false]);
     $fieldMaps['style_content'] = $fieldset->addField('style_content', 'select', ['label' => __('Select available Slider Styles'), 'name' => 'style_content', 'values' => [['value' => Status::STATUS_ENABLE, 'label' => __('Yes')], ['value' => Status::STATUS_DISABLE, 'label' => __('No')]]]);
     $fieldMaps['custom_code'] = $fieldset->addField('custom_code', 'editor', ['name' => 'custom_code', 'label' => __('Custom slider'), 'title' => __('Custom slider'), 'wysiwyg' => true, 'required' => false]);
     $previewUrl = $this->_bannersliderHelper->getBackendUrl('*/*/preview', ['_current' => false]);
     $fieldMaps['style_slide'] = $fieldset->addField('style_slide', 'select', ['label' => __('Select Slider Mode'), 'name' => 'style_slide', 'values' => $this->_bannersliderHelper->getStyleSlider(), 'note' => '<a data-preview-url="' . $previewUrl . '" href="' . $previewUrl . '" target="_blank" id="style-slide-view">Preview</a>']);
     $fieldMaps['sort_type'] = $fieldset->addField('sort_type', 'select', ['label' => __('Sort type'), 'name' => 'sort_type', 'values' => [['value' => \Tuna\BannerSlider\Model\Slider::SORT_TYPE_RANDOM, 'label' => __('Random')], ['value' => \Tuna\BannerSlider\Model\Slider::SORT_TYPE_ORDERLY, 'label' => __('Orderly')]]]);
     $fieldMaps['width'] = $fieldset->addField('width', 'text', ['label' => __('Width'), 'name' => 'width', 'required' => true, 'class' => 'required-entry validate-number validate-greater-than-zero']);
     $fieldMaps['height'] = $fieldset->addField('height', 'text', ['label' => __('Height'), 'name' => 'height', 'required' => true, 'class' => 'required-entry validate-number validate-greater-than-zero']);
     $fieldMaps['animationB'] = $fieldset->addField('animationB', 'select', ['label' => __('Animation Effect'), 'name' => 'animationB', 'values' => $this->_bannersliderHelper->getAnimationB()]);
     $fieldMaps['animationA'] = $fieldset->addField('animationA', 'select', ['label' => __('Animation Effect'), 'name' => 'animationA', 'values' => $this->_bannersliderHelper->getAnimationA()]);
     $fieldMaps['note_color'] = $fieldset->addField('note_color', 'select', ['name' => 'note_color', 'label' => __('Color'), 'title' => __('Color'), 'values' => $this->_bannersliderHelper->getOptionColor()]);
     $fieldMaps['slider_speed'] = $fieldset->addField('slider_speed', 'text', ['label' => __('Speed'), 'name' => 'slider_speed', 'note' => 'mini seconds. This is the display time of a banner']);
     $fieldMaps['position_note'] = $fieldset->addField('position_note', 'select', ['name' => 'position_note', 'label' => __('Position'), 'title' => __('Position'), 'values' => $slider->getPositionNoteOptions(), 'note' => 'is position will be shown on all pages']);
     $fieldMaps['description'] = $fieldset->addField('description', 'editor', ['name' => 'description', 'label' => __('Note\'s content'), 'title' => __('Note\'s content'), 'wysiwyg' => true, 'required' => false]);
     $positionImage = [];
     for ($i = 1; $i <= 5; ++$i) {
         $positionImage[] = $this->getViewFileUrl("Tuna_BannerSlider::images/position/bannerslider-ex{$i}.png");
     }
     $fieldMaps['position'] = $fieldset->addField('position', 'select', ['name' => 'position', 'label' => __('Position'), 'title' => __('Position'), 'values' => $this->_bannersliderHelper->getBlockIdsToOptionsArray(), 'note' => '<a title="" data-position-image=\'' . json_encode($positionImage) . '\' data-tooltip-image="">Preview</a>']);
     $fieldMaps['position_custom'] = $fieldset->addField('position_custom', 'select', ['name' => 'position_custom', 'label' => __('Position'), 'title' => __('Position'), 'values' => $this->_bannersliderHelper->getBlockIdsToOptionsArray(), 'note' => '<a title="" data-position-image=\'' . json_encode($positionImage) . '\' data-tooltip-image="">Preview</a>']);
     $fieldMaps['category_ids'] = $fieldset->addField('category_ids', 'multiselect', ['label' => __('Categories'), 'name' => 'category_ids', 'values' => $this->_bannersliderHelper->getCategoriesArray()]);
     $dependenceBlock = $this->getLayout()->createBlock('Magento\\Backend\\Block\\Widget\\Form\\Element\\Dependence');
     foreach ($fieldMaps as $fieldMap) {
         $dependenceBlock->addFieldMap($fieldMap->getHtmlId(), $fieldMap->getName());
     }
     $mappingFieldDependence = $this->getMappingFieldDependence();
     foreach ($mappingFieldDependence as $dependence) {
         $negative = isset($dependence['negative']) && $dependence['negative'];
         if (is_array($dependence['fieldName'])) {
             foreach ($dependence['fieldName'] as $fieldName) {
                 $dependenceBlock->addFieldDependence($fieldMaps[$fieldName]->getName(), $fieldMaps[$dependence['fieldNameFrom']]->getName(), $this->getDependencyField($dependence['refField'], $negative));
             }
         } else {
             $dependenceBlock->addFieldDependence($fieldMaps[$dependence['fieldName']]->getName(), $fieldMaps[$dependence['fieldNameFrom']]->getName(), $this->getDependencyField($dependence['refField'], $negative));
         }
     }
     $this->setChild('form_after', $dependenceBlock);
     $defaultData = ['width' => 400, 'height' => 200, 'slider_speed' => 4500];
     if (!$slider->getId()) {
         $slider->setStatus($isElementDisabled ? Status::STATUS_ENABLE : Status::STATUS_DISABLE);
         $slider->addData($defaultData);
     }
     if ($slider->hasData('animationB')) {
         $slider->setData('animationA', $slider->getData('animationB'));
     }
     if ($slider->hasData('position')) {
         $slider->setPositionCustom($slider->getPosition());
     }
     $form->setValues($slider->getData());
     $form->addFieldNameSuffix(self::FIELD_NAME_SUFFIX);
     $this->setForm($form);
     return parent::_prepareForm();
 }
Ejemplo n.º 4
0
 protected function _prepareForm()
 {
     $banner = $this->_coreRegistry->registry('banner');
     $dateFormat = $this->_localeDate->getDateFormat(\IntlDateFormatter::SHORT);
     $timeFormat = $this->_localeDate->getTimeFormat(\IntlDateFormatter::SHORT);
     $bannerAttributes = $this->_banner->getStoreAttributes();
     $bannerAttributesInStores = ['store_id' => ''];
     foreach ($bannerAttributes as $bannerAttribute) {
         $bannerAttributesInStores[$bannerAttribute . '_in_store'] = '';
     }
     $dataObj = $this->_objectFactory->create(['data' => $bannerAttributesInStores]);
     if ($sliderId = $this->getRequest()->getParam('current_slider_id')) {
         $banner->setSliderId($sliderId);
     }
     $storeViewId = $this->getRequest()->getParam('store');
     $attributesInStore = $this->_valueCollectionFactory->create()->addFieldToFilter('banner_id', $banner->getId())->addFieldToFilter('store_id', $storeViewId)->getColumnValues('attribute_code');
     /** @var \Magento\Framework\Data\Form $form */
     $form = $this->_formFactory->create();
     $form->setHtmlIdPrefix($this->_banner->getFormFieldHtmlIdPrefix());
     //pass formPrefix: banner_
     // required class fieldset-wide here
     $fieldset = $form->addFieldset('base_fieldset', ['legend' => __('Banner Information'), 'class' => 'fieldset-wide']);
     if ($banner->getId()) {
         $fieldset->addField('banner_id', 'hidden', ['name' => 'banner_id']);
     }
     $elements = [];
     // list all field
     $elements['banner_name'] = $fieldset->addField('banner_name', 'text', ['name' => 'banner_name', 'label' => __('Banner Name'), 'title' => __('Banner Name'), 'required' => true]);
     if ($this->_storeManager->isSingleStoreMode()) {
         $fieldset->addField('store_id', 'hidden', ['name' => 'stores[]', 'value' => $this->_storeManager->getStore(true)->getId()]);
         $banner->setStoreId($this->_storeManager->getStore(true)->getId());
     }
     $elements['status'] = $fieldset->addField('status', 'select', ['label' => __('Status'), 'title' => __('Banner Status'), 'name' => 'status', 'options' => Status::getAvailableStatuses()]);
     $slider = $this->_sliderFactory->create()->load($sliderId);
     if ($slider->getId()) {
         $elements['slider_id'] = $fieldset->addField('slider_id', 'select', ['label' => __('Slider'), 'name' => 'slider_id', 'values' => [['value' => $slider->getId(), 'label' => $slider->getTitle()]]]);
     } else {
         $elements['slider_id'] = $fieldset->addField('slider_id', 'select', ['label' => __('Slider'), 'name' => 'slider_id', 'values' => $banner->getAvailableSlides()]);
     }
     $elements['image_alt'] = $fieldset->addField('image_alt', 'text', ['title' => __('Alt Text'), 'label' => __('Alt Text'), 'name' => 'image_alt', 'note' => 'Used for SEO']);
     $elements['click_url'] = $fieldset->addField('click_url', 'text', ['title' => __('URL'), 'label' => __('URL'), 'name' => 'click_url']);
     $elements['image'] = $fieldset->addField('image', 'image', ['title' => __('Banner Image'), 'label' => __('Banner Image'), 'name' => 'image', 'note' => 'Allow image type: jpg, jpeg, gif, png', 'required' => true]);
     if ($dataObj->hasData('start_time')) {
         $datetime = new \DateTime($dataObj->getData('start_time'));
         $dataObj->setData('start_time', $datetime->setTimezone(new \DateTimeZone($this->_localeDate->getConfigTimezone())));
     }
     if ($dataObj->hasData('end_time')) {
         $datetime = new \DateTime($dataObj->getData('end_time'));
         $dataObj->setData('end_time', $datetime->setTimezone(new \DateTimeZone($this->_localeDate->getConfigTimezone())));
     }
     $style = 'color: #000;background-color: #fff; font-weight: bold; font-size: 13px;';
     $elements['start_time'] = $fieldset->addField('start_time', 'date', ['name' => 'start_time', 'label' => __('Start at'), 'title' => __('Start at'), 'required' => true, 'readonly' => true, 'style' => $style, 'class' => 'required-entry', 'date_format' => $dateFormat, 'time_format' => $timeFormat, 'note' => $this->_localeDate->getDateTimeFormat(\IntlDateFormatter::SHORT)]);
     $elements['end_time'] = $fieldset->addField('end_time', 'date', ['name' => 'end_time', 'label' => __('End at'), 'title' => __('End at'), 'required' => true, 'readonly' => true, 'style' => $style, 'class' => 'required-entry', 'date_format' => $dateFormat, 'time_format' => $timeFormat, 'note' => $this->_localeDate->getDateTimeFormat(\IntlDateFormatter::SHORT)]);
     $elements['target'] = $fieldset->addField('target', 'select', ['label' => __('Target'), 'name' => 'target', 'values' => [['value' => \Tuna\BannerSlider\Model\Banner::BANNER_TARGET_SELF, 'label' => __('New Window with Browser Navigation')], ['value' => \Tuna\BannerSlider\Model\Banner::BANNER_TARGET_PARENT, 'label' => __('Parent Window with Browser Navigation')], ['value' => \Tuna\BannerSlider\Model\Banner::BANNER_TARGET_BLANK, 'label' => __('New Window without Browser Navigation')]]]);
     foreach ($attributesInStore as $attribute) {
         if (isset($elements[$attribute])) {
             $elements[$attribute]->setStoreViewId($storeViewId);
         }
     }
     $form->addValues($dataObj->getData());
     $this->setForm($form);
     return parent::_prepareForm();
 }