WIP: migrate to livewire

This commit is contained in:
Marcus Moore 2023-08-01 17:29:23 -07:00
parent 65de9c5e07
commit 6349d52803
No known key found for this signature in database
3 changed files with 150 additions and 96 deletions

View file

@ -0,0 +1,46 @@
<?php
namespace App\Http\Livewire;
use Livewire\Component;
class CategoryEditForm extends Component
{
// public bool $displayEmailMessage = false;
public bool $checkinEmail;
public $defaultEulaText;
public $eulaText;
public bool $requireAcceptance;
public bool $useDefaultEula;
public function mount()
{
}
public function updated($a, $b)
{
// dd($a, $b);
}
public function render()
{
return view('livewire.category-edit-form');
}
public function getDisplayEmailMessageProperty(): bool
{
return false;
}
public function getEmailMessageProperty(): string
{
// @todo:
return '';
}
}

View file

@ -23,62 +23,13 @@
</div> </div>
</div> </div>
<livewire:category-edit-form
:checkin-email="old('checkin_email', $item->checkin_email)"
<!-- EULA text --> :default-eula-text="$snipeSettings->default_eula_text"
<div class="form-group {{ $errors->has('eula_text') ? 'error' : '' }}"> :eula-text="old('eula_text', $item->eula_text)"
<label for="eula_text" class="col-md-3 control-label">{{ trans('admin/categories/general.eula_text') }}</label> :require-acceptance="old('require_acceptance', $item->require_acceptance)"
<div class="col-md-7"> :use-default-eula="old('use_default_eula', $item->use_default_eula)"
{{ Form::textarea('eula_text', old('eula_text', $item->eula_text), array('class' => 'form-control', 'aria-label'=>'eula_text')) }} />
<p class="help-block">{!! trans('admin/categories/general.eula_text_help') !!} </p>
<p class="help-block">{!! trans('admin/settings/general.eula_markdown') !!} </p>
{!! $errors->first('eula_text', '<span class="alert-msg" aria-hidden="true">:message</span>') !!}
</div>
</div>
<!-- Use default checkbox -->
<div class="form-group">
<div class="col-md-9 col-md-offset-3">
@if ($snipeSettings->default_eula_text!='')
<label class="form-control">
{{ Form::checkbox('use_default_eula', '1', old('use_default_eula', $item->use_default_eula), ['aria-label'=>'use_default_eula']) }}
<span>{!! trans('admin/categories/general.use_default_eula') !!}</span>
</label>
@else
<label class="form-control form-control--disabled">
{{ Form::checkbox('use_default_eula', '0', old('use_default_eula'), ['class'=>'disabled','disabled' => 'disabled', 'aria-label'=>'use_default_eula']) }}
<span>{!! trans('admin/categories/general.use_default_eula_disabled') !!}</span>
</label>
@endif
</div>
</div>
<!-- Require Acceptance -->
<div class="form-group">
<div class="col-md-9 col-md-offset-3">
<label class="form-control">
{{ Form::checkbox('require_acceptance', '1', old('require_acceptance', $item->require_acceptance), ['aria-label'=>'require_acceptance']) }}
{{ trans('admin/categories/general.require_acceptance') }}
</label>
</div>
</div>
<!-- Email on Checkin -->
<div class="form-group">
<div class="col-md-9 col-md-offset-3">
<label class="form-control">
{{ Form::checkbox('checkin_email', '1', old('checkin_email', $item->checkin_email), ['aria-label'=>'checkin_email']) }}
{{ trans('admin/categories/general.checkin_email') }}
</label>
<div id="email_will_be_sent" class="callout callout-info">
<i class="far fa-envelope"></i>
<span id="email_will_be_sent_message"></span>
</div>
</div>
</div>
@include ('partials.forms.edit.image-upload', ['image_path' => app('categories_upload_path')]) @include ('partials.forms.edit.image-upload', ['image_path' => app('categories_upload_path')])
@ -114,51 +65,53 @@
@stop @stop
@section('moar_scripts') @section('moar_scripts')
<script type="text/javascript"> {{-- <script type="text/javascript">--}}
$(document).ready(function () { {{-- $(document).ready(function () {--}}
function checkAndDisableEmailCheckbox() { {{-- function checkAndDisableEmailCheckbox() {--}}
shouldSendEmail.prop('checked', true); {{-- shouldSendEmail.prop('checked', true);--}}
shouldSendEmail.prop('disabled', true); {{-- shouldSendEmail.prop('disabled', true);--}}
} {{-- }--}}
function uncheckAndEnableEmailCheckbox() { {{-- function uncheckAndEnableEmailCheckbox() {--}}
shouldSendEmail.prop('checked', false); {{-- shouldSendEmail.prop('checked', false);--}}
shouldSendEmail.prop('disabled', false); {{-- shouldSendEmail.prop('disabled', false);--}}
} {{-- }--}}
let eula = $('textarea[name="eula_text"]'); {{-- let eula = $('textarea[name="eula_text"]');--}}
let useDefaultEula = $('input[name="use_default_eula"]'); {{-- let useDefaultEula = $('input[name="use_default_eula"]');--}}
let shouldSendEmail = $('input[name="checkin_email"]') {{-- let shouldSendEmail = $('input[name="checkin_email"]')--}}
let messageWrapper = $('#email_will_be_sent'); {{-- let messageWrapper = $('#email_will_be_sent');--}}
let messageSpan = $('#email_will_be_sent_message'); {{-- let messageSpan = $('#email_will_be_sent_message');--}}
let messages = { {{-- let messages = {--}}
global: '{{ trans('admin/categories/general.email_will_be_sent_due_to_global_eula') }}', {{-- global: '{{ trans('admin/categories/general.email_will_be_sent_due_to_global_eula') }}',--}}
local: '{{ trans('admin/categories/general.email_will_be_sent_due_to_category_eula') }}', {{-- local: '{{ trans('admin/categories/general.email_will_be_sent_due_to_category_eula') }}',--}}
}; {{-- };--}}
function handleEulaChange() { {{-- function handleEulaChange() {--}}
if (eula.val().trim() !== '' || useDefaultEula.is(":checked")) { {{-- if (eula.val().trim() !== '' || useDefaultEula.is(":checked")) {--}}
checkAndDisableEmailCheckbox(); {{-- checkAndDisableEmailCheckbox();--}}
useDefaultEula.is(":checked") ? messageSpan.text(messages.global) : messageSpan.text(messages.local); {{-- useDefaultEula.is(":checked") ? messageSpan.text(messages.global) : messageSpan.text(messages.local);--}}
messageWrapper.show(); {{-- messageWrapper.show();--}}
eula.prop('disabled', useDefaultEula.is(":checked")); {{-- eula.prop('disabled', useDefaultEula.is(":checked"));--}}
} else { {{-- } else {--}}
uncheckAndEnableEmailCheckbox(); {{-- uncheckAndEnableEmailCheckbox();--}}
messageWrapper.hide(); {{-- messageWrapper.hide();--}}
eula.prop('disabled', useDefaultEula.is(":checked")); {{-- eula.prop('disabled', useDefaultEula.is(":checked"));--}}
} {{-- }--}}
} {{-- }--}}
eula.on('change keyup', function () { {{-- eula.on('change keyup', function () {--}}
handleEulaChange(); {{-- handleEulaChange();--}}
}); {{-- });--}}
useDefaultEula.change(function () { {{-- useDefaultEula.change(function () {--}}
handleEulaChange(); {{-- handleEulaChange();--}}
}); {{-- });--}}
handleEulaChange(); {{-- @if (! old('checkin_email', $item->checkin_email))--}}
}); {{-- handleEulaChange();--}}
</script> {{-- @endif--}}
{{-- });--}}
{{-- </script>--}}
@stop @stop

