@extends('base.layout')

@section('content')
<div class="wrapper">
	<div class="container-fluid">
		<div class="row">
			<div class="col-lg-12">
			   <div class="card-box ribbon-box">
					<div class="ribbon ribbon-primary">User List</div>
					<p class="m-b-0"></p>
					<button type="button" class="btn btn-info waves-light waves-effect" data-toggle="modal" data-target="#addModal">Add New User</button>

					@if(Session::has('message'))
						<div class="alert {{ Session::get('alert-class') }} alert-dismissable">
							<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
							<h4><i class="icon fa fa-check"></i> {{ Session::get('status') }}</h4>
								{!! Session::get('message') !!}
						</div>
					@endif
					<div class="table-responsive">
						<table id="datatable" class="table table-bordered display">
							<thead>
								<tr>
									<th>Name</th>
									<th>Username</th>
									<th>Previlage</th>
									<th>Register</th>
									<th>Action</th>
								</tr>
							</thead>
							<tbody>
								@foreach($users as $user)
									<tr>
										<td>{{ $user->nama }}</td>
										<td>{{ $user->username }}</td>
										<td>{{ $user->previlage }}</td>
										<td>{{ $user->created_at }}</td>
										<td>
											<div class="btn-group">
												<button type="button" class="btn btn-light dropdown-toggle waves-effect" data-toggle="dropdown" aria-expanded="false"> <i class="icon-settings"></i> </button>
												<div class="dropdown-menu" aria-labelledby="btnGroupDrop1">
													<a class="dropdown-item update" href="#" user-id="{{ $user->id }}" data-toggle="modal" data-target="#updateModal">Update</a>
													<a class="dropdown-item delete" href="#" user-id="{{ $user->id }}">Delete</a>
												</div>
											</div>
										</td>
									</tr>
								@endforeach
							</tbody>
						</table>
					</div>
					<form id="formDelete" action="{{ route('deleteUser') }}" method="POST">
					  {{ csrf_field() }}
					  <input type="hidden" name="user_id" id="delete_user">
					</form>
				</div>
			</div>
		</div>
	</div>
</div>

<!-- Add Modal -->
<div id="addModal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
				<h4 class="modal-title" id="myModalLabel">Add Users</h4>
			</div>
			<div class="modal-body">
				<form class="form-horizontal" action="{{ url('user/store') }}" method="POST">
				{{ csrf_field() }}
					<div class="form-group m-b-25">
						<div class="col-12">
							<label>Full Name</label>
							<input class="form-control" type="text" name="nama" required="">
						</div>
					</div>
					<div class="form-group m-b-25">
						<div class="col-12">
							<label>Username</label>
							<input class="form-control" type="text" name="username" required="">
						</div>
					</div>
					<div class="form-group m-b-25">
						<div class="col-12">
							<label>Password</label>
							<input class="form-control" type="password" name="password" required="">
						</div>
					</div>
					<div class="form-group m-b-25">
						<div class="col-12">
							<label>Privilage</label>
							<select class="form-control" name="previlage">
								<option value="">Pilih Akses</option>
								<option value="supervisor">Supervisor</option>
								<option value="admin">Pendaftaran</option>
								<option value="analis">Analis</option>
								<option value="ppds">PPDS</option>
							</select>
						</div>
					</div>
					<div class="form-group account-btn text-center m-t-10">
						<div class="col-12">
							<button class="btn w-lg btn-custom waves-effect waves-light" type="submit">Save</button>
						</div>
					</div>
				</form>
			</div>
		</div><!-- /.modal-content -->
	</div><!-- /.modal-dialog -->
</div>
<div id="updateModal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
				<h4 class="modal-title" id="myModalLabel">Update User Data</h4>
			</div>
			<div class="modal-body">
				<form class="form-horizontal" action="{{ url('user/update') }}" method="POST">
				{{ csrf_field() }}
					<div class="form-group m-b-25">
						<div class="form-group m-b-25">
							<div class="col-12">
								<label>Username</label>
								<input class="form-control" type="text" id="username" name="username" readonly>
							</div>
						</div>
						<div class="col-12">
							<label>Name</label>
							<input class="form-control" type="text" id="nama" name="nama" required="">
						</div>
					</div>
					<div class="form-group m-b-25">
						<div class="col-12">
							<label>New Password</label>
							<input class="form-control" type="password" name="password">
						</div>
					</div>
					<div class="form-group m-b-25">
						<div class="col-12">
							<label>Repeat Password</label>
							<input class="form-control" type="password" name="password_confirmation">
						</div>
					</div>
					<div class="form-group m-b-25">
						<div class="col-12">
							<label>Privilage</label>
							<select class="form-control" name="previlage">
								<option value="">Pilih Akses</option>
								<option value="supervisor">Supervisor</option>
								<option value="admin">Pendaftaran</option>
								<option value="analis">Analis</option>
								<option value="ppds">PPDS</option>
							</select>
						</div>
					</div>
					<input type="hidden" name="id_user" id="id_user">
					<div class="form-group account-btn text-center m-t-10">
						<div class="col-12">
							<button class="btn w-lg btn-custom waves-effect waves-light" type="submit">Update</button>
						</div>
					</div>
				</form>
			</div>
		</div><!-- /.modal-content -->
	</div><!-- /.modal-dialog -->
