summaryrefslogtreecommitdiffstats
path: root/install/ui/src/freeipa/widget.js
diff options
context:
space:
mode:
authorPetr Vobornik <pvoborni@redhat.com>2014-02-12 18:57:41 +0100
committerPetr Vobornik <pvoborni@redhat.com>2014-04-15 12:41:53 +0200
commit0c8b04699b35ea48b897bcd3419a94dd90a07c5d (patch)
treea2ce44e9b9ddbdef3359930c9f09b3cb8c2fecec /install/ui/src/freeipa/widget.js
parentcb486136dbf86d52e75e1684d4876fd46c44aa22 (diff)
downloadfreeipa-0c8b04699b35ea48b897bcd3419a94dd90a07c5d.tar.gz
freeipa-0c8b04699b35ea48b897bcd3419a94dd90a07c5d.tar.xz
freeipa-0c8b04699b35ea48b897bcd3419a94dd90a07c5d.zip
webui: validation summary widget
A widget which aggregates warnings and errors and shows them on one place. https://fedorahosted.org/freeipa/ticket/3903 Reviewed-By: Adam Misnyovszki <amisnyov@redhat.com>
Diffstat (limited to 'install/ui/src/freeipa/widget.js')
-rw-r--r--install/ui/src/freeipa/widget.js86
1 files changed, 86 insertions, 0 deletions
diff --git a/install/ui/src/freeipa/widget.js b/install/ui/src/freeipa/widget.js
index a074c4f72..0c02019e1 100644
--- a/install/ui/src/freeipa/widget.js
+++ b/install/ui/src/freeipa/widget.js
@@ -5352,6 +5352,91 @@ IPA.value_map_widget = function(spec) {
return that;
};
+exp.validation_summary_widget = IPA.validation_summary_widget = function(spec) {
+
+ var that = IPA.widget(spec);
+
+ /**
+ * Map of errors to display
+ *
+ * - key: source ie. widget name
+ * - value: error text
+ * @protected
+ * @property {ordered_map}
+ */
+ that.errors = $.ordered_map();
+
+ /**
+ * Map of warning s to display
+ *
+ * - key: source ie. widget name
+ * - value: warning text
+ * @protected
+ * @property {ordered_map}
+ */
+ that.warnings = $.ordered_map();
+
+ that.errors_node = null;
+ that.warnings_node = null;
+
+ that.create = function(container) {
+ that.widget_create(container);
+ that.add_class('validation-summary');
+
+ that.errors_node = $('<div/>', {
+ 'class': 'text-error'
+ }).appendTo(container);
+ that.warnings_node = $('<div/>', {
+ 'class': 'text-warning'
+ }).appendTo(container);
+ that.render_items(that.errors, that.errors_node);
+ that.render_items(that.warnings, that.warnings_node);
+ };
+
+ that.render_items = function(items, node) {
+
+ if (that.enabled) {
+ that.set_visible(that.errors.length > 0 || that.warnings.length > 0);
+ }
+
+ if (!node) return;
+
+ node.empty();
+
+ var values = items.values;
+ var keys = items.keys;
+
+ for (var i=0; i<values.length; i++) {
+ $('<div/>', {
+ 'data-name': keys[i],
+ html: values[i]
+ }).appendTo(node);
+ }
+ };
+
+ that.add_error = function(name, text) {
+ that.errors.put(name, text);
+ that.render_items(that.errors, that.errors_node);
+ };
+
+ that.remove_error = function(name) {
+ that.errors.remove(name);
+ that.render_items(that.errors, that.errors_node);
+ };
+
+ that.add_warning = function(name, text) {
+ that.warnings.put(name, text);
+ that.render_items(that.warnings, that.warnings_node);
+ };
+
+ that.remove_warning = function(name) {
+ that.warnings.remove(name);
+ that.render_items(that.warnings, that.warnings_node);
+ };
+
+ return that;
+};
+
/**
* Activity widget
*
@@ -5519,6 +5604,7 @@ exp.register = function() {
w.register('sshkeys', IPA.sshkeys_widget);
w.register('textarea', IPA.textarea_widget);
w.register('text', IPA.text_widget);
+ w.register('validation_summary', IPA.validation_summary_widget);
w.register('value_map', IPA.value_map_widget);
f.register('boolean', IPA.boolean_formatter);