Added support for custom "single" button to gui tables

This commit is contained in:
Adolfo Gómez 2013-12-14 02:37:11 +00:00
parent 53258f2d7b
commit e925a2a356
4 changed files with 318 additions and 259 deletions

View File

@ -67,7 +67,7 @@ class DeployedServices(ModelHandler):
'name': item.name,
'comments': item.comments,
'state' : item.state,
'service': Services.serviceToDict(item.service),
'service_id': item.service_id,
'initial_srvs' : item.initial_srvs,
'cache_l1_srvs' : item.cache_l1_srvs,
'cache_l2_srvs' : item.cache_l2_srvs,
@ -76,7 +76,7 @@ class DeployedServices(ModelHandler):
}
if item.osmanager is not None:
val['osmanager'] = OsManagers.osmToDict(item.osmanager)
val['osmanager_id'] = item.osmanager.id
return val

View File

@ -12,10 +12,27 @@ gui.deployedservices.link = function(event) {
}));
gui.setLinksEvents();
var testClick = function(val, value, btn, tbl, refreshFnc) {
gui.doLog(value);
};
var counter = 0;
var testSelect = function(val, value, btn, tbl, refreshFnc) {
if( !val ) {
$(btn).removeClass('btn3d-info').addClass('disabled');
return;
}
$(btn).removeClass('disabled').addClass('btn3d-info');
counter = counter + 1;
gui.doLog('Select', counter.toString(), val, value);
};
var tableId = gui.deployedservices.table({
container : 'deployed-services-placeholder',
rowSelect : 'single',
buttons : [ 'new', 'edit', 'delete', 'xls' ],
buttons : [ 'new', 'edit', 'delete', { text: gettext('Test'), css: 'disabled', click: testClick, select: testSelect }, 'xls' ],
onData: function(data) {
gui.doLog(data);
}
});
});

View File

@ -45,10 +45,12 @@ GuiElement.prototype = {
// Options: dictionary
// container: container ID of parent for the table. If undefined, table will be appended to workspace
// buttons: array of visible buttons (strings), valid are [ 'new', 'edit', 'refresh', 'delete', 'xls' ],
// Can contain also objects with {'text': ..., 'fnc': ...}
// rowSelect: type of allowed row selection, valid values are 'single' and 'multi'
// scrollToTable: if True, will scroll page to show table
// deferedRender: if True, datatable will be created with "bDeferRender": true, that will improve a lot creation of huge tables
//
// onData: Event (function). If defined, will be invoked on data load (to allow preprocess of data)
// onLoad: Event (function). If defined, will be invoked when table is fully loaded.
// Receives 1 parameter, that is the gui element (GuiElement) used to render table
// onRowSelect: Event (function). If defined, will be invoked when a row of table is selected
@ -206,6 +208,10 @@ GuiElement.prototype = {
})).appendTo('head');
self.rest.overview(function(data) { // Gets "overview" data for table (table contents, but resume form)
if( options.onData ) {
options.onData(data);
}
var table = gui.table(title, tableId);
if (options.container === undefined) {
gui.appendToWorkspace('<div class="row"><div class="col-lg-12">' + table.text + '</div></div>');
@ -280,7 +286,7 @@ GuiElement.prototype = {
};
$.each(options.buttons, function(index, value) { // Iterate through button definition
var btn;
var btn = null;
switch (value) {
case 'new':
if(Object.keys(self.types).length !== 0) {
@ -387,6 +393,38 @@ GuiElement.prototype = {
}, // End export to excell
"sButtonClass" : gui.config.dataTableButtons.xls.css,
};
break;
default: // Custom button, this has to be
try {
var css = (value.css ? value.css + ' ' : '') + gui.config.dataTableButtons.custom.css;
btn = {
"sExtends" : "text",
"sButtonText" : value.text,
"sButtonClass" : css,
};
if( value.click ) {
btn.fnClick = function(btn) {
var tbl = $('#' + tableId).dataTable();
var val = this.fnGetSelectedData()[0];
setTimeout(function() {
value.click(val, value, btn, tbl, refreshFnc);
}, 0);
};
}
if( value.select ){
btn.fnSelect = function(btn) {
var tbl = $('#' + tableId).dataTable();
var val = this.fnGetSelectedData()[0];
setTimeout(function() {
value.select(val, value, btn, tbl, refreshFnc);
}, 0);
};
}
} catch (e) {
gui.doLog('Button', value, e);
}
}
if(btn) {
@ -431,7 +469,7 @@ GuiElement.prototype = {
var field = row_style.field;
var dct = row_style.dict;
var prefix = row_style.prefix;
dataTableOptions["fnCreatedRow"] = function( nRow, aData, iDataIndex ) {
dataTableOptions.fnCreatedRow = function( nRow, aData, iDataIndex ) {
var v = dct !== undefined ? dct[this.fnGetData(iDataIndex)[field]] : this.fnGetData(iDataIndex)[field];
$(nRow).addClass(prefix + v);
gui.doLog(prefix + v);

View File

@ -49,6 +49,10 @@
text: '<span class="fa fa-save"></span> <span class="label-tbl-button">' + gettext('Xls') + '</span>',
css: 'btn btn3d-info btn3d btn3d-tables',
},
'custom': {
text: null,
css: 'btn btn3d-default btn3d btn3d-tables',
},
};
gui.genRamdonId = function(prefix) {