<?php
/* @var $this AnswerController */
/* @var $answer Answer */
/* @var $form CActiveForm */
?>


<div class="form-normal form-horizontal clearfix">
	<div class="col-md-10 col-md-offset-1">

		<?php $form=$this->beginWidget('CActiveForm', array(
			'id'=>'answer-form',
			'enableAjaxValidation'=>false,
			'enableClientValidation' => true,
			'clientOptions' => array(
				'validateOnSubmit' => true,
			),
			'errorMessageCssClass' => 'label label-danger',
			'htmlOptions' => array('class' => 'form-horizontal', 'role' => 'form')
		)); ?>

		<?php echo $form->errorSummary($answer, null, null, array('class' => 'alert alert-warning')); ?>

		<div class="form-group">

			<div class="col-sm-12 be-radio">
				<?php echo $form->error($answer,'answer_status'); ?>
				<?php
				echo $form->radioButtonList($answer,'answer_status',
					array('0'=>'Tidak','1'=>'Ada'),
					array(
						'template'=>'{input}{label}',
						'separator'=>'',
						'labelOptions'=>array(
							'style'=>'padding-right:25px'),

					)
				);
				?>
			</div>

		</div>

		<div id="showAnswer" style="display: none">

			<?php if($data->type==1): ?>

				<div class="form-group">
					<div class="col-sm-12 be-radio be-radio-color inline">
						<p class="alert alert-primary">Jika Ya, apa Bentuknya</p>
						<?php echo $form->error($answer,'answer_id'); ?>
						<?php echo $form->radioButtonList($answer,'answer_id',CHtml::listData(QuestionAnswer::model()->findAll(array('condition'=>'question_id=','order'=>'name ASC')),
							'id_question_asnwer', 'name'
						),
						array(
							'template'=>'{input}{label}',
							'separator'=>'',
							'labelOptions'=>array(
								'style'=>'padding-right:50px;'),

						)
					); ?>
				</div>
			</div>

		<?php endif; ?>

		<?php if($data->type==2): ?>

			<div class="form-group">
				<div class="col-sm-12">
					<div class="be-checkbox be-checkbox-color inline">
						<?php echo $form->error($answer,'answer_id'); ?>
						<?php echo $form->checkBoxlist($answer,'answer_id',CHtml::listData(QuestionAnswer::model()->findAll(array('condition'=>'question_id'=>$model->id_question,'order'=>'name ASC')),
							'id_question_asnwer', 'name'
						),
						array(
							'template'=>'{input}{label}',
							'separator'=>'',
							'labelOptions'=>array(
								'style'=>'padding-right:50px;',
								'class'=>'get_value'
							),

						)
					); ?>
				</div>
			</div>
		</div>

		<script>
			$(document).ready(function(){
				$('#submit').click(function(){
					var languages = [];
					$('.get_value').each(function(){
						if($(this).is(":checked"))
						{
							languages.push($(this).val());
						}
					});
					languages = languages.toString();
					$.ajax({
						url:"insert.php",
						method:"POST",
						data:{languages:languages},
						success:function(data){
							$('#result').html(data);
						}
					});
				});
			});
		</script>

	<?php endif; ?>

	<div class="form-group">

		<div class="col-sm-1">
			<?php echo $form->labelEx($answer,'answer'); ?>
		</div>
		<div class="col-sm-11">
			<?php echo $form->error($answer,'answer'); ?>
			<?php echo $form->textArea($answer,'answer',array('class'=>'form-control','placeHolder'=>'Catatan')); ?>
		</div>

	</div>


	<?php if($data->attachment==1): ?>

		<div class="form-group">

			<div class="col-sm-1">
				<?php echo $form->labelEx($answer,'attachment'); ?>
			</div>
			<div class="col-sm-11">
				<?php echo $form->error($answer,'attachment'); ?>
				<?php echo $form->textField($answer,'attachment',array('class'=>'form-control','value'=>$data->attachment)); ?>
			</div>

		</div>

	<?php endif; ?>

	<?php if($data->total_children==1): ?>

		<div class="form-group">

			<div class="col-sm-1">
			</div>
			<div class="col-sm-11 no-padding">

				<div class="col-sm-6">
					<div class="col-sm-5">
						<?php echo $form->labelEx($answer,'male'); ?>
					</div>
					<div class="col-sm-7">
						<?php echo $form->error($answer,'male'); ?>
						<?php echo $form->textField($answer,'male',array('class'=>'form-control','placeHolder'=>'Total Anak Laki-laki')); ?>
					</div>
				</div>



				<div class="col-sm-6">
					<div class="col-sm-5">
						<?php echo $form->labelEx($answer,'female'); ?>
					</div>
					<div class="col-sm-7">
						<?php echo $form->error($answer,'female'); ?>
						<?php echo $form->textField($answer,'female',array('class'=>'form-control','placeHolder'=>'Total Anak Perempuan')); ?>
					</div>
				</div>

			</div>

		</div>

	<?php endif; ?>


</div>


<div id="showReason" style="display: none">

	<div class="form-group">

		<div class="col-sm-12">
			<?php echo $form->error($answer,'reason'); ?>
			<?php echo $form->textArea($answer,'reason',array('class'=>'form-control','placeHolder'=>'Alasan memilih Tidak ?')); ?>
		</div>

	</div>

</div>



<div class="form-group">
	<div class="col-md-12">
	</br></br>
	<?php echo CHtml::submitButton($answer->isNewRecord ? 'Simpan Jawaban' : 'Edit', array('class' => 'btn btn-info btn-flat pull-right')); ?>
</div>
</div>

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

</div></div><!-- form -->


<script type="text/javascript">
	$(function () {
		$("input[name='Answer[answer_status]']").click(function () {
			if ($("#Answer_answer_status_1").is(":checked")) {
				$("#showAnswer").show();
				$("#showReason").hide();
			} else {
				$("#showAnswer").hide();
				$("#showReason").show();
			}
		});
	});
</script>