</div>
<div id="modaladdmodlist" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
				<h4 class="modal-title" id="myModalLabel">Add Modality List</h4>
			</div>
			<div class="modal-body">
				<div class="form-group m-b-25">
					<div class="col-12">
						<label>AE Title</label>
						<input class="form-control" type="text" id="work_title">
					</div>
				</div>
				<div class="form-group m-b-25">
					<div class="col-12">
						<label>IP Address</label>
						<input class="form-control" type="text" id="work_ipaddress">
					</div>
				</div>
				<div class="form-group m-b-25">
					<div class="col-12">
						<label>Port Number</label>
						<input class="form-control" type="text" id="work_port">
					</div>
				</div>
				<div class="form-group m-b-25">
					<div class="col-12">
						<label>Modality</label>
						<select class="form-control" id="work_modaliti" name="modaliti">
							<option value="OT">Other</option>
							<option value="AR">Autorefraction</option>
							<option value="ASMT">Content Assessment Results</option>
							<option value="AU">Audio</option>
							<option value="BDUS">Bone Densitometry (ultrasound)</option>
							<option value="BI">Biomagnetic imaging</option>
							<option value="BMD">Bone Densitometry (X-Ray)</option>
							<option value="CR">Computed Radiography</option>
							<option value="CT">Computed Tomography</option>
							<option value="DG">Diaphanography</option>
							<option value="DOC">Document</option>
							<option value="DX">Digital Radiography</option>
							<option value="ECG">Electrocardiography</option>
							<option value="EPS">Cardiac Electrophysiology</option>
							<option value="ES">Endoscopy</option>
							<option value="FID">Fiducials</option>
							<option value="GM">General Microscopy</option>
							<option value="HC">Hard Copy</option>
							<option value="HD">Hemodynamic Waveform</option>
							<option value="IO">Intra-Oral Radiography</option>
							<option value="IOL">Intraocular Lens Data</option>
							<option value="IVOCT">Intravascular Optical Coherence Tomography</option>
							<option value="IVUS">Intravascular Ultrasound</option>
							<option value="KER">Keratometry</option>
							<option value="KO">Key Object Selection</option>
							<option value="LEN">Lensometry</option>
							<option value="LS">Laser surface scan</option>
							<option value="MG">Mammography</option>
							<option value="MR">Magnetic Resonance</option>
							<option value="NM">Nuclear Medicine</option>
							<option value="OAM">Ophthalmic Axial Measurements</option>
							<option value="OCT">Optical Coherence Tomography (non-Ophthalmic)</option>
							<option value="OP">Ophthalmic Photography</option>
							<option value="OPM">Ophthalmic Mapping</option>
							<option value="OPT">Ophthalmic Tomography</option>
							<option value="OPV">Ophthalmic Visual Field</option>
							<option value="OSS">Optical Surface Scan</option>
							<option value="PLAN">Plan</option>
							<option value="PR">Presentation State</option>
							<option value="PT">Positron emission tomography (PET)</option>
							<option value="PX">Panoramic X-Ray</option>
							<option value="REG">Registration</option>
							<option value="RESP">Respiratory Waveform</option>
							<option value="RF">Radio Fluoroscopy</option>
							<option value="RG">Radiographic imaging (conventional film/screen)</option>
							<option value="RTDOSE">Radiotherapy Dose</option>
							<option value="RTIMAGE">Radiotherapy Image</option>
							<option value="RTPLAN">Radiotherapy Plan</option>
							<option value="RTRECORD">RT Treatment Record</option>
							<option value="RTSTRUCT">Radiotherapy Structure Set</option>
							<option value="RWV">Real World Value Map</option>
							<option value="SEG">Segmentation</option>
							<option value="SM">Slide Microscopy</option>
							<option value="SMR">Stereometric Relationship</option>
							<option value="SR">SR Document</option>
							<option value="SRF">Subjective Refraction</option>
							<option value="STAIN">Automated Slide Stainer</option>
							<option value="TG">Thermography</option>
							<option value="US">Ultrasound</option>
							<option value="VA">Visual Acuity</option>
							<option value="XA">X-Ray Angiography</option>
							<option value="XC">External-camera Photography</option>
						</select>
					</div>
				</div>
				<div class="form-group m-b-25">
					<div class="col-12">
						<label>Location</label>
						<input class="form-control" type="text" id="work_location" >
					</div>
				</div>
				<div class="form-group account-btn text-center m-t-10">
					<div class="col-12">
						<input class="form-control" type="hidden" id="work_idne">
						<button class="btn w-lg btn-custom waves-effect waves-light" type="button" id="btnsaveworklist">Save</button>
					</div>
				</div>
			</div>
		</div><!-- /.modal-content -->
	</div><!-- /.modal-dialog -->
</div>
@endsection

@push('script')
<script type="text/javascript">
    $(document).ready(function() {
        $('form').parsley();
		$("#btnaddmod").click(function(){
			$("#work_idne").val('new');
			$('#modaladdmodlist').modal('show');
		});
    });
    $('.delete').click(function () {
        var user_id     =   $(this).attr("user-id");
        $("#delete_user").val(user_id);
        swal({
            title: 'Are you sure?',
            text: "Do you realy want to delete this data!",
            type: 'warning',
            showCancelButton: true,
            confirmButtonClass: 'btn btn-confirm mt-2',
            cancelButtonClass: 'btn btn-cancel ml-2 mt-2',
            confirmButtonText: 'Yes, delete it!'
        }).then(function () {
            swal({
                title: 'Deleted !',
                text: "Data has been deleted",
                type: 'success',
                confirmButtonClass: 'btn btn-confirm mt-2'
            })
            $("#formDelete").submit();
        })
    });
    $(document).on('click', '.update', function(e) {
        var id  =   $(this).attr('user-id');
        $.ajax({
            type : 'POST', 
            url  : '{{ route("getUser") }}',
            data : {'id' : id, _token : "{{ csrf_token() }}"},
            success : function(response) {
                var data  =   JSON.parse(response);
                $("#nama").val(data['nama']);
                $("#username").val(data['username']);
                $("#previlage").val(data['previlage']);
                $("#id_user").val(data['id']);
            }
        });
    });
</script>
@endpush