diff --git a/install/ui/ipa.js b/install/ui/ipa.js index 8a3dd4e7d..9a252f1e5 100644 --- a/install/ui/ipa.js +++ b/install/ui/ipa.js @@ -417,6 +417,11 @@ IPA.batch_command = function (spec) { var that = IPA.command(spec); that.commands = []; + that.errors = []; + 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' ? + true : spec.show_error; that.add_command = function(command) { that.commands.push(command); @@ -429,7 +434,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 +463,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 +502,22 @@ 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.show_error && that.errors.length > 0) { + var dialog = IPA.error_dialog({ + xhr: xhr, + text_status: text_status, + error_thrown: { + name: IPA.messages.dialogs ? IPA.messages.dialogs.batch_error_title : + 'Operations Error', + message: that.error_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 +673,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 +687,54 @@ IPA.error_dialog = function(spec) { $('

', { html: that.error_thrown.message }).appendTo(that.container); + + if(that.errors && that.errors.length > 0) { + //render errors + var errors_title_div = $('

', { + 'class': 'errors_title' + }).appendTo(that.container); + + var show_details = $('', { + href: '#', + title: IPA.messages.dialogs.show_details, + text: IPA.messages.dialogs.show_details + }).appendTo(errors_title_div); + + var hide_details = $('', { + href: '#', + title: IPA.messages.dialogs.hide_details, + text: IPA.messages.dialogs.hide_details, + style : 'display: none' + }).appendTo(errors_title_div); + + var errors_container = $('