From 3e5d2b53853ecf5d16fd300227b95b6576db9e6e Mon Sep 17 00:00:00 2001 From: snipe Date: Thu, 28 Jul 2016 08:10:15 -0700 Subject: [PATCH] Ability to remove field from fieldset --- .../Controllers/CustomFieldsController.php | 21 +++++++++++++++++++ app/Http/routes.php | 1 + resources/views/custom_fields/show.blade.php | 9 +++++++- resources/views/hardware/edit.blade.php | 2 +- 4 files changed, 31 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/CustomFieldsController.php b/app/Http/Controllers/CustomFieldsController.php index 12f44e993..d2d911bb2 100644 --- a/app/Http/Controllers/CustomFieldsController.php +++ b/app/Http/Controllers/CustomFieldsController.php @@ -147,6 +147,25 @@ class CustomFieldsController extends Controller } } + + /** + * Detach a custom field from a fieldset. + * + * @author [A. Gianotto] [] + * @since [v3.0] + * @return Redirect + */ + public function deleteFieldFromFieldset($field_id, $fieldset_id) + { + $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()->back()->withErrors(['message' => "Field is in-use"]); + } + /** * Delete a custom field. * @@ -158,6 +177,8 @@ class CustomFieldsController extends Controller { $field=CustomField::find($field_id); + + if ($field->fieldset->count()>0) { return redirect()->back()->withErrors(['message' => "Field is in-use"]); } else { diff --git a/app/Http/routes.php b/app/Http/routes.php index f0ac9f226..c010d4bcd 100755 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -638,6 +638,7 @@ Route::group([ 'prefix' => 'admin','middleware' => ['web','auth']], function () Route::get('custom_fields/create-field', ['uses' =>'CustomFieldsController@createField','as' => 'admin.custom_fields.create-field']); Route::post('custom_fields/create-field', ['uses' => 'CustomFieldsController@storeField','as' => 'admin.custom_fields.store-field']); Route::post('custom_fields/{id}/associate', ['uses' => 'CustomFieldsController@associate','as' => 'admin.custom_fields.associate']); + Route::get('custom_fields/{field_id}/{fieldset_id}/disassociate', ['uses' => 'CustomFieldsController@deleteFieldFromFieldset','as' => 'admin.custom_fields.disassociate']); Route::match(['DELETE'], 'custom_fields/delete-field/{id}', ['uses' => 'CustomFieldsController@deleteField','as' => 'admin.custom_fields.delete-field']); Route::resource('custom_fields', 'CustomFieldsController'); diff --git a/resources/views/custom_fields/show.blade.php b/resources/views/custom_fields/show.blade.php index eff90959e..e32a76fed 100644 --- a/resources/views/custom_fields/show.blade.php +++ b/resources/views/custom_fields/show.blade.php @@ -6,6 +6,11 @@ @parent @stop +@section('header_right') + + {{ trans('general.back') }} +@stop + @section('content') @@ -32,10 +37,11 @@ {{ trans('admin/custom_fields/general.order') }} - {{ trans('admin/custom_fields/general.field_name') }} + {{ trans('admin/custom_fields/general.field_name') }} {{ trans('admin/custom_fields/general.field_format') }} {{ trans('admin/custom_fields/general.field_element') }} {{ trans('admin/custom_fields/general.required') }} + @@ -66,6 +72,7 @@ {{$field->format}} {{$field->element}} {{$field->pivot->required ? "REQUIRED" : "OPTIONAL"}} + Remove @endforeach diff --git a/resources/views/hardware/edit.blade.php b/resources/views/hardware/edit.blade.php index 4b0b5504a..58b17d210 100755 --- a/resources/views/hardware/edit.blade.php +++ b/resources/views/hardware/edit.blade.php @@ -12,7 +12,7 @@ @section('header_right') - {{ trans('general.back') }} + {{ trans('general.back') }} @stop