mirror of
https://github.com/prurigro/hypothetical.git
synced 2024-11-25 16:51:25 -05:00
Implement functionality that allows an additional button with customizable functionality to be added to dashboard edit-list pages
This commit is contained in:
parent
bbd6aeb68d
commit
01fcbd5cef
3 changed files with 40 additions and 0 deletions
|
@ -48,6 +48,7 @@ First add a function to generate the page:
|
||||||
'model' => 'shows',
|
'model' => 'shows',
|
||||||
'rows' => Shows::getShowsList(),
|
'rows' => Shows::getShowsList(),
|
||||||
'column' => 'title',
|
'column' => 'title',
|
||||||
|
'button' => [ 'Email Show', 'Are you sure you want to send an email?', 'Email successfully sent', 'Failed to send email', '/email-show' ],
|
||||||
'sortcol' => false,
|
'sortcol' => false,
|
||||||
'delete' => true,
|
'delete' => true,
|
||||||
'create' => true,
|
'create' => true,
|
||||||
|
@ -69,6 +70,7 @@ First add a function to generate the page:
|
||||||
'model' => 'news',
|
'model' => 'news',
|
||||||
'rows' => News::getNewsList(),
|
'rows' => News::getNewsList(),
|
||||||
'column' => 'title',
|
'column' => 'title',
|
||||||
|
'button' => [ 'Email Show', 'Are you sure you want to send an email?', 'Email successfully sent', 'Failed to send email', '/email-show' ],
|
||||||
'sortcol' => 'order',
|
'sortcol' => 'order',
|
||||||
'delete' => false,
|
'delete' => false,
|
||||||
'create' => true,
|
'create' => true,
|
||||||
|
@ -82,6 +84,7 @@ First add a function to generate the page:
|
||||||
* `model`: The model that will be accessed on this page
|
* `model`: The model that will be accessed on this page
|
||||||
* `rows`: A function returning an array containing the data to be shown on this page
|
* `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)
|
* `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
|
||||||
* `sortcol`: The name of the column containing the sort order or `false` to disable
|
* `sortcol`: The name of the column containing the sort order or `false` to disable
|
||||||
* `delete`: A `delete` button will appear in the list if this is set to `true`
|
* `delete`: A `delete` button will appear in the list if this is set to `true`
|
||||||
* `create`: A `new` button will appear in the heading if this is set to `true`
|
* `create`: A `new` button will appear in the heading if this is set to `true`
|
||||||
|
|
|
@ -157,6 +157,38 @@ function editListInit() {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// initialize action button functionality
|
||||||
|
const actionButtonInit = function() {
|
||||||
|
const $actionButtons = $(".btn.action-button");
|
||||||
|
|
||||||
|
$actionButtons.on("click", function() {
|
||||||
|
const $this = $(this),
|
||||||
|
$listItem = $this.closest(".list-group-item"),
|
||||||
|
itemId = $listItem.data("id"),
|
||||||
|
confirmationMessage = $this.data("confirmation"),
|
||||||
|
successMessage = $this.data("success"),
|
||||||
|
errorMessage = $this.data("error"),
|
||||||
|
postUrl = $this.data("url");
|
||||||
|
|
||||||
|
askConfirmation(confirmationMessage, function() {
|
||||||
|
$.ajax({
|
||||||
|
type: "POST",
|
||||||
|
url: postUrl,
|
||||||
|
data: {
|
||||||
|
id: itemId,
|
||||||
|
_token: $("#token").val()
|
||||||
|
}
|
||||||
|
}).always(function(response) {
|
||||||
|
if (response === "success") {
|
||||||
|
showAlert(successMessage);
|
||||||
|
} else {
|
||||||
|
showAlert("ERROR: " + errorMessage);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
// initialize sort functionality if data-sort is set
|
// initialize sort functionality if data-sort is set
|
||||||
const sortRowInit = function() {
|
const sortRowInit = function() {
|
||||||
let sortOrder = {}, sortCol, sortable;
|
let sortOrder = {}, sortCol, sortable;
|
||||||
|
@ -210,6 +242,7 @@ function editListInit() {
|
||||||
newButtonInit();
|
newButtonInit();
|
||||||
editButtonInit();
|
editButtonInit();
|
||||||
deleteButtonInit();
|
deleteButtonInit();
|
||||||
|
actionButtonInit();
|
||||||
sortRowInit();
|
sortRowInit();
|
||||||
filterInputInit();
|
filterInputInit();
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,6 +44,10 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="button-column">
|
<div class="button-column">
|
||||||
|
@if(isset($button) && is_array($button))
|
||||||
|
<button type="button" class="action-button btn btn-default" data-confirmation="{{ $button[1] }}" data-success="{{ $button[2] }}" data-error="{{ $button[3] }}" data-url="{{ $button[4] }}">{{ $button[0] }}</button>
|
||||||
|
@endif
|
||||||
|
|
||||||
<button type="button" class="edit-button btn btn-warning">Edit</button>
|
<button type="button" class="edit-button btn btn-warning">Edit</button>
|
||||||
|
|
||||||
@if($delete)
|
@if($delete)
|
||||||
|
|
Loading…
Reference in a new issue