forked from shaba/openuds
Advancing on test buttons
This commit is contained in:
parent
c29e2d4dcb
commit
e071a1afbc
@ -229,6 +229,12 @@ class DetailHandler(BaseModelHandler):
|
|||||||
|
|
||||||
return self.saveItem(parent, item)
|
return self.saveItem(parent, item)
|
||||||
|
|
||||||
|
def post(self):
|
||||||
|
'''
|
||||||
|
Post will be used for, for example, testing
|
||||||
|
'''
|
||||||
|
raise NotFound('TODO: do it :-)')
|
||||||
|
|
||||||
def delete(self):
|
def delete(self):
|
||||||
'''
|
'''
|
||||||
Put is delegated to specific implementation
|
Put is delegated to specific implementation
|
||||||
@ -404,6 +410,15 @@ class ModelHandler(BaseModelHandler):
|
|||||||
return self.processDetail()
|
return self.processDetail()
|
||||||
|
|
||||||
raise RequestError('invalid request')
|
raise RequestError('invalid request')
|
||||||
|
|
||||||
|
def post(self):
|
||||||
|
# right now
|
||||||
|
logger.debug('method POST for {0}, {1}'.format(self.__class__.__name__, self._args))
|
||||||
|
if len(self._args) == 2:
|
||||||
|
if self._args[0] == 'test':
|
||||||
|
return 'tested'
|
||||||
|
|
||||||
|
raise NotFound('Method not found')
|
||||||
|
|
||||||
def put(self):
|
def put(self):
|
||||||
logger.debug('method PUT for {0}, {1}'.format(self.__class__.__name__, self._args))
|
logger.debug('method PUT for {0}, {1}'.format(self.__class__.__name__, self._args))
|
||||||
|
@ -54,7 +54,7 @@
|
|||||||
api.doLog('Ajax GET Json for "' + url + '"');
|
api.doLog('Ajax GET Json for "' + url + '"');
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url : url,
|
url : url,
|
||||||
type : "GET",
|
type : options.method || "GET", // Will use GET if no method provided
|
||||||
dataType : "json",
|
dataType : "json",
|
||||||
success : function(data) {
|
success : function(data) {
|
||||||
api.doLog('Success on GET "' + url + '".');
|
api.doLog('Success on GET "' + url + '".');
|
||||||
@ -80,7 +80,7 @@
|
|||||||
api.doLog('Ajax PUT Json for "' + url + '"');
|
api.doLog('Ajax PUT Json for "' + url + '"');
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url : url,
|
url : url,
|
||||||
type : "PUT",
|
type : options.method || "PUT", // Will use PUT if no method provided
|
||||||
dataType : "json",
|
dataType : "json",
|
||||||
data: JSON.stringify(data),
|
data: JSON.stringify(data),
|
||||||
success: function(data) {
|
success: function(data) {
|
||||||
@ -170,6 +170,7 @@ function BasicModelRest(path, options) {
|
|||||||
this.path = path;
|
this.path = path;
|
||||||
this.getPath = options.getPath || path;
|
this.getPath = options.getPath || path;
|
||||||
this.putPath = options.putPath || path;
|
this.putPath = options.putPath || path;
|
||||||
|
this.testPath = options.testPath || (path + '/test');
|
||||||
this.delPath = options.delPath || path;
|
this.delPath = options.delPath || path;
|
||||||
this.typesPath = options.typesPath || (path + '/types');
|
this.typesPath = options.typesPath || (path + '/types');
|
||||||
this.guiPath = options.guiPath || (path + '/gui');
|
this.guiPath = options.guiPath || (path + '/gui');
|
||||||
@ -284,6 +285,20 @@ BasicModelRest.prototype = {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// Testing
|
||||||
|
test: function(type, data, success_fnc, fail_fnc) {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
var path = this.testPath + '/' + type;
|
||||||
|
|
||||||
|
api.putJson(path, data, {
|
||||||
|
success: success_fnc,
|
||||||
|
fail: fail_fnc,
|
||||||
|
method: 'POST'
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
// --------------
|
// --------------
|
||||||
// Delete
|
// Delete
|
||||||
// --------------
|
// --------------
|
||||||
@ -380,6 +395,12 @@ DetailModelRestApi.prototype = {
|
|||||||
fail: fail_fnc
|
fail: fail_fnc
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
// Testing
|
||||||
|
test: function(type, data, success_fnc, fail_fnc) {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
return this.base.test(type, data, success_fnc, fail_fnc);
|
||||||
|
},
|
||||||
// --------------
|
// --------------
|
||||||
// Delete
|
// Delete
|
||||||
// --------------
|
// --------------
|
||||||
|
@ -29,7 +29,15 @@ gui.dashboard.link = function(event) {
|
|||||||
gui.providers = new GuiElement(api.providers, 'provi');
|
gui.providers = new GuiElement(api.providers, 'provi');
|
||||||
gui.providers.link = function(event) {
|
gui.providers.link = function(event) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
// Button definition to trigger "Test" action
|
||||||
|
var testButton = {
|
||||||
|
testButton: {
|
||||||
|
text: gettext('Test provider'),
|
||||||
|
css: 'btn-info',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
api.templates.get('providers', function(tmpl) {
|
api.templates.get('providers', function(tmpl) {
|
||||||
gui.clearWorkspace();
|
gui.clearWorkspace();
|
||||||
gui.appendToWorkspace(api.templates.evaluate(tmpl, {
|
gui.appendToWorkspace(api.templates.evaluate(tmpl, {
|
||||||
@ -83,8 +91,8 @@ gui.providers.link = function(event) {
|
|||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
buttons : [ 'new', 'edit', 'delete', 'xls' ],
|
buttons : [ 'new', 'edit', 'delete', 'xls' ],
|
||||||
onNew : gui.methods.typedNew(gui.providers, gettext('New provider'), gettext('Error creating provider')),
|
onNew : gui.methods.typedNew(gui.providers, gettext('New provider'), gettext('Error creating provider'), testButton),
|
||||||
onEdit: gui.methods.typedEdit(gui.providers, gettext('Edit provider'), gettext('Error processing provider')),
|
onEdit: gui.methods.typedEdit(gui.providers, gettext('Edit provider'), gettext('Error processing provider'), testButton),
|
||||||
onDelete: gui.methods.del(gui.providers, gettext('Delete provider'), gettext('Error deleting provider')),
|
onDelete: gui.methods.del(gui.providers, gettext('Delete provider'), gettext('Error deleting provider')),
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -99,10 +107,15 @@ gui.authenticators = new GuiElement(api.authenticators, 'auth');
|
|||||||
|
|
||||||
gui.authenticators.link = function(event) {
|
gui.authenticators.link = function(event) {
|
||||||
"use strict";
|
"use strict";
|
||||||
// Cleans up memory used by other datatables
|
|
||||||
$.each($.fn.dataTable.fnTables(), function(undefined, tbl){
|
// Button definition to trigger "Test" action
|
||||||
$(tbl).dataTable().fnDestroy();
|
var testButton = {
|
||||||
});
|
testButton: {
|
||||||
|
text: gettext('Test authenticator'),
|
||||||
|
css: 'btn-info',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
gui.doLog('enter auths');
|
gui.doLog('enter auths');
|
||||||
api.templates.get('authenticators', function(tmpl) {
|
api.templates.get('authenticators', function(tmpl) {
|
||||||
gui.clearWorkspace();
|
gui.clearWorkspace();
|
||||||
@ -113,20 +126,6 @@ gui.authenticators.link = function(event) {
|
|||||||
}));
|
}));
|
||||||
gui.setLinksEvents();
|
gui.setLinksEvents();
|
||||||
|
|
||||||
|
|
||||||
// Button definition to trigger "Test" action
|
|
||||||
var testButton = {
|
|
||||||
buttons: [
|
|
||||||
{
|
|
||||||
text: gettext('Test authenticator'),
|
|
||||||
css: 'btn-info',
|
|
||||||
action: function(event, form_selector, closeFnc) {
|
|
||||||
var fields = gui.forms.read(form_selector);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
]
|
|
||||||
};
|
|
||||||
|
|
||||||
gui.authenticators.table({
|
gui.authenticators.table({
|
||||||
container : 'auths-placeholder',
|
container : 'auths-placeholder',
|
||||||
rowSelect : 'single',
|
rowSelect : 'single',
|
||||||
|
@ -247,24 +247,43 @@
|
|||||||
|
|
||||||
gui.methods = {};
|
gui.methods = {};
|
||||||
|
|
||||||
|
gui.methods.typedTestButton = function(rest, text, css, type) {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
text: text,
|
||||||
|
css: css,
|
||||||
|
action: function(event, form_selector, closeFnc) {
|
||||||
|
var fields = gui.forms.read(form_selector);
|
||||||
|
gui.doLog('Fields: ', fields);
|
||||||
|
rest.test(type, fields, function(data){
|
||||||
|
gui.launchModal(gettext('Test result'), data, { actionButton: ' '});
|
||||||
|
}, gui.failRequestModalFnc(gettext('Test error')))
|
||||||
|
}
|
||||||
|
},
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
// "Generic" edit method to set onEdit table
|
// "Generic" edit method to set onEdit table
|
||||||
gui.methods.typedEdit = function(parent, modalTitle, modalErrorMsg, options) {
|
gui.methods.typedEdit = function(parent, modalTitle, modalErrorMsg, options) {
|
||||||
options = options || {}
|
options = options || {};
|
||||||
var self = parent;
|
|
||||||
return function(value, event, table, refreshFnc) {
|
return function(value, event, table, refreshFnc) {
|
||||||
self.rest.gui(value.type, function(guiDefinition) {
|
parent.rest.gui(value.type, function(guiDefinition) {
|
||||||
|
var buttons;
|
||||||
|
if( options.testButton ) {
|
||||||
|
buttons = gui.methods.typedTestButton(parent.rest, options.testButton.text, options.testButton.css, value.type);
|
||||||
|
}
|
||||||
var tabs = options.guiProcessor ? options.guiProcessor(guiDefinition) : guiDefinition; // Preprocess fields (probably generate tabs...)
|
var tabs = options.guiProcessor ? options.guiProcessor(guiDefinition) : guiDefinition; // Preprocess fields (probably generate tabs...)
|
||||||
self.rest.item(value.id, function(item) {
|
parent.rest.item(value.id, function(item) {
|
||||||
gui.forms.launchModal({
|
gui.forms.launchModal({
|
||||||
title: modalTitle+' <b>'+value.name+'</b>',
|
title: modalTitle+' <b>'+value.name+'</b>',
|
||||||
fields: tabs,
|
fields: tabs,
|
||||||
item: item,
|
item: item,
|
||||||
buttons: options.buttons,
|
buttons: buttons,
|
||||||
success: function(form_selector, closeFnc) {
|
success: function(form_selector, closeFnc) {
|
||||||
var fields = gui.forms.read(form_selector);
|
var fields = gui.forms.read(form_selector);
|
||||||
fields.data_type = value.type;
|
fields.data_type = value.type;
|
||||||
fields = options.fieldsProcessor ? options.fieldsProcessor(fields) : fields;
|
fields = options.fieldsProcessor ? options.fieldsProcessor(fields) : fields;
|
||||||
self.rest.save(fields, function(data) { // Success on put
|
parent.rest.save(fields, function(data) { // Success on put
|
||||||
closeFnc();
|
closeFnc();
|
||||||
refreshFnc();
|
refreshFnc();
|
||||||
gui.alert(gettext('Edition successfully done'), 'success');
|
gui.alert(gettext('Edition successfully done'), 'success');
|
||||||
@ -282,12 +301,16 @@
|
|||||||
var self = parent;
|
var self = parent;
|
||||||
return function(type, table, refreshFnc) {
|
return function(type, table, refreshFnc) {
|
||||||
self.rest.gui(type, function(guiDefinition) {
|
self.rest.gui(type, function(guiDefinition) {
|
||||||
|
var buttons;
|
||||||
|
if( options.testButton ) {
|
||||||
|
buttons = gui.methods.typedTestButton(parent.rest, options.testButton.text, options.testButton.css, type);
|
||||||
|
}
|
||||||
var tabs = options.guiProcessor ? options.guiProcessor(guiDefinition) : guiDefinition; // Preprocess fields (probably generate tabs...)
|
var tabs = options.guiProcessor ? options.guiProcessor(guiDefinition) : guiDefinition; // Preprocess fields (probably generate tabs...)
|
||||||
gui.forms.launchModal({
|
gui.forms.launchModal({
|
||||||
title: modalTitle,
|
title: modalTitle,
|
||||||
fields: tabs,
|
fields: tabs,
|
||||||
item: undefined,
|
item: undefined,
|
||||||
buttons: options.buttons,
|
buttons: buttons,
|
||||||
success: function(form_selector, closeFnc) {
|
success: function(form_selector, closeFnc) {
|
||||||
var fields = gui.forms.read(form_selector);
|
var fields = gui.forms.read(form_selector);
|
||||||
fields.data_type = type;
|
fields.data_type = type;
|
||||||
|
Loading…
Reference in New Issue
Block a user