mirror of
https://github.com/snipe/snipe-it.git
synced 2025-01-23 11:43:47 -08:00
Merge pull request #13407 from marcusmoore/feature/sc-23465
Added messaging to category edit page to improve clarity around when users will be emailed
This commit is contained in:
commit
a6a742d8d8
67
app/Http/Livewire/CategoryEditForm.php
Normal file
67
app/Http/Livewire/CategoryEditForm.php
Normal file
|
@ -0,0 +1,67 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Livewire;
|
||||
|
||||
use Livewire\Component;
|
||||
|
||||
class CategoryEditForm extends Component
|
||||
{
|
||||
public $defaultEulaText;
|
||||
|
||||
public $eulaText;
|
||||
|
||||
public $originalSendCheckInEmailValue;
|
||||
|
||||
public $requireAcceptance;
|
||||
|
||||
public $sendCheckInEmail;
|
||||
|
||||
public $useDefaultEula;
|
||||
|
||||
public function mount()
|
||||
{
|
||||
$this->originalSendCheckInEmailValue = $this->sendCheckInEmail;
|
||||
|
||||
if ($this->eulaText || $this->useDefaultEula) {
|
||||
$this->sendCheckInEmail = 1;
|
||||
}
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.category-edit-form');
|
||||
}
|
||||
|
||||
public function updated($property, $value)
|
||||
{
|
||||
if (! in_array($property, ['eulaText', 'useDefaultEula'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->sendCheckInEmail = $this->eulaText || $this->useDefaultEula ? 1 : $this->originalSendCheckInEmailValue;
|
||||
}
|
||||
|
||||
public function getShouldDisplayEmailMessageProperty(): bool
|
||||
{
|
||||
return $this->eulaText || $this->useDefaultEula;
|
||||
}
|
||||
|
||||
public function getEmailMessageProperty(): string
|
||||
{
|
||||
if ($this->useDefaultEula) {
|
||||
return trans('admin/categories/general.email_will_be_sent_due_to_global_eula');
|
||||
}
|
||||
|
||||
return trans('admin/categories/general.email_will_be_sent_due_to_category_eula');
|
||||
}
|
||||
|
||||
public function getEulaTextDisabledProperty()
|
||||
{
|
||||
return (bool)$this->useDefaultEula;
|
||||
}
|
||||
|
||||
public function getSendCheckInEmailDisabledProperty()
|
||||
{
|
||||
return $this->eulaText || $this->useDefaultEula;
|
||||
}
|
||||
}
|
|
@ -8,6 +8,8 @@ return array(
|
|||
'clone' => 'Clone Category',
|
||||
'create' => 'Create Category',
|
||||
'edit' => 'Edit Category',
|
||||
'email_will_be_sent_due_to_global_eula' => 'An email will be sent to the user because the global EULA is being used.',
|
||||
'email_will_be_sent_due_to_category_eula' => 'An email will be sent to the user because a EULA is set for this category.',
|
||||
'eula_text' => 'Category EULA',
|
||||
'eula_text_help' => 'This field allows you to customize your EULAs for specific types of assets. If you only have one EULA for all of your assets, you can check the box below to use the primary default.',
|
||||
'name' => 'Category Name',
|
||||
|
|
|
@ -23,59 +23,13 @@
|
|||
</div>
|
||||
</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', 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>
|
||||
</div>
|
||||
|
||||
<livewire:category-edit-form
|
||||
:default-eula-text="$snipeSettings->default_eula_text"
|
||||
:eula-text="old('eula_text', $item->eula_text)"
|
||||
:require-acceptance="old('require_acceptance', $item->require_acceptance)"
|
||||
:send-check-in-email="old('checkin_email', $item->checkin_email)"
|
||||
:use-default-eula="old('use_default_eula', $item->use_default_eula)"
|
||||
/>
|
||||
|
||||
@include ('partials.forms.edit.image-upload', ['image_path' => app('categories_upload_path')])
|
||||
|
||||
|
|
61
resources/views/livewire/category-edit-form.blade.php
Normal file
61
resources/views/livewire/category-edit-form.blade.php
Normal file
|
@ -0,0 +1,61 @@
|
|||
<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, ['wire:model' => 'eulaText', 'class' => 'form-control', 'aria-label'=>'eula_text', 'disabled' => $this->eulaTextDisabled]) }}
|
||||
<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>
|
||||
@if ($this->eulaTextDisabled)
|
||||
<input type="hidden" name="eula_text" wire:model="eulaText" />
|
||||
@endif
|
||||
</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' => 'sendCheckInEmail', 'aria-label'=>'checkin_email', 'disabled' => $this->sendCheckInEmailDisabled]) }}
|
||||
{{ trans('admin/categories/general.checkin_email') }}
|
||||
</label>
|
||||
@if ($this->shouldDisplayEmailMessage)
|
||||
<div class="callout callout-info">
|
||||
<i class="far fa-envelope"></i>
|
||||
<span>{{ $this->emailMessage }}</span>
|
||||
</div>
|
||||
@endif
|
||||
@if ($this->sendCheckInEmailDisabled)
|
||||
<input type="hidden" name="checkin_email" wire:model="sendCheckInEmail" />
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
105
tests/Feature/Livewire/CategoryEditFormTest.php
Normal file
105
tests/Feature/Livewire/CategoryEditFormTest.php
Normal file
|
@ -0,0 +1,105 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Feature\Livewire;
|
||||
|
||||
use App\Http\Livewire\CategoryEditForm;
|
||||
use Livewire\Livewire;
|
||||
use Tests\TestCase;
|
||||
|
||||
class CategoryEditFormTest extends TestCase
|
||||
{
|
||||
public function testTheComponentCanRender()
|
||||
{
|
||||
Livewire::test(CategoryEditForm::class)->assertStatus(200);
|
||||
}
|
||||
|
||||
public function testSendEmailCheckboxIsCheckedOnLoadWhenSendEmailIsExistingSetting()
|
||||
{
|
||||
Livewire::test(CategoryEditForm::class, [
|
||||
'sendCheckInEmail' => true,
|
||||
'eulaText' => '',
|
||||
'useDefaultEula' => false,
|
||||
])->assertSet('sendCheckInEmail', true);
|
||||
}
|
||||
|
||||
public function testSendEmailCheckboxIsCheckedOnLoadWhenCategoryEulaSet()
|
||||
{
|
||||
Livewire::test(CategoryEditForm::class, [
|
||||
'sendCheckInEmail' => false,
|
||||
'eulaText' => 'Some Content',
|
||||
'useDefaultEula' => false,
|
||||
])->assertSet('sendCheckInEmail', true);
|
||||
}
|
||||
|
||||
public function testSendEmailCheckboxIsCheckedOnLoadWhenUsingDefaultEula()
|
||||
{
|
||||
Livewire::test(CategoryEditForm::class, [
|
||||
'sendCheckInEmail' => false,
|
||||
'eulaText' => '',
|
||||
'useDefaultEula' => true,
|
||||
])->assertSet('sendCheckInEmail', true);
|
||||
}
|
||||
|
||||
public function testSendEmailCheckBoxIsUncheckedOnLoadWhenSendEmailIsFalseNoCategoryEulaSetAndNotUsingDefaultEula()
|
||||
{
|
||||
Livewire::test(CategoryEditForm::class, [
|
||||
'sendCheckInEmail' => false,
|
||||
'eulaText' => '',
|
||||
'useDefaultEula' => false,
|
||||
])->assertSet('sendCheckInEmail', false);
|
||||
}
|
||||
|
||||
public function testSendEmailCheckboxIsCheckedWhenCategoryEulaEntered()
|
||||
{
|
||||
Livewire::test(CategoryEditForm::class, [
|
||||
'sendCheckInEmail' => false,
|
||||
'useDefaultEula' => false,
|
||||
])->assertSet('sendCheckInEmail', false)
|
||||
->set('eulaText', 'Some Content')
|
||||
->assertSet('sendCheckInEmail', true);
|
||||
}
|
||||
|
||||
public function testSendEmailCheckboxCheckedAndDisabledAndEulaTextDisabledWhenUseDefaultEulaSelected()
|
||||
{
|
||||
Livewire::test(CategoryEditForm::class, [
|
||||
'sendCheckInEmail' => false,
|
||||
'useDefaultEula' => false,
|
||||
])->assertSet('sendCheckInEmail', false)
|
||||
->set('useDefaultEula', true)
|
||||
->assertSet('sendCheckInEmail', true)
|
||||
->assertSet('eulaTextDisabled', true)
|
||||
->assertSet('sendCheckInEmailDisabled', true);
|
||||
}
|
||||
|
||||
public function testSendEmailCheckboxEnabledAndSetToOriginalValueWhenNoCategoryEulaAndNotUsingGlobalEula()
|
||||
{
|
||||
Livewire::test(CategoryEditForm::class, [
|
||||
'eulaText' => 'Some Content',
|
||||
'sendCheckInEmail' => false,
|
||||
'useDefaultEula' => true,
|
||||
])
|
||||
->set('useDefaultEula', false)
|
||||
->set('eulaText', '')
|
||||
->assertSet('sendCheckInEmail', false)
|
||||
->assertSet('sendCheckInEmailDisabled', false);
|
||||
|
||||
Livewire::test(CategoryEditForm::class, [
|
||||
'eulaText' => 'Some Content',
|
||||
'sendCheckInEmail' => true,
|
||||
'useDefaultEula' => true,
|
||||
])
|
||||
->set('useDefaultEula', false)
|
||||
->set('eulaText', '')
|
||||
->assertSet('sendCheckInEmail', true)
|
||||
->assertSet('sendCheckInEmailDisabled', false);
|
||||
}
|
||||
|
||||
public function testEulaFieldEnabledOnLoadWhenNotUsingDefaultEula()
|
||||
{
|
||||
Livewire::test(CategoryEditForm::class, [
|
||||
'sendCheckInEmail' => false,
|
||||
'eulaText' => '',
|
||||
'useDefaultEula' => false,
|
||||
])->assertSet('eulaTextDisabled', false);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue