This commit is contained in:
Kekskurse 2021-01-20 00:41:02 +01:00
parent de07eee4d1
commit b92a83554f
3 changed files with 47 additions and 19 deletions

View file

@ -230,4 +230,18 @@ class GalleryController extends BaseController
$image->saveOrFail(); $image->saveOrFail();
return "OK"; return "OK";
} }
public function saveImage($name, Request $request) {
$gallery = Gallery::getByTenantAndUrl(session("current_tenant_id"), $name);
$image = Image::query()->where("id", "=", $request->input("id"))->firstOrFail();
if($image->gallery != $gallery->id) {
abort(400);
}
$image->name = $request->input("name");
$image->description = $request->input("description");
$image->rating = $request->input("rating");
$image->saveOrFail();
return "OK";
}
} }

View file

@ -32,6 +32,8 @@
<span aria-hidden="true">&times;</span> <span aria-hidden="true">&times;</span>
</button> </button>
</div> </div>
<form method="post" id="imageEditForm">
@csrf
<div class="modal-body"> <div class="modal-body">
<img src="" id="imagePreview" style="width: 100%;"> <img src="" id="imagePreview" style="width: 100%;">
<input style="display: none;" name="name" id="edit-name" placeholder="Name" class="form-control"> <input style="display: none;" name="name" id="edit-name" placeholder="Name" class="form-control">
@ -40,18 +42,18 @@
<input name="name" id="name" class="form-control"> <input name="name" id="name" class="form-control">
<b>Beschreibung</b> <b>Beschreibung</b>
<textarea name="description" class="form-control" id="description"></textarea> <textarea name="description" class="form-control" id="description"></textarea>
<b>Rating</b> <b>Sorting</b>
<input name="rating" class="form-control" id="rating"> <input name="rating" class="form-control" id="rating">
<hr>
<button type="button" id="makeGalleryDefault" class="btn btn-warning" style="width: 100%;" data-dismiss="modal">Make Gallery Preview Image</button>
<button type="button" id="deleteImage" class="btn btn-danger" style="width: 100%;" data-dismiss="modal">Delete</button>
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
<button type="button" id="deleteImage" class="btn btn-danger">Delete</button>
<button type="button" id="makeGalleryDefault" class="btn btn-warning">Make Galery Preview</button>
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button> <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<!--<button type="button" class="btn btn-primary">Save changes</button>!--> <button type="button" id="saveForm" class="btn btn-success" data-dismiss="modal">Save</button>
</div> </div>
</form>
</div> </div>
</div> </div>
</div> </div>
@ -59,7 +61,9 @@
@endsection @endsection
@section('js') @section('js')
<script> <script>
var g = null;
$(".editImage").click(function () { $(".editImage").click(function () {
g = this
$("#imagePreview").attr("src", $(this).attr("x-image-url")); $("#imagePreview").attr("src", $(this).attr("x-image-url"));
$("#edit-name").val($(this).attr("x-name")); $("#edit-name").val($(this).attr("x-name"));
$("#edit-id").val($(this).attr("x-id")); $("#edit-id").val($(this).attr("x-id"));
@ -78,6 +82,15 @@
alert("Image deleted"); alert("Image deleted");
}); });
}); });
$("#saveForm").click(function () {
var form = $("#imageEditForm").serialize();
$.post("/g/{{ $gallery->url }}/save?id="+$("#edit-id").val(), form, function () {
$(g).attr("data-name", $("#name").val());
$(g).attr("data-rating", $("#rating").val());
$(g).attr("data-description", $("#description").val());
alert("Saved");
});
});
</script> </script>

View file

@ -44,6 +44,7 @@ Route::middleware([\App\Http\Middleware\TenanMiddleware::class])->group(function
Route::post("/g/{url}/edit", [\App\Http\Controllers\GalleryController::class, 'editGallery']); Route::post("/g/{url}/edit", [\App\Http\Controllers\GalleryController::class, 'editGallery']);
Route::get("/g/{url}/setDefault", [\App\Http\Controllers\GalleryController::class, 'setDefault']); Route::get("/g/{url}/setDefault", [\App\Http\Controllers\GalleryController::class, 'setDefault']);
Route::get("/g/{url}/delete", [\App\Http\Controllers\GalleryController::class, 'deleteImage']); Route::get("/g/{url}/delete", [\App\Http\Controllers\GalleryController::class, 'deleteImage']);
Route::post("/g/{url}/save", [\App\Http\Controllers\GalleryController::class, 'saveImage']);
}); });
Route::get("/{name}", [\App\Http\Controllers\PublicController::class, 'listGalleriesView'])->middleware([\App\Http\Middleware\TenanMiddleware::class]); Route::get("/{name}", [\App\Http\Controllers\PublicController::class, 'listGalleriesView'])->middleware([\App\Http\Middleware\TenanMiddleware::class]);