@extends('admin/layouts/default')

{{-- Page title --}}
@section('title')
    Content Access
    @parent
@stop

{{-- page level styles --}}
@section('header_styles')
   @include('admin.user_access.includes.user_access_header')
@stop

{{-- Page content --}}
@section('content')

    <section class="content-header">
        <h1>Token Access Form</h1>
        <ol class="breadcrumb">
            <li>
                <a href="{{ route('admin.dashboard') }}">
                    <i class="livicon" data-name="home" data-size="14" data-color="#000"></i>
                    Dashboard
                </a>
            </li>
            <li><a href="#"> Users</a></li>
            <li class="active">Token Access Form</li>
        </ol>
    </section>
	
<section class="content">

	{{ Form::open(array('url' => 'admin/useraccess/edit')) }}
	
		@csrf()
		
		<input type="hidden" name="request_id" value="{{$param['request_id']}}"/>
	
<div class="row">
<div class="col-md-12">
<div class="portlet box @if(isset($param['request_id'])) primary @else default @endif">
	<div class="portlet-title">
		<div class="caption">
			<i class="livicon" data-name="responsive" data-size="16" data-loop="true" data-c="#fff" data-hc="white"></i> Add Token Access 
		</div>	
	</div>

	<div class="portlet-body table-responsive">		
		
				
		@if(isset($param['org_name']))
		<div class="form-row col-md-12">

			<div class="form-group col-md-3">
				<label>Orgnization:</label>
			</div>
			
			<div class="form-group col-md-6">		
			<label>{{$param['org_name']}}</label>
				<input type="hidden" name="org_name" value="{{$param['org_name']}}">
			</div>
		</div>
		@endif
		
		<div class="form-row col-md-12">	
		
			<div class="form-group col-md-3">
				<label>Select Token Type: *</label>
			</div>
			<div class="form-group col-md-6">	

				<select class="form-control" id="access_type_id" name="access_type_id" required="required">
				<option value="">Select Access Type</option>
					<option @if($param['access_type_id'] == 444) selected @endif value="444">Restricted Single Key</option>
					<option @if($param['access_type_id'] == 555) selected @endif value="555">Restricted Multiple Key</option>
					<option @if($param['access_type_id'] == 666) selected @endif value="666">Restricted Download WithOut Key</option>
				</select>
			</div>
			
		</div>
		
		<div class="form-row col-md-12">	
		
			<div class="form-group col-md-3">
				<label>Select Access On: *</label>
			</div>
			<div class="form-group col-md-6">	

				<select class="form-control" id="access_on" name="access_on" required="required">
				<option value="">Select Access Type on</option>
					<option @if($param['access_on'] == 'journal_volume') selected @endif value="journal_volume">Journal Volume</option>
					<option @if($param['access_on'] == 'ebook_volume') selected @endif value="ebook_volume">eBook Volume</option>
					<option @if($param['access_on'] == 'issue') selected @endif value="issue">Issue</option>
					<option @if($param['access_on'] == 'article') selected @endif value="article">Article</option>
					<option @if($param['access_on'] == 'chapter') selected @endif value="chapter">Chapter</option>
				</select>
			</div>
			
		</div>

		<div class="form-row col-md-12">

			<div class="form-group col-md-3">
				<label>User Name:</label>
			</div>
			
			<div class="form-group col-md-6 {{ $errors->first('user_name', 'has-error') }}">
			
				<input type="text" maxlength="50" id="user_name" name="user_name" size="60" class="form-control" required = 'required' value="@if(isset($param['user_name'])){{$param['user_name']}}@endif">
				<label class="text-danger"><i>{{ $errors->first('user_name',':message') }}</i></label>
			</div>
			<div class="form-group col-md-3">		
				<button type="submit" class="btn btn-primary" name="token_search" value ="submit"> <span class="glyphicon glyphicon-search"></span>  Search </button>
			</div>
		</div>
		
		@if( isset($search['token_search']))
			@php $token = $search['token_search']->token @endphp	
		@elseif( isset($param['token_limit']) )
			@php $token = $param['token_limit'] @endphp	
		@endif
		
		@isset($token)
		<div class="form-row col-md-12">
			<div class="form-group col-md-3">
				<label>Previous Token: </label>
			</div>		
			
			<div class="form-group col-md-6">
				<label id="previous_limit_lbl" class="label-control">{{$token}}</label>
				<input type="hidden" id="token_limit" name="token_limit" size="60" value="{{$token}}" class="form-control" placeholder="Insert Download Limit"></input>		
			</div>
		</div>	
		
		<div class="form-row col-md-12">
			
			<div class="form-group col-md-3">
				<label>Additional Token: *</label>
			</div>		
			
			<div class="form-group col-md-6">
				<input type="text" id="download_limit" name="download_limit" value="" class="form-control col-md-4" placeholder="Insert Download Limit"></input>
				<label class="text-danger"><i>{{ $errors->first('download_limit',':message') }}</i></label>
			</div>
			
		</div>	
		
		<div class="form-row col-md-12">
			
			<div class="form-group col-md-3">
				<label>Total Token: </label>
			</div>		
			
			<div class="form-group col-md-6">
			
				<label id="total_token_limit"></label>
					
			</div>
			
		</div>	
		
		
		<div class="form_control col-md-12">
		
		@if(isset($param['request_id']))
			<div class="form-group col-md-12">
		
		
				<!-- Trigger the modal with a button -->
				<button id="btn_update" type="button" class="btn btn-primary" data-toggle="modal" data-target="#update_token" style="display:none;"><span class="glyphicon glyphicon-plus"></span> Update</button>

				<!-- Modal -->
				<div id="update_token" class="modal fade" role="dialog">
				  <div class="modal-dialog">

					<!-- Modal content-->
					<div class="modal-content">
					  <div class="modal-header text-center">
						<button type="button" class="close" data-dismiss="modal">&times;</button>
						<h4 class="modal-title">Are you Sure ?</h4>
					  </div>
					  <div class="modal-body text-center">
						<p>Do you want to add addition tokens ? </p>
					  </div>
					  <div class="modal-footer">
						<button type="submit" class="btn btn-success" name="btn_update" value ="submit"> Yes </button>
						<button type="button" class="btn btn-danger" data-dismiss="modal">No</button>
					  </div>
					</div>

				  </div>
				</div>
				
			</div>	
		@endif	
			
		</div>
		
		@endisset
		
	</div>
