Location: PHPKode > projects > SimpleHRM > simplehrm-1.0-beta1/simplehrm-1.0-beta1/templates/default/employee/addLeave.tpl.html
<div style="width:405px;">
    <div class="modal_heading">
        <div class="lft fltlft"></div>
        <div class="mdl fltlft" style="width:333px;">
            <b>Send a leave request</b>
        </div>
        <div class="rht fltlft"></div>
        <div class="clear"></div>
    </div>
    <div class="modal_body">




            <form id="leave_form" name="leave_form" action="##LBL_SITE_URL##leave/insertLeave" method='post'>
                <input type="hidden" id="upd_id" name="upd_id" class="text" value="{$sm.res.id_leave_req}">	
                <table class="listing_tbl">
                    <tr>
                        <td class="fltrht">Leave type:</td>
                        <td>
                            <select id="leave_type" name="leave[leave_type]">
                                <option value="" selected="selected">-Select-</option>
                                {html_options options=$sm.leave_type_res selected=$sm.res.leave_type}
                            </select>			
                        </td>	
                    </tr>
                    <tr>
                        <td class="fltrht">Dates:</td>
                        <td class="divimg"><input type="text" id="leave_date" name="leave_date" class="text" value="{if $sm.res}{$sm.res.from_date|date_format:'%d-%m-%Y'} to {$sm.res.to_date|date_format:'%d-%m-%Y'}{/if}"><img src="##LBL_SITE_URL##templates/css_theme/img/daterange/calendar.gif" id="imgrange1"></td>	
                    </tr>
                    <tr>
                        <td class="fltrht">Working days:</td>
                        <td>
                            <input type="text" id="work_days" name="leave[work_days]" class="text" readonly="true" value="{$sm.res.work_days}">			
                        </td>	
                    </tr>
                    <tr>
                        <td class="fltrht">Notes:</td>
                        <td>
                            <textarea id="notes" name="leave[notes]" class="text">{$sm.res.notes}</textarea>
                        </td>	
                    </tr>
                    <tr>
                    	<td></td>
                        <td>
                            <input type="button" value="Send" onclick="save();" class="login_btn">
                        </td>	
                    </tr>
                </table>
            </form>
	</div>
</div>

{literal}
<script type="text/javascript">
forminfo("#leave_form");
$(document).ready(function(){
	var id = "imgrange1";
	$(".divimg").find('img').daterangepicker({dateFormat: 'dd-mm-yy',posX:'800px', posY:'350px', datepickerOptions:{changeMonth:true,changeYear:true,yearRange:"-0:+50"},
	onClose:function(id,rangeA,rangeB){
		if(rangeA!=undefined && rangeB!=undefined){
			nrangeBA = rangeB.split("-");
			nrangeB = nrangeBA[1]+"/"+nrangeBA[0]+"/"+nrangeBA[2];
			nrangeAA = rangeA.split("-");
			nrangeA = nrangeAA[1]+"/"+nrangeAA[0]+"/"+nrangeAA[2];
			
			if(new Date(nrangeB) >= new Date(nrangeA)){
				//jqueryAlert(nrangeB);
				$('#leave_date').val(rangeA+" to "+rangeB);
				
				var days=dateDiff(nrangeA,nrangeB);
				//for(i in days)jqueryAlert(days[i]);
				$("#work_days").val(days);
			}else{
				//jqueryAlert("End date should be > start date.");
				return false;
			}
		}else{
			jqueryAlert("No date selected.");
			return false;
		}
	}
	}); 
});
function dateDiff( str1, str2 ) {
	//jqueryAlert(Date.parse( str2 ))
    	var diff = Date.parse( str2 ) - Date.parse( str1 ); 
	return (diff/86400000)+1;
    
}
function save(){
	var ch,qstart=0;
	var res = leaveForm();
	var flag='{/literal}{$sm.res.id_leave_req}{literal}';
	var leavestatus='';
	if(flag!=''){
		ch="updateLeave";
		$('.leavestatus').each(function(){
			if($(this).is(':checked'))
			leavestatus=leavestatus+","+$(this).val();
		});
		qstart=$("#qstart").val();
	}else{
		ch="insertLeave";
	}
	if(res){
		cShowActivity('2');
		var data=$("#leave_form").serialize();
		var url="##LBL_SITE_URL##index.php/employee/"+ch+"?"+data;
		$.post(url,{ce:0,chk:1,qstart:qstart,leavestatus:leavestatus},function (response){
			$("#employee_leaveRequest").html(response);
			closeFancyBox = 2;
			$.fancybox.close();
			closeFancyBox = 0;
			cHideActivity();
		});
	}else
		return false;
}
function leaveForm(){		
	var validator_leave_form=$("#leave_form").validate({
		rules: {
			"leave[leave_type]": {
				required:true
			},
			"leave_date]": {
				required:true
			},
			"leave[notes]": {
				required:true
			}
		},
		messages: {
			"leave[leave_type]":{
				required:flexymsg.required
			},
			"leave_date":{
				required:flexymsg.required
			},
			"leave[notes]":{
				required:flexymsg.required
			}
		}
	});
	return validator_leave_form.form();
}
</script>
<style type="text/css">
select,option { text-transform : capitalize ;}
#leave_form .text {
	width:210px;
	margin-right:10px;
	padding:3px;
	border:1px solid #ccc;
	letter-spacing:1px;
}
#leave_form select {
	border:1px solid #ccc;
	width:219px;	
	padding:4px;
}
</style>
{/literal}
Return current item: SimpleHRM