1
0
mirror of https://github.com/dkmstr/openuds.git synced 2024-12-22 13:34:04 +03:00

* Fixed Datatables tools width

* Refactoring of API (again...)
This commit is contained in:
Adolfo Gómez 2013-11-22 11:33:54 +00:00
parent ceecb0823d
commit b7bfecf87c
11 changed files with 375 additions and 326 deletions

View File

@ -91,12 +91,23 @@ class ModelHandlerMixin(object):
def get(self): def get(self):
logger.debug('method GET for {0}, {1}'.format(self.__class__.__name__, self._args)) logger.debug('method GET for {0}, {1}'.format(self.__class__.__name__, self._args))
if len(self._args) == 0: if len(self._args) == 0:
result = []
for val in self.model.objects.all():
res = self.item_as_dict(val)
if hasattr(val, 'getInstance'):
for key, value in val.getInstance().valuesDict().iteritems():
res[key] = value
result.append(res)
return result
if self._args[0] == 'overview':
return list(self.getItems()) return list(self.getItems())
# If has detail and is requesting detail # If has detail and is requesting detail
if self.detail is not None and len(self._args) > 1: if self.detail is not None and len(self._args) > 1:
return self.processDetail() return self.processDetail()
try: try:
val = self.model.objects.get(pk=self._args[0]) val = self.model.objects.get(pk=self._args[0])
res = self.item_as_dict(val) res = self.item_as_dict(val)

View File

@ -60,7 +60,7 @@
}; };
// Simple JavaScript Templating, using HandleBars // Simple JavaScript Templating, using HandleBars
api.templates.evaluate = function (str, context) { api.templates.evaluate = function(str, context) {
// Figure out if we're getting a template, or if we need to // Figure out if we're getting a template, or if we need to
// load the template - and be sure to cache the result. // load the template - and be sure to cache the result.
var cached; var cached;

View File

@ -128,28 +128,50 @@ BasicModelRest.prototype = {
}); });
} }
}, },
get : function(options) { get : function(success_fnc, options) {
"use strict"; "use strict";
options = options || {}; options = options || {};
var path = this.getPath; var path = this.getPath;
if (options.id !== undefined) if ( options.id )
path += '/' + options.id; path += '/' + options.id;
return this._requestPath(path, { return this._requestPath(path, {
cacheKey: '.', // Right now, do not cache this cacheKey: '.', // Right now, do not cache any "get" method
success: options.success, success: success_fnc,
}); });
}, },
types : function(options) { list: function(success_fnc, options) { // This is "almost" an alias for get
"use strict";
options = options || {};
return this.get(success_fnc, {
id: '',
});
},
overview: function(success_fnc, options) {
"use strict";
options = options || {};
return this.get(success_fnc, {
id: 'overview',
});
},
item: function(itemId, success_fnc, options) {
"use strict";
options = options || {};
return this.get(success_fnc, {
id: itemId,
});
},
types : function(success_fnc, options) {
"use strict"; "use strict";
options = options || {}; options = options || {};
return this._requestPath(this.typesPath, { return this._requestPath(this.typesPath, {
cacheKey: 'type', cacheKey: 'type',
success: options.success, success: success_fnc,
}); });
}, },
gui: function(typeName, options) { gui: function(typeName, success_fnc, options) {
// GUI returns a dict, that contains: // GUI returns a dict, that contains:
// name: Name of the field // name: Name of the field
// value: value of the field (selected element in choice, text for inputs, etc....) // value: value of the field (selected element in choice, text for inputs, etc....)
@ -159,31 +181,18 @@ BasicModelRest.prototype = {
var path = [this.typesPath, typeName, 'gui'].join('/'); var path = [this.typesPath, typeName, 'gui'].join('/');
return this._requestPath(path, { return this._requestPath(path, {
cacheKey: typeName + '-gui', cacheKey: typeName + '-gui',
success: options.success, success: success_fnc,
}); });
}, },
tableInfo : function(options) { tableInfo : function(success_fnc, options) {
"use strict"; "use strict";
options = options || {}; options = options || {};
var success_fnc = options.success || function(){api.doLog('success not provided for tableInfo');}; success_fnc = success_fnc || function(){api.doLog('success not provided for tableInfo');};
var path = this.tableInfoPath; var path = this.tableInfoPath;
// Cache types locally, will not change unless new broker version this._requestPath(path, {
if( this.cache.get(path) ) { success: success_fnc,
if (success_fnc) {
success_fnc(this.cache.get(path));
}
return;
}
var $this = this;
api.getJson(path, {
success: function(data) {
$this.cache.put(path, data);
success_fnc(data);
},
}); });
}, },
detail: function(id, child) { detail: function(id, child) {
@ -209,14 +218,27 @@ DetailModelRestApi.prototype = {
"use strict"; "use strict";
return this.base.get(options); return this.base.get(options);
}, },
types: function(options) {
"use strict";
return this.base.types(options);
},
tableInfo: function(options) { tableInfo: function(options) {
"use strict"; "use strict";
return this.base.tableInfo(options); return this.base.tableInfo(options);
}, },
list: function(success_fnc, options) { // This is "almost" an alias for get
"use strict";
return this.base.list(success_fnc, options);
},
overview: function(success_fnc, options) {
"use strict";
return this.base.overview(success_fnc, options);
},
item: function(itemId, success_fnc, options) {
"use strict";
return this.base.item(success_fnc, options);
},
types: function(options) {
"use strict";
return this.base.types(options);
},
}; };
// Populate api // Populate api

