mirror of
https://github.com/lucaspalomodevelop/core.git
synced 2026-03-15 09:04:39 +00:00
mvc, bootgrid, add useRequestHandlerOnGet option to bootstrap options into get call so you can send parameters when constructing new items. for https://github.com/opnsense/plugins/pull/1274
This commit is contained in:
parent
892e4011b6
commit
ffdcbdd5dc
@ -110,6 +110,7 @@ $.fn.UIBootgrid = function (params) {
|
||||
multiSelect: true,
|
||||
rowCount:[7,14,20,50,100,-1],
|
||||
url: params['search'],
|
||||
useRequestHandlerOnGet: false,
|
||||
formatters: {
|
||||
"commands": function (column, row) {
|
||||
return "<button type=\"button\" class=\"btn btn-xs btn-default command-edit\" data-row-id=\"" + row.uuid + "\"><span class=\"fa fa-pencil\"></span></button> " +
|
||||
@ -146,6 +147,12 @@ $.fn.UIBootgrid = function (params) {
|
||||
});
|
||||
}
|
||||
|
||||
if (gridopt.useRequestHandlerOnGet) {
|
||||
this_grid.requestHandler = gridopt.requestHandler;
|
||||
} else {
|
||||
this_grid.requestHandler = null;
|
||||
}
|
||||
|
||||
if ($(this_grid).data('store-selection') === true && window.localStorage) {
|
||||
// fetch last selected rowcount, sort on top so it will be the current active selection
|
||||
let grid_id = window.location.pathname + '#' + this_grid.attr('id');
|
||||
@ -188,8 +195,13 @@ $.fn.UIBootgrid = function (params) {
|
||||
let editDlg = this_grid.attr('data-editDialog');
|
||||
if (editDlg !== undefined) {
|
||||
let urlMap = {};
|
||||
let server_params = undefined;
|
||||
urlMap['frm_' + editDlg] = params['get'];
|
||||
mapDataToFormUI(urlMap).done(function(){
|
||||
if (this_grid.requestHandler !== null) {
|
||||
// our requestHandler returns a JSON object, convert it back first
|
||||
server_params = this_grid.requestHandler({});
|
||||
}
|
||||
mapDataToFormUI(urlMap, server_params).done(function(){
|
||||
// update selectors
|
||||
formatTokenizersUI();
|
||||
$('.selectpicker').selectpicker('refresh');
|
||||
|
||||
@ -100,9 +100,10 @@ function saveFormToEndpoint(url,formid,callback_ok, disable_dialog) {
|
||||
/**
|
||||
* standard data mapper to map json request data to forms on this page
|
||||
* @param data_get_map named array containing form names and source url's to get data from {'frm_example':"/api/example/settings/get"};
|
||||
* @param server_params parameters to send to server
|
||||
* @return promise object, resolves when all are loaded
|
||||
*/
|
||||
function mapDataToFormUI(data_get_map) {
|
||||
function mapDataToFormUI(data_get_map, server_params) {
|
||||
const dfObj = new $.Deferred();
|
||||
|
||||
// calculate number of items for deferred object to resolve
|
||||
@ -112,9 +113,13 @@ function mapDataToFormUI(data_get_map) {
|
||||
data_map_count += 1;
|
||||
});
|
||||
|
||||
if (server_params === undefined) {
|
||||
server_params = {};
|
||||
}
|
||||
|
||||
const collected_data = {};
|
||||
$.each(data_get_map, function(data_index, data_url) {
|
||||
ajaxGet(data_url,{}, function(data, status) {
|
||||
ajaxGet(data_url,server_params , function(data, status) {
|
||||
if (status === "success") {
|
||||
$("form").each(function() {
|
||||
if ( $(this).attr('id') && $(this).attr('id').split('-')[0] === data_index) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user