/**
  * Renders the forms of a container.
  *
  * @param WizardContainer $container
  * @param string $layout
  * @param array $parameter
  * @return string
  */
 public function render(WizardContainer $container, $layout = Form::LAYOUT_HORIZONTAL, $parameter = array())
 {
     $content = '';
     $content .= $container->renderPre($this->getView());
     $tabsNav = '';
     $tabsContent = '';
     $containerParams = ['finish_label' => 'Finish', 'finish_href' => 'javascript:;', 'finish_enabled' => true];
     if (isset($parameter['wizard'])) {
         $containerParams = array_merge($containerParams, $parameter['wizard']);
         unset($parameter['wizard']);
     }
     $translate = $this->getView()->plugin('translate');
     $formContainer = $this->getView()->plugin('formcontainer');
     if ($container instanceof ViewPartialProviderInterface) {
         return $this->getView()->partial($container->getViewPartial(), array('element' => $container));
     }
     $containerId = $container->getAttribute('id');
     if (!$containerId) {
         $containerId = 'wizardcontainer-' . strtolower(str_replace('\\', '-', get_class($container)));
     }
     foreach ($container as $tabElement) {
         $tabId = $containerId . '-' . strtolower($tabElement->getName());
         $tabsNav .= '<li><a data-toggle="tab" href="#' . $tabId . '">' . $translate($tabElement->getLabel()) . '</a></li>';
         $tabsContent .= '<div class="tab-pane" id="' . $tabId . '">' . $formContainer($tabElement, $layout, $parameter) . '</div>';
     }
     $content .= '<div class="wizard-container" id="' . $containerId . '">' . '<ul>' . $tabsNav . '</ul>' . '<div class="tab-content">' . $tabsContent . '</div>' . '<ul class="pager wizard">' . '<li class="previous"><a href="javascript:;">&larr; ' . $translate('previous') . '</a></li>' . '<li class="next"><a href="javascript:;">' . $translate('Next') . ' &rarr;</a></li>' . '<li class="finish' . ($containerParams['finish_enabled'] ? '' : ' disabled') . '">' . (false !== $containerParams['finish_label'] ? '<a class="pull-right" href="' . $containerParams['finish_href'] . '">' . $translate($containerParams['finish_label']) . ' &bull;</a>' : '') . '</li></div>';
     $content .= $container->renderPost($this->getView());
     return $content;
 }
Example #2
0
    public function renderPost(Renderer $renderer)
    {
        $coreformsjs = $renderer->basepath('/Core/js/core.forms.js');
        $javaScript = <<<JS
        \$(document).ready(function() {

            console.log('attached yk.forms.done to ', \$('form'));

             \$('form').on('yk.forms.done', function(event, data) {
                //if (typeof data != 'undefined' && typeof data['data'] != 'undefined') {}
                if (typeof data != 'undefined' && typeof data['data'] != 'undefined') {
                    if (typeof data['data']['jobvalid'] != 'undefined' && data['data']['jobvalid'] === true) {
                        \$('#job_incomplete').hide();
                        \$('.wizard-container .finish').removeClass('disabled');
                    }
                    else {
                        \$('#job_incomplete').show();
                        \$('.wizard-container .finish').addClass('disabled');
                    }
                }
                \$('#job_errormessages').empty();

                if (typeof data['data']['errorMessage'] != 'undefined') {
                    \$('#job_errormessages').append(data['data']['errorMessage']);
                }
                console.debug('job-form-inline', event, data);
             });
             \$('.wizard-container').on('wizard:tabShow.jobcontainer', function(e, \$tab, \$nav, index) {
                var \$link = \$tab.find('a');
                var href = \$link.attr('href');
                var \$target = \$(href);
                var \$iframe = \$target.find('iframe');

                \$iframe.each(function() { this.contentDocument.location.reload(true); });

                var \$productList = \$target.find('#product-list-wrapper');
                if (\$productList.length) {
                    \$productList.html('').load('/' + lang + '/jobs/channel-list?id=' + \$('#general-nameForm-job').val());
                }
             });

             \$('.wizard-container .finish a').click(function (e) {
                if (\$(e.currentTarget).parent().hasClass('disabled')) {
                    e.preventDefault();
                    return false;
                }
             });

        });
JS;
        $renderer->headScript()->appendScript($javaScript);
        return parent::renderPost($renderer);
    }