<?php
$this->beginWidget('zii.widgets.jui.CJuiDialog', array(
    'id' => 'select-widget-dialog',
    'options' => array(
        'title' => Yii::t('admin', 'Select Widget'),
		//'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,
    ),
));

$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 modal-dialog" role="document">
    <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["Article_content"].insertText(selectedPage);
                                jQuery("#select-widget-dialog").dialog("close");
                            }
                        });'
    );
    ?>
</div>
<?php $this->endWidget('zii.widgets.jui.CJuiDialog'); ?>