Add support to add time for voucher expires_at

This commit is contained in:
Jovan Jovanovic 2021-07-28 18:22:12 +02:00
parent 07e4537e01
commit f0a31fd4e2
5 changed files with 310 additions and 314 deletions

View file

@ -48,7 +48,7 @@ class VoucherController extends Controller
'code' => 'required|string|alpha_dash|max:36|min:4', 'code' => 'required|string|alpha_dash|max:36|min:4',
'uses' => 'required|numeric|max:2147483647|min:1', 'uses' => 'required|numeric|max:2147483647|min:1',
'credits' => 'required|numeric|between:0,99999999', 'credits' => 'required|numeric|between:0,99999999',
'expires_at' => ['nullable','date_format:d-m-Y','after:today',"before:10 years"], 'expires_at' => 'nullable|multiple_date_format:d-m-Y H:i:s,d-m-Y|after:now|before:10 years',
]); ]);
Voucher::create($request->except('_token')); Voucher::create($request->except('_token'));
@ -75,7 +75,7 @@ class VoucherController extends Controller
*/ */
public function edit(Voucher $voucher) public function edit(Voucher $voucher)
{ {
return view('admin.vouchers.edit' , [ return view('admin.vouchers.edit', [
'voucher' => $voucher 'voucher' => $voucher
]); ]);
} }
@ -94,7 +94,7 @@ class VoucherController extends Controller
'code' => 'required|string|alpha_dash|max:36|min:4', 'code' => 'required|string|alpha_dash|max:36|min:4',
'uses' => 'required|numeric|max:2147483647|min:1', 'uses' => 'required|numeric|max:2147483647|min:1',
'credits' => 'required|numeric|between:0,99999999', 'credits' => 'required|numeric|between:0,99999999',
'expires_at' => ['nullable','date_format:d-m-Y','after:today',"before:10 years"], 'expires_at' => 'nullable|multiple_date_format:d-m-Y H:i:s,d-m-Y|after:now|before:10 years',
]); ]);
$voucher->update($request->except('_token')); $voucher->update($request->except('_token'));
@ -127,7 +127,7 @@ class VoucherController extends Controller
]); ]);
#get voucher by code #get voucher by code
$voucher = Voucher::where('code' , '=' , $request->input('code'))->firstOrFail(); $voucher = Voucher::where('code', '=', $request->input('code'))->firstOrFail();
#extra validations #extra validations
if ($voucher->getStatus() == 'USES_LIMIT_REACHED') throw ValidationException::withMessages([ if ($voucher->getStatus() == 'USES_LIMIT_REACHED') throw ValidationException::withMessages([
@ -138,7 +138,7 @@ class VoucherController extends Controller
'code' => 'This voucher has expired' 'code' => 'This voucher has expired'
]); ]);
if (!$request->user()->vouchers()->where('id' , '=' , $voucher->id)->get()->isEmpty()) throw ValidationException::withMessages([ if (!$request->user()->vouchers()->where('id', '=', $voucher->id)->get()->isEmpty()) throw ValidationException::withMessages([
'code' => 'You already redeemed this voucher code' 'code' => 'You already redeemed this voucher code'
]); ]);
@ -191,5 +191,4 @@ class VoucherController extends Controller
->rawColumns(['actions', 'code', 'status']) ->rawColumns(['actions', 'code', 'status'])
->make(); ->make();
} }
} }

View file

