implements cookie to maintain display preference

This commit is contained in:
Achmad Fienan Rahardianto 2022-06-01 11:54:05 +07:00
parent dafe353050
commit fe65de1207
2 changed files with 52 additions and 22 deletions

View file

@ -20,6 +20,7 @@ use Gate;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Storage; use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Facades\Cookie;
use Input; use Input;
use Intervention\Image\Facades\Image; use Intervention\Image\Facades\Image;
use League\Csv\Reader; use League\Csv\Reader;
@ -201,18 +202,36 @@ class AssetsController extends Controller
} }
$success = true; $success = true;
// $cookie = Cookie::queue(Cookie::make('optional_info', $_POST['options'],$minutes));
// $data = $request->session()->all();
// dd($_POST['options']);
} }
} }
if ($success) { if ($success) {
// Redirect to the asset listing page // Redirect to the asset listing page
$minutes = 518400;
// dd( $_POST['options']);
// Cookie::queue(Cookie::make('optional_info', json_decode($_POST['options']), $minutes));
return redirect()->route('hardware.index') return redirect()->route('hardware.index')
->with('success', trans('admin/hardware/message.create.success')); ->with('success', trans('admin/hardware/message.create.success'))
->withCookie(cookie('optional_info',json_encode($_POST['options']),$minutes,null,null,null,false));
} }
return redirect()->back()->withInput()->withErrors($asset->getErrors()); return redirect()->back()->withInput()->withErrors($asset->getErrors());
} }
public function getOptionCookie(Request $request){
$value = $request->cookie('optional_info');
echo $value;
return $value;
}
/** /**
* Returns a view that presents a form to edit an existing asset. * Returns a view that presents a form to edit an existing asset.
* *

View file

@ -10,15 +10,16 @@
{{-- Page content --}} {{-- Page content --}}
@section('inputFields') @section('inputFields')
@include ('partials.forms.edit.company-select', ['translated_name' => trans('general.company'), 'fieldname' => 'company_id']) @include ('partials.forms.edit.company-select', ['translated_name' => trans('general.company'), 'fieldname' => 'company_id'])
<!-- {{Request::cookie('optional_info');}} -->
<!-- Asset Tag --> <!-- Asset Tag -->
<div class="form-group {{ $errors->has('asset_tag') ? ' has-error' : '' }}"> <div class="form-group {{ $errors->has('asset_tag') ? ' has-error' : '' }}">
<label for="asset_tag" class="col-md-3 control-label">{{ trans('admin/hardware/form.tag') }}</label> <label for="asset_tag" class="col-md-3 control-label">{{ trans('admin/hardware/form.tag') }}</label>
<!-- we are editing an existing asset --> <!-- we are editing an existing asset -->
@if ($item->id) @if ($item->id)
<div class="col-md-7 col-sm-12{{ (Helper::checkIfRequired($item, 'asset_tag')) ? ' required' : '' }}"> <div class="col-md-7 col-sm-12{{ (Helper::checkIfRequired($item, 'asset_tag')) ? ' required' : '' }}">
@ -101,13 +102,14 @@
<div class="form-group" > <div class="form-group" >
<label class="col-md-3 control-label"></label> <label class="col-md-3 control-label"></label>
<div class="col-md-2 col-sm-2 text-left form-check" style="z-index:1;"> <div class="col-md-2 col-sm-2 text-left form-check" style="z-index:1;">
<input class="form-check-input" type="checkbox" id="optional_info" >
<input class="form-check-input" type="checkbox" id="optional_info" name="options[]" value="optional" <?php if (!empty (json_decode(Cookie::get('optional_info')))) {if(in_array('optional',json_decode(Cookie::get('optional_info')))) {echo 'checked';} else {echo 'unchecked';}} else {echo 'unchecked';} ?>>
<label class="form-check-label" for="flexCheckDefault"> <label class="form-check-label" for="flexCheckDefault">
{{ trans('admin/hardware/form.optional_infos') }} {{ trans('admin/hardware/form.optional_infos') }}
</label> </label>
</div> </div>
<div id="optional_details" class="col-md-12"> <div id="optional_details" class="col-md-12" style="display:none">
@include ('partials.forms.edit.name', ['translated_name' => trans('admin/hardware/form.name')]) @include ('partials.forms.edit.name', ['translated_name' => trans('admin/hardware/form.name')])
@include ('partials.forms.edit.warranty') @include ('partials.forms.edit.warranty')
</div> </div>
@ -116,13 +118,13 @@
<div class="form-group"> <div class="form-group">
<label class="col-md-3 control-label"></label> <label class="col-md-3 control-label"></label>
<div class="col-md-2 col-sm-2 text-left form-check" style="z-index:2;"> <div class="col-md-2 col-sm-2 text-left form-check" style="z-index:2;">
<input class="form-check-input" type="checkbox" id="order_info" > <input class="form-check-input" type="checkbox" id="order_info" name="options[]" value="order" <?php if (!empty (json_decode(Cookie::get('optional_info')))) {if(in_array('order',json_decode(Cookie::get('optional_info')))) {echo 'checked';} else {echo 'unchecked';}} else {echo 'unchecked';} ?>>
<label class="form-check-label" for="flexCheckDefault"> <label class="form-check-label" for="flexCheckDefault">
{{ trans('admin/hardware/form.order_details') }} {{ trans('admin/hardware/form.order_details') }}
</label> </label>
</div> </div>
<div id='order_details' class="col-md-12" style="z-index:1;"> <div id='order_details' class="col-md-12" style="z-index:1;" style="display:none">
@include ('partials.forms.edit.order_number') @include ('partials.forms.edit.order_number')
@include ('partials.forms.edit.purchase_date') @include ('partials.forms.edit.purchase_date')
@include ('partials.forms.edit.supplier-select', ['translated_name' => trans('general.supplier'), 'fieldname' => 'supplier_id']) @include ('partials.forms.edit.supplier-select', ['translated_name' => trans('general.supplier'), 'fieldname' => 'supplier_id'])
@ -137,7 +139,7 @@
</div> </div>
</div> </div>
@stop @stop
@section('moar_scripts') @section('moar_scripts')
@ -146,7 +148,6 @@
<script nonce="{{ csrf_token() }}"> <script nonce="{{ csrf_token() }}">
var transformed_oldvals={}; var transformed_oldvals={};
function fetchCustomFields() { function fetchCustomFields() {
@ -303,32 +304,42 @@
}) })
}); });
$( document ).ready(function() { $(document).ready(function() {
checkOrderDetailOption(); checkOrderDetailOption();
checkOptionalOption(); checkOptionalOption();
}); });
if ($('#order_info').is(":checked")){
checkOrderDetailOption();
}
$('#order_info').change(function(){ $('#order_info').change(function(){
checkOrderDetailOption(); checkOrderDetailOption();
}); });
if ($('#optional_info').is(":checked")){
checkOptionalOption();
}
$('#optional_info').change(function(){ $('#optional_info').change(function(){
checkOptionalOption(); checkOptionalOption();
}); });
function checkOptionalOption(){ function checkOptionalOption(){
if ($("#optional_info").prop('checked')==true) { if ($("#optional_info").prop('checked')==true) {
$('#optional_details').fadeIn('slow'); $('#optional_details').show();
} else { } else {
$('#optional_details').fadeOut('slow'); $('#optional_details').hide();
} }
} }
function checkOrderDetailOption(){ function checkOrderDetailOption(){
if ($("#order_info").prop('checked')==true) { if ($("#order_info").prop('checked')==true) {
$('#order_details').fadeIn('slow'); $('#order_details').show();
} else { } else {
$('#order_details').fadeOut('slow'); $('#order_details').hide();
} }
} }
</script> </script>
@stop @stop