View File

@ -139,6 +139,6 @@ if ($.fn.DataTable.TableTools) {
"button" : "li", "button" : "li",
"liner" : "a" "liner" : "a"
}, },
"button" : "button", // "button" : "button",
}); });
} }

View File

@ -35,17 +35,14 @@ gui.providers.link = function(event) {
var tableId = gui.providers.table({ var tableId = gui.providers.table({
rowSelect : 'single', rowSelect : 'single',
onEdit: function(value, event, table) { onEdit: function(value, event, table) {
gui.providers.rest.gui(value.type, { gui.providers.rest.gui(value.type, function(data) {
success: function(data){
var form = gui.fields(data); var form = gui.fields(data);
gui.appendToWorkspace(gui.modal('edit_modal', gettext('Edit service provider'), form)); gui.appendToWorkspace(gui.modal('edit_modal', gettext('Edit service provider'), form));
$('#edit_modal').modal() $('#edit_modal').modal()
.on('hidden.bs.modal', function () { .on('hidden.bs.modal', function () {
$('#edit_modal').remove(); $('#edit_modal').remove();
}) });
; });
},
});
}, },
buttons : [ 'edit', 'delete', 'xls' ], buttons : [ 'edit', 'delete', 'xls' ],
}); });
@ -90,7 +87,7 @@ gui.authenticators.link = function(event) {
user.table({ user.table({
container : 'users-placeholder', container : 'users-placeholder',
rowSelect : 'multi', rowSelect : 'multi',
buttons : [ 'edit', 'delete', 'xls' ], buttons : [ 'new', 'edit', 'delete', 'xls' ],
scrollToTable : true, scrollToTable : true,
onLoad: function(k) { onLoad: function(k) {
api.tools.unblockUI(); api.tools.unblockUI();
@ -102,12 +99,10 @@ gui.authenticators.link = function(event) {
$('#users-placeholder').empty(); // Remove detail on parent refresh $('#users-placeholder').empty(); // Remove detail on parent refresh
}, },
onEdit: function(value, event, table) { onEdit: function(value, event, table) {
gui.authenticators.rest.gui(value.type, { gui.authenticators.rest.gui(value.type, function(data){
success: function(data){
var form = gui.fields(data); var form = gui.fields(data);
gui.launchModal(gettext('Edit authenticator')+' '+value.name, form); gui.launchModal(gettext('Edit authenticator')+' '+value.name, form);
}, });
});
}, },
}); });
}); });
@ -146,29 +141,26 @@ gui.connectivity.link = function(event) {
gui.connectivity.transports.table({ gui.connectivity.transports.table({
rowSelect : 'multi', rowSelect : 'multi',
container : 'transports-placeholder', container : 'transports-placeholder',
buttons : [ 'edit', 'delete', 'xls' ], buttons : [ 'new', 'edit', 'delete', 'xls' ],
onEdit: function(value, event, table) { onEdit: function(value, event, table) {
gui.connectivity.transports.rest.gui(value.type, { gui.connectivity.transports.rest.gui(value.type, function(itemGui){
success: function(itemGui){ gui.connectivity.transports.rest.item(value.id, function(item) {
gui.connectivity.transports.rest.get({
id:value.id,
success: function(item) {
var form = gui.fields(itemGui, item); var form = gui.fields(itemGui, item);
gui.launchModal(gettext('Edit transport')+' '+value.name,form, function(form_selector) { gui.launchModal(gettext('Edit transport')+' '+value.name,form, function(form_selector) {
var fields = gui.fields.read(form_selector); var fields = gui.fields.read(form_selector);
return false; return false;
}); });
}, });
}); });
}, },
}); onNew: function(type) {
gui.doLog(type);
}, },
}); });
gui.connectivity.networks.table({ gui.connectivity.networks.table({
rowSelect : 'multi', rowSelect : 'multi',
container : 'networks-placeholder', container : 'networks-placeholder',
buttons : [ 'edit', 'delete', 'xls' ], buttons : [ 'new', 'edit', 'delete', 'xls' ],
}); });
}); });

