diff options
Diffstat (limited to 'install')
-rw-r--r-- | install/ui/dialog.js | 10 | ||||
-rw-r--r-- | install/ui/dns.js | 2 | ||||
-rw-r--r-- | install/ui/entitle.js | 12 | ||||
-rw-r--r-- | install/ui/host.js | 2 | ||||
-rw-r--r-- | install/ui/ipa.js | 23 | ||||
-rw-r--r-- | install/ui/service.js | 4 | ||||
-rw-r--r-- | install/ui/widget.js | 86 |
7 files changed, 101 insertions, 38 deletions
diff --git a/install/ui/dialog.js b/install/ui/dialog.js index f60db5ca..2c9fdb0e 100644 --- a/install/ui/dialog.js +++ b/install/ui/dialog.js @@ -74,11 +74,19 @@ IPA.dialog = function(spec) { that.fields_by_name[field.name] = field; }; - that.field = function(field){ + that.field = function(field) { that.add_field(field); 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.field(IPA.text_widget({ name: name, diff --git a/install/ui/dns.js b/install/ui/dns.js index f52a0642..5cb49e55 100644 --- a/install/ui/dns.js +++ b/install/ui/dns.js @@ -69,7 +69,7 @@ IPA.entity_factories.dnszone = function() { }; 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.label = param_info.label; spec.tooltip = param_info.doc; diff --git a/install/ui/entitle.js b/install/ui/entitle.js index 1b434d3f..193468c2 100644 --- a/install/ui/entitle.js +++ b/install/ui/entitle.js @@ -86,7 +86,7 @@ IPA.entity_factories.entitle = function() { }, { name: 'password', - label: IPA.get_method_param('entitle_register', 'password').label, + label: IPA.get_method_option('entitle_register', 'password').label, type: 'password', undo: false } @@ -114,7 +114,8 @@ IPA.entity_factories.entitle = function() { { name: '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.search_facet_setup(container); var buttons = that.entity_header.buttons; @@ -408,6 +408,7 @@ IPA.entitle.certificate_column = function(spec) { var that = IPA.column(spec); that.setup = function(container, record) { + container.empty(); var certificate = record[that.name]; @@ -527,6 +528,11 @@ IPA.entitle.consume_dialog = function(spec) { var that = IPA.dialog(spec); that.add_button('Consume', function() { + + if (!that.is_valid()) { + return; + } + var record = {}; that.save(record); diff --git a/install/ui/host.js b/install/ui/host.js index 44479de6..bd694ee6 100644 --- a/install/ui/host.js +++ b/install/ui/host.js @@ -122,7 +122,7 @@ IPA.utc_date_column_format = function(value){ 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.label = param_info.label; spec.tooltip = param_info.doc; diff --git a/install/ui/ipa.js b/install/ui/ipa.js index 60b27633..f551fc64 100644 --- a/install/ui/ipa.js +++ b/install/ui/ipa.js @@ -539,7 +539,28 @@ IPA.get_entity_param = function(entity_name, name) { 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]; if (!metadata) { diff --git a/install/ui/service.js b/install/ui/service.js index daf4e621..f76af900 100644 --- a/install/ui/service.js +++ b/install/ui/service.js @@ -127,8 +127,8 @@ IPA.service_add_dialog = function(spec) { field( IPA.checkbox_widget({ name: 'force', - label: IPA.get_method_param('service_add', 'force').label, - tooltip: IPA.get_method_param('service_add', 'force').doc, + label: IPA.get_method_option('service_add', 'force').label, + tooltip: IPA.get_method_option('service_add', 'force').doc, undo: false })); diff --git a/install/ui/widget.js b/install/ui/widget.js index ba02a844..a376c3ac 100644 --- a/install/ui/widget.js +++ b/install/ui/widget.js @@ -57,10 +57,12 @@ IPA.widget = function(spec) { that.load = spec.load || load; that.save = spec.save || save; that.update = spec.update || update; - that.validate_input = spec.validate_input || validate_input; - that.valid = true; + that.param_info = spec.param_info; + that.metadata = spec.metadata; + that.values = []; + that.valid = true; that.__defineGetter__("entity_name", function(){ return that._entity_name; @@ -73,29 +75,58 @@ IPA.widget = function(spec) { /*returns true and clears the error message if the field value passes the validation pattern. If the field value does not pass validation, displays the error message and returns false. */ - function validate_input(text) { - if (!(that.param_info && that.param_info.pattern)) { - that.valid = true; + that.validate = function() { + + that.hide_error(); + + that.valid = true; + + var values = that.save(); + if (!values || !values.length) { return; } - var error_link = that.get_error_link(); - if (!error_link) { - that.valid = true; + + var value = values[0]; + if (!value) { return; } - var regex = new RegExp( that.param_info.pattern ); - //If the field is empty, don't validate - if ( !text || text.match(regex) ) { - error_link.css('display', 'none'); - that.valid = true; - } else { - error_link.css('display', 'block'); - if (that.param_info.pattern_errmsg) { - error_link.html(that.param_info.pattern_errmsg); + + if (that.metadata) { + if (that.metadata.type == 'int') { + if (!value.match(/^-?\d+$/)) { + that.valid = false; + // TODO: I18n + that.show_error('must be an integer'); + return; + } + + 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() { if (that.entity_name) { @@ -247,12 +278,13 @@ IPA.widget = function(spec) { return $('span[name="error_link"]', that.container); }; - that.show_error_link = function() { + that.show_error = function(message) { 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(); error_link.css('display', 'none'); }; @@ -323,8 +355,7 @@ IPA.text_widget = function(spec) { if (that.undo) { that.show_undo(); } - var value = $(this).val(); - that.validate_input(value); + that.validate(); }); var undo = that.get_undo(); @@ -539,8 +570,7 @@ IPA.multivalued_text_widget = function(spec) { remove_link.css('display', 'inline'); } } - var value = $(this).val(); - that.validate_input(value); + that.validate(); }); remove_link.click(function() { @@ -965,9 +995,7 @@ IPA.textarea_widget = function (spec) { var input = $('textarea[name="'+that.name+'"]', that.container); input.keyup(function() { that.show_undo(); - - var value = $(this).val(); - that.validate_input(value); + that.validate(); }); |