diff --git a/app/Http/Controllers/CustomFieldsController.php b/app/Http/Controllers/CustomFieldsController.php index b16a0c89a7..7aca1739a9 100644 --- a/app/Http/Controllers/CustomFieldsController.php +++ b/app/Http/Controllers/CustomFieldsController.php @@ -42,67 +42,8 @@ class CustomFieldsController extends Controller } - /** - * Returns a view with a form for creating a new custom fieldset. - * - * @author [Brady Wetherington] [] - * @since [v1.8] - * @return View - */ - public function create() - { - return View::make("custom_fields.create"); - } - /** - * Validates and stores a new custom fieldset. - * - * @author [Brady Wetherington] [] - * @since [v1.8] - * @return Redirect - */ - public function store(Request $request) - { - // - $cfset = new CustomFieldset( - [ - "name" => e($request->get("name")), - "user_id" => Auth::user()->id] - ); - - $validator = Validator::make(Input::all(), $cfset->rules); - if ($validator->passes()) { - $cfset->save(); - return redirect()->route("admin.custom_fields.show", [$cfset->id])->with('success', trans('admin/custom_fields/message.fieldset.create.success')); - } else { - return redirect()->back()->withInput()->withErrors($validator); - } - } - - /** - * Associate the custom field with a custom fieldset. - * - * @author [Brady Wetherington] [] - * @since [v1.8] - * @return View - */ - public function associate($id) - { - - $set = CustomFieldset::find($id); - - foreach ($set->fields as $field) { - if ($field->id == Input::get('field_id')) { - return redirect()->route("admin.custom_fields.show", [$id])->withInput()->withErrors(['field_id' => trans('admin/custom_fields/message.field.already_added')]); - } - } - - $results=$set->fields()->attach(Input::get('field_id'), ["required" => (Input::get('required') == "on"),"order" => Input::get('order')]); - - return redirect()->route("admin.custom_fields.show", [$id])->with("success", trans('admin/custom_fields/message.field.create.assoc_success')); - } - /** * Returns a view with a form to create a new custom field. @@ -112,7 +53,7 @@ class CustomFieldsController extends Controller * @since [v1.8] * @return View */ - public function createField() + public function create() { return View::make("custom_fields.create_field"); } @@ -126,7 +67,7 @@ class CustomFieldsController extends Controller * @since [v1.8] * @return Redirect */ - public function storeField(Request $request) + public function store(Request $request) { $field = new CustomField([ "name" => e($request->get("name")), @@ -150,7 +91,7 @@ class CustomFieldsController extends Controller if ($validator->passes()) { $results = $field->save(); if ($results) { - return redirect()->route("admin.custom_fields.index")->with("success", trans('admin/custom_fields/message.field.create.success')); + return redirect()->route("fields.index")->with("success", trans('admin/custom_fields/message.field.create.success')); } else { dd($field); return redirect()->back()->withInput()->with('error', trans('admin/custom_fields/message.field.create.error')); @@ -173,7 +114,7 @@ class CustomFieldsController extends Controller $field = CustomField::find($field_id); if ($field->fieldset()->detach($fieldset_id)) { - return redirect()->route("admin.custom_fields.index")->with("success", trans('admin/custom_fields/message.field.delete.success')); + return redirect()->route('fieldsets.show',['fieldset' => $fieldset_id])->with("success", trans('admin/custom_fields/message.field.delete.success')); } return redirect()->back()->withErrors(['message' => "Field is in-use"]); @@ -186,7 +127,7 @@ class CustomFieldsController extends Controller * @since [v1.8] * @return Redirect */ - public function deleteField($field_id) + public function destroy($field_id) { $field = CustomField::find($field_id); @@ -194,35 +135,10 @@ class CustomFieldsController extends Controller return redirect()->back()->withErrors(['message' => "Field is in-use"]); } else { $field->delete(); - return redirect()->route("admin.custom_fields.index")->with("success", trans('admin/custom_fields/message.field.delete.success')); + return redirect()->route("fields.index")->with("success", trans('admin/custom_fields/message.field.delete.success')); } } - /** - * Validates and stores a new custom field. - * - * @author [Brady Wetherington] [] - * @param int $id - * @since [v1.8] - * @return View - */ - public function getCustomFieldset($id) - { - $cfset = CustomFieldset::with('fields')->where('id','=',$id)->orderBy('id','ASC')->first(); - $custom_fields_list = ["" => "Add New Field to Fieldset"] + CustomField::pluck("name", "id")->toArray(); - - $maxid = 0; - foreach ($cfset->fields() as $field) { - if ($field->pivot->order > $maxid) { - $maxid=$field->pivot->order; - } - if (isset($custom_fields_list[$field->id])) { - unset($custom_fields_list[$field->id]); - } - } - - return View::make("custom_fields.show")->with("custom_fieldset", $cfset)->with("maxid", $maxid+1)->with("custom_fields_list", $custom_fields_list); - } /** @@ -255,29 +171,6 @@ class CustomFieldsController extends Controller } - /** - * Validates a custom fieldset and then deletes if it has no models associated. - * - * @author [Brady Wetherington] [] - * @param int $id - * @since [v1.8] - * @return View - */ - public function destroy($id) - { - // - $fieldset = CustomFieldset::find($id); - - $models = AssetModel::where("fieldset_id", "=", $id); - if ($models->count() == 0) { - $fieldset->delete(); - return redirect()->route("admin.custom_fields.index")->with("success", trans('admin/custom_fields/message.fieldset.delete.success')); - } else { - return redirect()->route("admin.custom_fields.index")->with("error", trans('admin/custom_fields/message.fieldset.delete.in_use')); - } - } - - /** * Reorder the custom fields within a fieldset * diff --git a/app/Http/Controllers/CustomFieldsetsController.php b/app/Http/Controllers/CustomFieldsetsController.php new file mode 100644 index 0000000000..1026da218c --- /dev/null +++ b/app/Http/Controllers/CustomFieldsetsController.php @@ -0,0 +1,173 @@ +] + */ + +class CustomFieldsetsController extends Controller +{ + + /** + * Validates and stores a new custom field. + * + * @author [Brady Wetherington] [] + * @param int $id + * @since [v1.8] + * @return View + */ + public function show($id) + { + $cfset = CustomFieldset::with('fields')->where('id','=',$id)->orderBy('id','ASC')->first(); + $custom_fields_list = ["" => "Add New Field to Fieldset"] + CustomField::pluck("name", "id")->toArray(); + + $maxid = 0; + foreach ($cfset->fields() as $field) { + if ($field->pivot->order > $maxid) { + $maxid=$field->pivot->order; + } + if (isset($custom_fields_list[$field->id])) { + unset($custom_fields_list[$field->id]); + } + } + + return View::make("custom_fields.fieldset")->with("custom_fieldset", $cfset)->with("maxid", $maxid+1)->with("custom_fields_list", $custom_fields_list); + } + + + /** + * Returns a view with a form for creating a new custom fieldset. + * + * @author [Brady Wetherington] [] + * @since [v1.8] + * @return View + */ + public function create() + { + return View::make("custom_fields.create"); + } + + + /** + * Validates and stores a new custom fieldset. + * + * @author [Brady Wetherington] [] + * @since [v1.8] + * @return Redirect + */ + public function store(Request $request) + { + // + $cfset = new CustomFieldset( + [ + "name" => e($request->get("name")), + "user_id" => Auth::user()->id] + ); + + $validator = Validator::make(Input::all(), $cfset->rules); + if ($validator->passes()) { + $cfset->save(); + return redirect()->route("fieldsets.show", [$cfset->id])->with('success', trans('admin/custom_fields/message.fieldset.create.success')); + } else { + return redirect()->back()->withInput()->withErrors($validator); + } + } + + + + + /** + * What the actual fuck, Brady? + * + * @todo Uhh, build this? + * @author [Brady Wetherington] [] + * @param int $id + * @since [v1.8] + * @return Fuckall + */ + public function edit($id) + { + // + } + + + /** + * GET IN THE SEA BRADY. + * + * @todo Uhh, build this too? + * @author [Brady Wetherington] [] + * @param int $id + * @since [v1.8] + * @return Fuckall + */ + public function update($id) + { + // + } + + + /** + * Validates a custom fieldset and then deletes if it has no models associated. + * + * @author [Brady Wetherington] [] + * @param int $id + * @since [v1.8] + * @return View + */ + public function destroy($id) + { + // + $fieldset = CustomFieldset::find($id); + + $models = AssetModel::where("fieldset_id", "=", $id); + if ($models->count() == 0) { + $fieldset->delete(); + return redirect()->route("fields.show")->with("success", trans('admin/custom_fields/message.fieldset.delete.success')); + } else { + return redirect()->route("fields.show")->with("error", trans('admin/custom_fields/message.fieldset.delete.in_use')); + } + } + + + /** + * Associate the custom field with a custom fieldset. + * + * @author [Brady Wetherington] [] + * @since [v1.8] + * @return View + */ + public function associate($id) + { + + $set = CustomFieldset::find($id); + + foreach ($set->fields as $field) { + if ($field->id == Input::get('field_id')) { + return redirect()->route("fieldsets.show", [$id])->withInput()->withErrors(['field_id' => trans('admin/custom_fields/message.field.already_added')]); + } + } + + $results=$set->fields()->attach(Input::get('field_id'), ["required" => (Input::get('required') == "on"),"order" => Input::get('order')]); + + return redirect()->route("fieldsets.show", [$id])->with("success", trans('admin/custom_fields/message.field.create.assoc_success')); + } + +} diff --git a/app/Providers/RouteServiceProvider.php b/app/Providers/RouteServiceProvider.php index 791911b004..7f59c11b90 100644 --- a/app/Providers/RouteServiceProvider.php +++ b/app/Providers/RouteServiceProvider.php @@ -60,6 +60,7 @@ class RouteServiceProvider extends ServiceProvider require base_path('routes/web/accessories.php'); require base_path('routes/web/licenses.php'); require base_path('routes/web/consumables.php'); + require base_path('routes/web/fields.php'); require base_path('routes/web.php'); }); } diff --git a/resources/views/custom_fields/create.blade.php b/resources/views/custom_fields/create.blade.php index 092ff704af..ecef658053 100644 --- a/resources/views/custom_fields/create.blade.php +++ b/resources/views/custom_fields/create.blade.php @@ -22,7 +22,7 @@
- {{ Form::open(['route' => 'admin.custom_fields.store', 'class'=>'form-horizontal']) }} + {{ Form::open(['route' => 'fieldsets.store', 'class'=>'form-horizontal']) }} diff --git a/resources/views/custom_fields/create_field.blade.php b/resources/views/custom_fields/create_field.blade.php index ebde371b73..440acad005 100644 --- a/resources/views/custom_fields/create_field.blade.php +++ b/resources/views/custom_fields/create_field.blade.php @@ -23,7 +23,7 @@
- {{ Form::open(['route' => 'admin.custom_fields.store-field', 'class'=>'form-horizontal']) }} + {{ Form::open(['route' => 'fields.store', 'class'=>'form-horizontal']) }} diff --git a/resources/views/custom_fields/show.blade.php b/resources/views/custom_fields/fieldset.blade.php similarity index 92% rename from resources/views/custom_fields/show.blade.php rename to resources/views/custom_fields/fieldset.blade.php index 507ebfebe6..ed13db8e15 100644 --- a/resources/views/custom_fields/show.blade.php +++ b/resources/views/custom_fields/fieldset.blade.php @@ -7,7 +7,7 @@ @stop @section('header_right') - + {{ trans('general.back') }} @stop @@ -49,7 +49,7 @@ {{ Form::open(['route' => - ["admin.custom_fields.associate",$custom_fieldset->id], + ["fieldsets.associate",$custom_fieldset->id], 'class'=>'form-horizontal', 'id' => 'ordering']) }} {{ Form::checkbox("required","on") }} @@ -77,7 +77,7 @@ {{$field->element}} {{ $field->field_encrypted=='1' ? trans('general.yes') : trans('general.no') }} {{$field->pivot->required ? "REQUIRED" : "OPTIONAL"}} - Remove + Remove @endforeach diff --git a/resources/views/custom_fields/index.blade.php b/resources/views/custom_fields/index.blade.php index 7f9e4109c1..300f38ff69 100644 --- a/resources/views/custom_fields/index.blade.php +++ b/resources/views/custom_fields/index.blade.php @@ -17,7 +17,7 @@
@@ -39,18 +39,18 @@ @foreach($custom_fieldsets AS $fieldset) - {{ link_to_route("admin.custom_fields.show",$fieldset->name,['id' => $fieldset->id]) }} + {{ link_to_route("fieldsets.show",$fieldset->name,['id' => $fieldset->id]) }} {{ $fieldset->fields->count() }} @foreach($fieldset->models as $model) - {{ link_to_route("view/model",$model->name,[$model->id]) }} + {{ link_to_route("models.show",$model->name,[$model->id]) }} @endforeach - {{ Form::open(array('route' => array('admin.custom_fields.delete-field', $fieldset->id), 'method' => 'delete')) }} + {{ Form::open(array('route' => array('fieldsets.destroy', $fieldset->id), 'method' => 'delete')) }} @if($fieldset->models->count() > 0) @@ -86,7 +86,7 @@
@@ -112,11 +112,11 @@ {{ $field->element }} @foreach($field->fieldset as $fieldset) - {{link_to_route("admin.custom_fields.show",$fieldset->name,[$fieldset->id])}} + {{ link_to_route("fieldsets.show",$fieldset->name,[$fieldset->id])}} @endforeach - {{ Form::open(array('route' => array('admin.custom_fields.delete-field', $field->id), 'method' => 'delete')) }} + {{ Form::open(array('route' => array('fields.destroy', $field->id), 'method' => 'delete')) }} @if($field->fieldset->count()>0) diff --git a/resources/views/layouts/default.blade.php b/resources/views/layouts/default.blade.php index 1499cfe08d..e8a8c92c5c 100644 --- a/resources/views/layouts/default.blade.php +++ b/resources/views/layouts/default.blade.php @@ -367,7 +367,7 @@
  • - + @lang('admin/custom_fields/general.custom_fields')
  • diff --git a/routes/web.php b/routes/web.php index 54458c3d0f..4f77e1d9b7 100644 --- a/routes/web.php +++ b/routes/web.php @@ -3,12 +3,6 @@ use App\Models\CheckoutRequest; use App\Models\Location; use App\Models\Statuslabel; -/* -* Custom Fields Routes -*/ -Route::resource('fields', 'CustomFieldsController', [ -'parameters' => ['customfield' => 'field_id', 'fieldset' => 'fieldset_id'] -]); /* * Companies @@ -188,46 +182,7 @@ Route::group([ 'prefix' => 'admin','middleware' => ['web','auth']], function () }); - # Custom fields support - Route::get('customfields/field/create', - ['uses' =>'CustomFieldsController@createField', - 'as' => 'admin.custom_fields.create-field'] - ); - Route::get('customfields/fieldset/create', - ['as' => 'admin.custom_fields.create-fieldset', - 'uses' => 'CustomFieldsController@create'] - ); - - Route::post('customfields/field/create', - ['uses' => 'CustomFieldsController@storeField', - 'as' => 'admin.custom_fields.store-field'] - ); - - Route::post('customfields/field/{id}/associate', - ['uses' => 'CustomFieldsController@associate', - ' as' => 'admin.custom_fields.associate'] - ); - - Route::get('customfields/fieldset/{fieldset_id}/{field_id}/disassociate', - ['uses' => 'CustomFieldsController@deleteFieldFromFieldset', - 'as' => 'admin.custom_fields.disassociate'] - ); - - Route::get('custom_fields/field/{id}/delete', - ['uses' =>'CustomFieldsController@deleteField', - 'as' => 'admin.custom_fields.delete-field'] - ); - - Route::get('customfields/fieldset/{id}/view', - ['uses' =>'CustomFieldsController@getCustomFieldset', - 'as' => 'admin.custom_fields.show'] - ); - - Route::get('customfields', - ['uses' =>'CustomFieldsController@getIndex', - 'as' => 'admin.custom_fields.index'] - ); # User Management diff --git a/routes/web/fields.php b/routes/web/fields.php new file mode 100644 index 0000000000..f4b8565899 --- /dev/null +++ b/routes/web/fields.php @@ -0,0 +1,26 @@ + ['field' => 'field_id', 'fieldset' => 'fieldset_id'] +]); + +Route::group([ 'prefix' => 'fields' ], function () { + + Route::get('{field_id}/fieldset/{fieldset_id}/disassociate', + ['uses' => 'CustomFieldsController@deleteFieldFromFieldset', + 'as' => 'fields.disassociate'] + ); + + Route::post('fieldsets/{id}/associate', + ['uses' => 'CustomFieldsetsController@associate', + 'as' => 'fieldsets.associate'] + ); + + Route::resource('fieldsets', 'CustomFieldsetsController', [ + 'parameters' => ['fieldset' => 'field_id', 'field' => 'field_id'] + ]); +});