<?php
$baseUrl = $this->baseUrl();
$this->placeholder('headling_1')->captureStart(); ?>
<h1>
    <?php echo $this->placeholder('headling_1_content') ?>
        <?php if ($this->previous):?>
            <a class="icon icon-prev" href="<?php echo $this->url(array('id' => $this->previous->id));?>"><?php echo $this->translate('Previous'); ?></a>
        <?php else:?>
            &nbsp;
        <?php
        endif;
        ?>
        <?php if ($this->next):?>
            <a class="icon icon-next" href="<?php echo $this->url(array('id' => $this->next->id));?>"><?php echo $this->translate('Next')?></a>
        <?php else:?>
            &nbsp;
        <?php endif;?>
</h1>
<?php /*?>
    <div class="pager" >
        <span class="infos"><?php echo $this->translate('<strong>%d</strong> of <strong>%d</strong>', $this->currentCount,
                                                    $this->totalCount);?></span>
    </div>
    <?php */ ?>
<?php $this->placeholder('headling_1')->captureEnd(); ?>
<?php 
if (isset($this->error) || isset($this->infos)) : ?>
    <div class="ui-state-message">
        <?php if (isset($this->errors)):
            $this->errors = (array) $this->errors;
            foreach ($this->errors as $error):
                ?>
                <p class="ui-state-error"">
                    <?php echo $error;?>
                </p>
            <?php
            endforeach;
        ?>
        <?php endif;?>
        <?php if (isset($this->infos)):
            $this->infos = (array) $this->infos;

            foreach ($this->infos as $info):
                ?>
                    <p class="ui-state-highlight">
                        <?php echo $info;?>
                    </p>
                <?php
            endforeach;
        endif;?>
    </div>
<?php endif;?>
<?php 
$this->headScript()->captureStart();
?>
$(function(){
    $(".form .form-main .form-group").CUI('fieldset', {basePath: '<?php echo $baseUrl; ?>', autoClose: <?php  echo (method_exists($this->form, 'hasInstance') && $this->form->hasInstance()) ? 'true':'false'?>});
    $(".field-multiselect:not(.sortable)").CUI('multiselect', {basePath: '<?php echo $baseUrl; ?>'});
    $(".field-multiselect.sortable").CUI('multiselect', {basePath: '<?php echo $baseUrl; ?>', multiselectSortable:true});
    $(".field-switcher").CUI('switcher', {basePath: '<?php echo $baseUrl; ?>'});

    $(".field-letterlimit").CUI('letterLimit', { basePath: '<?php echo $baseUrl; ?>', maxChar: 100 });

    $(".field-datepicker").CUI('datepicker', {
        basePath: '<?php echo $baseUrl; ?>', 
        changeMonth: true,
        changeYear: true,
        dateFormat: '<?php echo $this->dateFormat; ?>'
    });
    
    $(".field-datetimepicker").CUI('datetimepicker', {
                basePath: '<?php echo $baseUrl; ?>', 
                duration: '',
                showTime: true,
                showHour: true,
                showMinute: true,
                constrainInput: false,
                stepMinutes: 1,
                stepHours: 1,
                altTimeField: '',
                time24h: false,
                dateFormat: '<?php echo $this->dateFormat; ?>'
             });

     $('.field-rte').CUI('rte', {
         basePath: '<?php echo $baseUrl; ?>', 
        convert_urls : false,
        content_css : "<?php echo $baseUrl; ?>/layouts/frontoffice/css/rte.css"
     });
        $(".field-file").CUI('file', {basePath: '<?php echo $baseUrl; ?>'});
});
<?php $this->headScript()->captureEnd(); ?>

<?php

$this->form->addElements(array(
    //'_cancel'       =>  array('button', array('type' => 'button', 'label' => $this->form->getTranslator()->_('Cancel'))),
    '_save'         =>  array('button', array('type' => 'submit', 'label' => $this->translate('Save@backoffice'))),
    '_addanother'   =>  array('button', array('type' => 'submit', 'label' => $this->translate('Save and add another@backoffice'))),
    '_continue'     =>  array('button', array('type' => 'submit', 'label' => $this->form->getTranslator()->_('Save and continue'))),
));

$this->Cui_MakeSaveButton($this->form);

$this->form->addDisplayGroup(array('_save', '_cancel', '_addanother', '_continue'), 'submit');

$this->form->getDisplayGroup('submit')->addDecorator('HtmlTag', array('tag'  => 'div',
                                                                     'class' => 'clear'
                                                                ));

$this->getHelper('gridForm')->makeOnOff($this->form);


// move elements to ensure the form will be rendered correctly
if ($this->form->_aside) {
    $this->form->moveElement('_aside', Centurion_Form::FIRST);
}

if ($this->form->_main) {
    $this->form->moveElement('_main', Centurion_Form::FIRST);
}

if ($this->form->_header) {
    $this->form->moveElement('_header', Centurion_Form::FIRST);
}

$decoratorsArray = array(
    'FormElements',
    array('HtmlTag', array('tag' => 'div'))
);

if ($this->form->getDisplayGroup('_main')) {
    $decoratorsArray = array(
        'FormElements',
        array('HtmlTag', array('tag' => 'div', 'class' => 'form-submit clear'))
    );

    $this->form->addInDisplayGroup('submit', '_main');
}

if (null !== $this->form->getDisplayGroup('_header')) {
    $this->form->getDisplayGroup('_header')->addDecorators(array(array(array('tollbar' => 'ViewScript'), array('viewScript' => 'grid/_formtoolbar.phtml', 'toolbars' => $this->form->getToolbar()))));
}

$this->form->getDisplayGroup('submit')->setDecorators($decoratorsArray);
echo $this->form->render(null, true);
