/** * Verify that js element is added */ public function testGetAfterElementJs() { $this->_model->setAfterElementJs('<script language="text/javascript">var website = "website1";</script>'); $elementHtml = $this->_model->getAfterElementJs(); $this->assertContains('var website = "website1";', $elementHtml); }
/** * @param \Magento\Framework\Data\Form\Element\Factory $factoryElement * @param \Magento\Framework\Data\Form\Element\CollectionFactory $factoryCollection * @param \Magento\Framework\Escaper $escaper * @param \Magento\Catalog\Model\Resource\Category\CollectionFactory $collectionFactory * @param \Magento\Backend\Helper\Data $backendData * @param \Magento\Framework\View\LayoutInterface $layout * @param \Magento\Framework\Json\EncoderInterface $jsonEncoder * @param AuthorizationInterface $authorization * @param array $data */ public function __construct(\Magento\Framework\Data\Form\Element\Factory $factoryElement, \Magento\Framework\Data\Form\Element\CollectionFactory $factoryCollection, \Magento\Framework\Escaper $escaper, \Magento\Catalog\Model\Resource\Category\CollectionFactory $collectionFactory, \Magento\Backend\Helper\Data $backendData, \Magento\Framework\View\LayoutInterface $layout, \Magento\Framework\Json\EncoderInterface $jsonEncoder, AuthorizationInterface $authorization, array $data = []) { $this->_jsonEncoder = $jsonEncoder; $this->_collectionFactory = $collectionFactory; $this->_backendData = $backendData; $this->authorization = $authorization; parent::__construct($factoryElement, $factoryCollection, $escaper, $data); $this->_layout = $layout; }
/** * @param \Magento\Catalog\Model\ResourceModel\Category\CollectionFactory $collectionFactory * @param \Magento\Backend\Helper\Data $backendData * @param \Magento\Framework\View\LayoutInterface $layout * @param \Magento\Framework\Json\EncoderInterface $jsonEncoder * @param \Magento\Framework\AuthorizationInterface $authorization * @param \Magento\Framework\Data\Form\Element\Factory $factoryElement * @param \Magento\Framework\Data\Form\Element\CollectionFactory $factoryCollection * @param \Magento\Framework\Escaper $escaper * @param array $data */ public function __construct(CollectionFactory $collectionFactory, DataHelper $backendData, LayoutInterface $layout, EncoderInterface $jsonEncoder, AuthorizationInterface $authorization, ElementFactory $factoryElement, ElementCollectionFactory $factoryCollection, Escaper $escaper, array $data = []) { $this->collectionFactory = $collectionFactory; $this->backendData = $backendData; $this->layout = $layout; $this->jsonEncoder = $jsonEncoder; $this->authorization = $authorization; parent::__construct($factoryElement, $factoryCollection, $escaper, $data); }
/** * @return string */ public function getElementHtml() { $elementAttributeHtml = ''; if ($this->getReadonly()) { $elementAttributeHtml = $elementAttributeHtml . ' readonly="readonly"'; } if ($this->getDisabled()) { $elementAttributeHtml = $elementAttributeHtml . ' disabled="disabled"'; } $html = '<select onchange="toggleApplyVisibility(this)"' . $elementAttributeHtml . '>' . '<option value="0">' . $this->getModeLabels('all') . '</option>' . '<option value="1" ' . ($this->getValue() == null ? '' : 'selected') . '>' . $this->getModeLabels('custom') . '</option>' . '</select><br /><br />'; $html .= parent::getElementHtml(); return $html; }
/** * Retrieve HTML markup of the element * * @return string */ public function getElementHtml() { $html = parent::getElementHtml(); $selectConfig = $this->getData('select_config'); if ($this->getData('disabled')) { $selectConfig['is_entity_editable'] = false; } $elementJsClass = self::DEFAULT_ELEMENT_JS_CLASS; if ($this->getData('element_js_class')) { $elementJsClass = $this->getData('element_js_class'); } $selectConfigJson = \Zend_Json::encode($selectConfig); $jsObjectName = $this->getJsObjectName(); $html .= '<script type="text/javascript">' . '/*<![CDATA[*/' . '(function($) { $().ready(function () { ' . "var {$jsObjectName} = new {$elementJsClass}({$selectConfigJson}); " . "{$jsObjectName}.init(); }); })(jQuery);" . '/*]]>*/' . '</script>'; return $html; }
/** * Retrieve HTML markup of the element * * @return string */ public function getElementHtml() { $html = parent::getElementHtml(); $selectConfig = $this->getData('select_config'); if ($this->getData('disabled')) { $selectConfig['is_entity_editable'] = false; } $elementJsClass = self::DEFAULT_ELEMENT_JS_CLASS; if ($this->getData('element_js_class')) { $elementJsClass = $this->getData('element_js_class'); } $selectConfigJson = \Zend_Json::encode($selectConfig); $jsObjectName = $this->getJsObjectName(); // TODO: TaxRateEditableMultiselect should be moved to a static .js module. $html .= "\n <script type='text/javascript'>\n require([\n 'jquery',\n 'jquery/ui'\n ], function( \$ ){\n\n function isResolved(){\n return typeof window['{$elementJsClass}'] !== 'undefined'; \n }\n\n function init(){\n var {$jsObjectName} = new {$elementJsClass}({$selectConfigJson});\n \n {$jsObjectName}.init();\n }\n\n function check( tries, delay ){\n if( isResolved() ){\n init();\n }\n else if( tries-- ){\n setTimeout( check.bind(this, tries, delay), delay);\n }\n else{\n console.warn( 'Unable to resolve dependency: {$elementJsClass}' );\n }\n }\n\n check(8, 500);\n\n });\n </script>"; return $html; }
/** * Retrieve Element HTML fragment * * @return string */ public function getElementHtml() { $elementDisabled = $this->getDisabled() == 'disabled'; $disabled = false; if (!$this->getValue() || $elementDisabled) { $this->setData('disabled', 'disabled'); $disabled = true; } $html = parent::getElementHtml(); $htmlId = 'use_config_' . $this->getHtmlId(); $html .= '<input id="' . $htmlId . '" name="use_config[]" value="' . $this->getId() . '"'; $html .= $disabled ? ' checked="checked"' : ''; if ($this->getReadonly() || $elementDisabled) { $html .= ' disabled="disabled"'; } $html .= ' onclick="toggleValueElements(this, this.parentNode);" class="checkbox" type="checkbox" />'; $html .= ' <label for="' . $htmlId . '" class="normal">' . __('Use All Available Attributes') . '</label>'; $html .= '<script>require(["prototype"], function(){toggleValueElements($(\'' . $htmlId . '\'), $(\'' . $htmlId . '\').parentNode);});</script>'; return $html; }
/** * @return string */ public function getElementHtml() { $this->setSize($this->calculateSize()); return parent::getElementHtml(); }