<?php 
/********************************************************************************* 
 *  This file is part of Sentrifugo.
 *  Copyright (C) 2014 Sapplica
 *   
 *  Sentrifugo is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  Sentrifugo is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with Sentrifugo.  If not, see <http://www.gnu.org/licenses/>.
 *
 *  Sentrifugo Support <support@sentrifugo.com>
 ********************************************************************************/
?>
        	<div class="new-form-ui" id="ffdiv">
	            <label>Feedforward</label>
	            <div class="division">
	            	<select id="ff_id" name="ff_id" onchange="getFFStatusEmps(this.value)">
						<option  value="">Select Feedforward</option>
						<?php if(!empty($this->ffdataarr)) { 
									foreach($this->ffdataarr as $value) {?>
							<option  value="<?php echo $value['id']?>"><?php echo $value['mode']?></option>
						<?php }}?>
					</select>
					<span class="errors" id="errors-ff_id"></span>
				</div>
        	</div>
        	
        	<div class="new-form-ui" >
	            <label>Feedforward Status</label>
	            <button type="button" id="ffstatusclear" name="ffstatusclear" class="inputclear" style="display:none;"  onclick="clearffstatus(1)">Clear</button>
	            <div class="division">
	            	<select id="ff_status_id" name="ff_status_id" onchange="getfeedforwardStatus(this.value)">
						<option  value="">Select Feedforward Status</option>
							<option  value='1'>Pending employee ratings</option>
							<option  value='2'>Completed</option>
					</select>
					<span class="errors" id="errors-ff_id"></span>
				</div>
        	</div>
        	
			<div id="feedforward_emp_status" class="feedforward_emp_status">
			</div>

<script type="text/javascript">
function clearffstatus(flag)
{
	
	var feedforwardval = $('#ff_id').val();
	$("#ffstatusclear").hide();
	$('#ff_status_id').val('');
	$('#s2id_ff_status_id .select2-choice span').html('Select Feedforward Status');
	if(flag==1)
		getFFStatusEmps(feedforwardval);
}
function getfeedforwardStatus(value)
{
	var feedforwardval = $('#ff_id').val();
	$("#errors-ff_id").html('');
	var val = $("#ff_id option:selected").text();
	if(value)
	{
		
		if(feedforwardval == '')
		{
			$("#errors-ff_id").html("Please select feedforward");
			$('#ff_status_id').val('');
			$('#s2id_ff_status_id .select2-choice span').html('Select feedforward Status');
		}else
		{
			$("#ffstatusclear").show();
			
			$.ajax({
	         	url: base_url+"/feedforwardstatus/getfeedforwardstatus/format/html",
	         	type : 'POST',	
				data : 'id='+feedforwardval+'&ffstatus='+value,
				dataType: 'html',
				beforeSend: function () {
					$.blockUI({ width:'50px',message: $("#spinner").html() });
				},
				success : function(response){
					$.unblockUI();
					$("#feedforward_emp_status").html(response);	
					$("#appraisalinfo").html(val);
				}
	    	});	
			
		}	
	}else
	{
		$("#ffstatusclear").hide();
		getFFStatusEmps(feedforwardval);
	}	
	
}
function getFFStatusEmps(id){

	$("#ffstatusclear").hide();
	$('#ff_status_id').val('');
	$('#s2id_ff_status_id .select2-choice span').html('Select Feedforward Status');
	$("#feedforward_emp_status").html("");

	if(id)
	{
		var val = $("#ff_id option:selected").text();
		
		$.ajax({
         	url: base_url+"/feedforwardstatus/getffstatusemps/format/html",
         	type : 'POST',	
			data : 'id='+id,
			dataType: 'html',
			beforeSend: function () {
				$.blockUI({ width:'50px',message: $("#spinner").html() });
			},
			success : function(response){
				$.unblockUI();
				$("#feedforward_emp_status").html(response);	
				$("#appraisalinfo").html(val);
			}
    	});			
	}else
	{
		$("#feedforward_emp_status").html("");
		clearffstatus(2);
	}
}

</script>