
<?php $__env->startSection('title'); ?> Locations <?php $__env->stopSection(); ?>
<?php $__env->startSection('body'); ?>

<div class="row">
	<div class="form-group col-md-3">
		<button class="btn btn-primary generate" style="margin-top: 25px;">Generate</button>
		<button class="btn btn-primary export pull-right" style="margin-top: 25px;">Export</button>
	</div>
</div>

<div class="row">
	<div class="col-md-8">
		<div class="table-responsive">
			<table class="table table-bordered table-condensed report">
				<thead>
					<tr>
						<th width="100px">#</th>
						<th>Location</th>
					</tr>
				</thead>
				<tbody>
					<tr>
						<th colspan="2">Sorry, No results found.</th>
					</tr>
				</tbody>
			</table>
		</div>
	</div>
</div>

<?php $__env->stopSection(); ?>
<?php $__env->startSection('script'); ?>
<script type="text/javascript">
	$(function(){
		var _token = $('meta[name="_token"]').attr('content');
		var errors = JSON.parse('<?php echo json_encode($errors->toArray()) ?>');
		$('body').highlight({errors: errors.errors});
		$('.chosen-select').chosen({search_contains:true});

		$(document).ajaxStart(function () {
	        $('button').data('loading-text', '...');
	        $('button').button('loading');
	    }).ajaxStop(function () {
	        $('button').button('reset');
	    });
	    
	    
	    $(".export").click(function(){
			exportReport();
		});

		$(".generate").click(function(){
			generate();
		});
		

		function highlightOrThrow(e, callback){
			$.clearHighlights();
			if(e != undefined && typeof(e) == 'object'){
				if(e.hasOwnProperty('errors')){
					$.each(e.errors, function(i, k){
						$('.'+i).highlightElement({msg: k});
					});
				}else if(e.hasOwnProperty('ok') && e.hasOwnProperty('msg') && e.ok == 0){
					$.notify.error({msg: e.msg});
				}else if(e.hasOwnProperty('ok') && e.hasOwnProperty('msg')  && e.ok == 1){
					$.notify.success({msg: e.msg});
					if(callback != undefinded && typeof(callback) == 'function'){
						callback();
					}
				}else{
					callback();
				}
			}else{
				console.log('object expected.');
			}
		}

		function exportReport(){
			var data = {
	            
	        };
	        
			var dom = '<input type="hidden" name="_token" value="'+ _token +'"/>';
			$.each(data, function(k, v){
				if(v == null){
					v = '';
				}
				if(typeof(v) == "object"){
					$.each(v, function(i, j){
						dom += '<input type="hidden" name="'+ k +'['+ i +']" value="'+ j +'"/>';
					});
				}else{
					dom += '<input type="hidden" name="'+ k +'" value="'+ v +'"/>';
				}
			});
			$('<form action="<?php echo e(url("/report16/export")); ?>" method="post">'+ dom +'</form>').appendTo('body').submit();
			
			$.clearHighlights();
		}

		function generate(){

			$.post("<?php echo e(url('/report16/generate')); ?>", {_token: _token}, function(e){

				highlightOrThrow(e, function(){
					report(e);
				});
				
			}, 'json');
		}

		function report(e){
			if(e != undefined && typeof(e) == "object"){
				var dom = '';
				if(Object.keys(e).length > 0){
					$.each(e, function(i, k){
						dom += '<tr>';
						dom += '	<td>'+ (i + 1) +'</td>';
						dom += '	<td>'+ k.name +'</td>';
						dom += '</tr>';
					});
				}else{
					dom = '<th colspan="2">Sorry, No results found</th>';
				}
				$(".report tbody").html(dom);
			}
		}
	});
</script>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('layouts.master', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>