<?php
/* @var $this TabberTabController */
/* @var $model TabberTab */
/* @var $form CActiveForm */
?>
<h6>For Tabber: <?php echo $model->tabber->title ?></h6>
<br/>
<div class="col-xs-12">
    <?php
    $form = $this->beginWidget('bootstrap.widgets.TbActiveForm', array(
        'id' => 'tabber-tab-form',
        // Please note: When you enable ajax validation, make sure the corresponding
        // controller action is handling ajax validation correctly.
        // There is a call to performAjaxValidation() commented in generated controller code.
        // See class documentation of CActiveForm for details on this.
        'enableAjaxValidation' => false,
    ));
    ?>
    <?php echo $form->errorSummary($model); ?>

    <?php echo $form->textFieldControlGroup($model, 'title', array('maxlength' => 400)); ?>


    <?php
    $this->beginWidget('zii.widgets.jui.CJuiDialog', array(
        'id' => 'select-widget-dialog',
        'options' => array(
            'title' => "<div class='widget-header widget-header-small'><h4 class='smaller'><i class='icon-list'></i> " . Yii::t('admin', 'Select Widget') . "</h4></div>",
            'width' => 700,
            'closeText' => '',
            'height' => 300,
            'autoOpen' => false,
            'modal' => true,
        ),
    ));

    Yii::import('admin.modules.widgets.models.Widget');
    Yii::import('admin.modules.widgets.models.WidgetInstance');
    $data = WidgetInstance::model()->findAll();
    $options = array();
    if ($data) {
        foreach ($data as $item) {
            $shortcode_name = $item->widget->shortcode;
            $shortcode_id = $item->id;
            $shortcode_code = "[shortcode:{$shortcode_name}:{$shortcode_id}]";
            $options[$shortcode_code] = $item->title;
        }
    }
    ?>

    <div class="col-xs-12">
        <div class="space"></div>
        <div class="form-group">
            <label class="col-md-3 control-label required" for="select-widget-select">
                <?php echo Yii::t('admin', 'Select Widget'); ?>
            </label>
            <div class="col-md-5 controls">
                <?php echo CHtml::dropDownList(false, false, $options, array('empty' => '', 'id' => 'select-widget-select', 'class' => 'form-control input-60')); ?>
            </div>
        </div>



        <div class="clearfix clear"></div>
        <?php
        echo TbHtml::formActions(array(
            TbHtml::button(Yii::t('admin', 'Select Widget'), array('color' => TbHtml::BUTTON_COLOR_PRIMARY, 'id' => 'select-widget-button')),
        ));
        Yii::app()->clientScript->registerScript('select-widget-button', 'jQuery("#select-widget-button").on("click",function(){
                            var selectedPage = jQuery("#select-widget-select").val();
                            if(selectedPage.length>0)
                            {
                                CKEDITOR.instances["TabberTab_content"].insertText(selectedPage);
                                jQuery("#select-widget-dialog").dialog("close");
                            }
                        });'
        );
        ?>
    </div>
    <?php $this->endWidget('zii.widgets.jui.CJuiDialog'); ?>


    <div class="widget-box">
        <div class="widget-header  widget-header-flat">
            <h4><?php echo $model->generateAttributeLabel('content') ?></h4>
            <div class="widget-toolbar">
                <?php
                echo CHtml::link(Yii::t('admin', 'Insert Widget'), '#', array('onclick' => '$("#select-widget-dialog").dialog("open"); return false;', 'class' => 'btn btn-xs btn-success'));
                ?>
            </div>
        </div>
        <div class="widget-body">
            <div class="control-group clearfix ">
                <div class="clearfix clear">
                    <?php
                    $this->widget('ext.fckeditor.FCKEditor', array(
                        'model' => $model,
                        'attribute' => 'content',
                    ));
                    ?>
                </div>
            </div>
        </div>
    </div>

    <?php echo $form->hiddenField($model, 'tabber_id'); ?>


    <?php echo TbHtml::formActions(array(TbHtml::submitButton($model->isNewRecord ? 'Create' : 'Save', array('color' => TbHtml::BUTTON_COLOR_PRIMARY)), TbHtml::resetButton('Reset'),)); ?>

    <!-- <p class="note">Fields with <span class="required">*</span> are required.</p> -->

    <?php $this->endWidget(); ?>
</div>