<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;
use yii\helpers\ArrayHelper;
use app\models\Departments;

/* @var $this yii\web\View */
/* @var $model app\models\Labmaster */
/* @var $form yii\widgets\ActiveForm */

$departments = ArrayHelper::map(Departments::find()->orderBy(["lab_dept_name" => SORT_DESC])->all(), 'lab_dept_code', 'lab_dept_name');

$JS="
	
	$('#labmaster-lab_spot_test').change(function(){
		if($(this).prop('checked')) {
			$('#labmaster-lab_subsequent_result').prop('disabled', false);
			}
		else {
			$('#labmaster-lab_subsequent_result').prop('checked', false).prop('disabled', true);
            $('#labmaster-lab_subsequent_result').val('');			
		}		
	});

	$('#labmaster-lab_spot_test').trigger('change');


";
$this->registerJs($JS);
?>

<div class="labmaster-form">
	<div class="panel panel-default">
		<div class="panel-heading">
			
		</div>
		<div class="panel-body">
			<div class="row">
				<div class="col-lg-12">
					<?php
						$form = ActiveForm::begin(['options' => ['class' => 'form-horizontal']]);
						$template = [
							'labelOptions' => ['class' => 'form-label'],
							'template' => '<div class="col-sm-5">{label}{hint}</div><div class="col-sm-4">{input}{error}</div>',
						];
						$htemplate = [
							'options' => ['tag' => false],
							'template' => '{input}'
						];					
						
					?>
					<?= $form->field($model, 'lab_dept_code', $template)->dropDownList($departments, ['prompt'=>$model->getAttributeLabel("lab_dept_code")]) ?>
					<?= $form->field($model, 'lab_test_code', $template)->textInput(['maxlength' => true]) ?>
					<?= $form->field($model, 'lab_test_name', $template)->textInput(['maxlength' => true]) ?>
					<?= $form->field($model, 'lab_spot_test', $template)->checkbox(['label' => null])->label() ?>
					<?= $form->field($model, 'lab_subsequent_result', $template)->checkbox(['label' => null])->label() ?>
					<?= $form->field($model, 'status', $template)->checkbox(['label' => null])->label() ?>
					<?= $form->field($model, $model->isNewRecord ? 'create_user' : 'update_user', $htemplate)->hiddenInput(['value' => yii::$app->user->identity->id])->label("") ?>
					<div class="form-group">
						<div class="col-sm-offset-5 col-sm-7">
							<?= Html::submitButton($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
							<?= Html::a('Cancel', ['/'.Yii::$app->controller->id], ['class' => 'btn btn-default']) ?>
						</div>
					</div>
					<?php ActiveForm::end(); ?>
				</div>
				<!-- /.col-lg-6 (nested) -->
			</div>
			<!-- /.row (nested) -->
		</div>
		<!-- /.panel-body -->
	</div>
	<!-- /.panel -->
</div>