<?php
N2Html::topBar(array(
    'back'    => N2Html::tag('a', array(
        'id'    => 'n2-ss-preview',
        'href'  => $this->appType->router->createUrl(array(
            "preview/index",
            array('sliderid' => $sliderid) + N2Form::tokenizeUrl()
        )),
        'class' => 'n2-h4 n2-uc'
    ), n2_('Preview')),
    "actions" => array(
        N2Html::tag('a', array(
            'href'  => $this->appType->router->createUrl(array(
                "slider/edit",
                array(
                    "sliderid" => $sliderid
                )
            )),
            'class' => 'n2-button n2-button-normal n2-button-l n2-radius-s n2-button-red n2-h4 n2-b n2-uc'
        ), n2_('Cancel')),
        N2Html::tag('a', array(
            'href'    => '#',
            'class'   => 'n2-button n2-button-normal n2-button-l n2-radius-s n2-button-green n2-h4 n2-b n2-uc',
            'onclick' => 'return N2Classes.Form.submit("#smartslider-form");'
        ), n2_('Save'))
    )
));
?>

<form id="smartslider-form" action="#" method="post">
    <?php
    $params = new N2Data($generator['params'], true);

    $group = $generator['group'];
    $type  = $generator['type'];

    N2HTML::heading(array(
        'title' => $generatorGroup->getLabel() . ' - ' . $generatorSource->getLabel()
    ));

    $form = new N2Form();
    $form->loadArray($params->toArray());

    $generatorSource->renderFields($form);

    echo $form->render('generator');


    $slideParams = new N2Data($slide['params'], true);
    $params->set('record-slides', $slideParams->get('record-slides', 1));

    $generatorModel->generatorCommonForm($params->toArray());
    ?>
    <input name="save" value="1" type="hidden"/>
</form>
<style>
    #generatorrecords {
        overflow: auto;
        width: 100%;
    }

    #generatorrecords table div {
        max-width: 200px;
        max-height: 200px;
        overflow: auto;
    }
</style>
<?php

N2JS::addInline('new N2Classes.SmartSliderGeneratorRecords("' . $this->appType->router->createAjaxUrl(array(
        'generator/recordstable',
        array('generator_id' => $generator['id'])
    )) . '");');
?>
<script type="text/javascript">

    N2R('documentReady', function ($) {

        var form = $('#smartslider-form'),
            formAction = form.attr('action'),
            isPreview = false;
        var newWindow = <?php echo intval(N2SmartSliderSettings::get('preview-new-window', 0)); ?>;

        if (!newWindow) {
            var modal = new N2Classes.NextendSimpleModal('<iframe name="n2-tab-preview" src="about:blank" style="width: 100%;height:100%;"></iframe>', {
                "class": 'n2-ss-preview-modal'
            });
            modal.modal.on('ModalHide', function () {
                modal.modal.find('iframe').attr('src', 'about:blank');
                $(window).trigger('SSPreviewHide');
            });
        }

        $('#n2-ss-preview').on('click', function (e) {
            isPreview = true;
            e.preventDefault();
            if (!newWindow) {
                modal.show();
            } else {
                N2Classes.NextendModal.newFullWindow('', 'n2-tab-preview');
            }
            form.attr({
                action: '<?php echo $this->appType->router->createUrl(array(
                    "preview/generator",
                    N2Form::tokenizeUrl() + array('generator_id' => $generator['id'])
                ))?>',
                target: 'n2-tab-preview'
            }).submit().attr({
                action: formAction,
                target: null
            });
            isPreview = false;
        });
    });
</script>

<div style="height: 200px"></div>