mirror of
https://github.com/lucaspalomodevelop/core.git
synced 2026-03-15 00:54:41 +00:00
MVC: add jQuery plugin to support a simple service reload/action button.
Example usage:
<button class="btn btn-primary" id="reconfigureAct"
data-endpoint='/api/syslog/service/reconfigure'
data-label="{{ lang._('Apply') }}"
data-service-widget="syslog"
data-error-title="{{ lang._('Error reconfiguring syslog') }}"
type="button"
></button>
and the JS init:
$("#reconfigureAct").SimpleActionButton();
closes https://github.com/opnsense/core/pull/3788
This commit is contained in:
parent
6c3726d719
commit
f0163e9d57
@ -470,3 +470,40 @@ stdDialogRemoveItem.defaults = {
|
||||
'accept': 'Yes',
|
||||
'decline': 'Cancel'
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Action button, expects the following data attributes on the widget
|
||||
* data-endpoint='/path/to/my/endpoint'
|
||||
* data-label="Apply text"
|
||||
* data-service-widget="service" (optional service widget to signal)
|
||||
* data-error-title="My error message"
|
||||
*/
|
||||
$.fn.SimpleActionButton = function (params) {
|
||||
let this_button = this;
|
||||
this.construct = function() {
|
||||
let label_content = '<b>' + this_button.data('label') + '</b> <i class="reload_progress">';
|
||||
this_button.html(label_content);
|
||||
this_button.on('click', function(){
|
||||
this_button.find('.reload_progress').addClass("fa fa-spinner fa-pulse");
|
||||
ajaxCall(this_button.data('endpoint'), {}, function(data,status) {
|
||||
if (status != "success" || data['status'] != 'ok') {
|
||||
BootstrapDialog.show({
|
||||
type: BootstrapDialog.TYPE_WARNING,
|
||||
title: this_button.data('error-title'),
|
||||
message: data['status'],
|
||||
draggable: true
|
||||
});
|
||||
}
|
||||
this_button.find('.reload_progress').removeClass("fa fa-spinner fa-pulse");
|
||||
if (this_button.data('service-widget')) {
|
||||
updateServiceControlUI(this_button.data('service-widget'));
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
return this.each(function(){
|
||||
const button = this_button.construct();
|
||||
return button;
|
||||
});
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user