mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
Fixed adding host without DNS reverse zone
https://fedorahosted.org/freeipa/ticket/1481 Shows status dialog instead of error dialog (error 4304 is treated like success). Refactored error dialog. Added generic message dialog (IPA.message_dialog) Modified core tests to work with dialog.
This commit is contained in:
parent
966fbd6485
commit
08905eb9a9
@ -31,6 +31,9 @@ IPA.add_dialog = function (spec) {
|
|||||||
|
|
||||||
that.method = spec.method || 'add';
|
that.method = spec.method || 'add';
|
||||||
that.pre_execute_hook = spec.pre_execute_hook;
|
that.pre_execute_hook = spec.pre_execute_hook;
|
||||||
|
that.on_error = spec.on_error ;
|
||||||
|
that.retry = typeof spec.retry !== 'undefined' ? spec.retry : true;
|
||||||
|
that.command = null;
|
||||||
|
|
||||||
function show_edit_page(entity,result){
|
function show_edit_page(entity,result){
|
||||||
var pkey_name = entity.metadata.primary_key;
|
var pkey_name = entity.metadata.primary_key;
|
||||||
@ -51,9 +54,11 @@ IPA.add_dialog = function (spec) {
|
|||||||
var command = IPA.command({
|
var command = IPA.command({
|
||||||
entity: that.entity.name,
|
entity: that.entity.name,
|
||||||
method: that.method,
|
method: that.method,
|
||||||
|
retry: that.retry,
|
||||||
on_success: on_success,
|
on_success: on_success,
|
||||||
on_error: on_error
|
on_error: on_error
|
||||||
});
|
});
|
||||||
|
that.command = command;
|
||||||
|
|
||||||
pkey_prefix = that.entity.get_primary_key_prefix();
|
pkey_prefix = that.entity.get_primary_key_prefix();
|
||||||
|
|
||||||
@ -127,8 +132,8 @@ IPA.add_dialog = function (spec) {
|
|||||||
var table = facet.table;
|
var table = facet.table;
|
||||||
table.refresh();
|
table.refresh();
|
||||||
that.close();
|
that.close();
|
||||||
}
|
},
|
||||||
);
|
that.on_error);
|
||||||
});
|
});
|
||||||
|
|
||||||
that.add_button(IPA.messages.buttons.add_and_add_another, function() {
|
that.add_button(IPA.messages.buttons.add_and_add_another, function() {
|
||||||
@ -141,8 +146,8 @@ IPA.add_dialog = function (spec) {
|
|||||||
var table = facet.table;
|
var table = facet.table;
|
||||||
table.refresh();
|
table.refresh();
|
||||||
that.reset();
|
that.reset();
|
||||||
}
|
},
|
||||||
);
|
that.on_error);
|
||||||
});
|
});
|
||||||
|
|
||||||
that.add_button(IPA.messages.buttons.add_and_edit, function() {
|
that.add_button(IPA.messages.buttons.add_and_edit, function() {
|
||||||
@ -154,8 +159,8 @@ IPA.add_dialog = function (spec) {
|
|||||||
that.close();
|
that.close();
|
||||||
var result = data.result.result;
|
var result = data.result.result;
|
||||||
that.show_edit_page(that.entity,result);
|
that.show_edit_page(that.entity,result);
|
||||||
}
|
},
|
||||||
);
|
that.on_error);
|
||||||
});
|
});
|
||||||
|
|
||||||
that.add_button(IPA.messages.buttons.cancel, function() {
|
that.add_button(IPA.messages.buttons.cancel, function() {
|
||||||
|
@ -32,6 +32,7 @@ IPA.dialog = function(spec) {
|
|||||||
|
|
||||||
that.entity = spec.entity;
|
that.entity = spec.entity;
|
||||||
that.name = spec.name;
|
that.name = spec.name;
|
||||||
|
that.id = spec.id;
|
||||||
that.title = spec.title;
|
that.title = spec.title;
|
||||||
that.width = spec.width || 400;
|
that.width = spec.width || 400;
|
||||||
that.height = spec.height;
|
that.height = spec.height;
|
||||||
@ -194,7 +195,7 @@ IPA.dialog = function(spec) {
|
|||||||
*/
|
*/
|
||||||
that.open = function(container) {
|
that.open = function(container) {
|
||||||
|
|
||||||
that.container = $('<div/>');
|
that.container = $('<div/>', { id : that.id });
|
||||||
if (container) {
|
if (container) {
|
||||||
container.append(that.container);
|
container.append(that.container);
|
||||||
}
|
}
|
||||||
@ -257,6 +258,7 @@ IPA.dialog = function(spec) {
|
|||||||
|
|
||||||
that.dialog_create = that.create;
|
that.dialog_create = that.create;
|
||||||
that.dialog_open = that.open;
|
that.dialog_open = that.open;
|
||||||
|
that.dialog_close = that.close;
|
||||||
|
|
||||||
var fields = spec.fields || [];
|
var fields = spec.fields || [];
|
||||||
for (var i=0; i<fields.length; i++) {
|
for (var i=0; i<fields.length; i++) {
|
||||||
@ -656,3 +658,31 @@ IPA.deleter_dialog = function (spec) {
|
|||||||
|
|
||||||
return that;
|
return that;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
IPA.message_dialog = function(spec) {
|
||||||
|
|
||||||
|
var that = IPA.dialog(spec);
|
||||||
|
|
||||||
|
var init = function() {
|
||||||
|
spec = spec || {};
|
||||||
|
that.message = spec.message || '';
|
||||||
|
that.on_ok = spec.on_ok;
|
||||||
|
};
|
||||||
|
|
||||||
|
that.create = function() {
|
||||||
|
$('<p/>', {
|
||||||
|
'text': that.message
|
||||||
|
}).appendTo(that.container);
|
||||||
|
};
|
||||||
|
|
||||||
|
that.add_button(IPA.messages.buttons.ok, function() {
|
||||||
|
that.close();
|
||||||
|
if(that.on_ok) {
|
||||||
|
that.on_ok();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
init();
|
||||||
|
|
||||||
|
return that;
|
||||||
|
};
|
||||||
|
@ -102,6 +102,7 @@ IPA.entity_factories.host = function () {
|
|||||||
}).
|
}).
|
||||||
standard_association_facets().
|
standard_association_facets().
|
||||||
adder_dialog({
|
adder_dialog({
|
||||||
|
factory: IPA.host_adder_dialog,
|
||||||
width: 400,
|
width: 400,
|
||||||
height: 250,
|
height: 250,
|
||||||
fields:[
|
fields:[
|
||||||
@ -128,6 +129,47 @@ IPA.entity_factories.host = function () {
|
|||||||
build();
|
build();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
IPA.host_adder_dialog = function(spec)
|
||||||
|
{
|
||||||
|
spec = spec || {};
|
||||||
|
spec.retry = typeof spec.retry !== 'undefined' ? spec.retry : false;
|
||||||
|
|
||||||
|
var that = IPA.add_dialog(spec);
|
||||||
|
|
||||||
|
that.on_error = function(xhr, text_status, error_thrown)
|
||||||
|
{
|
||||||
|
var command = that.command;
|
||||||
|
var data = error_thrown.data;
|
||||||
|
var dialog = null;
|
||||||
|
|
||||||
|
if(data && data.error && data.error.code === 4304) {
|
||||||
|
dialog = IPA.message_dialog({
|
||||||
|
message: data.error.message,
|
||||||
|
title: spec.title,
|
||||||
|
on_ok: function() {
|
||||||
|
data.result = {
|
||||||
|
result: {
|
||||||
|
fqdn: that.get_field('fqdn').save()
|
||||||
|
}
|
||||||
|
};
|
||||||
|
command.on_success(data, text_status, xhr);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
dialog = IPA.error_dialog({
|
||||||
|
xhr: xhr,
|
||||||
|
text_status: text_status,
|
||||||
|
error_thrown: error_thrown,
|
||||||
|
command: command
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
dialog.open(that.container);
|
||||||
|
};
|
||||||
|
|
||||||
|
return that;
|
||||||
|
};
|
||||||
|
|
||||||
IPA.host_deleter_dialog = function(spec) {
|
IPA.host_deleter_dialog = function(spec) {
|
||||||
|
|
||||||
spec = spec || {};
|
spec = spec || {};
|
||||||
|
@ -243,57 +243,13 @@ IPA.command = function(spec) {
|
|||||||
that.execute = function() {
|
that.execute = function() {
|
||||||
|
|
||||||
function dialog_open(xhr, text_status, error_thrown) {
|
function dialog_open(xhr, text_status, error_thrown) {
|
||||||
|
var dialog = IPA.error_dialog({
|
||||||
IPA.error_dialog = $('<div/>', {
|
xhr: xhr,
|
||||||
id: 'error_dialog'
|
text_status: text_status,
|
||||||
});
|
error_thrown: error_thrown,
|
||||||
|
command: that
|
||||||
if (error_thrown.url) {
|
|
||||||
$('<p/>', {
|
|
||||||
text: 'URL: '+error_thrown.url
|
|
||||||
}).appendTo(IPA.error_dialog);
|
|
||||||
}
|
|
||||||
|
|
||||||
$('<p/>', {
|
|
||||||
html: error_thrown.message
|
|
||||||
}).appendTo(IPA.error_dialog);
|
|
||||||
|
|
||||||
function close() {
|
|
||||||
IPA.error_dialog.dialog('destroy');
|
|
||||||
IPA.error_dialog.remove();
|
|
||||||
IPA.error_dialog = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
var buttons = {};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* When a user initially opens the Web UI without a Kerberos
|
|
||||||
* ticket, the messages including the button labels have not
|
|
||||||
* been loaded yet, so the button labels need default values.
|
|
||||||
*/
|
|
||||||
var label = IPA.messages.buttons ? IPA.messages.buttons.retry : 'Retry';
|
|
||||||
buttons[label] = function() {
|
|
||||||
close();
|
|
||||||
that.execute();
|
|
||||||
};
|
|
||||||
|
|
||||||
label = IPA.messages.buttons ? IPA.messages.buttons.cancel : 'Cancel';
|
|
||||||
buttons[label] = function() {
|
|
||||||
close();
|
|
||||||
if (that.on_error) {
|
|
||||||
that.on_error.call(this, xhr, text_status, error_thrown);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
IPA.error_dialog.dialog({
|
|
||||||
modal: true,
|
|
||||||
title: error_thrown.name,
|
|
||||||
width: 400,
|
|
||||||
buttons: buttons,
|
|
||||||
close: function() {
|
|
||||||
close();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
dialog.open();
|
||||||
}
|
}
|
||||||
|
|
||||||
function error_handler(xhr, text_status, error_thrown) {
|
function error_handler(xhr, text_status, error_thrown) {
|
||||||
@ -331,6 +287,7 @@ IPA.command = function(spec) {
|
|||||||
dialog_open.call(this, xhr, text_status, error_thrown);
|
dialog_open.call(this, xhr, text_status, error_thrown);
|
||||||
|
|
||||||
} else if (that.on_error) {
|
} else if (that.on_error) {
|
||||||
|
//custom error handling, maintaining AJAX call's context
|
||||||
that.on_error.call(this, xhr, text_status, error_thrown);
|
that.on_error.call(this, xhr, text_status, error_thrown);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -349,11 +306,13 @@ IPA.command = function(spec) {
|
|||||||
// error_handler() calls IPA.hide_activity_icon()
|
// error_handler() calls IPA.hide_activity_icon()
|
||||||
error_handler.call(this, xhr, text_status, /* error_thrown */ {
|
error_handler.call(this, xhr, text_status, /* error_thrown */ {
|
||||||
name: 'IPA Error '+data.error.code,
|
name: 'IPA Error '+data.error.code,
|
||||||
message: data.error.message
|
message: data.error.message,
|
||||||
|
data: data
|
||||||
});
|
});
|
||||||
|
|
||||||
} else if (that.on_success) {
|
} else if (that.on_success) {
|
||||||
IPA.hide_activity_icon();
|
IPA.hide_activity_icon();
|
||||||
|
//custom success handling, maintaining AJAX call's context
|
||||||
that.on_success.call(this, data, text_status, xhr);
|
that.on_success.call(this, data, text_status, xhr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -610,3 +569,57 @@ IPA.dirty_dialog = function(spec) {
|
|||||||
|
|
||||||
return that;
|
return that;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
IPA.error_dialog = function(spec) {
|
||||||
|
var that = IPA.dialog(spec);
|
||||||
|
|
||||||
|
var init = function() {
|
||||||
|
spec = spec || {};
|
||||||
|
|
||||||
|
that.id = 'error_dialog';
|
||||||
|
that.xhr = spec.xhr || {};
|
||||||
|
that.text_status = spec.text_status || '';
|
||||||
|
that.error_thrown = spec.error_thrown || {};
|
||||||
|
that.command = spec.command;
|
||||||
|
that.title = spec.error_thrown.name;
|
||||||
|
};
|
||||||
|
|
||||||
|
that.create = function() {
|
||||||
|
if (that.error_thrown.url) {
|
||||||
|
$('<p/>', {
|
||||||
|
text: 'URL: '+that.error_thrown.url
|
||||||
|
}).appendTo(that.container);
|
||||||
|
}
|
||||||
|
|
||||||
|
$('<p/>', {
|
||||||
|
html: that.error_thrown.message
|
||||||
|
}).appendTo(that.container);
|
||||||
|
};
|
||||||
|
|
||||||
|
that.create_buttons = function() {
|
||||||
|
/**
|
||||||
|
* When a user initially opens the Web UI without a Kerberos
|
||||||
|
* ticket, the messages including the button labels have not
|
||||||
|
* been loaded yet, so the button labels need default values.
|
||||||
|
*/
|
||||||
|
var label = IPA.messages.buttons ? IPA.messages.buttons.retry : 'Retry';
|
||||||
|
|
||||||
|
that.add_button(label, function() {
|
||||||
|
that.close();
|
||||||
|
that.command.execute();
|
||||||
|
});
|
||||||
|
|
||||||
|
label = IPA.messages.buttons ? IPA.messages.buttons.cancel : 'Cancel';
|
||||||
|
that.add_button(label, function() {
|
||||||
|
that.close();
|
||||||
|
if (that.command.retry && that.command.on_error) {
|
||||||
|
that.command.on_error(that.xhr, that.text_status, that.error_thrown);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
init();
|
||||||
|
that.create_buttons();
|
||||||
|
|
||||||
|
return that;
|
||||||
|
};
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
<script type="text/javascript" src="../jquery-ui.js"></script>
|
<script type="text/javascript" src="../jquery-ui.js"></script>
|
||||||
<script type="text/javascript" src="../jquery.ordered-map.js"></script>
|
<script type="text/javascript" src="../jquery.ordered-map.js"></script>
|
||||||
<script type="text/javascript" src="../ipa.js"></script>
|
<script type="text/javascript" src="../ipa.js"></script>
|
||||||
|
<script type="text/javascript" src="../dialog.js"></script>
|
||||||
<script type="text/javascript" src="ipa_tests.js"></script>
|
<script type="text/javascript" src="ipa_tests.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
@ -162,8 +162,10 @@ test("Testing successful IPA.command().", function() {
|
|||||||
"Checking ajax invocation counter"
|
"Checking ajax invocation counter"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
var dialog = $('#error_dialog');
|
||||||
|
|
||||||
ok(
|
ok(
|
||||||
!IPA.error_dialog,
|
dialog.length == 0,
|
||||||
"The dialog box is not created."
|
"The dialog box is not created."
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -237,7 +239,8 @@ test("Testing unsuccessful IPA.command().", function() {
|
|||||||
on_error: error_handler
|
on_error: error_handler
|
||||||
}).execute();
|
}).execute();
|
||||||
|
|
||||||
var dialog = IPA.error_dialog.parent('.ui-dialog');
|
var dialog = $('#error_dialog');
|
||||||
|
var ui_dialog = dialog.parent('.ui-dialog');
|
||||||
|
|
||||||
equals(
|
equals(
|
||||||
ajax_counter, 1,
|
ajax_counter, 1,
|
||||||
@ -245,7 +248,7 @@ test("Testing unsuccessful IPA.command().", function() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
ok(
|
ok(
|
||||||
dialog.length == 1 && IPA.error_dialog.dialog('isOpen'),
|
ui_dialog.length == 1 && dialog.dialog('isOpen'),
|
||||||
"The dialog box is created and open."
|
"The dialog box is created and open."
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -255,7 +258,7 @@ test("Testing unsuccessful IPA.command().", function() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// search the retry button from the beginning
|
// search the retry button from the beginning
|
||||||
var retry = $('button', dialog).first();
|
var retry = $('button', ui_dialog).first();
|
||||||
retry.trigger('click');
|
retry.trigger('click');
|
||||||
|
|
||||||
equals(
|
equals(
|
||||||
@ -270,8 +273,8 @@ test("Testing unsuccessful IPA.command().", function() {
|
|||||||
|
|
||||||
// search the retry button from the beginning again because the dialog
|
// search the retry button from the beginning again because the dialog
|
||||||
// has been recreated
|
// has been recreated
|
||||||
dialog = IPA.error_dialog.parent('.ui-dialog');
|
ui_dialog = $('#error_dialog').parent('.ui-dialog');
|
||||||
retry = $('button', dialog).first();
|
retry = $('button', ui_dialog).first();
|
||||||
retry.trigger('click');
|
retry.trigger('click');
|
||||||
|
|
||||||
equals(
|
equals(
|
||||||
@ -286,8 +289,8 @@ test("Testing unsuccessful IPA.command().", function() {
|
|||||||
|
|
||||||
// search the cancel button from the beginning because the dialog has
|
// search the cancel button from the beginning because the dialog has
|
||||||
// been recreated
|
// been recreated
|
||||||
dialog = IPA.error_dialog.parent('.ui-dialog');
|
ui_dialog = $('#error_dialog').parent('.ui-dialog');
|
||||||
var cancel = $('button', dialog).first().next();
|
var cancel = $('button', ui_dialog).first().next();
|
||||||
cancel.trigger('click');
|
cancel.trigger('click');
|
||||||
|
|
||||||
equals(
|
equals(
|
||||||
@ -295,8 +298,10 @@ test("Testing unsuccessful IPA.command().", function() {
|
|||||||
"Checking ajax invocation counter"
|
"Checking ajax invocation counter"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
dialog = $('#error_dialog');
|
||||||
|
|
||||||
ok(
|
ok(
|
||||||
!IPA.error_dialog,
|
dialog.length == 0,
|
||||||
"After cancel, the dialog box is closed."
|
"After cancel, the dialog box is closed."
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user