FEATURE: make adding custom fields working

This commit is contained in:
Michal Kváček
2016-01-26 22:44:15 +01:00
parent fedb5abae6
commit 271f27be0b
5 changed files with 77 additions and 28 deletions
@@ -4,6 +4,7 @@ namespace App\Http\Controllers\Admin;
use App\Enumerations\CustomFieldTypes; use App\Enumerations\CustomFieldTypes;
use App\Http\Requests\NewCustomFieldRequest; use App\Http\Requests\NewCustomFieldRequest;
use App\Models\CustomField;
class CreateNewCustomField extends Controller class CreateNewCustomField extends Controller
{ {
@@ -16,5 +17,41 @@ class CreateNewCustomField extends Controller
public function postNew(NewCustomFieldRequest $request) public function postNew(NewCustomFieldRequest $request)
{ {
$customField = new CustomField();
// @todo add support for determination of resource for custom field (module, user, ...)
// @todo add possible values
$customField->name = $request->name;
$customField->type_id = $request->type;
$customField->required = $request->has('required');
// set non-mandatory fields
if ($request->description) {
$customField->description = $request->description;
}
if ($request->defaultValue) {
$customField->default_value = $request->defaultValue;
}
if ($request->regExp) {
$customField->regexp = $request->regExp;
}
if ($request->minLength) {
$customField->min_length = $request->minLength;
}
if ($request->maxLength) {
$customField->max_length = $request->maxLength;
}
$customField->save();
return redirect()
->route('customfields.new')
->with('success', trans('admin/customFields.successfullyCreated'));
} }
} }
+2 -2
View File
@@ -13,9 +13,9 @@ class NewCustomFieldRequest extends Request
{ {
return [ return [
'name' => 'required', 'name' => 'required',
'type' => 'required|exists:custom_field_types', 'type' => 'required|exists:custom_field_types,id',
'minLength' => 'numeric|min:0', 'minLength' => 'numeric|min:0',
'maxLength' => 'numeric|mix:0' 'maxLength' => 'numeric|min:0',
]; ];
} }
} }
+19 -18
View File
@@ -1,21 +1,22 @@
<?php <?php
return [ return [
'overview' => 'List of all custom fields', 'overview' => 'List of all custom fields',
'new' => 'New custom field', 'new' => 'New custom field',
'noFields' => 'No custom fields defined.', 'noFields' => 'No custom fields defined.',
'users' => 'Custom fields for user', 'users' => 'Custom fields for user',
'content' => 'Custom fields for content page', 'content' => 'Custom fields for content page',
'name' => 'Name', 'name' => 'Name',
'description' => 'Description', 'description' => 'Description',
'type' => 'Type of custom field', 'type' => 'Type of custom field',
'required' => 'Is field required?', 'required' => 'Is field required?',
'defaultValue' => 'Default value', 'defaultValue' => 'Default value',
'regExp' => 'Match only this regular expression', 'regExp' => 'Match only this regular expression',
'minLength' => 'Minimum length', 'minLength' => 'Minimum length',
'maxLength' => 'Maximum length', 'maxLength' => 'Maximum length',
'createNew' => 'Create new field', 'createNew' => 'Create new field',
'date' => 'Date', 'date' => 'Date',
'number' => 'Number', 'number' => 'Number',
'selectboxList' => 'List (selectbox)', 'selectboxList' => 'List (selectbox)',
'string' => 'Short text' 'string' => 'Short text',
'successfullyCreated' => 'Custom field successfully created.'
]; ];
@@ -10,6 +10,17 @@
</div> </div>
<div class="row"> <div class="row">
@if (session('success'))
<div data-alert class="callout success">
<strong>{{ session('success') }}</strong>
</div>
@endif
@if (session('error'))
<div data-alert class="callout alert">
<strong>{{ session('error') }}</strong>
</div>
@endif
@include('admin.customFields.newForm') @include('admin.customFields.newForm')
</div> </div>
@stop @stop
@@ -5,7 +5,7 @@
<div class="large-6 columns"> <div class="large-6 columns">
<label> <label>
@lang('admin/customFields.name') @lang('admin/customFields.name')
<input type="text" placeholder="@lang('admin/customFields.name')" name="name"> <input type="text" placeholder="@lang('admin/customFields.name')" value="{{old('name')}}" name="name">
@if (isset($errors) && $errors->has('name')) @if (isset($errors) && $errors->has('name'))
<div class="callout alert"> <div class="callout alert">
@@ -20,7 +20,7 @@
<select name="type"> <select name="type">
@foreach($types as $type => $translation) @foreach($types as $type => $translation)
<option value="{{$type}}">@lang($translation)</option> <option value="{{$type}}"@if(old('type') == $type) selected @endif>@lang($translation)</option>
@endforeach @endforeach
</select> </select>
@@ -37,7 +37,7 @@
<label> <label>
@lang('admin/customFields.description') @lang('admin/customFields.description')
<textarea rows="5" name="description" placeholder="@lang('admin/customFields.description')"></textarea> <textarea rows="5" name="description" placeholder="@lang('admin/customFields.description')">{{old('description')}}</textarea>
</label> </label>
</div> </div>
@@ -45,19 +45,19 @@
<label> <label>
@lang('admin/customFields.required') @lang('admin/customFields.required')
<input type="checkbox" placeholder="@lang('admin/customFields.required')" name="required"> <input type="checkbox" placeholder="@lang('admin/customFields.required')" @if (old('required')) checked="checked" @endif name="required">
</label> </label>
<label> <label>
@lang('admin/customFields.defaultValue') @lang('admin/customFields.defaultValue')
<input type="text" placeholder="@lang('admin/customFields.defaultValue')" name="defaultValue"> <input type="text" placeholder="@lang('admin/customFields.defaultValue')" value="{{old('defaultValue')}}" name="defaultValue">
</label> </label>
<label> <label>
@lang('admin/customFields.regExp') @lang('admin/customFields.regExp')
<input type="text" placeholder="@lang('admin/customFields.regExp')" name="regExp"> <input type="text" placeholder="@lang('admin/customFields.regExp')" value="{{old('regExp')}}" name="regExp">
</label> </label>
</div> </div>
</div> </div>
@@ -67,7 +67,7 @@
<label> <label>
@lang('admin/customFields.minLength') @lang('admin/customFields.minLength')
<input type="text" placeholder="@lang('admin/customFields.minLength')" name="minLength"> <input type="text" placeholder="@lang('admin/customFields.minLength')" value="{{old('minLength')}}" name="minLength">
@if (isset($errors) && $errors->has('minLength')) @if (isset($errors) && $errors->has('minLength'))
<div class="callout alert"> <div class="callout alert">
@@ -80,7 +80,7 @@
<label> <label>
@lang('admin/customFields.maxLength') @lang('admin/customFields.maxLength')
<input type="text" placeholder="@lang('admin/customFields.maxLength')" name="maxLength"> <input type="text" placeholder="@lang('admin/customFields.maxLength')" value="{{old('macLength')}}" name="maxLength">
@if (isset($errors) && $errors->has('maxLength')) @if (isset($errors) && $errors->has('maxLength'))
<div class="callout alert"> <div class="callout alert">