[PATCH] error dialog for batch command
https://fedorahosted.org/freeipa/ticket/1597
https://fedorahosted.org/freeipa/ticket/1592
Added option to show multiple errors in error dialog.
Notes:
- also covering '[ipa webui] Does not return appropriate error when
deleting an external host but checking update dns' (1592)
- added support(element's classes) for css styling of aggregated errors
- except search dialog delete (1592) - no other batch command uses this
feature (has to be explicitly turned on).
--
Petr Vobornik
From 52254b91e3c2546fea01c18f8bc879316ae7bb3d Mon Sep 17 00:00:00 2001
From: Petr Vobornik <pvobo...@redhat.com>
Date: Thu, 11 Aug 2011 10:28:50 +0200
Subject: [PATCH] error dialog for batch command
https://fedorahosted.org/freeipa/ticket/1597
https://fedorahosted.org/freeipa/ticket/1592
Added option to show multiple errors in error dialog.
---
install/ui/ipa.js | 125 ++++++++++++++++++++++++++++++++---
install/ui/search.js | 5 +-
install/ui/test/data/ipa_init.json | 1 +
ipalib/plugins/internal.py | 1 +
4 files changed, 120 insertions(+), 12 deletions(-)
diff --git a/install/ui/ipa.js b/install/ui/ipa.js
index 8a3dd4e7d596914687e412aefdda27d7d699261d..e9de88b9ca1235d4bc6c6115dc74acdb0d882348 100644
--- a/install/ui/ipa.js
+++ b/install/ui/ipa.js
@@ -417,6 +417,10 @@ IPA.batch_command = function (spec) {
var that = IPA.command(spec);
that.commands = [];
+ that.errors = [];
+ that.partial_success_message = spec.partial_success_message || '';
+ that.partial_success_notify = typeof spec.partial_success_notify == 'undefined' ?
+ false : spec.partial_success_notify;
that.add_command = function(command) {
that.commands.push(command);
@@ -429,7 +433,21 @@ IPA.batch_command = function (spec) {
}
};
+ var clear_errors = function() {
+ that.errors = [];
+ };
+
+ var add_error = function(command, name, message, status) {
+ that.errors.push({
+ command: command,
+ name: name,
+ message: message,
+ status: status
+ });
+ };
+
that.execute = function() {
+ clear_errors();
IPA.command({
name: that.name,
@@ -444,25 +462,38 @@ IPA.batch_command = function (spec) {
var command = that.commands[i];
var result = data.result.results[i];
+ var name = '';
+ var message = '';
+
if (!result) {
+ name = 'Internal Error '+xhr.status;
+ message = result ? xhr.statusText : "Internal error";
+
+ add_error(command, name, message, text_status);
+
if (command.on_error) command.on_error.call(
this,
xhr,
text_status,
{
- name: 'Internal Error '+xhr.status,
- message: result ? xhr.statusText : "Internal error"
+ name: name,
+ message: message
}
);
} else if (result.error) {
+ name = 'IPA Error ' + (result.error.code || '');
+ message = result.error.message || result.error;
+
+ add_error(command, name, message, text_status);
+
if (command.on_error) command.on_error.call(
this,
xhr,
text_status,
{
- name: 'IPA Error '+result.error.code,
- message: result.error.message
+ name: name,
+ message: message
}
);
@@ -470,6 +501,21 @@ IPA.batch_command = function (spec) {
if (command.on_success) command.on_success.call(this, result, text_status, xhr);
}
}
+ //check for partial errors and show error dialog
+ if(that.partial_success_notify && that.errors.length > 0) {
+ var dialog = IPA.error_dialog({
+ xhr: xhr,
+ text_status: text_status,
+ error_thrown: {
+ name: that.partial_success_message,
+ message: that.partial_success_message
+ },
+ command: that,
+ errors: that.errors,
+ visible_buttons: ['ok']
+ });
+ dialog.open();
+ }
if (that.on_success) that.on_success.call(this, data, text_status, xhr);
},
on_error: function(xhr, text_status, error_thrown) {
@@ -625,6 +671,8 @@ IPA.error_dialog = function(spec) {
that.error_thrown = spec.error_thrown || {};
that.command = spec.command;
that.title = spec.error_thrown.name;
+ that.errors = spec.errors;
+ that.visible_buttons = spec.visible_buttons || ['retry', 'cancel'];
};
that.create = function() {
@@ -637,6 +685,47 @@ IPA.error_dialog = function(spec) {
$('<p/>', {
html: that.error_thrown.message
}).appendTo(that.container);
+
+ if(that.errors && that.errors.length > 0) {
+ //render errors
+ var error_title_div = $('<div />', {
+ 'class': 'error_title'
+ }).appendTo(that.container);
+
+ var show_errors_checkbox = $('<input />', {
+ type: 'checkbox',
+ id: 'show_errors_checkbox',
+ title: 'Show all errors'
+ }).appendTo(error_title_div);
+
+ $('<label />', {
+ 'for': 'show_errors_checkbox',
+ text: 'Show all errors'
+ }).appendTo(error_title_div);
+
+ var errors_container = $('<div />', {
+ 'class' : 'error-container',
+ style : 'display: none'
+ }).appendTo(that.container);
+
+ for(var i=0; i < that.errors.length; i++) {
+ var error = that.errors[i];
+ if(error.message) {
+ var error_div = $('<div />', {
+ 'class': 'error',
+ text: error.message
+ }).appendTo(errors_container);
+ }
+ }
+
+ show_errors_checkbox.click(function() {
+ if(show_errors_checkbox.is(':checked')) {
+ errors_container.show();
+ } else {
+ errors_container.hide();
+ }
+ });
+ }
};
that.create_buttons = function() {
@@ -646,15 +735,25 @@ IPA.error_dialog = function(spec) {
* been loaded yet, so the button labels need default values.
*/
var label = IPA.messages.buttons ? IPA.messages.buttons.retry : 'Retry';
+ if(that.visible_buttons.indexOf('retry') > -1) {
+ that.add_button(label, function() {
+ that.on_retry();
+ });
+ }
- that.add_button(label, function() {
- that.on_retry();
- });
+ if(that.visible_buttons.indexOf('ok') > -1) {
+ label = IPA.messages.buttons ? IPA.messages.buttons.ok : 'OK';
+ that.add_button(label, function() {
+ that.on_ok();
+ });
+ }
- label = IPA.messages.buttons ? IPA.messages.buttons.cancel : 'Cancel';
- that.add_button(label, function() {
- that.on_cancel();
- });
+ if(that.visible_buttons.indexOf('cancel') > -1) {
+ label = IPA.messages.buttons ? IPA.messages.buttons.cancel : 'Cancel';
+ that.add_button(label, function() {
+ that.on_cancel();
+ });
+ }
};
that.on_retry = function() {
@@ -662,6 +761,10 @@ IPA.error_dialog = function(spec) {
that.command.execute();
};
+ that.on_ok = function() {
+ that.close();
+ };
+
that.on_cancel = function() {
that.close();
};
diff --git a/install/ui/search.js b/install/ui/search.js
index fe0b07f72ccae17077cf48732cb4e8d26fdb91b4..a98f11f10646b3ddb31dec1ebbb744d229b5f7ba 100644
--- a/install/ui/search.js
+++ b/install/ui/search.js
@@ -300,7 +300,10 @@ IPA.search_deleter_dialog = function(spec) {
var that = IPA.deleter_dialog(spec);
that.create_command = function() {
- var batch = IPA.batch_command();
+ var batch = IPA.batch_command({
+ partial_success_notify: true,
+ partial_success_message: IPA.messages.search.partial_delete
+ });
var pkeys = that.entity.get_primary_key_prefix();
diff --git a/install/ui/test/data/ipa_init.json b/install/ui/test/data/ipa_init.json
index 659ddfc61d006441a9161e3c5a964730eb452af0..c84f536bab6a0a86506f3ff8b923d504123fc20b 100644
--- a/install/ui/test/data/ipa_init.json
+++ b/install/ui/test/data/ipa_init.json
@@ -16125,6 +16125,7 @@
},
"search": {
"delete_confirm": "Are you sure you want to delete selected entries?",
+ "partial_delete": "Some entries were not deleted",
"quick_links": "Quick Links",
"select_all": "Select All",
"truncated": "Query returned more results than the configured size limit. Displaying the first ${counter} results.",
diff --git a/ipalib/plugins/internal.py b/ipalib/plugins/internal.py
index 0c16841b9e6cc51f555b2be867837275239e45c8..f61fd99c3fefdd3373b12feacae195e397332406 100644
--- a/ipalib/plugins/internal.py
+++ b/ipalib/plugins/internal.py
@@ -369,6 +369,7 @@ class i18n_messages(Command):
"details": _("Settings"),
},
"search": {
+ "partial_delete":_("Some entries were not deleted"),
"quick_links":_("Quick Links"),
"select_all":_("Select All"),
"unselect_all":_("Unselect All"),
--
1.7.6
_______________________________________________
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel