<head>
    <style>
        #tblproject th, tr, td {
            border-bottom:1px black solid; border-top:1px black solid;
        }        
    </style>
</head>

@extends('layouts.app')

@section('title')

@endsection

@section('breadcrumb')
   @parent
   <li>Project Perumahan</li>
@endsection


@section('content')   
<div class="row">
	<div class="container-fluid">
		<div class="card">
			<div class="card-block">  
			
    <a onclick="addForm()" class="btn btn-success btn-sm"><i class="fa fa-plus-circle"> </i> New Project </a> 			
    
<form method="post" id="form-project">
{{ csrf_field() }}

<input type="hidden" id="mgr" name ="mgr" value="{{ Auth::user()->group }}"> 

<table class="table table-padding table-striped table-responsive" id="tblproject" width="100%">
<thead>
   <tr class="tblheader">
   
        <th width="250px">Nama Perumahan</th>
        <th width="30px">Init</th>
        <th width="300px">Alamat</th>
        <th width="300px">Deskripsi</th>
        <th width="50px">Act</th>
 
	</tr>
</thead>
<tbody></tbody>

</table>
</form>

			</div>
		</div>
	</div>	
</div>

@include('project.project_create')
@include('project.listrumah')


@endsection

@section('script')
<script type="text/javascript">
var table, save_method;

$(function(){
    table = $('#tblproject').DataTable({
        "processing" : true,
        "lengthMenu": [[8, 25, 50, -1], [8, 25, 50, "All"]],       //pilihan jumlah record show
        "order" : [0,'DESC'],
        "ajax" : {
            "url" : "{{ route('project.dataproject') }}",
            "type" : "GET"
        }
    }); 
});   

//submit
$('#form-create').on("submit", function(e) {

    if(!e.isDefaultPrevented()){
		 
		$('#submit-control').html(' Simpan Create ... ');
		$('#submit-control').attr('disabled','disabled');
		  
        var id = $('#id').val();
        if(save_method == "add") { url = "{{ route('project.store') }}"; }
        else { url = "{{ DIR_APP }}project/"+id; }

        $.ajax({
            url : url,
            type : "POST",
            data : $('#form-create').serialize(),
            dataType: 'JSON',		   
            success : function(data){
			    if(data.msg=="error"){
					$('#submit-control').html('Save');
					$('#submit-control').removeAttr('disabled');
					swal("WARNING", " Gagal menyimpan data !","error");
					$('#prj').focus().select();
				}else{
					$('#modal-form_create').modal('hide');
					$('#submit-control').html('Save');
					$('#submit-control').removeAttr('disabled');		
					$('#tblproject').DataTable().ajax.reload(null, false);
				}   
 		    },
            error : function(){
			    swal("WARNING"," DATA tidak dapat disimpan, harap hubungi IT !","error");
			    $('#submit-control').html('Save');
			    $('#submit-control').removeAttr('disabled');			 
            }   
        });
        return false;
	}
});
   

function addForm(){
   save_method = "add";
   $('input[name=_method]').val('POST');
   $('#modal-form_create').modal('show');
   $('#modal-form_create form')[0].reset();            
} 	 


function editproject(id){
    save_method = "edit";

    $('input[name=_method]').val('PATCH');
    $('#modal-form_create form')[0].reset();
    $.ajax({
        url : "{{ DIR_APP }}project/"+id+"/edit",
        type : "GET",
        dataType : "JSON",
        success : function(data){
            $('#modal-form_create').modal('show');
            $('#id').val(data.id);

            $('#prj').val(data.project_name).attr('disabled', 'disabled');
            $('#ini').val(data.initial);
            $('#alm').val(data.address);
	        $('#kota').val(data.kota);
	        $('#ket').val(data.deskripsi);
	 
	    },
        error : function(){
            alert("Tidak dapat menampilkan data!");
        }
    });   
}


function tampilDetail(id){

    tbdetail.ajax.url("{{ DIR_APP }}sales/"+id+"/datadetail");
	tbdetail.ajax.reload();
}    

function tampil_Detail(id){
    tbldetail = $('#tbldetail').DataTable({
        "processing" : true,
        "lengthMenu": [[8, 25, 50, -1], [8, 25, 50, "All"]],       //pilihan jumlah record show
        "ajax" : {
            "url" : "{{ DIR_APP }}sales/"+id+"/datadetail",
            "type" : "GET"
        }
    });     
}


tblrumah = $('#tblrumah').DataTable({
    "scrollY": '55vh',
    "scrollCollapse": true,
    "bSort": false,
    "destroy": true,
    "processing" : true,
    "paging" : false,
    "dom" : 'bti',
});


function listrumah(id){
    $('#modal-rumah').modal('show');

    tblrumah.ajax.url("{{ DIR_APP }}rumah/"+id+"/listrumah");
	tblrumah.ajax.reload();
}

</script>


@endsection
