Add functionality allowing an alternative path to be set instead of the model in the dashboard edit array

This commit is contained in:
Kevin MacMartin 2018-01-11 23:48:26 -05:00
parent 51e6b5ef10
commit bf0703b7d3
3 changed files with 7 additions and 4 deletions

View file

@ -71,6 +71,7 @@ First add a function to generate the page:
return view('dashboard.edit-list', [
'heading' => 'Shows',
'model' => 'shows',
'path' => 'shows-page',
'rows' => Shows::getShowsList(),
'column' => 'title',
'button' => [ 'Email Show', 'Are you sure you want to send an email?', 'Email successfully sent', 'Failed to send email', '/email-show' ],
@ -107,6 +108,7 @@ First add a function to generate the page:
* `heading`: The title that will appear for this page
* `model`: The model that will be accessed on this page
* `path`: (optional) This can be used to set a different URL path than the default of the model name
* `rows`: A function returning an array containing the data to be shown on this page
* `column`: The column name in the array that contains the data to display in each row (an array can be used to specify multiple columns)
* `button`: Add a button with a title, confirmation, success and error messages, and a post request path that takes an id and returns `success` on success

View file

@ -103,14 +103,15 @@ function showAlert(message, command) {
function editListInit() {
const editList = document.getElementById("edit-list"),
$editList = $(editList),
model = $editList.data("model");
model = $editList.data("model"),
path = $editList.data("path");
// initialize new button functionality
const newButtonInit = function() {
const $newButton = $(".btn.new-button");
$newButton.on("click", function() {
window.location.href = "/dashboard/" + model + "-edit/new";
window.location.href = "/dashboard/" + path + "-edit/new";
});
};
@ -124,7 +125,7 @@ function editListInit() {
itemId = $listItem.data("id");
// go to the edit page
window.location.href = "/dashboard/" + model + "-edit/" + itemId;
window.location.href = "/dashboard/" + path + "-edit/" + itemId;
});
};

View file

@ -16,7 +16,7 @@
<input id="filter-input" class="search" placeholder="Filter" />
@endif
<ul id="edit-list" class="list-group edit-list list" data-model="{{ $model }}" {{ $sortcol != false ? "data-sort=$sortcol" : '' }}>
<ul id="edit-list" class="list-group edit-list list" data-model="{{ $model }}" data-path="{{ isset($path) ? $path : $model }}" {{ $sortcol != false ? "data-sort=$sortcol" : '' }}>
<input type="hidden" name="_token" id="token" value="{{ csrf_token() }}" />
@foreach($rows as $row)