<?php
Yii::app()->clientScript->registerScript('submit', '
$(document).ready( function() {
   $("#submit_button").click(function() {
      $(this).prop("disabled",true)
         .parents("form").submit();
      });
})
');
?>

<div class="form">

	<?php
		$form = $this->beginWidget('GxActiveForm', array(
			'id' => 'criterios-form',
			'enableAjaxValidation' => false,
		    'focus'=>array($model,'CRI_TITULO'),
		)
	);
	?>

	<?php echo FaHtml::getFormInfo($form, $model); ?>
	<div class="frm_col frm_col_1">
		<div class="row">
			<?php echo $form->labelEx($model,'CRI_TITULO'); ?>
			<?php echo $form->textField($model, 'CRI_TITULO', array('maxlength' => 100)); ?>
			<?php echo $form->error($model,'CRI_TITULO'); ?>
		</div><!-- row -->
		<div class="row">
			<?php echo $form->labelEx($model,'CRI_DESCRICAO'); ?>
			<?php echo $form->textArea($model, 'CRI_DESCRICAO'); ?>
			<?php echo $form->error($model,'CRI_DESCRICAO'); ?>
		</div><!-- row -->

		<div class="row">
			<?php echo $form->labelEx($model,'CRI_SITUACAO'); ?>
			<?php echo $form->dropDownList($model, 'CRI_SITUACAO', array('A' => 'Ativo','I' => 'Inativo')); ?>
			<?php echo $form->error($model,'CRI_SITUACAO'); ?>
		</div><!-- row -->
    </div>
    <div class="frm_col frm_col_1">
    	<a href="script:void(0);" class="add-criterio-local-privilegio"><i class="fa fa-user-plus"></i> Adicionar Permissão Local/Privilégio</a>
    	<div class="criterios-locais-privilegios">
    		<?php
    		if(!empty($model->CriteriosLocaisPrivilegios)) {
				foreach ($model->CriteriosLocaisPrivilegios as $key => $related) {
					$this->renderPartial('_criterio_local_privilegio', array('model' => $related));
				}
			}
    		?>
    	</div>
    </div>
    <div class="clearfix"></div>
	<?php
	echo FaHtml::saveButton();
	$this->endWidget();
	?>
</div><!-- form -->
<script type="text/javascript">
    $(".add-criterio-local-privilegio").on("click", function(e){
        e.preventDefault();
        $.post('<?php echo Yii::app()->request->baseUrl ?>/index.php?r=criterios/AddCriterioLocalPrivilegio', {}, function (data) {
            $('.criterios-locais-privilegios').append(data);
        });
    });

    $(document).on("click", ".excluir-criterio-local-privilegio", function(e){
        e.preventDefault();
        if(confirm('Tem certeza que deseja excluír este item?')) {
            $(this).parents(".criterio-local-privilegio").remove();
        }
    });
</script>
<style type="text/css">
	.criterios-locais-privilegios,
	.criterio-local-privilegio {
		display: block;
		float: left;
		width: 100%;
	}
	.criterios-locais-privilegios .half {
		width: 50%!important;
		padding: 5px 10px;
		float: left!important;
		display: inline!important;
		-webkit-box-sizing: border-box;
    	-moz-box-sizing: border-box;
        box-sizing: border-box;
	}
	.criterios-locais-privilegios label,
	.criterios-locais-privilegios select {
		display: block;
		width: 100%!important;
	}
	.link-excluir-item {
		display: block;
		float: right;
		margin-right: -27px;
		margin-top: -27.5px;
	}
	.add-criterio-local-privilegio {
		color: #3973AD;
	}
</style>