From bf0703b7d3e7f3bd5f790915190b96e8e0628a9f Mon Sep 17 00:00:00 2001 From: Kevin MacMartin Date: Thu, 11 Jan 2018 23:48:26 -0500 Subject: [PATCH] Add functionality allowing an alternative path to be set instead of the model in the dashboard edit array --- readme.md | 2 ++ resources/assets/js/dashboard.js | 7 ++++--- resources/views/dashboard/edit-list.blade.php | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/readme.md b/readme.md index b2ae071..5221c82 100644 --- a/readme.md +++ b/readme.md @@ -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 diff --git a/resources/assets/js/dashboard.js b/resources/assets/js/dashboard.js index 772ee14..6cddccf 100644 --- a/resources/assets/js/dashboard.js +++ b/resources/assets/js/dashboard.js @@ -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; }); }; diff --git a/resources/views/dashboard/edit-list.blade.php b/resources/views/dashboard/edit-list.blade.php index a0ceed8..c960aca 100644 --- a/resources/views/dashboard/edit-list.blade.php +++ b/resources/views/dashboard/edit-list.blade.php @@ -16,7 +16,7 @@ @endif -