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:
parent
ceecb0823d
commit
b7bfecf87c
@ -91,12 +91,23 @@ class ModelHandlerMixin(object):
|
||||
def get(self):
|
||||
logger.debug('method GET for {0}, {1}'.format(self.__class__.__name__, self._args))
|
||||
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())
|
||||
|
||||
# If has detail and is requesting detail
|
||||
if self.detail is not None and len(self._args) > 1:
|
||||
return self.processDetail()
|
||||
|
||||
|
||||
try:
|
||||
val = self.model.objects.get(pk=self._args[0])
|
||||
res = self.item_as_dict(val)
|
||||
|
@ -128,28 +128,50 @@ BasicModelRest.prototype = {
|
||||
});
|
||||
}
|
||||
},
|
||||
get : function(options) {
|
||||
get : function(success_fnc, options) {
|
||||
"use strict";
|
||||
options = options || {};
|
||||
|
||||
var path = this.getPath;
|
||||
if (options.id !== undefined)
|
||||
if ( options.id )
|
||||
path += '/' + options.id;
|
||||
return this._requestPath(path, {
|
||||
cacheKey: '.', // Right now, do not cache this
|
||||
success: options.success,
|
||||
cacheKey: '.', // Right now, do not cache any "get" method
|
||||
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";
|
||||
options = options || {};
|
||||
return this._requestPath(this.typesPath, {
|
||||
cacheKey: 'type',
|
||||
success: options.success,
|
||||
success: success_fnc,
|
||||
});
|
||||
},
|
||||
gui: function(typeName, options) {
|
||||
gui: function(typeName, success_fnc, options) {
|
||||
// GUI returns a dict, that contains:
|
||||
// name: Name of the field
|
||||
// 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('/');
|
||||
return this._requestPath(path, {
|
||||
cacheKey: typeName + '-gui',
|
||||
success: options.success,
|
||||
success: success_fnc,
|
||||
});
|
||||
},
|
||||
tableInfo : function(options) {
|
||||
tableInfo : function(success_fnc, options) {
|
||||
"use strict";
|
||||
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;
|
||||
// Cache types locally, will not change unless new broker version
|
||||
if( this.cache.get(path) ) {
|
||||
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);
|
||||
},
|
||||
this._requestPath(path, {
|
||||
success: success_fnc,
|
||||
});
|
||||
|
||||
},
|
||||
|
||||
detail: function(id, child) {
|
||||
@ -209,14 +218,27 @@ DetailModelRestApi.prototype = {
|
||||
"use strict";
|
||||
return this.base.get(options);
|
||||
},
|
||||
types: function(options) {
|
||||
"use strict";
|
||||
return this.base.types(options);
|
||||
},
|
||||
tableInfo: function(options) {
|
||||
"use strict";
|
||||
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
|
||||
|
@ -139,6 +139,6 @@ if ($.fn.DataTable.TableTools) {
|
||||
"button" : "li",
|
||||
"liner" : "a"
|
||||
},
|
||||
"button" : "button",
|
||||
// "button" : "button",
|
||||
});
|
||||
}
|
||||
|
@ -35,16 +35,13 @@ gui.providers.link = function(event) {
|
||||
var tableId = gui.providers.table({
|
||||
rowSelect : 'single',
|
||||
onEdit: function(value, event, table) {
|
||||
gui.providers.rest.gui(value.type, {
|
||||
success: function(data){
|
||||
gui.providers.rest.gui(value.type, function(data) {
|
||||
var form = gui.fields(data);
|
||||
gui.appendToWorkspace(gui.modal('edit_modal', gettext('Edit service provider'), form));
|
||||
$('#edit_modal').modal()
|
||||
.on('hidden.bs.modal', function () {
|
||||
$('#edit_modal').remove();
|
||||
})
|
||||
;
|
||||
},
|
||||
});
|
||||
});
|
||||
},
|
||||
buttons : [ 'edit', 'delete', 'xls' ],
|
||||
@ -90,7 +87,7 @@ gui.authenticators.link = function(event) {
|
||||
user.table({
|
||||
container : 'users-placeholder',
|
||||
rowSelect : 'multi',
|
||||
buttons : [ 'edit', 'delete', 'xls' ],
|
||||
buttons : [ 'new', 'edit', 'delete', 'xls' ],
|
||||
scrollToTable : true,
|
||||
onLoad: function(k) {
|
||||
api.tools.unblockUI();
|
||||
@ -102,11 +99,9 @@ gui.authenticators.link = function(event) {
|
||||
$('#users-placeholder').empty(); // Remove detail on parent refresh
|
||||
},
|
||||
onEdit: function(value, event, table) {
|
||||
gui.authenticators.rest.gui(value.type, {
|
||||
success: function(data){
|
||||
gui.authenticators.rest.gui(value.type, function(data){
|
||||
var form = gui.fields(data);
|
||||
gui.launchModal(gettext('Edit authenticator')+' '+value.name, form);
|
||||
},
|
||||
});
|
||||
},
|
||||
});
|
||||
@ -146,29 +141,26 @@ gui.connectivity.link = function(event) {
|
||||
gui.connectivity.transports.table({
|
||||
rowSelect : 'multi',
|
||||
container : 'transports-placeholder',
|
||||
buttons : [ 'edit', 'delete', 'xls' ],
|
||||
buttons : [ 'new', 'edit', 'delete', 'xls' ],
|
||||
onEdit: function(value, event, table) {
|
||||
gui.connectivity.transports.rest.gui(value.type, {
|
||||
success: function(itemGui){
|
||||
gui.connectivity.transports.rest.get({
|
||||
id:value.id,
|
||||
success: function(item) {
|
||||
gui.connectivity.transports.rest.gui(value.type, function(itemGui){
|
||||
gui.connectivity.transports.rest.item(value.id, function(item) {
|
||||
var form = gui.fields(itemGui, item);
|
||||
gui.launchModal(gettext('Edit transport')+' '+value.name,form, function(form_selector) {
|
||||
var fields = gui.fields.read(form_selector);
|
||||
return false;
|
||||
});
|
||||
},
|
||||
});
|
||||
});
|
||||
},
|
||||
});
|
||||
onNew: function(type) {
|
||||
gui.doLog(type);
|
||||
},
|
||||
|
||||
});
|
||||
gui.connectivity.networks.table({
|
||||
rowSelect : 'multi',
|
||||
container : 'networks-placeholder',
|
||||
buttons : [ 'edit', 'delete', 'xls' ],
|
||||
buttons : [ 'new', 'edit', 'delete', 'xls' ],
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -2,10 +2,10 @@
|
||||
(function(gui, $, undefined) {
|
||||
"use strict";
|
||||
// "public" methods
|
||||
gui.doLog = function(data) {
|
||||
gui.doLog = function() {
|
||||
if (gui.debug) {
|
||||
try {
|
||||
console.log(data);
|
||||
console.log(arguments);
|
||||
} catch (e) {
|
||||
// nothing can be logged
|
||||
}
|
||||
@ -212,8 +212,7 @@ GuiElement.prototype = {
|
||||
"use strict";
|
||||
gui.doLog('Initializing ' + this.name);
|
||||
var $this = this;
|
||||
this.rest.types({
|
||||
success: function(data) {
|
||||
this.rest.types(function(data) {
|
||||
var styles = '';
|
||||
$.each(data, function(index, value) {
|
||||
var className = $this.name + '-' + value.type;
|
||||
@ -231,7 +230,6 @@ GuiElement.prototype = {
|
||||
styles = '<style media="screen">' + styles + '</style>';
|
||||
$(styles).appendTo('head');
|
||||
}
|
||||
},
|
||||
});
|
||||
},
|
||||
// Options: dictionary
|
||||
@ -268,6 +266,7 @@ GuiElement.prototype = {
|
||||
// 4.- the DataTable that raised the event
|
||||
table : function(options) {
|
||||
"use strict";
|
||||
console.log('Types: ', this.types);
|
||||
options = options || {};
|
||||
gui.doLog('Composing table for ' + this.name);
|
||||
var tableId = this.name + '-table';
|
||||
@ -313,8 +312,7 @@ GuiElement.prototype = {
|
||||
return dict[data] || renderEmptyCell('');
|
||||
};
|
||||
};
|
||||
this.rest.tableInfo({
|
||||
success: function(data) {
|
||||
this.rest.tableInfo(function(data) {
|
||||
var title = data.title;
|
||||
var columns = [];
|
||||
$.each(data.fields, function(index, value) {
|
||||
@ -333,7 +331,7 @@ GuiElement.prototype = {
|
||||
if (opts.searchable !== undefined)
|
||||
column.bSearchable = opts.searchable;
|
||||
|
||||
if (opts.type !== undefined && column.bVisible ) {
|
||||
if (opts.type && column.bVisible ) {
|
||||
switch(opts.type) {
|
||||
case 'date':
|
||||
column.sType = 'date';
|
||||
@ -367,7 +365,7 @@ GuiElement.prototype = {
|
||||
columns.push(column);
|
||||
}
|
||||
});
|
||||
// Generate styles for responsible table, just the name of fields
|
||||
// Generate styles for responsible table, just the name of fields (append header to table)
|
||||
var respStyles = [];
|
||||
var counter = 0;
|
||||
$.each(columns, function(col, value) {
|
||||
@ -376,15 +374,12 @@ GuiElement.prototype = {
|
||||
counter += 1;
|
||||
respStyles.push('#' + tableId + ' td:nth-of-type(' + counter + '):before { content: "' +
|
||||
(value.sTitle || '') + '";}\n');
|
||||
respStyles.push('#' + tableId + ' td:nth-of-type(' + counter + '):empty { background-color: red ;}\n');
|
||||
});
|
||||
// If styles already exists, remove them before adding new ones
|
||||
$('style-' + tableId).remove();
|
||||
$('<style id="style-' + tableId + '" media="screen">@media (max-width: 979px) { ' + respStyles.join('') + '};</style>').appendTo('head');
|
||||
$('<style id="style-' + tableId + '" media="screen">@media (max-width: 768px) { ' + respStyles.join('') + '};</style>').appendTo('head');
|
||||
|
||||
$this.rest.get({
|
||||
success : function(data) {
|
||||
var refreshFnc;
|
||||
$this.rest.overview(function(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>');
|
||||
@ -393,16 +388,45 @@ GuiElement.prototype = {
|
||||
$('#' + options.container).append(table.text);
|
||||
}
|
||||
|
||||
// What execute on refresh button push
|
||||
var onRefresh = options.onRefresh || function(){};
|
||||
|
||||
var refreshFnc = function() {
|
||||
// Refreshes table content
|
||||
var tbl = $('#' + tableId).dataTable();
|
||||
// Clears selection first
|
||||
TableTools.fnGetInstance(tableId).fnSelectNone();
|
||||
if( data.length > 1000 )
|
||||
api.tools.blockUI();
|
||||
|
||||
$this.rest.overview(function(data) {
|
||||
/*$(btn).removeClass('disabled').width('').html(saved);*/
|
||||
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) {
|
||||
var handleFnc = handler || function(val, action, tbl) {gui.doLog('Default handler called for ' + action + ': ' + JSON.stringify(val));};
|
||||
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 val = this.fnGetSelectedData()[0];
|
||||
setTimeout(function() {
|
||||
handleFnc(val, action, tbl);
|
||||
if( newHandler ) {
|
||||
if( handleFnc(action, tbl) === true ) // Reload table?
|
||||
refreshFnc();
|
||||
} else {
|
||||
if( handleFnc(val, action, tbl) === true ) // Reload table?
|
||||
refreshFnc();
|
||||
}
|
||||
}, 0);
|
||||
};
|
||||
};
|
||||
@ -425,42 +449,34 @@ GuiElement.prototype = {
|
||||
}
|
||||
};
|
||||
|
||||
// What execute on refresh button push
|
||||
var onRefresh = options.onRefresh || function(){};
|
||||
|
||||
refreshFnc = function() {
|
||||
// Refreshes table content
|
||||
var tbl = $('#' + tableId).dataTable();
|
||||
// Clears selection first
|
||||
TableTools.fnGetInstance(tableId).fnSelectNone();
|
||||
if( data.length > 1000 )
|
||||
api.tools.blockUI();
|
||||
|
||||
$this.rest.get({
|
||||
success : function(data) {
|
||||
/*$(btn).removeClass('disabled').width('').html(saved);*/
|
||||
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
|
||||
};
|
||||
|
||||
$.each(options.buttons, function(index, value) {
|
||||
var btn;
|
||||
switch (value) {
|
||||
case 'new':
|
||||
if(Object.keys($this.types).length === 0) {
|
||||
btn = {
|
||||
"sExtends" : "text",
|
||||
"sButtonText" : gui.config.dataTableButtons['new'].text,
|
||||
"fnSelect" : deleteSelected,
|
||||
"fnClick" : clickHandlerFor(options.onDelete, 'delete'),
|
||||
"fnClick" : clickHandlerFor(options.onNew, 'new'),
|
||||
"sButtonClass" : gui.config.dataTableButtons['new'].css,
|
||||
};
|
||||
} else {
|
||||
// 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 = {
|
||||
"sExtends" : "collection",
|
||||
"aButtons": newButtons,
|
||||
"sButtonText" : gui.config.dataTableButtons['new'].text,
|
||||
"sButtonClass" : gui.config.dataTableButtons['new'].css,
|
||||
};
|
||||
}
|
||||
break;
|
||||
case 'edit':
|
||||
btn = {
|
||||
@ -589,10 +605,7 @@ GuiElement.prototype = {
|
||||
if( options.onLoad ) {
|
||||
options.onLoad($this);
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
});
|
||||
return '#' + tableId;
|
||||
}
|
||||
|
@ -1,3 +1,3 @@
|
||||
{% verbatim %}
|
||||
<input type="hidden" class="{{ css }}" name="{{ name }}}" value="{{ value }}">
|
||||
<input type="hidden" class="{{ css }}" name="{{ name }}" value="{{ value }}">
|
||||
{% endverbatim %}
|
@ -9,6 +9,8 @@
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
{{{ content }}}
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
{{# if button1 }}
|
||||
{{{ button1 }}}
|
||||
{{ else }}
|
||||
|
@ -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 %}
|
@ -1,5 +1,4 @@
|
||||
{% verbatim %}
|
||||
<?xml version="1.0"?>
|
||||
{% verbatim %}<?xml version="1.0"?>
|
||||
<?mso-application progid="Excel.Sheet"?>
|
||||
<Workbook
|
||||
xmlns="urn:schemas-microsoft-com:office:spreadsheet"
|
||||
|
@ -10,7 +10,7 @@
|
||||
</h3>
|
||||
</div>
|
||||
<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>
|
||||
</div>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user