Merge pull request #2147 from dmeltzer/Fix-Asset-Creation-with-old-data

Fix editing assets.
This commit is contained in:
snipe 2016-06-10 05:51:33 -07:00 committed by GitHub
commit ac15fb9be9
2 changed files with 6 additions and 6 deletions

View file

@ -296,9 +296,9 @@ class AssetsController extends Controller
* @since [v1.0] * @since [v1.0]
* @return Redirect * @return Redirect
*/ */
public function postEdit(Request $request, $assetId = null)
public function postEdit(AssetRequest $request, $assetId = null)
{ {
exit;
// Check if the asset exists // Check if the asset exists
if (!$asset = Asset::find($assetId)) { if (!$asset = Asset::find($assetId)) {
// Redirect to the asset management page with error // Redirect to the asset management page with error
@ -388,10 +388,11 @@ class AssetsController extends Controller
// Was the asset updated? // Was the asset updated?
if ($asset->save()) { if ($asset->save()) {
// Redirect to the new asset page // Redirect to the new asset page
return redirect()->to("hardware/$assetId/view")->with('success', trans('admin/hardware/message.update.success')); \Session::flash('success', trans('admin/hardware/message.update.success'));
return response()->json(['redirect_url' => route("view/hardware", $assetId)]);
} }
return redirect()->back()->withInput()->withErrors($asset->getErrors()); return response()->json(['errors' => $asset->getErrors()]);
} }

View file

@ -501,7 +501,6 @@ $(function () {
function sendForm() { function sendForm() {
var form = $("#create-form").get(0); var form = $("#create-form").get(0);
var successRoute = "{{route('hardware')}}";
var formData = $('#create-form').serializeArray(); var formData = $('#create-form').serializeArray();
formData.push({name:'image', value:imageData}); formData.push({name:'image', value:imageData});
$.ajax({ $.ajax({
@ -512,7 +511,7 @@ $(function () {
dataType: 'json', dataType: 'json',
success: function(data) { success: function(data) {
// AssetController flashes success to session, redirect to hardware page. // AssetController flashes success to session, redirect to hardware page.
window.location.href = successRoute; window.location.href = data.redirect_url;
}, },
error: function(data) { error: function(data) {
// AssetRequest Validator will flash all errors to session, this just refreshes to see them. // AssetRequest Validator will flash all errors to session, this just refreshes to see them.