@ -44,7 +44,7 @@ class VoucherController extends Controller
'code' => 'required|string|alpha_dash|max:36|min:4', 'code' => 'required|string|alpha_dash|max:36|min:4',
'uses' => 'required|numeric|max:2147483647|min:1', 'uses' => 'required|numeric|max:2147483647|min:1',
'credits' => 'required|numeric|between:0,99999999', 'credits' => 'required|numeric|between:0,99999999',
'expires_at' => 'nullable|date_format:d-m-Y|after:today|before:10 years' 'expires_at' => 'nullable|multiple_date_format:d-m-Y H:i:s,d-m-Y|after:now|before:10 years'
]); ]);
return Voucher::create($request->all()); return Voucher::create($request->all());
@ -88,7 +88,7 @@ class VoucherController extends Controller
'code' => 'required|string|alpha_dash|max:36|min:4', 'code' => 'required|string|alpha_dash|max:36|min:4',
'uses' => 'required|numeric|max:2147483647|min:1', 'uses' => 'required|numeric|max:2147483647|min:1',
'credits' => 'required|numeric|between:0,99999999', 'credits' => 'required|numeric|between:0,99999999',
'expires_at' => 'nullable|date_format:d-m-Y|after:today|before:10 years' 'expires_at' => 'nullable|multiple_date_format:d-m-Y H:i:s,d-m-Y|after:now|before:10 years'
]); ]);
$voucher->update($request->all()); $voucher->update($request->all());
@ -116,7 +116,8 @@ class VoucherController extends Controller
* @param Voucher $voucher * @param Voucher $voucher
* @return LengthAwarePaginator * @return LengthAwarePaginator
*/ */
public function users(Request $request, Voucher $voucher){ public function users(Request $request, Voucher $voucher)
{
$request->validate([ $request->validate([
'include' => [ 'include' => [
'nullable', 'nullable',
@ -125,7 +126,7 @@ class VoucherController extends Controller
] ]
]); ]);
if($request->input('include') == 'discorduser'){ if ($request->input('include') == 'discorduser') {
return $voucher->users()->with('discordUser')->paginate($request->query('per_page') ?? 50); return $voucher->users()->with('discordUser')->paginate($request->query('per_page') ?? 50);
} }

View file

@ -4,6 +4,7 @@ namespace App\Providers;
use Illuminate\Pagination\Paginator; use Illuminate\Pagination\Paginator;
use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\ServiceProvider; use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider class AppServiceProvider extends ServiceProvider
@ -27,5 +28,27 @@ class AppServiceProvider extends ServiceProvider
{ {
Paginator::useBootstrap(); Paginator::useBootstrap();
Schema::defaultStringLength(191); Schema::defaultStringLength(191);
Validator::extend('multiple_date_format', function ($attribute, $value, $parameters, $validator) {
$ok = true;
$result = [];
// iterate through all formats
foreach ($parameters as $parameter) {
//validate with laravels standard date format validation
$result[] = $validator->validateDateFormat($attribute, $value, [$parameter]);
}
//if none of result array is true. it sets ok to false
if (!in_array(true, $result)) {
$ok = false;
$validator->setCustomMessages(['multiple_date_format' => 'The format must be one of ' . join(",", $parameters)]);
}
return $ok;
});
} }
} }

View file

