<?php
/* @var $this BadgeAssignmentRuleController */
/* @var $model BadgeAssignmentRule */
/* @var $form CActiveForm */
?>
<?php
$form = $this->beginWidget('bootstrap.widgets.FTbActiveForm', array(
            'id' => 'badge-assignment-rule-form',
            'enableAjaxValidation' => false,
        ));

$this->widget('bootstrap.widgets.TbAlert');


echo $form->dropDownListRow($model, 'person_type_id', CHtml::listData(PersonType::getAll("Active"), 'id', 'name'), array('empty' => Yii::t('default', 'Select Person Type')));

echo $form->dropDownListRow($model, 'badge_type_id', CHtml::listData(BadgeType::getAll("Active"), 'id', 'name'), array('empty' => Yii::t('default', 'Select Badge Type')));

if ($model->isNewRecord)
{
    $model->only_manager = 0;
    $model->only_food_manager = 0;
    $model->no_limit_on_badges_number = 0;
}
echo $form->radioButtonListInlineRow($model, 'only_manager', array('1' => Yii::t('default', 'Required'), '0' => Yii::t('default', 'Not required')));

echo $form->radioButtonListInlineRow($model, 'only_food_manager', array('1' => Yii::t('default', 'Required'), '0' => Yii::t('default', 'Not required')));

echo $form->radioButtonListInlineRow($model, 'no_limit_on_badges_number', array('0' => Yii::t('default', 'Yes'), '1' => Yii::t('default', 'No')), array(
    'onchange' => 'manage_max_badges_allowed_visibility()',
));

if ($model->no_limit_on_badges_number == 1)
{
    echo $form->textFieldRow($model, 'max_badges_allowed', array('disabled' => 'disabled'));
}
else
{
    echo $form->textFieldRow($model, 'max_badges_allowed');
}
?>



<div class="actions">
    <?php echo CHtml::submitButton(Yii::t('default', 'Save'), array('class' => 'btn primary')); ?>
    &ensp;
<?php echo CHtml::link(Yii::t('default', 'Cancel'), array('index'), array('class' => 'btn primary')); ?>
</div>

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

<script language="javascript" type="text/javascript">
    // this function will toggle the price input field if the program changed to free, and will display it again if the program changed to not free
    function manage_max_badges_allowed_visibility(){
        //TODO: bug fix
        if($("#BadgeAssignmentRule_no_limit_on_badges_number_1").attr('checked')){
            $('#BadgeAssignmentRule_max_badges_allowed').attr('disabled','disabled').val('');
        }
        else{
            $('#BadgeAssignmentRule_max_badges_allowed').removeAttr('disabled');
        }
    }
</script>