<?php
/* @var $this WidgetInstanceController */
/* @var $model WidgetInstance */
/* @var $form CActiveForm */
?>
<div class="col-xs-12">
    <?php
    $form = $this->beginWidget('bootstrap.widgets.TbActiveForm', array(
        'id' => 'widget-instance-form',
        'enableAjaxValidation' => false,
    ));
    ?>
    <!-- <p class="note">Fields with <span class="required">*</span> are required.</p> -->
    <?php echo $form->errorSummary($model); ?>
    <?php echo $form->hiddenField($model, 'id'); ?>
    <?php echo $form->textFieldControlGroup($model, 'title', array('maxlength' => 200)); ?>

    <?php
    $ajaxOptions = array(
        'type' => 'POST',
        'data' => new CJavaScriptExpression('jQuery("#widget-instance-form").serialize()'),
        'url' => CController::createUrl('/admin/widgets/widgetInstance/options'),
        'update' => '#widget_instance_options',
        'beforeSend' => 'function() {          
			$("#widget_instance_options-container").hide();
			$(".loading-sm").show();
		    }',
        'complete' => 'function() {
			$("#widget_instance_options-container").show();
			$(".loading-sm").hide();
		    }',
            //'data'=>'js:javascript statement' 
            //leave out the data key to pass all form values through
    );
    echo $form->dropDownListControlGroup($model, 'widget_id', CHtml::listData(Widget::model()->findAll(), 'id', 'title'), array(
        'ajax' => $ajaxOptions, 'empty' => ''));
    ?>
    <div class="row">
        <div class="col-md-5 col-md-offset-3">
            <div class="loading-sm center">
                <small><?php echo Yii::t('admin', 'Loading Widget Options...'); ?></small>
            </div>

            <div class="widget-box display-none" id="widget_instance_options-container">
                <div class="widget-header">
                    <h4><?php echo Yii::t('admin', 'Widget Options'); ?></h4>
                </div>
                <div class="widget-body">
                    <div class="widget-main clearfix">
                        <div id="widget_instance_options" class="col-xs-12">
                            <?php
                            if (!$model->isNewRecord):
                                $ajax = CHtml::ajax($ajaxOptions);
                                Yii::app()->clientScript->registerScript('init-widgetintane-options', $ajax, CClientScript::POS_READY);
                                $this->renderPartial('_optionsForm', array('model' => $model));
                            endif;
                            ?>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

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

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