@ -1,181 +1,170 @@
@extends('layouts.main') @extends('layouts.main')
@section('content') @section('content')
<!-- CONTENT HEADER --> <!-- CONTENT HEADER -->
<section class="content-header"> <section class="content-header">
<div class="container-fluid"> <div class="container-fluid">
<div class="row mb-2"> <div class="row mb-2">
<div class="col-sm-6"> <div class="col-sm-6">
<h1>Vouchers</h1> <h1>Vouchers</h1>
</div> </div>
<div class="col-sm-6"> <div class="col-sm-6">
<ol class="breadcrumb float-sm-right"> <ol class="breadcrumb float-sm-right">
<li class="breadcrumb-item"><a href="{{route('home')}}">Dashboard</a></li> <li class="breadcrumb-item"><a href="{{route('home')}}">Dashboard</a></li>
<li class="breadcrumb-item"><a href="{{route('admin.vouchers.index')}}">Vouchers</a></li> <li class="breadcrumb-item"><a href="{{route('admin.vouchers.index')}}">Vouchers</a></li>
<li class="breadcrumb-item"><a class="text-muted" href="{{route('admin.products.create')}}">Create</a> <li class="breadcrumb-item"><a class="text-muted" href="{{route('admin.products.create')}}">Create</a>
</li> </li>
</ol> </ol>
</div>
</div> </div>
</div> </div>
</section> </div>
<!-- END CONTENT HEADER --> </section>
<!-- END CONTENT HEADER -->
<!-- MAIN CONTENT --> <!-- MAIN CONTENT -->
<section class="content"> <section class="content">
<div class="container-fluid"> <div class="container-fluid">
<div class="row"> <div class="row">
<div class="col-lg-6"> <div class="col-lg-6">
<div class="card"> <div class="card">
<div class="card-header"> <div class="card-header">
<h5 class="card-title"> <h5 class="card-title">
<i class="fas fa-money-check-alt mr-2"></i>Voucher details <i class="fas fa-money-check-alt mr-2"></i>Voucher details
</h5> </h5>
</div> </div>
<div class="card-body"> <div class="card-body">
<form action="{{route('admin.vouchers.store')}}" method="POST"> <form action="{{route('admin.vouchers.store')}}" method="POST">
@csrf @csrf
<div class="form-group"> <div class="form-group">
<label for="memo">Memo <i data-toggle="popover" data-trigger="hover" data-content="Only admins can see this" class="fas fa-info-circle"></i></label> <label for="memo">Memo <i data-toggle="popover" data-trigger="hover" data-content="Only admins can see this" class="fas fa-info-circle"></i></label>
<input value="{{old('memo')}}" placeholder="Summer break voucher" id="memo" <input value="{{old('memo')}}" placeholder="Summer break voucher" id="memo" name="memo" type="text" class="form-control @error('memo') is-invalid @enderror">
name="memo" type="text" @error('memo')
class="form-control @error('memo') is-invalid @enderror"> <div class="text-danger">
@error('memo') {{$message}}
<div class="text-danger">
{{$message}}
</div>
@enderror
</div> </div>
@enderror
</div>
<div class="form-group"> <div class="form-group">
<label for="credits">* Credits</label> <label for="credits">* Credits</label>
<input value="{{old('credits')}}" placeholder="500" id="credits" <input value="{{old('credits')}}" placeholder="500" id="credits" name="credits" type="number" step="any" min="0" max="99999999" class="form-control @error('credits') is-invalid @enderror">
name="credits" type="number" step="any" min="0" @error('credits')
max="99999999" <div class="text-danger">
class="form-control @error('credits') is-invalid @enderror"> {{$message}}
@error('credits')
<div class="text-danger">
{{$message}}
</div>
@enderror
</div> </div>
@enderror
</div>
<div class="form-group"> <div class="form-group">
<label for="code">* Code</label> <label for="code">* Code</label>
<div class="input-group"> <div class="input-group">
<input value="{{old('code')}}" placeholder="SUMMER" id="code" name="code" <input value="{{old('code')}}" placeholder="SUMMER" id="code" name="code" type="text" class="form-control @error('code') is-invalid @enderror" required="required">
type="text" <div class="input-group-append">
class="form-control @error('code') is-invalid @enderror" <button class="btn btn-info" onclick="setRandomCode()" type="button">
required="required"> Random
<div class="input-group-append"> </button>
<button class="btn btn-info" onclick="setRandomCode()" type="button">
Random
</button>
</div>
</div> </div>
@error('code')
<div class="text-danger">
{{$message}}
</div>
@enderror
</div> </div>
@error('code')
<div class="form-group"> <div class="text-danger">
<label for="uses">* Uses<i data-toggle="popover" data-trigger="hover" data-content="A voucher can only be used one time per user. Uses specifies the number of different users that can use this voucher." class="fas fa-info-circle"></i></label> {{$message}}
<div class="input-group">
<input value="{{old('uses') ?? 1}}" id="uses" min="1" max="2147483647"
name="uses" type="number"
class="form-control @error('uses') is-invalid @enderror"
required="required">
<div class="input-group-append">
<button class="btn btn-info" onclick="setMaxUses()" type="button">Max
</button>
</div>
</div>
@error('uses')
<div class="text-danger">
{{$message}}
</div>
@enderror
</div> </div>
@enderror
</div>
<div class="form-group mb-3"> <div class="form-group">
<label for="expires_at">Expires at</label> <label for="uses">* Uses <i data-toggle="popover" data-trigger="hover" data-content="A voucher can only be used one time per user. Uses specifies the number of different users that can use this voucher." class="fas fa-info-circle"></i></label>
<div class="input-group date" id="expires_at" data-target-input="nearest"> <div class="input-group">
<input value="{{old('expires_at')}}" name="expires_at" placeholder="dd-mm-yyyy" type="text" class="form-control @error('expires_at') is-invalid @enderror datetimepicker-input" data-target="#expires_at"/> <input value="{{old('uses') ?? 1}}" id="uses" min="1" max="2147483647" name="uses" type="number" class="form-control @error('uses') is-invalid @enderror" required="required">
<div class="input-group-append" data-target="#expires_at" data-toggle="datetimepicker"> <div class="input-group-append">
<div class="input-group-text"><i class="fa fa-calendar"></i></div> <button class="btn btn-info" onclick="setMaxUses()" type="button">Max
</div> </button>
</div> </div>
@error('expires_at')
<div class="text-danger">
{{$message}}
</div>
@enderror
</div> </div>
@error('uses')
<div class="text-danger">
{{$message}}
</div>
@enderror
</div>
<div class="form-group text-right"> <div class="form-group mb-3">
<button type="submit" class="btn btn-primary"> <label for="expires_at">Expires at <i data-toggle="popover" data-trigger="hover" data-content="Timezone: {{ Config::get('app.timezone') }}" class="fas fa-info-circle"></i></label>
Submit <div class="input-group date" id="expires_at" data-target-input="nearest">
</button> <input value="{{old('expires_at')}}" name="expires_at" placeholder="dd-mm-yyyy hh:mm:ss" type="text" class="form-control @error('expires_at') is-invalid @enderror datetimepicker-input" data-target="#expires_at" />
<div class="input-group-append" data-target="#expires_at" data-toggle="datetimepicker">
<div class="input-group-text"><i class="fa fa-calendar"></i></div>
</div>
</div> </div>
</form> @error('expires_at')
</div> <div class="text-danger">
{{$message}}
</div>
@enderror
</div>
<div class="form-group text-right">
<button type="submit" class="btn btn-primary">
Submit
</button>
</div>
</form>
</div> </div>
</div> </div>
</div> </div>
<i class="fas"></i>
</div> </div>
</section>
<!-- END CONTENT --> <i class="fas"></i>
</div>
</section>
<!-- END CONTENT -->
<script> <script>
document.addEventListener('DOMContentLoaded', (event) => { document.addEventListener('DOMContentLoaded', (event) => {
$('#expires_at').datetimepicker({ $('#expires_at').datetimepicker({
format : 'DD-MM-yyyy', format: 'DD-MM-yyyy HH:mm:ss',
icons: { icons: {
time: 'far fa-clock', time: 'far fa-clock',
date: 'far fa-calendar', date: 'far fa-calendar',
up: 'fas fa-arrow-up', up: 'fas fa-arrow-up',
down: 'fas fa-arrow-down', down: 'fas fa-arrow-down',
previous: 'fas fa-chevron-left', previous: 'fas fa-chevron-left',
next: 'fas fa-chevron-right', next: 'fas fa-chevron-right',
today: 'fas fa-calendar-check', today: 'fas fa-calendar-check',
clear: 'far fa-trash-alt', clear: 'far fa-trash-alt',
close: 'far fa-times-circle' close: 'far fa-times-circle'
}
});
})
function setMaxUses() {
let element = document.getElementById('uses')
element.value = element.max;
console.log(element.max)
}
function setRandomCode() {
let element = document.getElementById('code')
element.value = getRandomCode(36)
}
function getRandomCode(length) {
let result = '';
let characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-';
let charactersLength = characters.length;
for (let i = 0; i < length; i++) {
result += characters.charAt(Math.floor(Math.random() *
charactersLength));
} }
return result; });
})
function setMaxUses() {
let element = document.getElementById('uses')
element.value = element.max;
console.log(element.max)
}
function setRandomCode() {
let element = document.getElementById('code')
element.value = getRandomCode(36)
}
function getRandomCode(length) {
let result = '';
let characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-';
let charactersLength = characters.length;
for (let i = 0; i < length; i++) {
result += characters.charAt(Math.floor(Math.random() *
charactersLength));
} }
</script> return result;
}
</script>
@endsection @endsection