View File

@ -2,10 +2,10 @@
(function(gui, $, undefined) { (function(gui, $, undefined) {
"use strict"; "use strict";
// "public" methods // "public" methods
gui.doLog = function(data) { gui.doLog = function() {
if (gui.debug) { if (gui.debug) {
try { try {
console.log(data); console.log(arguments);
} catch (e) { } catch (e) {
// nothing can be logged // nothing can be logged
} }
@ -212,8 +212,7 @@ GuiElement.prototype = {
"use strict"; "use strict";
gui.doLog('Initializing ' + this.name); gui.doLog('Initializing ' + this.name);
var $this = this; var $this = this;
this.rest.types({ this.rest.types(function(data) {
success: function(data) {
var styles = ''; var styles = '';
$.each(data, function(index, value) { $.each(data, function(index, value) {
var className = $this.name + '-' + value.type; var className = $this.name + '-' + value.type;
@ -231,8 +230,7 @@ GuiElement.prototype = {
styles = '<style media="screen">' + styles + '</style>'; styles = '<style media="screen">' + styles + '</style>';
$(styles).appendTo('head'); $(styles).appendTo('head');
} }
}, });
});
}, },
// Options: dictionary // Options: dictionary
// container: container ID of parent for the table. If undefined, table will be appended to workspace // container: container ID of parent for the table. If undefined, table will be appended to workspace
@ -268,6 +266,7 @@ GuiElement.prototype = {
// 4.- the DataTable that raised the event // 4.- the DataTable that raised the event
table : function(options) { table : function(options) {
"use strict"; "use strict";
console.log('Types: ', this.types);
options = options || {}; options = options || {};
gui.doLog('Composing table for ' + this.name); gui.doLog('Composing table for ' + this.name);
var tableId = this.name + '-table'; var tableId = this.name + '-table';
@ -313,287 +312,301 @@ GuiElement.prototype = {
return dict[data] || renderEmptyCell(''); return dict[data] || renderEmptyCell('');
}; };
}; };
this.rest.tableInfo({ this.rest.tableInfo(function(data) {
success: function(data) { var title = data.title;
var title = data.title; var columns = [];
var columns = []; $.each(data.fields, function(index, value) {
$.each(data.fields, function(index, value) { for ( var v in value) {
for ( var v in value) { var opts = value[v];
var opts = value[v]; var column = {
var column = { mData : v,
mData : v, };
}; column.sTitle = opts.title;
column.sTitle = opts.title; column.mRender = renderEmptyCell;
column.mRender = renderEmptyCell; if (opts.width)
if (opts.width) column.sWidth = opts.width;
column.sWidth = opts.width; column.bVisible = opts.visible === undefined ? true : opts.visible;
column.bVisible = opts.visible === undefined ? true : opts.visible; if (opts.sortable !== undefined)
if (opts.sortable !== undefined) column.bSortable = opts.sortable;
column.bSortable = opts.sortable; if (opts.searchable !== undefined)
if (opts.searchable !== undefined) column.bSearchable = opts.searchable;
column.bSearchable = opts.searchable;
if (opts.type && column.bVisible ) {
if (opts.type !== undefined && column.bVisible ) { switch(opts.type) {
switch(opts.type) { case 'date':
case 'date': column.sType = 'date';
column.sType = 'date'; column.mRender = renderDate(api.tools.djangoFormat(get_format('SHORT_DATE_FORMAT')));
column.mRender = renderDate(api.tools.djangoFormat(get_format('SHORT_DATE_FORMAT'))); break;
break; case 'datetime':
case 'datetime': column.sType = 'date';
column.sType = 'date'; column.mRender = renderDate(api.tools.djangoFormat(get_format('SHORT_DATETIME_FORMAT')));
column.mRender = renderDate(api.tools.djangoFormat(get_format('SHORT_DATETIME_FORMAT'))); break;
break; case 'time':
case 'time': column.mRender = renderDate(api.tools.djangoFormat(get_format('TIME_FORMAT')));
column.mRender = renderDate(api.tools.djangoFormat(get_format('TIME_FORMAT'))); break;
break; case 'iconType':
case 'iconType': //columnt.sType = 'html'; // html is default, so this is not needed
//columnt.sType = 'html'; // html is default, so this is not needed column.mRender = renderTypeIcon;
column.mRender = renderTypeIcon; break;
break; case 'icon':
case 'icon': if( opts.icon !== undefined ) {
if( opts.icon !== undefined ) { column.mRender = renderIcon(opts.icon);
column.mRender = renderIcon(opts.icon); }
} break;
break; case 'dict':
case 'dict': if( opts.dict !== undefined ) {
if( opts.dict !== undefined ) { column.mRender = renderTextTransform(opts.dict);
column.mRender = renderTextTransform(opts.dict); }
} break;
break; default:
default: column.sType = opts.type;
column.sType = opts.type;
}
} }
columns.push(column);
} }
}); columns.push(column);
// Generate styles for responsible table, just the name of fields }
var respStyles = []; });
var counter = 0; // Generate styles for responsible table, just the name of fields (append header to table)
$.each(columns, function(col, value) { var respStyles = [];
if( value.bVisible === false ) var counter = 0;
return; $.each(columns, function(col, value) {
counter += 1; if( value.bVisible === false )
respStyles.push('#' + tableId + ' td:nth-of-type(' + counter + '):before { content: "' + return;
(value.sTitle || '') + '";}\n'); counter += 1;
respStyles.push('#' + tableId + ' td:nth-of-type(' + counter + '):empty { background-color: red ;}\n'); respStyles.push('#' + tableId + ' td:nth-of-type(' + counter + '):before { content: "' +
}); (value.sTitle || '') + '";}\n');
// If styles already exists, remove them before adding new ones });
$('style-' + tableId).remove(); // If styles already exists, remove them before adding new ones
$('<style id="style-' + tableId + '" media="screen">@media (max-width: 979px) { ' + respStyles.join('') + '};</style>').appendTo('head'); $('style-' + tableId).remove();
$('<style id="style-' + tableId + '" media="screen">@media (max-width: 768px) { ' + respStyles.join('') + '};</style>').appendTo('head');
$this.rest.get({
success : function(data) {
var refreshFnc;
var table = gui.table(title, tableId);
if (options.container === undefined) {
gui.appendToWorkspace('<div class="row"><div class="col-lg-12">' + table.text + '</div></div>');
} else {
$('#' + options.container).empty();
$('#' + options.container).append(table.text);
}
var btns = [];
if (options.buttons) {
var clickHandlerFor = function(handler, action) {
var handleFnc = handler || function(val, action, tbl) {gui.doLog('Default handler called for ' + action + ': ' + JSON.stringify(val));};
return function(btn) {
var tbl = $('#' + tableId).dataTable();
var val = this.fnGetSelectedData()[0];
setTimeout(function() {
handleFnc(val, action, tbl);
}, 0);
};
};
// methods for buttons on row select $this.rest.overview(function(data) {
var editSelected = function(btn, obj, node) { var table = gui.table(title, tableId);
var sel = this.fnGetSelectedData(); if (options.container === undefined) {
if (sel.length == 1) { gui.appendToWorkspace('<div class="row"><div class="col-lg-12">' + table.text + '</div></div>');
$(btn).removeClass('disabled').addClass('btn3d-success'); } else {
} else { $('#' + options.container).empty();
$(btn).removeClass('btn3d-success').addClass('disabled'); $('#' + options.container).append(table.text);
} }
};
var deleteSelected = function(btn, obj, node) { // What execute on refresh button push
var sel = this.fnGetSelectedData(); var onRefresh = options.onRefresh || function(){};
if (sel.length > 0) {
$(btn).removeClass('disabled').addClass('btn3d-warning'); var refreshFnc = function() {
} else { // Refreshes table content
$(btn).removeClass('btn3d-warning').addClass('disabled'); var tbl = $('#' + tableId).dataTable();
} // Clears selection first
}; TableTools.fnGetInstance(tableId).fnSelectNone();
if( data.length > 1000 )
// What execute on refresh button push api.tools.blockUI();
var onRefresh = options.onRefresh || function(){};
$this.rest.overview(function(data) {
refreshFnc = function() { /*$(btn).removeClass('disabled').width('').html(saved);*/
// Refreshes table content setTimeout( function() {
tbl.fnClearTable();
tbl.fnAddData(data);
onRefresh($this);
api.tools.unblockUI();
}, 0);
});
return false; // This may be used on button or href, better disable execution of it
};
var btns = [];
if (options.buttons) {
var clickHandlerFor = function(handler, action, newHandler) {
var handleFnc = handler || function(val, action, tbl) {gui.doLog('Default handler called for ', action);};
return function(btn) {
var tbl = $('#' + tableId).dataTable(); var tbl = $('#' + tableId).dataTable();
// Clears selection first var val = this.fnGetSelectedData()[0];
TableTools.fnGetInstance(tableId).fnSelectNone(); setTimeout(function() {
if( data.length > 1000 ) if( newHandler ) {
api.tools.blockUI(); if( handleFnc(action, tbl) === true ) // Reload table?
refreshFnc();
$this.rest.get({ } else {
success : function(data) { if( handleFnc(val, action, tbl) === true ) // Reload table?
/*$(btn).removeClass('disabled').width('').html(saved);*/ refreshFnc();
setTimeout( function() {
tbl.fnClearTable();
tbl.fnAddData(data);
onRefresh($this);
api.tools.unblockUI();
}, 0);
} }
}); }, 0);
return false; // This may be used on button or href, better disable execution of it
}; };
};
$.each(options.buttons, function(index, value) {
var btn; // methods for buttons on row select
switch (value) { var editSelected = function(btn, obj, node) {
case 'new': var sel = this.fnGetSelectedData();
if (sel.length == 1) {
$(btn).removeClass('disabled').addClass('btn3d-success');
} else {
$(btn).removeClass('btn3d-success').addClass('disabled');
}
};
var deleteSelected = function(btn, obj, node) {
var sel = this.fnGetSelectedData();
if (sel.length > 0) {
$(btn).removeClass('disabled').addClass('btn3d-warning');
} else {
$(btn).removeClass('btn3d-warning').addClass('disabled');
}
};
$.each(options.buttons, function(index, value) {
var btn;
switch (value) {
case 'new':
if(Object.keys($this.types).length === 0) {
btn = { btn = {
"sExtends" : "text", "sExtends" : "text",
"sButtonText" : gui.config.dataTableButtons['new'].text, "sButtonText" : gui.config.dataTableButtons['new'].text,
"fnSelect" : deleteSelected, "fnClick" : clickHandlerFor(options.onNew, 'new'),
"fnClick" : clickHandlerFor(options.onDelete, 'delete'),
"sButtonClass" : gui.config.dataTableButtons['new'].css, "sButtonClass" : gui.config.dataTableButtons['new'].css,
}; };
break; } else {
case 'edit': // This table has "types, so we create a dropdown with Types
var newButtons = [];
$.each($this.types, function(i, val){
newButtons.push({
"sExtends" : "text",
"sButtonText" : '<span class="' + val.css + '"></span> ' + val.name,
"fnClick" : clickHandlerFor(options.onNew, i, true),
});
});
btn = { btn = {
"sExtends" : "text", "sExtends" : "collection",
"sButtonText" : gui.config.dataTableButtons.edit.text, "aButtons": newButtons,
"fnSelect" : editSelected, "sButtonText" : gui.config.dataTableButtons['new'].text,
"fnClick" : clickHandlerFor(options.onEdit, 'edit'), "sButtonClass" : gui.config.dataTableButtons['new'].css,
"sButtonClass" : gui.config.dataTableButtons.edit.css, };
}; }
break; break;
case 'delete': case 'edit':
btn = { btn = {
"sExtends" : "text", "sExtends" : "text",
"sButtonText" : gui.config.dataTableButtons['delete'].text, "sButtonText" : gui.config.dataTableButtons.edit.text,
"fnSelect" : deleteSelected, "fnSelect" : editSelected,
"fnClick" : clickHandlerFor(options.onDelete, 'delete'), "fnClick" : clickHandlerFor(options.onEdit, 'edit'),
"sButtonClass" : gui.config.dataTableButtons['delete'].css, "sButtonClass" : gui.config.dataTableButtons.edit.css,
}; };
break; break;
case 'refresh': case 'delete':
btn = { btn = {
"sExtends" : "text", "sExtends" : "text",
"sButtonText" : gui.config.dataTableButtons.refresh.text, "sButtonText" : gui.config.dataTableButtons['delete'].text,
"fnClick" : refreshFnc, "fnSelect" : deleteSelected,
"sButtonClass" : gui.config.dataTableButtons.refresh.css, "fnClick" : clickHandlerFor(options.onDelete, 'delete'),
}; "sButtonClass" : gui.config.dataTableButtons['delete'].css,
break; };
case 'xls': break;
btn = { case 'refresh':
"sExtends" : "text", btn = {
"sButtonText" : gui.config.dataTableButtons.xls.text, "sExtends" : "text",
"fnClick" : function(){ "sButtonText" : gui.config.dataTableButtons.refresh.text,
api.templates.get('spreadsheet', function(tmpl) { "fnClick" : refreshFnc,
var styles = { 'bold': 's21', }; "sButtonClass" : gui.config.dataTableButtons.refresh.css,
var uri = 'data:application/vnd.ms-excel;base64,', };
base64 = function(s) { return window.btoa(unescape(encodeURIComponent(s))); }; break;
case 'xls':
var headings = [], rows = []; btn = {
$.each(columns, function(index, heading){ "sExtends" : "text",
if( heading.bVisible === false ) { "sButtonText" : gui.config.dataTableButtons.xls.text,
"fnClick" : function(){
api.templates.get('spreadsheet', function(tmpl) {
var styles = { 'bold': 's21', };
var uri = 'data:application/vnd.ms-excel;base64,',
base64 = function(s) { return window.btoa(unescape(encodeURIComponent(s))); };
var headings = [], rows = [];
$.each(columns, function(index, heading){
if( heading.bVisible === false ) {
return;
}
headings.push(api.spreadsheet.cell(heading.sTitle, 'String', styles.bold));
});
rows.push(api.spreadsheet.row(headings));
$.each(data, function(index, row) {
var cells = [];
$.each(columns, function(index, col){
if( col.bVisible === false ) {
return; return;
} }
headings.push(api.spreadsheet.cell(heading.sTitle, 'String', styles.bold)); var type = col.sType == 'numeric' ? 'Number':'String';
cells.push(api.spreadsheet.cell(row[col.mData], type));
}); });
rows.push(api.spreadsheet.row(headings)); rows.push(api.spreadsheet.row(cells));
$.each(data, function(index, row) {
var cells = [];
$.each(columns, function(index, col){
if( col.bVisible === false ) {
return;
}
var type = col.sType == 'numeric' ? 'Number':'String';
cells.push(api.spreadsheet.cell(row[col.mData], type));
});
rows.push(api.spreadsheet.row(cells));
});
var ctx = {
creation_date: (new Date()).toISOString(),
worksheet: title,
columns_count: headings.length,
rows_count: rows.length,
rows: rows.join('\n')
};
setTimeout( function() {
saveAs(new Blob([api.templates.evaluate(tmpl, ctx)],
{type: 'application/vnd.ms-excel'} ), title + '.xls');
}, 20);
}); });
},
"sButtonClass" : gui.config.dataTableButtons.xls.css, var ctx = {
}; creation_date: (new Date()).toISOString(),
} worksheet: title,
columns_count: headings.length,
if (btn !== undefined) rows_count: rows.length,
btns.push(btn); rows: rows.join('\n')
}); };
} setTimeout( function() {
saveAs(new Blob([api.templates.evaluate(tmpl, ctx)],
// Initializes oTableTools {type: 'application/vnd.ms-excel'} ), title + '.xls');
var oTableTools = { }, 20);
"aButtons" : btns });
}; },
"sButtonClass" : gui.config.dataTableButtons.xls.css,
// Type of row selection };
if (options.rowSelect) { }
oTableTools.sRowSelect = options.rowSelect;
} if (btn !== undefined)
btns.push(btn);
if (options.onRowSelect) {
var rowSelectedFnc = options.onRowSelect;
oTableTools.fnRowSelected = function() {
rowSelectedFnc(this.fnGetSelectedData(), $('#' + tableId).dataTable(), this);
};
}
if (options.onRowDeselect) {
var rowDeselectedFnc = options.onRowDeselect;
oTableTools.fnRowDeselected = function() {
rowDeselectedFnc(this.fnGetSelectedData(), $('#' + tableId).dataTable(), this);
};
}
$('#' + tableId).dataTable({
"aaData" : data,
"aoColumns" : columns,
"oLanguage" : gui.config.dataTablesLanguage,
"oTableTools" : oTableTools,
// First is upper row,
// second row is lower
// (pagination) row
"sDom" : "<'row'<'col-xs-8'T><'col-xs-4'f>r>t<'row'<'col-xs-5'i><'col-xs-7'p>>",
}); });
// Fix 3dbuttons }
api.tools.fix3dButtons('#' + tableId + '_wrapper .btn-group-3d');
// Fix form // Initializes oTableTools
$('#' + tableId + '_filter input').addClass('form-control'); var oTableTools = {
// Add refresh action to panel "aButtons" : btns
$(table.refreshSelector).click(refreshFnc); };
if (options.scrollToTable === true ) { // Type of row selection
var tableTop = $('#' + tableId).offset().top; if (options.rowSelect) {
$('html, body').scrollTop(tableTop); oTableTools.sRowSelect = options.rowSelect;
} }
// if table rendered event
if( options.onLoad ) { if (options.onRowSelect) {
options.onLoad($this); var rowSelectedFnc = options.onRowSelect;
} oTableTools.fnRowSelected = function() {
rowSelectedFnc(this.fnGetSelectedData(), $('#' + tableId).dataTable(), this);
};
}
if (options.onRowDeselect) {
var rowDeselectedFnc = options.onRowDeselect;
oTableTools.fnRowDeselected = function() {
rowDeselectedFnc(this.fnGetSelectedData(), $('#' + tableId).dataTable(), this);
};
}
$('#' + tableId).dataTable({
"aaData" : data,
"aoColumns" : columns,
"oLanguage" : gui.config.dataTablesLanguage,
"oTableTools" : oTableTools,
// First is upper row,
// second row is lower
// (pagination) row
"sDom" : "<'row'<'col-xs-8'T><'col-xs-4'f>r>t<'row'<'col-xs-5'i><'col-xs-7'p>>",
});
// Fix 3dbuttons
api.tools.fix3dButtons('#' + tableId + '_wrapper .btn-group-3d');
// Fix form
$('#' + tableId + '_filter input').addClass('form-control');
// Add refresh action to panel
$(table.refreshSelector).click(refreshFnc);
if (options.scrollToTable === true ) {
var tableTop = $('#' + tableId).offset().top;
$('html, body').scrollTop(tableTop);
}
// if table rendered event
if( options.onLoad ) {
options.onLoad($this);
} }
}); });
}, });
});
return '#' + tableId; return '#' + tableId;
} }

View File

@ -1,3 +1,3 @@
{% verbatim %} {% verbatim %}
<input type="hidden" class="{{ css }}" name="{{ name }}}" value="{{ value }}"> <input type="hidden" class="{{ css }}" name="{{ name }}" value="{{ value }}">
{% endverbatim %} {% endverbatim %}

View File

@ -9,6 +9,8 @@
</div> </div>
<div class="modal-body"> <div class="modal-body">
{{{ content }}} {{{ content }}}
</div>
<div class="modal-footer">
{{# if button1 }} {{# if button1 }}
{{{ button1 }}} {{{ button1 }}}
{{ else }} {{ else }}

View File

@ -0,0 +1,10 @@
{% verbatim %}
<style id="style-{{ tableId }}" media="screen">
@media (max-width: 768px) {
{{#each columns }}
#{{ tableId }} td:nth-of-type({{@index}}):before { content: "{{ this.sTitle }}"}\n');
respStyles.push('#' + tableId + ' td:nth-of-type(' + counter + '):empty { background-color: red ;}\n');
{{/each }}
};
</style>
{% endverbatim %}

View File

@ -1,5 +1,4 @@
{% verbatim %} {% verbatim %}<?xml version="1.0"?>
<?xml version="1.0"?>
<?mso-application progid="Excel.Sheet"?> <?mso-application progid="Excel.Sheet"?>
<Workbook <Workbook
xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns="urn:schemas-microsoft-com:office:spreadsheet"

View File

@ -10,7 +10,7 @@
</h3> </h3>
</div> </div>
<div class="panel-body collapse in"> <div class="panel-body collapse in">
<table class="table table-striped table-bordered table-hover" id="{{ table_id }}"> <table class="table table-striped table-bordered table-hover" id="{{ table_id }}" width="100%">
</table> </table>
</div> </div>
</div> </div>