Ability to remove field from fieldset

This commit is contained in:
snipe 2016-07-28 08:10:15 -07:00
parent fbd0059bbb
commit 3e5d2b5385
4 changed files with 31 additions and 2 deletions

View file

@ -147,6 +147,25 @@ class CustomFieldsController extends Controller
}
}
/**
* Detach a custom field from a fieldset.
*
* @author [A. Gianotto] [<snipe@snipe.net>]
* @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 {

View file

@ -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');

View file

@ -6,6 +6,11 @@
@parent
@stop
@section('header_right')
<a href="{{ route('admin.custom_fields.index') }}" class="btn btn-primary pull-right">
{{ trans('general.back') }}</a>
@stop
@section('content')
@ -32,10 +37,11 @@
<tr>
<th class="col-md-1"></th>
<th class="col-md-1">{{ trans('admin/custom_fields/general.order') }}</th>
<th class="col-md-5">{{ trans('admin/custom_fields/general.field_name') }}</th>
<th class="col-md-4">{{ trans('admin/custom_fields/general.field_name') }}</th>
<th class="col-md-2">{{ trans('admin/custom_fields/general.field_format') }}</th>
<th class="col-md-2">{{ trans('admin/custom_fields/general.field_element') }}</th>
<th class="col-md-1">{{ trans('admin/custom_fields/general.required') }}</th>
<th class="col-md-1"></th>
</tr>
</thead>
<tfoot>
@ -66,6 +72,7 @@
<td>{{$field->format}}</td>
<td>{{$field->element}}</td>
<td>{{$field->pivot->required ? "REQUIRED" : "OPTIONAL"}}</td>
<td><a href="{{ route('admin.custom_fields.disassociate', [$field,$custom_fieldset->id]) }}" class="btn btn-sm btn-danger">Remove</a></td>
</tr>
@endforeach
</tbody>

View file

@ -12,7 +12,7 @@
@section('header_right')
<a href="{{ URL::previous() }}" class="btn btn-primary pull-right">
{{ trans('general.back') }}</a>
{{ trans('general.back') }}</a>
@stop