mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
Entitlement quantity validation.
The widget base class has been modified to validate integer value if the type is specified in the metadata. This is used to validate entitlement quantity.
This commit is contained in:
committed by
Endi Sukma Dewata
parent
000ba0531e
commit
f256b8857f
@@ -74,11 +74,19 @@ IPA.dialog = function(spec) {
|
|||||||
that.fields_by_name[field.name] = field;
|
that.fields_by_name[field.name] = field;
|
||||||
};
|
};
|
||||||
|
|
||||||
that.field = function(field){
|
that.field = function(field) {
|
||||||
that.add_field(field);
|
that.add_field(field);
|
||||||
return that;
|
return that;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
that.is_valid = function() {
|
||||||
|
for (var i=0; i<that.fields.length; i++) {
|
||||||
|
var field = that.fields[i];
|
||||||
|
if (!field.valid) return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
that.text = function(name){
|
that.text = function(name){
|
||||||
that.field(IPA.text_widget({
|
that.field(IPA.text_widget({
|
||||||
name: name,
|
name: name,
|
||||||
|
@@ -69,7 +69,7 @@ IPA.entity_factories.dnszone = function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
IPA.force_dnszone_add_checkbox_widget = function (spec){
|
IPA.force_dnszone_add_checkbox_widget = function (spec){
|
||||||
var param_info = IPA.get_method_param('dnszone_add', 'force');
|
var param_info = IPA.get_method_option('dnszone_add', 'force');
|
||||||
spec.name = 'force';
|
spec.name = 'force';
|
||||||
spec.label = param_info.label;
|
spec.label = param_info.label;
|
||||||
spec.tooltip = param_info.doc;
|
spec.tooltip = param_info.doc;
|
||||||
|
@@ -86,7 +86,7 @@ IPA.entity_factories.entitle = function() {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'password',
|
name: 'password',
|
||||||
label: IPA.get_method_param('entitle_register', 'password').label,
|
label: IPA.get_method_option('entitle_register', 'password').label,
|
||||||
type: 'password',
|
type: 'password',
|
||||||
undo: false
|
undo: false
|
||||||
}
|
}
|
||||||
@@ -114,7 +114,8 @@ IPA.entity_factories.entitle = function() {
|
|||||||
{
|
{
|
||||||
name: 'quantity',
|
name: 'quantity',
|
||||||
label: 'Quantity',
|
label: 'Quantity',
|
||||||
undo: false
|
undo: false,
|
||||||
|
metadata: IPA.get_method_arg('entitle_consume', 'quantity')
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}).
|
}).
|
||||||
@@ -261,7 +262,6 @@ IPA.entitle.search_facet = function(spec) {
|
|||||||
|
|
||||||
that.setup = function(container) {
|
that.setup = function(container) {
|
||||||
|
|
||||||
|
|
||||||
that.search_facet_setup(container);
|
that.search_facet_setup(container);
|
||||||
|
|
||||||
var buttons = that.entity_header.buttons;
|
var buttons = that.entity_header.buttons;
|
||||||
@@ -408,6 +408,7 @@ IPA.entitle.certificate_column = function(spec) {
|
|||||||
var that = IPA.column(spec);
|
var that = IPA.column(spec);
|
||||||
|
|
||||||
that.setup = function(container, record) {
|
that.setup = function(container, record) {
|
||||||
|
|
||||||
container.empty();
|
container.empty();
|
||||||
|
|
||||||
var certificate = record[that.name];
|
var certificate = record[that.name];
|
||||||
@@ -527,6 +528,11 @@ IPA.entitle.consume_dialog = function(spec) {
|
|||||||
var that = IPA.dialog(spec);
|
var that = IPA.dialog(spec);
|
||||||
|
|
||||||
that.add_button('Consume', function() {
|
that.add_button('Consume', function() {
|
||||||
|
|
||||||
|
if (!that.is_valid()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var record = {};
|
var record = {};
|
||||||
that.save(record);
|
that.save(record);
|
||||||
|
|
||||||
|
@@ -122,7 +122,7 @@ IPA.utc_date_column_format = function(value){
|
|||||||
|
|
||||||
|
|
||||||
IPA.force_host_add_checkbox_widget = function (spec){
|
IPA.force_host_add_checkbox_widget = function (spec){
|
||||||
var param_info = IPA.get_method_param('host_add', 'force');
|
var param_info = IPA.get_method_option('host_add', 'force');
|
||||||
spec.name = 'force';
|
spec.name = 'force';
|
||||||
spec.label = param_info.label;
|
spec.label = param_info.label;
|
||||||
spec.tooltip = param_info.doc;
|
spec.tooltip = param_info.doc;
|
||||||
|
@@ -539,7 +539,28 @@ IPA.get_entity_param = function(entity_name, name) {
|
|||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
IPA.get_method_param = function(method_name, name) {
|
IPA.get_method_arg = function(method_name, name) {
|
||||||
|
|
||||||
|
var metadata = IPA.metadata.methods[method_name];
|
||||||
|
if (!metadata) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
var args = metadata.takes_args;
|
||||||
|
if (!args) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var i=0; i<args.length; i++) {
|
||||||
|
if (args[i].name === name) {
|
||||||
|
return args[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
|
||||||
|
IPA.get_method_option = function(method_name, name) {
|
||||||
|
|
||||||
var metadata = IPA.metadata.methods[method_name];
|
var metadata = IPA.metadata.methods[method_name];
|
||||||
if (!metadata) {
|
if (!metadata) {
|
||||||
|
@@ -127,8 +127,8 @@ IPA.service_add_dialog = function(spec) {
|
|||||||
field(
|
field(
|
||||||
IPA.checkbox_widget({
|
IPA.checkbox_widget({
|
||||||
name: 'force',
|
name: 'force',
|
||||||
label: IPA.get_method_param('service_add', 'force').label,
|
label: IPA.get_method_option('service_add', 'force').label,
|
||||||
tooltip: IPA.get_method_param('service_add', 'force').doc,
|
tooltip: IPA.get_method_option('service_add', 'force').doc,
|
||||||
undo: false
|
undo: false
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
@@ -57,10 +57,12 @@ IPA.widget = function(spec) {
|
|||||||
that.load = spec.load || load;
|
that.load = spec.load || load;
|
||||||
that.save = spec.save || save;
|
that.save = spec.save || save;
|
||||||
that.update = spec.update || update;
|
that.update = spec.update || update;
|
||||||
that.validate_input = spec.validate_input || validate_input;
|
|
||||||
that.valid = true;
|
|
||||||
that.param_info = spec.param_info;
|
that.param_info = spec.param_info;
|
||||||
|
that.metadata = spec.metadata;
|
||||||
|
|
||||||
that.values = [];
|
that.values = [];
|
||||||
|
that.valid = true;
|
||||||
|
|
||||||
that.__defineGetter__("entity_name", function(){
|
that.__defineGetter__("entity_name", function(){
|
||||||
return that._entity_name;
|
return that._entity_name;
|
||||||
@@ -73,29 +75,58 @@ IPA.widget = function(spec) {
|
|||||||
/*returns true and clears the error message if the field value passes
|
/*returns true and clears the error message if the field value passes
|
||||||
the validation pattern. If the field value does not pass validation,
|
the validation pattern. If the field value does not pass validation,
|
||||||
displays the error message and returns false. */
|
displays the error message and returns false. */
|
||||||
function validate_input(text) {
|
that.validate = function() {
|
||||||
if (!(that.param_info && that.param_info.pattern)) {
|
|
||||||
that.valid = true;
|
that.hide_error();
|
||||||
|
|
||||||
|
that.valid = true;
|
||||||
|
|
||||||
|
var values = that.save();
|
||||||
|
if (!values || !values.length) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var error_link = that.get_error_link();
|
|
||||||
if (!error_link) {
|
var value = values[0];
|
||||||
that.valid = true;
|
if (!value) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var regex = new RegExp( that.param_info.pattern );
|
|
||||||
//If the field is empty, don't validate
|
if (that.metadata) {
|
||||||
if ( !text || text.match(regex) ) {
|
if (that.metadata.type == 'int') {
|
||||||
error_link.css('display', 'none');
|
if (!value.match(/^-?\d+$/)) {
|
||||||
that.valid = true;
|
that.valid = false;
|
||||||
} else {
|
// TODO: I18n
|
||||||
error_link.css('display', 'block');
|
that.show_error('must be an integer');
|
||||||
if (that.param_info.pattern_errmsg) {
|
return;
|
||||||
error_link.html(that.param_info.pattern_errmsg);
|
}
|
||||||
|
|
||||||
|
if (that.metadata.minvalue && value < that.metadata.minvalue) {
|
||||||
|
that.valid = false;
|
||||||
|
// TODO: I18n
|
||||||
|
that.show_error('minimum value is '+that.metadata.minvalue);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (that.metadata.maxvalue && value > that.metadata.maxvalue) {
|
||||||
|
that.valid = false;
|
||||||
|
// TODO: I18n
|
||||||
|
that.show_error('maximum value is '+that.metadata.maxvalue);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
that.valid = false;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
if (that.param_info) {
|
||||||
|
if (that.param_info.pattern) {
|
||||||
|
var regex = new RegExp(that.param_info.pattern);
|
||||||
|
if (!value.match(regex)) {
|
||||||
|
that.valid = false;
|
||||||
|
that.show_error(that.param_info.pattern_errmsg);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
if (that.entity_name) {
|
if (that.entity_name) {
|
||||||
@@ -247,12 +278,13 @@ IPA.widget = function(spec) {
|
|||||||
return $('span[name="error_link"]', that.container);
|
return $('span[name="error_link"]', that.container);
|
||||||
};
|
};
|
||||||
|
|
||||||
that.show_error_link = function() {
|
that.show_error = function(message) {
|
||||||
var error_link = that.get_error_link();
|
var error_link = that.get_error_link();
|
||||||
error_link.css('display', 'inline');
|
error_link.html(message);
|
||||||
|
error_link.css('display', 'block');
|
||||||
};
|
};
|
||||||
|
|
||||||
that.hide_error_link = function() {
|
that.hide_error = function() {
|
||||||
var error_link = that.get_error_link();
|
var error_link = that.get_error_link();
|
||||||
error_link.css('display', 'none');
|
error_link.css('display', 'none');
|
||||||
};
|
};
|
||||||
@@ -323,8 +355,7 @@ IPA.text_widget = function(spec) {
|
|||||||
if (that.undo) {
|
if (that.undo) {
|
||||||
that.show_undo();
|
that.show_undo();
|
||||||
}
|
}
|
||||||
var value = $(this).val();
|
that.validate();
|
||||||
that.validate_input(value);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
var undo = that.get_undo();
|
var undo = that.get_undo();
|
||||||
@@ -539,8 +570,7 @@ IPA.multivalued_text_widget = function(spec) {
|
|||||||
remove_link.css('display', 'inline');
|
remove_link.css('display', 'inline');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var value = $(this).val();
|
that.validate();
|
||||||
that.validate_input(value);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
remove_link.click(function() {
|
remove_link.click(function() {
|
||||||
@@ -965,9 +995,7 @@ IPA.textarea_widget = function (spec) {
|
|||||||
var input = $('textarea[name="'+that.name+'"]', that.container);
|
var input = $('textarea[name="'+that.name+'"]', that.container);
|
||||||
input.keyup(function() {
|
input.keyup(function() {
|
||||||
that.show_undo();
|
that.show_undo();
|
||||||
|
that.validate();
|
||||||
var value = $(this).val();
|
|
||||||
that.validate_input(value);
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user