<?php

use app\base\Common;
use yii\helpers\Url;
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use kartik\select2\Select2;
use yii\helpers\ArrayHelper;
use app\models\Motincenmaster;
use rmrevin\yii\fontawesome\FA;

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

$this->title = Yii::t('app', 'Create {modelClass} ', [
    'modelClass' => 'Motincenmaster',
]);
$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Motincenmaster'), 'url' => ['index']];
$this->params['breadcrumbs'][] = Yii::t('app', 'Create');
$this->params['menu'] = [
	['label' => FA::icon('align-justify fa-fw'), 'linkOptions' => ['class'=>'btn btn-default', 'title'=>'List'], 'url' => ['/'.Yii::$app->controller->id]],
];

$Surveys = Common::getSurvey();
//$PIDs = ArrayHelper::map(Motincenmaster::find()->where(["mot_inc_q1" => 0])->orderBy(["mot_inc_part_id" => SORT_ASC])->all(), 'mot_inc_part_id', 'mot_inc_part_id');
$PIDs = Common::getMotivationPIDs();


$JS = "
	$('.datepicker').datepicker({autoclose: true, startDate: '01-01-1900', endDate: '0', format: '".strtolower(Yii::$app->formatter->dateFormat)."'});
	
	$('#motincenmaster-mot_inc_part_id').on('select2:unselect', function (evt) {
		$('#pid_list').html('');
		$('#pid_list').addClass('hidden');
		$('button[type=submit]').prop('disabled', false);
	});

	$('#motincenmaster-mot_inc_part_id').on('select2:select', function (evt) {
		var pid = $(this)[0].value;
		$('button[type=submit]').prop('disabled', true);
		if(pid != '') {
			if(confirm('Have you checked nurse and all other entries prior to generating the incentives?   If Yes, Please click OK button and proceed')){
			if(confirm('Hope you know by hitting OK button, you are now assuring all entries have been checked and there is no error.  If Yes, Please click OK button and proceed')){
			
			var link = '".Url::toRoute(['index', 'ajaxload' => true, 'MotincenmasterSearch' => ['mot_inc_q1' => 0, 'mot_inc_part_id' => '']])."' + pid;
			$('#pid_list').removeClass('hidden');
			$('#pid_list').html('');
			$('#pid_list').load(link);
		}
		$('button[type=submit]').prop('disabled', false);
		}
		else {
			alert('Please check and get back');
			$('button[type=submit]').prop('disabled', true);
		}
		}
	});

	$('button[type=submit]').click(function() {
    	val = '';
		$('#motincenmaster-mot_inc_id').val(val);
    	$('input[type=checkbox].checkbox-row').each(function(){
    		if($(this).is(':checked')) {
    			val += $(this).val() + ',';
    			$('#motincenmaster-mot_inc_id').val(val);
    		}
    	});
	});
";
$this->registerJs($JS);
?>
<div class="motincenmaster-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}'
						];
					?>
					<?php // $form->errorSummary($model); ?>
					<?= $form->field($model, 'mot_inc_id', $htemplate)->hiddenInput()->label("") ?>
					<?= $form->field($model, 'mot_inc_survey', $template)->dropDownList($Surveys) ?>
					<?= $form->field($model, 'mot_inc_part_id', $template)->widget(Select2::classname(), ['data' => $PIDs, 'options' => ['prompt' => $model->getAttributeLabel("mot_inc_part_id")]])->hint("<strong>Please Bar Code Scan the ICC Client ID</strong>"); ?>
					<div id="pid_list" class="row-fluid popup"></div>
					<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>