FEATURE: add translations and more friendly look to categories

This commit is contained in:
Michal Kváček
2016-08-13 16:51:53 +02:00
parent 9f955d4544
commit 5aec27478a
7 changed files with 132 additions and 33 deletions
@@ -2,7 +2,6 @@
use App\Http\Requests\Request;
use App\Models\Module;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Str;
use Modules\Categories\Entities\Category;
use Pingpong\Modules\Routing\Controller;
@@ -52,19 +51,27 @@ class EditCategory extends Controller
$category->save();
if ($category->parent_id != $request->parentCategory) {
if ($category->parent_id !== $request->parentCategory) {
$category->parent_id = empty($request->parentCategory) ? null : $request->parentCategory;
$category->save();
if (empty($request->parentCategory)) {
$category->makeRoot(1);
$category->makeRoot($category->position);
}
}
return redirect()
->route('categories.edit', ['id' => $id])
->with('success', trans('categories::categories.saveSuccessfull'));
}
public function delete($id) {
$category = Category::findOrFail($id);
$category->delete();
return redirect()
->route('categories.overview')
->with('success', trans('categories::categories.deleteSuccessfull'));
}
}
@@ -0,0 +1,20 @@
<?php
return [
"actions" => "Akce",
"deleteSuccessfull" => "Kategorie úspěšně smazána",
"description" => "Modul pro správu a kategorizaci obsahu.",
"edit" => "Úprava kategorie",
"fields" => ["description" => "Popis",
"module" => "Modul",
"name" => "Jméno",
"parentCategory" => "Rodičovská kategorie",
"save" => "Uložit",
"url" => "URL",
],
"module" => "Modul",
"name" => "Kategorie",
"new" => "Nová kategorie",
"noCategories" => "Žádná vytvořená kategorie.",
"overview" => "Všechny kategorie",
"saveSuccessfull" => "Kategorie úspěšně uložena",
];
@@ -1,7 +1,21 @@
<?php
return [
'name' => 'Categories',
'description' => 'Module for category management and content categorization.',
'new' => 'New category',
'overview' => 'All categories',
'name' => 'Categories',
'description' => 'Module for category management and content categorization.',
'new' => 'New category',
'overview' => 'All categories',
'fields' => [
'name' => 'Name',
'description' => 'Description',
'url' => 'URL',
'module' => 'Module',
'parentCategory' => 'Parent category',
'save' => 'Save category'
],
'edit' => 'Edit category',
'saveSuccessfull' => 'Category successfully saved',
'deleteSuccessfull' => 'Category successfully deleted',
'module' => 'Module',
'actions' => 'Actions',
'noCategories' => 'No categories available'
];
@@ -3,5 +3,17 @@
@section('content')
<h2>@lang('categories::categories.edit')</h2>
@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('categories::admin.form', ['action' => route('categories.postEdit', ['id' => $category->id])])
@endsection
@@ -1,45 +1,63 @@
<form action="{{$action}}" method="post">
{!! csrf_field() !!}
<div class="row">
<div class="column large-5">
<label>
@lang('categories::categories.fields.name')
<label>
@lang('categories::categories.fields.name')
<input type="text" name="name" class="slug-source" value="{{old('name', $category->name)}}">
</label>
</div>
<div class="column large-5">
<label>
@lang('categories::categories.fields.url')
<input type="text" name="name" value="{{old('name', $category->name)}}">
</label>
<input type="text" name="url" class="slug-target" value="{{old('url', $category->url)}}">
</label>
<label>
@lang('categories::categories.fields.url')
</div>
<div class="column large-2 text-center">
<label>
@lang('admin/contents.lockUrl')<br />
<input type="text" name="url" value="{{old('url', $category->url)}}">
</label>
<input type="checkbox" value="1" id="lockUrl"
@if(old('lockUrl') || ($category->id > 0 && \Illuminate\Support\Str::slug($category->name) != $category->url)) checked
@endif name="lockUrl" />
</label>
</div>
</div>
<label>
@lang('categories::categories.fields.description')
<label>
@lang('categories::categories.fields.description')
<textarea name="description">{{old('description', $category->description)}}</textarea>
</label>
<textarea name="description">{{old('description', $category->description)}}</textarea>
</label>
@if(!$category->id)
<div class="row">
<div class="column large-6">
<label>
@lang('categories::categories.fields.module')
<select name="moduleId">
<select name="moduleId" @if($category->id) disabled @endif>
@foreach($modules as $module)
<option @if($module->id == $category->module_id) selected
@endif value="{{$module->id}}">{{trans($module->name)}}</option>
@endforeach
</select>
</label>
@endif
<label>
@lang('categories::categories.fields.parentCategory')
<select name="parentCategory">
<option value=""> ---</option>
@foreach($categories as $parentCategory)
@include('categories::admin.snippets.optionParentCategories', ['level' => 0, 'selectedCategory' => $category, 'currentCategory' => $parentCategory])
@endforeach
</select>
</label>
</div>
<div class="column large-6">
@if(count($categories))
<label>
@lang('categories::categories.fields.parentCategory')
<select name="parentCategory">
<option value=""> ---</option>
@foreach($categories as $parentCategory)
@include('categories::admin.snippets.optionParentCategories', ['level' => 0, 'selectedCategory' => $category, 'currentCategory' => $parentCategory])
@endforeach
</select>
</label>
@endif
</div>
</div>
<button type="submit" class="button primary">@lang('categories::categories.fields.save')</button>
@@ -3,5 +3,17 @@
@section('content')
<h2>@lang('categories::categories.new')</h2>
@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('categories::admin.form', ['action' => route('categories.postNew')])
@endsection
@@ -3,6 +3,19 @@
@section('content')
<h2>@lang('categories::categories.overview')</h2>
@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
@if(count($categories))
<table class="full-width">
<thead>
<tr>
@@ -17,4 +30,7 @@
@endforeach
</tbody>
</table>
@else
<em>@lang('categories::categories.noCategories')</em>
@endif
@stop