</div>
	
</div>
</div>

{{ Form::close() }}

</section>

@stop

{{-- page level scripts --}}
@section('footer_scripts')

	<script>
		$( "#download_limit" ).keyup(function() 
		{
		
			$('#total_token_limit').empty();
			
			
			var previous_limit = $('#token_limit').val();
			var new_limit = $('#download_limit').val()
			
			if (previous_limit != '' && new_limit != '' && total_token_limit != '')
			{
			
				var total_token_limit = parseInt(previous_limit) + parseInt(new_limit);
				
				console.log(previous_limit +' + '+ new_limit +' + '+ total_token_limit );
				
				$('#total_token_limit').append(previous_limit + " + " + new_limit + " = " + total_token_limit);	
				$('#btn_update').show();
			}
			else
			{
				$('#btn_update').hide();
			}
			
		});
	</script>
	
	<script src="{{ asset('assets/vendors/iCheck/js/icheck.js') }}"></script>
	<script src="{{ asset('assets/vendors/moment/js/moment.min.js') }}" ></script>    
	<script src="{{ asset('assets/vendors/select2/js/select2.js') }}" type="text/javascript"></script>    
	<script src="{{ asset('assets/js/pages/table-advanced2.js') }}" type="text/javascript"></script>    
	<script src="{{ asset('assets/vendors/datetimepicker/js/bootstrap-datetimepicker.min.js') }}" type="text/javascript"></script>

	<script src="{{ asset('assets/vendors/pickadate/js/picker.js') }}" type="text/javascript"></script>
	<script src="{{ asset('assets/vendors/pickadate/js/picker.date.js') }}" type="text/javascript"></script>
	<script src="{{ asset('assets/vendors/pickadate/js/picker.time.js') }}" type="text/javascript"></script>
	<script src="{{ asset('assets/vendors/flatpickrCalendar/js/flatpickr.min.js') }}" type="text/javascript"></script>
	<script src="{{ asset('assets/vendors/airDatepicker/js/datepicker.min.js') }}" type="text/javascript"></script>
	<script src="{{ asset('assets/vendors/airDatepicker/js/datepicker.en.js') }}" type="text/javascript"></script>
	<script src="{{ asset('assets/js/pages/custom_datepicker.js') }}" type="text/javascript"></script>  
    
@stop
