Beispiel #1
0
 /**
  * Forms script response
  *
  * @return string
  */
 public function _toHtml()
 {
     $updateResult = $this->_coreRegistry->registry('composite_update_result');
     $resultJson = $this->_jsonEncoder->encode($updateResult);
     $jsVarname = $updateResult->getJsVarName();
     return $this->_jsHelper->getScript(sprintf('var %s = %s', $jsVarname, $resultJson));
 }
Beispiel #2
0
 /**
  * Render block HTML
  *
  * @return string
  */
 protected function _toHtml()
 {
     $result = [];
     $layout = $this->getLayout();
     foreach ($this->getChildNames() as $name) {
         $result[$name] = $layout->renderElement($name);
     }
     $resultJson = $this->_jsonEncoder->encode($result);
     $jsVarname = $this->getRequest()->getParam('as_js_varname');
     if ($jsVarname) {
         return $this->_jsHelper->getScript(sprintf('var %s = %s', $jsVarname, $resultJson));
     } else {
         return $resultJson;
     }
 }
Beispiel #3
0
    /**
     * Render fieldset html
     *
     * @param \Magento\Framework\Data\Form\Element\AbstractElement $element
     * @return string
     */
    public function render(\Magento\Framework\Data\Form\Element\AbstractElement $element)
    {
        $elementOriginalData = $element->getOriginalData();
        if (isset($elementOriginalData['help_link'])) {
            $this->setHelpLink($elementOriginalData['help_link']);
        }
        $js = '
            paypalToggleSolution = function(id, url) {
                var doScroll = false;
                Fieldset.toggleCollapse(id, url);
                if ($(this).hasClassName("open")) {
                    $$(".with-button button.button").each(function(anotherButton) {
                        if (anotherButton != this && $(anotherButton).hasClassName("open")) {
                            $(anotherButton).click();
                            doScroll = true;
                        }
                    }.bind(this));
                }
                if (doScroll) {
                    var pos = Element.cumulativeOffset($(this));
                    window.scrollTo(pos[0], pos[1] - 45);
                }
            }

            togglePaypalSolutionConfigureButton = function(button, enable) {
                var $button = $(button);
                $button.disabled = !enable;
                if ($button.hasClassName("disabled") && enable) {
                    $button.removeClassName("disabled");
                } else if (!$button.hasClassName("disabled") && !enable) {
                    $button.addClassName("disabled");
                }
            }

            // check store-view disabling Express Checkout
            document.observe("dom:loaded", function() {
                $$(".pp-method-express button.button").each(function(ecButton){
                    var ecEnabler = $$(".paypal-ec-enabler")[0];
                    if (typeof ecButton == "undefined" || typeof ecEnabler != "undefined") {
                        return;
                    }
                    var $ecButton = $(ecButton);
                    $$(".with-button button.button").each(function(configureButton) {
                        if (configureButton != ecButton && !configureButton.disabled
                            && !$(configureButton).hasClassName("paypal-ec-separate")
                        ) {
                            togglePaypalSolutionConfigureButton(ecButton, false);
                        }
                    });
                });
            });
        ';
        return $this->toHtml() . $this->_jsHelper->getScript($js);
    }
Beispiel #4
0
 /**
  * Get country selector html
  *
  * @param \Magento\Framework\Data\Form\Element\AbstractElement $element
  * @return string
  */
 protected function _getElementHtml(\Magento\Framework\Data\Form\Element\AbstractElement $element)
 {
     $urlParams = ['section' => $this->getRequest()->getParam('section'), 'website' => $this->getRequest()->getParam('website'), 'store' => $this->getRequest()->getParam('store'), StructurePlugin::REQUEST_PARAM_COUNTRY => '__country__'];
     $urlString = $this->_escaper->escapeJsQuote($this->_url->getUrl('*/*/*', $urlParams));
     $jsString = '
         $("' . $element->getHtmlId() . '").observe("change", function () {
             location.href = \'' . $urlString . '\'.replace("__country__", this.value);
         });
     ';
     if ($this->_defaultCountry) {
         $urlParams[self::REQUEST_PARAM_DEFAULT_COUNTRY] = '__default__';
         $urlString = $this->_escaper->escapeJsQuote($this->_url->getUrl('*/*/*', $urlParams));
         $jsParentCountry = $this->_escaper->escapeJsQuote($this->_defaultCountry);
         $jsString .= '
             $("' . $element->getHtmlId() . '_inherit").observe("click", function () {
                 if (this.checked) {
                     location.href = \'' . $urlString . '\'.replace("__country__", \'' . $jsParentCountry . '\')
                         .replace("__default__", "1");
                 }
             });
         ';
     }
     return parent::_getElementHtml($element) . $this->_jsHelper->getScript('require([\'prototype\'], function(){document.observe("dom:loaded", function() {' . $jsString . '});});');
 }
Beispiel #5
0
 /**
  * Return js code for fieldset:
  * - observe fieldset rows;
  * - apply collapse;
  *
  * @param AbstractElement $element
  * @return string
  */
 protected function _getExtraJs($element)
 {
     $htmlId = $element->getHtmlId();
     $output = "require(['prototype'], function(){Fieldset.applyCollapse('{$htmlId}');});";
     return $this->_jsHelper->getScript($output);
 }