View file

@ -1,186 +1,170 @@
@extends('layouts.main') @extends('layouts.main')
@section('content') @section('content')
<!-- CONTENT HEADER --> <!-- CONTENT HEADER -->
<section class="content-header"> <section class="content-header">
<div class="container-fluid"> <div class="container-fluid">
<div class="row mb-2"> <div class="row mb-2">
<div class="col-sm-6"> <div class="col-sm-6">
<h1>Vouchers</h1> <h1>Vouchers</h1>
</div> </div>
<div class="col-sm-6"> <div class="col-sm-6">
<ol class="breadcrumb float-sm-right"> <ol class="breadcrumb float-sm-right">
<li class="breadcrumb-item"><a href="{{route('home')}}">Dashboard</a></li> <li class="breadcrumb-item"><a href="{{route('home')}}">Dashboard</a></li>
<li class="breadcrumb-item"><a href="{{route('admin.vouchers.index')}}">Vouchers</a></li> <li class="breadcrumb-item"><a href="{{route('admin.vouchers.index')}}">Vouchers</a></li>
<li class="breadcrumb-item"><a class="text-muted" <li class="breadcrumb-item"><a class="text-muted" href="{{route('admin.products.edit' , $voucher->id)}}">Edit</a>
href="{{route('admin.products.edit' , $voucher->id)}}">Edit</a> </li>
</li> </ol>
</ol>
</div>
</div> </div>
</div> </div>
</section> </div>
<!-- END CONTENT HEADER --> </section>
<!-- END CONTENT HEADER -->
<!-- MAIN CONTENT --> <!-- MAIN CONTENT -->
<section class="content"> <section class="content">
<div class="container-fluid"> <div class="container-fluid">
<div class="row"> <div class="row">
<div class="col-lg-6"> <div class="col-lg-6">
<div class="card"> <div class="card">
<div class="card-header"> <div class="card-header">
<h5 class="card-title"> <h5 class="card-title">
<i class="fas fa-money-check-alt mr-2"></i>Voucher details <i class="fas fa-money-check-alt mr-2"></i>Voucher details
</h5> </h5>
</div> </div>
<div class="card-body"> <div class="card-body">
<form action="{{route('admin.vouchers.update' , $voucher->id)}}" method="POST"> <form action="{{route('admin.vouchers.update' , $voucher->id)}}" method="POST">
@csrf @csrf
@method('PATCH') @method('PATCH')
<div class="form-group"> <div class="form-group">
<label for="memo">Memo <i data-toggle="popover" data-trigger="hover" <label for="memo">Memo <i data-toggle="popover" data-trigger="hover" data-content="Only admins can see this" class="fas fa-info-circle"></i></label>
data-content="Only admins can see this" <input value="{{ $voucher->memo }}" placeholder="Summer break voucher" id="memo" name="memo" type="text" class="form-control @error('memo') is-invalid @enderror">
class="fas fa-info-circle"></i></label> @error('memo')
<input value="{{ $voucher->memo }}" placeholder="Summer break voucher" id="memo" <div class="text-danger">
name="memo" type="text" {{$message}}
class="form-control @error('memo') is-invalid @enderror">
@error('memo')
<div class="text-danger">
{{$message}}
</div>
@enderror
</div> </div>
@enderror
</div>
<div class="form-group"> <div class="form-group">
<label for="credits">Credits *</label> <label for="credits">Credits *</label>
<input value="{{$voucher->credits}}" placeholder="500" id="credits" <input value="{{$voucher->credits}}" placeholder="500" id="credits" name="credits" type="number" step="any" min="0" max="99999999" class="form-control @error('credits') is-invalid @enderror">
name="credits" type="number" step="any" min="0" @error('credits')
max="99999999" <div class="text-danger">
class="form-control @error('credits') is-invalid @enderror"> {{$message}}
@error('credits')
<div class="text-danger">
{{$message}}
</div>
@enderror
</div> </div>
@enderror
</div>
<div class="form-group"> <div class="form-group">
<label for="code">Code *</label> <label for="code">Code *</label>
<div class="input-group"> <div class="input-group">
<input value="{{$voucher->code}}" placeholder="SUMMER" id="code" name="code" <input value="{{$voucher->code}}" placeholder="SUMMER" id="code" name="code" type="text" class="form-control @error('code') is-invalid @enderror" required="required">
type="text" <div class="input-group-append">
class="form-control @error('code') is-invalid @enderror" <button class="btn btn-info" onclick="setRandomCode()" type="button">
required="required"> Random
<div class="input-group-append"> </button>
<button class="btn btn-info" onclick="setRandomCode()" type="button">
Random
</button>
</div>
</div> </div>
@error('code')
<div class="text-danger">
{{$message}}
</div>
@enderror
</div> </div>
@error('code')
<div class="form-group"> <div class="text-danger">
<label for="uses">Uses * <i data-toggle="popover" data-trigger="hover" {{$message}}
data-content="A voucher can only be used one time per user. Uses specifies the number of different users that can use this voucher."
class="fas fa-info-circle"></i></label>
<div class="input-group">
<input value="{{$voucher->uses}}" id="uses" min="1" max="2147483647"
name="uses" type="number"
class="form-control @error('uses') is-invalid @enderror"
required="required">
<div class="input-group-append">
<button class="btn btn-info" onclick="setMaxUses()" type="button">Max
</button>
</div>
</div>
@error('uses')
<div class="text-danger">
{{$message}}
</div>
@enderror
</div> </div>
@enderror
</div>
<div class="form-group mb-3"> <div class="form-group">
<label for="expires_at">Expires at</label> <label for="uses">Uses * <i data-toggle="popover" data-trigger="hover" data-content="A voucher can only be used one time per user. Uses specifies the number of different users that can use this voucher." class="fas fa-info-circle"></i></label>
<div class="input-group date" id="expires_at" data-target-input="nearest"> <div class="input-group">
<input value="{{$voucher->expires_at ? $voucher->expires_at->format('d-m-Y') : ''}}" name="expires_at" placeholder="dd-mm-yyyy" type="text" class="form-control @error('expires_at') is-invalid @enderror datetimepicker-input" data-target="#expires_at"/> <input value="{{$voucher->uses}}" id="uses" min="1" max="2147483647" name="uses" type="number" class="form-control @error('uses') is-invalid @enderror" required="required">
<div class="input-group-append" data-target="#expires_at" data-toggle="datetimepicker"> <div class="input-group-append">
<div class="input-group-text"><i class="fa fa-calendar"></i></div> <button class="btn btn-info" onclick="setMaxUses()" type="button">Max
</div> </button>
</div> </div>
@error('expires_at') </div>
<div class="text-danger"> @error('uses')
{{$message}} <div class="text-danger">
{{$message}}
</div>
@enderror
</div>
<div class="form-group mb-3">
<label for="expires_at">Expires at <i data-toggle="popover" data-trigger="hover" data-content="Timezone: {{ Config::get('app.timezone') }}" class="fas fa-info-circle"></i></label>
<div class="input-group date" id="expires_at" data-target-input="nearest">
<input value="{{$voucher->expires_at ? $voucher->expires_at->format('d-m-Y H:i:s') : ''}}" name="expires_at" placeholder="dd-mm-yyyy hh:mm:ss" type="text" class="form-control @error('expires_at') is-invalid @enderror datetimepicker-input" data-target="#expires_at" />
<div class="input-group-append" data-target="#expires_at" data-toggle="datetimepicker">
<div class="input-group-text"><i class="fa fa-calendar"></i></div>
</div> </div>
@enderror
</div> </div>
@error('expires_at')
<div class="text-danger">
{{$message}}
</div>
@enderror
</div>
<div class="form-group text-right"> <div class="form-group text-right">
<button type="submit" class="btn btn-primary"> <button type="submit" class="btn btn-primary">
Submit Submit
</button> </button>
</div> </div>
</form> </form>
</div>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
</section>
<!-- END CONTENT --> </div>
</section>
<!-- END CONTENT -->
<script> <script>
document.addEventListener('DOMContentLoaded', (event) => { document.addEventListener('DOMContentLoaded', (event) => {
$('#expires_at').datetimepicker({ $('#expires_at').datetimepicker({
format : 'DD-MM-yyyy', format: 'DD-MM-yyyy HH:mm:ss',
icons: { icons: {
time: 'far fa-clock', time: 'far fa-clock',
date: 'far fa-calendar', date: 'far fa-calendar',
up: 'fas fa-arrow-up', up: 'fas fa-arrow-up',
down: 'fas fa-arrow-down', down: 'fas fa-arrow-down',
previous: 'fas fa-chevron-left', previous: 'fas fa-chevron-left',
next: 'fas fa-chevron-right', next: 'fas fa-chevron-right',
today: 'fas fa-calendar-check', today: 'fas fa-calendar-check',
clear: 'far fa-trash-alt', clear: 'far fa-trash-alt',
close: 'far fa-times-circle' close: 'far fa-times-circle'
}
});
})
function setMaxUses() {
let element = document.getElementById('uses')
element.value = element.max;
console.log(element.max)
}
function setRandomCode() {
let element = document.getElementById('code')
element.value = getRandomCode(36)
}
function getRandomCode(length) {
let result = '';
let characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-';
let charactersLength = characters.length;
for (let i = 0; i < length; i++) {
result += characters.charAt(Math.floor(Math.random() *
charactersLength));
} }
return result; });
})
function setMaxUses() {
let element = document.getElementById('uses')
element.value = element.max;
console.log(element.max)
}
function setRandomCode() {
let element = document.getElementById('code')
element.value = getRandomCode(36)
}
function getRandomCode(length) {
let result = '';
let characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-';
let charactersLength = characters.length;
for (let i = 0; i < length; i++) {
result += characters.charAt(Math.floor(Math.random() *
charactersLength));
} }
</script> return result;
}
</script>
@endsection @endsection