Fixes #4027 - proper redirect on fieldset delete

This commit is contained in:
snipe 2017-09-27 16:02:29 -07:00
parent 5410dc4255
commit ec8a3d2e56

View file

@ -37,19 +37,25 @@ class CustomFieldsetsController extends Controller
public function show($id) public function show($id)
{ {
$cfset = CustomFieldset::with('fields')->where('id', '=', $id)->orderBy('id', 'ASC')->first(); $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; if ($cfset) {
foreach ($cfset->fields() as $field) { $custom_fields_list = ["" => "Add New Field to Fieldset"] + CustomField::pluck("name", "id")->toArray();
if ($field->pivot->order > $maxid) {
$maxid=$field->pivot->order; $maxid = 0;
} foreach ($cfset->fields() as $field) {
if (isset($custom_fields_list[$field->id])) { if ($field->pivot->order > $maxid) {
unset($custom_fields_list[$field->id]); $maxid=$field->pivot->order;
}
if (isset($custom_fields_list[$field->id])) {
unset($custom_fields_list[$field->id]);
}
} }
return view("custom_fields.fieldsets.view")->with("custom_fieldset", $cfset)->with("maxid", $maxid+1)->with("custom_fields_list", $custom_fields_list);
} }
return view("custom_fields.fieldsets.view")->with("custom_fieldset", $cfset)->with("maxid", $maxid+1)->with("custom_fields_list", $custom_fields_list); return redirect()->route("fields.index")->with("error", trans('admin/custom_fields/message.fieldset.does_not_exist'));
} }
@ -133,16 +139,21 @@ class CustomFieldsetsController extends Controller
*/ */
public function destroy($id) public function destroy($id)
{ {
//
$fieldset = CustomFieldset::find($id); $fieldset = CustomFieldset::find($id);
$models = AssetModel::where("fieldset_id", "=", $id); if ($fieldset) {
if ($models->count() == 0) { $models = AssetModel::where("fieldset_id", "=", $id);
$fieldset->delete(); if ($models->count() == 0) {
return redirect()->route("fields.show")->with("success", trans('admin/custom_fields/message.fieldset.delete.success')); $fieldset->delete();
} else { return redirect()->route("fields.index")->with("success", trans('admin/custom_fields/message.fieldset.delete.success'));
return redirect()->route("fields.show")->with("error", trans('admin/custom_fields/message.fieldset.delete.in_use')); } else {
return redirect()->route("fields.index")->with("error", trans('admin/custom_fields/message.fieldset.delete.in_use'));
}
} }
return redirect()->route("fields.index")->with("error", trans('admin/custom_fields/message.fieldset.does_not_exist'));
} }