View file

@ -0,0 +1,55 @@
<div>
<!-- EULA text -->
<div class="form-group {{ $errors->has('eula_text') ? 'error' : '' }}">
<label for="eula_text" class="col-md-3 control-label">{{ trans('admin/categories/general.eula_text') }}</label>
<div class="col-md-7">
{{ Form::textarea('eula_text', null, array('wire:model.lazy' => 'eulaText', 'class' => 'form-control', 'aria-label'=>'eula_text')) }}
<p class="help-block">{!! trans('admin/categories/general.eula_text_help') !!} </p>
<p class="help-block">{!! trans('admin/settings/general.eula_markdown') !!} </p>
{!! $errors->first('eula_text', '<span class="alert-msg" aria-hidden="true">:message</span>') !!}
</div>
</div>
<!-- Use default checkbox -->
<div class="form-group">
<div class="col-md-9 col-md-offset-3">
@if ($defaultEulaText!='')
<label class="form-control">
{{ Form::checkbox('use_default_eula', '1', null, ['wire:model' => 'useDefaultEula', 'aria-label'=>'use_default_eula']) }}
<span>{!! trans('admin/categories/general.use_default_eula') !!}</span>
</label>
@else
<label class="form-control form-control--disabled">
{{ Form::checkbox('use_default_eula', '0', null, ['wire:model' => 'useDefaultEula', 'class'=>'disabled','disabled' => 'disabled', 'aria-label'=>'use_default_eula']) }}
<span>{!! trans('admin/categories/general.use_default_eula_disabled') !!}</span>
</label>
@endif
</div>
</div>
<!-- Require Acceptance -->
<div class="form-group">
<div class="col-md-9 col-md-offset-3">
<label class="form-control">
{{ Form::checkbox('require_acceptance', '1', null, ['wire:model' => 'requireAcceptance', 'aria-label'=>'require_acceptance']) }}
{{ trans('admin/categories/general.require_acceptance') }}
</label>
</div>
</div>
<!-- Email on Checkin -->
<div class="form-group">
<div class="col-md-9 col-md-offset-3">
<label class="form-control">
{{ Form::checkbox('checkin_email', '1', null, ['wire:model' => 'checkinEmail', 'aria-label'=>'checkin_email']) }}
{{ trans('admin/categories/general.checkin_email') }}
</label>
@if ($this->displayEmailMessage)
<div class="callout callout-info">
<i class="far fa-envelope"></i>
<span>{{ $this->emailMessage }}</span>
</div>
@endif
</div>
</div>
</div>