summaryrefslogtreecommitdiffstats
path: root/install
diff options
context:
space:
mode:
authorPetr Vobornik <pvoborni@redhat.com>2011-08-17 15:06:41 +0200
committerEndi S. Dewata <edewata@redhat.com>2011-08-24 15:10:01 +0000
commit37cef6f60d41d462ab08fa2fa97b33047948bdcf (patch)
tree6f899b6fa8b9622d21174ace3ae407ba01205fd4 /install
parentbe7de56e5d403fb97bcb583f6b7b5dd7e3fb914c (diff)
downloadfreeipa-37cef6f60d41d462ab08fa2fa97b33047948bdcf.tar.gz
freeipa-37cef6f60d41d462ab08fa2fa97b33047948bdcf.tar.xz
freeipa-37cef6f60d41d462ab08fa2fa97b33047948bdcf.zip
Show error in adding associations
https://fedorahosted.org/freeipa/ticket/1628
Diffstat (limited to 'install')
-rw-r--r--install/ui/ipa.js112
-rw-r--r--install/ui/test/association_tests.js4
2 files changed, 93 insertions, 23 deletions
diff --git a/install/ui/ipa.js b/install/ui/ipa.js
index 9a252f1e5..c6c8ef2fe 100644
--- a/install/ui/ipa.js
+++ b/install/ui/ipa.js
@@ -331,6 +331,7 @@ IPA.command = function(spec) {
}
function success_handler(data, text_status, xhr) {
+ var failed;
if (!data) {
// error_handler() calls IPA.hide_activity_icon()
@@ -347,7 +348,18 @@ IPA.command = function(spec) {
message: data.error.message,
data: data
});
+ } else if ((failed = that.get_failed(that, data.result, text_status, xhr)) &&
+ !failed.is_empty()) {
+ var message = failed.errors[0].message;
+ for(var i = 1; i < failed.errors.length; i++) {
+ message += '\n' + failed.errors[i].message;
+ }
+ error_handler.call(this, xhr, text_status, /* error_thrown */ {
+ name: failed.errors[0].name,
+ message: message,
+ data: data
+ });
} else if (that.on_success) {
IPA.hide_activity_icon();
//custom success handling, maintaining AJAX call's context
@@ -379,6 +391,27 @@ IPA.command = function(spec) {
$.ajax(request);
};
+ that.get_failed = function(command, result, text_status, xhr) {
+ var errors = IPA.error_list();
+ if(result && result.failed) {
+ for(var association in result.failed) {
+ for(var member_name in result.failed[association]) {
+ var member = result.failed[association][member_name];
+ for(var i = 0; i < member.length; i++) {
+ if(member[i].length > 1) {
+ var name = 'IPA Error';
+ var message = member[i][1];
+ if(member[i][0])
+ message = member[i][0] + ': ' + message;
+ errors.add(command, name, message, text_status);
+ }
+ }
+ }
+ }
+ }
+ return errors;
+ };
+
that.to_json = function() {
var json = {};
@@ -417,7 +450,7 @@ IPA.batch_command = function (spec) {
var that = IPA.command(spec);
that.commands = [];
- that.errors = [];
+ that.errors = IPA.error_list();
that.error_message = spec.error_message || (IPA.messages.dialogs ?
IPA.messages.dialogs.batch_error_message : 'Some operations failed.');
that.show_error = typeof spec.show_error == 'undefined' ?
@@ -434,21 +467,8 @@ 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();
+ that.errors.clear();
IPA.command({
name: that.name,
@@ -465,12 +485,13 @@ IPA.batch_command = function (spec) {
var name = '';
var message = '';
+ var failed;
if (!result) {
name = 'Internal Error '+xhr.status;
message = result ? xhr.statusText : "Internal error";
- add_error(command, name, message, text_status);
+ that.errors.add(command, name, message, text_status);
if (command.on_error) command.on_error.call(
this,
@@ -486,7 +507,7 @@ IPA.batch_command = function (spec) {
name = 'IPA Error ' + (result.error.code || '');
message = result.error.message || result.error;
- add_error(command, name, message, text_status);
+ that.errors.add(command, name, message, text_status);
if (command.on_error) command.on_error.call(
this,
@@ -494,7 +515,28 @@ IPA.batch_command = function (spec) {
text_status,
{
name: name,
- message: message
+ message: message,
+ data: result
+ }
+ );
+
+ } else if ((failed = that.get_failed(command, result, text_status, xhr)) &&
+ !failed.is_empty()) {
+ that.errors.add_range(failed);
+
+ message = failed.errors[0].message;
+ for(var j = 1; j < failed.errors.length; j++) {
+ message += '\n' + failed.errors[j].message;
+ }
+
+ if (command.on_error) command.on_error.call(
+ this,
+ xhr,
+ text_status,
+ {
+ name: failed.errors[0].name,
+ message: message,
+ data: result
}
);
@@ -503,7 +545,7 @@ IPA.batch_command = function (spec) {
}
}
//check for partial errors and show error dialog
- if(that.show_error && that.errors.length > 0) {
+ if(that.show_error && that.errors.errors.length > 0) {
var dialog = IPA.error_dialog({
xhr: xhr,
text_status: text_status,
@@ -513,7 +555,7 @@ IPA.batch_command = function (spec) {
message: that.error_message
},
command: that,
- errors: that.errors,
+ errors: that.errors.errors,
visible_buttons: ['ok']
});
dialog.open();
@@ -685,7 +727,7 @@ IPA.error_dialog = function(spec) {
}
$('<p/>', {
- html: that.error_thrown.message
+ html: that.error_thrown.message.replace('\n', '<br />')
}).appendTo(that.container);
if(that.errors && that.errors.length > 0) {
@@ -785,3 +827,31 @@ IPA.error_dialog = function(spec) {
return that;
};
+
+IPA.error_list = function() {
+ var that = {};
+
+ that.clear = function() {
+ that.errors = [];
+ };
+
+ that.add = function(command, name, message, status) {
+ that.errors.push({
+ command: command,
+ name: name,
+ message: message,
+ status: status
+ });
+ };
+
+ that.add_range = function(error_list) {
+ that.errors = that.errors.concat(error_list.errors);
+ };
+
+ that.is_empty = function () {
+ return that.errors.length === 0;
+ };
+
+ that.clear();
+ return that;
+};
diff --git a/install/ui/test/association_tests.js b/install/ui/test/association_tests.js
index 769355ae8..1cdc17ccb 100644
--- a/install/ui/test/association_tests.js
+++ b/install/ui/test/association_tests.js
@@ -60,7 +60,7 @@ test("Testing serial_associator().", function() {
'Checking IPA.command() parameter: primary key'
);
- that.on_success();
+ that.on_success({});
};
return that;
@@ -115,7 +115,7 @@ test("Testing bulk_associator().", function() {
'Checking IPA.command() parameter: options[\""+params.other_entity+"\"]'
);
- that.on_success();
+ that.on_success({});
};
return that;