2011-05-16 22:23:20 -05:00
|
|
|
/*jsl:import jquery.ordered-map.js */
|
2010-08-06 09:01:44 -05:00
|
|
|
/* Authors:
|
|
|
|
* Pavel Zuna <pzuna@redhat.com>
|
2011-01-14 11:16:25 -06:00
|
|
|
* Adam Young <ayoung@redhat.com>
|
|
|
|
* Endi Dewata <edewata@redhat.com>
|
2010-08-06 09:01:44 -05:00
|
|
|
*
|
|
|
|
* Copyright (C) 2010 Red Hat
|
|
|
|
* see file 'COPYING' for use and warranty information
|
|
|
|
*
|
2010-12-09 06:59:11 -06:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
2010-08-06 09:01:44 -05:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2010-12-09 06:59:11 -06:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2010-08-06 09:01:44 -05:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
2011-05-16 22:23:20 -05:00
|
|
|
/* REQUIRES: jquery.ordered-map.js */
|
2010-11-01 15:32:07 -05:00
|
|
|
/*global $:true, location:true */
|
2010-08-06 09:01:44 -05:00
|
|
|
|
2010-11-01 15:32:07 -05:00
|
|
|
var IPA = ( function () {
|
2010-08-06 09:01:44 -05:00
|
|
|
|
2010-11-01 15:32:07 -05:00
|
|
|
var that = {
|
|
|
|
jsonrpc_id: 0
|
|
|
|
};
|
2010-09-16 09:28:07 -05:00
|
|
|
|
2010-10-27 22:32:30 -05:00
|
|
|
that.use_static_files = false;
|
2010-11-15 12:20:07 -06:00
|
|
|
that.json_url = '/ipa/json';
|
|
|
|
if (that.use_static_files){
|
2011-01-12 13:47:29 -06:00
|
|
|
that.json_url = 'test/data';
|
2010-11-15 12:20:07 -06:00
|
|
|
}
|
|
|
|
|
2010-10-27 22:32:30 -05:00
|
|
|
that.ajax_options = {
|
|
|
|
type: 'POST',
|
|
|
|
contentType: 'application/json',
|
|
|
|
dataType: 'json',
|
|
|
|
async: true,
|
|
|
|
processData: false
|
|
|
|
};
|
|
|
|
|
|
|
|
that.metadata = {};
|
2011-02-16 12:46:59 -06:00
|
|
|
that.messages = {};
|
2010-11-17 21:15:09 -06:00
|
|
|
that.whoami = {};
|
|
|
|
|
2011-05-16 22:23:20 -05:00
|
|
|
that.entities = $.ordered_map();
|
2011-01-19 20:10:18 -06:00
|
|
|
that.entity_factories = {};
|
|
|
|
|
HBAC Details Page
The UI framework has been extended to include a collection of widgets:
- ipa_widget: base class
- ipa_text_widget: text field
- ipa_radio_widget: radio button
- ipa_textarea_widget: textarea
- ipa_button_widget: button
- ipa_column_widget: column for table
- ipa_table_widget: table
These widgets can be used to create input controls. They can also be
extended to create custom controls.
The framework has also been enhanced to support custom layouts. This
can be used to change the look of the application without changing
the code. Initially this is only available in details section.
Layout consists of a collection of HTML templates. Each template is a
complete and valid HTML file representing a portion of a page. The
template will be loaded and initialized by the code, then filled with
the data from the server. The layouts are located in
install/static/layouts/<name> folder.
By default, if no templates are used, the fields in the details page
are rendered vertically using dd/dt/dd tags. For pages that require
different layout, a custom UI needs to be developed. There are two ways
to do that:
- write a custom widget to generate the UI dynamically
- create an HTML template and write the initialization code
For components that are quite complex or used frequently, it's might
be better to use the first method. For simple pages that are used only
in one location or need to support customization, the second method
might be preferable. Other benefits of templates:
- cleaner code and UI separation
- more flexibility in customization
- new pages can be developed quickly and require less coding
- multiple templates can be used with the same initialization code
- easier to maintain
The HBAC details page has been implemented using both methods. By
default it will use custom widgets to generate the page. To use a
custom layout, add the following parameter to the URL, then reload
the page:
&layout=<name>
Currently the only available layout is 'default' which produces the
same look as the custom widgets.
The HBAC details page is usable, but it still needs additional work.
The access time is not working yet. There is no undo button, hint,
or validation yet.
The table in the association facet has also been changed to use
ipa_association_widget which is derived from ipa_table_widget.
The Makefile has been updated to include the layouts. The unit tests
have been updated as well.
2010-11-02 20:16:55 -05:00
|
|
|
that.layout = $.bbq.getState('layout');
|
|
|
|
that.layouts_dir = 'layouts';
|
|
|
|
|
2011-04-12 02:13:30 -05:00
|
|
|
that.network_call_count = 0;
|
|
|
|
|
HBAC Details Page
The UI framework has been extended to include a collection of widgets:
- ipa_widget: base class
- ipa_text_widget: text field
- ipa_radio_widget: radio button
- ipa_textarea_widget: textarea
- ipa_button_widget: button
- ipa_column_widget: column for table
- ipa_table_widget: table
These widgets can be used to create input controls. They can also be
extended to create custom controls.
The framework has also been enhanced to support custom layouts. This
can be used to change the look of the application without changing
the code. Initially this is only available in details section.
Layout consists of a collection of HTML templates. Each template is a
complete and valid HTML file representing a portion of a page. The
template will be loaded and initialized by the code, then filled with
the data from the server. The layouts are located in
install/static/layouts/<name> folder.
By default, if no templates are used, the fields in the details page
are rendered vertically using dd/dt/dd tags. For pages that require
different layout, a custom UI needs to be developed. There are two ways
to do that:
- write a custom widget to generate the UI dynamically
- create an HTML template and write the initialization code
For components that are quite complex or used frequently, it's might
be better to use the first method. For simple pages that are used only
in one location or need to support customization, the second method
might be preferable. Other benefits of templates:
- cleaner code and UI separation
- more flexibility in customization
- new pages can be developed quickly and require less coding
- multiple templates can be used with the same initialization code
- easier to maintain
The HBAC details page has been implemented using both methods. By
default it will use custom widgets to generate the page. To use a
custom layout, add the following parameter to the URL, then reload
the page:
&layout=<name>
Currently the only available layout is 'default' which produces the
same look as the custom widgets.
The HBAC details page is usable, but it still needs additional work.
The access time is not working yet. There is no undo button, hint,
or validation yet.
The table in the association facet has also been changed to use
ipa_association_widget which is derived from ipa_table_widget.
The Makefile has been updated to include the layouts. The unit tests
have been updated as well.
2010-11-02 20:16:55 -05:00
|
|
|
that.get_template = function(path) {
|
2010-12-02 22:12:59 -06:00
|
|
|
var layout = that.layout || 'default';
|
|
|
|
return that.layouts_dir+'/'+layout+'/'+path;
|
HBAC Details Page
The UI framework has been extended to include a collection of widgets:
- ipa_widget: base class
- ipa_text_widget: text field
- ipa_radio_widget: radio button
- ipa_textarea_widget: textarea
- ipa_button_widget: button
- ipa_column_widget: column for table
- ipa_table_widget: table
These widgets can be used to create input controls. They can also be
extended to create custom controls.
The framework has also been enhanced to support custom layouts. This
can be used to change the look of the application without changing
the code. Initially this is only available in details section.
Layout consists of a collection of HTML templates. Each template is a
complete and valid HTML file representing a portion of a page. The
template will be loaded and initialized by the code, then filled with
the data from the server. The layouts are located in
install/static/layouts/<name> folder.
By default, if no templates are used, the fields in the details page
are rendered vertically using dd/dt/dd tags. For pages that require
different layout, a custom UI needs to be developed. There are two ways
to do that:
- write a custom widget to generate the UI dynamically
- create an HTML template and write the initialization code
For components that are quite complex or used frequently, it's might
be better to use the first method. For simple pages that are used only
in one location or need to support customization, the second method
might be preferable. Other benefits of templates:
- cleaner code and UI separation
- more flexibility in customization
- new pages can be developed quickly and require less coding
- multiple templates can be used with the same initialization code
- easier to maintain
The HBAC details page has been implemented using both methods. By
default it will use custom widgets to generate the page. To use a
custom layout, add the following parameter to the URL, then reload
the page:
&layout=<name>
Currently the only available layout is 'default' which produces the
same look as the custom widgets.
The HBAC details page is usable, but it still needs additional work.
The access time is not working yet. There is no undo button, hint,
or validation yet.
The table in the association facet has also been changed to use
ipa_association_widget which is derived from ipa_table_widget.
The Makefile has been updated to include the layouts. The unit tests
have been updated as well.
2010-11-02 20:16:55 -05:00
|
|
|
};
|
|
|
|
|
2010-10-27 22:32:30 -05:00
|
|
|
/* initialize the IPA JSON-RPC helper
|
|
|
|
* arguments:
|
|
|
|
* url - JSON-RPC URL to use (optional) */
|
2010-11-01 15:32:07 -05:00
|
|
|
that.init = function (url, use_static_files, on_success, on_error) {
|
|
|
|
if (url) {
|
2010-10-27 22:32:30 -05:00
|
|
|
that.json_url = url;
|
2010-11-01 15:32:07 -05:00
|
|
|
}
|
2010-10-27 22:32:30 -05:00
|
|
|
|
2010-11-01 15:32:07 -05:00
|
|
|
if (use_static_files) {
|
2010-10-27 22:32:30 -05:00
|
|
|
that.use_static_files = use_static_files;
|
2010-11-01 15:32:07 -05:00
|
|
|
}
|
2010-10-27 22:32:30 -05:00
|
|
|
|
|
|
|
$.ajaxSetup(that.ajax_options);
|
|
|
|
|
2011-04-12 02:13:30 -05:00
|
|
|
var batch = IPA.batch_command({
|
|
|
|
name: 'ipa_init',
|
|
|
|
on_success: on_success,
|
|
|
|
on_error: on_error
|
|
|
|
});
|
2010-11-17 21:15:09 -06:00
|
|
|
|
2011-04-12 02:13:30 -05:00
|
|
|
batch.add_command(IPA.command({
|
|
|
|
method: 'json_metadata',
|
|
|
|
on_success: function(data, text_status, xhr) {
|
|
|
|
that.metadata = data;
|
|
|
|
}
|
|
|
|
}));
|
2010-11-17 21:15:09 -06:00
|
|
|
|
2011-04-12 02:13:30 -05:00
|
|
|
batch.add_command(IPA.command({
|
|
|
|
method: 'i18n_messages',
|
|
|
|
on_success: function(data, text_status, xhr) {
|
|
|
|
that.messages = data.messages;
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
|
|
|
|
batch.add_command(IPA.command({
|
|
|
|
entity: 'user',
|
|
|
|
method: 'find',
|
|
|
|
options: {
|
|
|
|
whoami: true,
|
|
|
|
all: true
|
|
|
|
},
|
|
|
|
on_success: function(data, text_status, xhr) {
|
|
|
|
that.whoami = data.result[0];
|
|
|
|
}
|
|
|
|
}));
|
2010-11-17 21:15:09 -06:00
|
|
|
|
2011-04-12 02:13:30 -05:00
|
|
|
batch.add_command(IPA.command({
|
|
|
|
method: 'env',
|
|
|
|
on_success: function(data, text_status, xhr) {
|
|
|
|
that.env = data.result;
|
|
|
|
}
|
|
|
|
}));
|
2011-02-16 12:46:59 -06:00
|
|
|
|
2011-04-12 02:13:30 -05:00
|
|
|
batch.add_command(IPA.command({
|
|
|
|
entity: 'dns',
|
|
|
|
method: 'is_enabled',
|
|
|
|
on_success: function(data, text_status, xhr) {
|
|
|
|
that.dns_enabled = data.result;
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
|
|
|
|
batch.execute();
|
2010-10-27 22:32:30 -05:00
|
|
|
};
|
|
|
|
|
2011-04-28 19:17:58 -05:00
|
|
|
that.get_entities = function() {
|
2011-05-16 22:23:20 -05:00
|
|
|
return that.entities.values;
|
2010-10-27 22:32:30 -05:00
|
|
|
};
|
|
|
|
|
2011-04-28 19:17:58 -05:00
|
|
|
that.get_entity = function(name) {
|
2011-05-23 09:39:09 -05:00
|
|
|
var entity = that.entities.get(name);
|
|
|
|
if (!entity){
|
|
|
|
var factory = that.entity_factories[name];
|
2011-04-20 19:11:10 -05:00
|
|
|
try {
|
2011-05-23 09:39:09 -05:00
|
|
|
entity = factory();
|
2011-04-20 19:11:10 -05:00
|
|
|
that.add_entity(entity);
|
2011-04-11 13:49:36 -05:00
|
|
|
entity.init();
|
2011-04-20 19:11:10 -05:00
|
|
|
} catch (e) {
|
|
|
|
/*exceptions thrown by builder just mean that entities
|
2011-04-11 13:49:36 -05:00
|
|
|
are not to be registered. */
|
2011-05-23 09:39:09 -05:00
|
|
|
return null;
|
2011-04-11 13:49:36 -05:00
|
|
|
}
|
2011-01-19 20:10:18 -06:00
|
|
|
}
|
2011-05-23 09:39:09 -05:00
|
|
|
return entity;
|
|
|
|
};
|
|
|
|
|
|
|
|
that.add_entity = function(entity) {
|
|
|
|
that.entities.put(entity.name, entity);
|
|
|
|
};
|
|
|
|
|
|
|
|
that.remove_entity = function(name) {
|
|
|
|
that.entities.remove(name);
|
2011-01-19 20:10:18 -06:00
|
|
|
};
|
2010-11-15 15:41:21 -06:00
|
|
|
|
2011-01-26 19:58:06 -06:00
|
|
|
that.test_dirty = function(){
|
|
|
|
if (IPA.current_entity){
|
|
|
|
var facet_name = IPA.current_facet(IPA.current_entity);
|
2011-04-11 13:49:36 -05:00
|
|
|
var facet = IPA.current_entity.get_facet(facet_name);
|
2011-05-06 16:04:09 -05:00
|
|
|
if (!facet) return false;
|
2011-03-04 15:05:02 -06:00
|
|
|
|
2011-01-26 19:58:06 -06:00
|
|
|
if (facet.is_dirty()){
|
2011-02-21 18:36:42 -06:00
|
|
|
|
2011-03-04 15:05:02 -06:00
|
|
|
var dialog = IPA.dialog({
|
|
|
|
title: IPA.messages.dialogs.dirty_title,
|
|
|
|
width: '20em'
|
|
|
|
});
|
2011-02-21 18:36:42 -06:00
|
|
|
|
2011-03-04 15:05:02 -06:00
|
|
|
dialog.create = function() {
|
|
|
|
dialog.container.append(IPA.messages.dialogs.dirty_message);
|
2011-02-21 18:36:42 -06:00
|
|
|
};
|
|
|
|
|
2011-03-04 15:05:02 -06:00
|
|
|
dialog.add_button(IPA.messages.buttons.ok, function() {
|
|
|
|
dialog.close();
|
2011-01-26 19:58:06 -06:00
|
|
|
});
|
2011-03-04 15:05:02 -06:00
|
|
|
|
|
|
|
dialog.init();
|
|
|
|
|
|
|
|
dialog.open($('#navigation'));
|
|
|
|
|
2011-01-26 19:58:06 -06:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
2011-01-27 19:30:22 -06:00
|
|
|
};
|
2011-01-26 19:58:06 -06:00
|
|
|
|
2011-04-12 02:13:30 -05:00
|
|
|
that.display_activity_icon = function() {
|
|
|
|
that.network_call_count++;
|
2011-04-28 19:17:58 -05:00
|
|
|
$('.network-activity-indicator').css('visibility', 'visible');
|
2011-04-12 02:13:30 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
that.hide_activity_icon = function() {
|
|
|
|
that.network_call_count--;
|
|
|
|
|
|
|
|
if (0 === that.network_call_count) {
|
2011-04-28 19:17:58 -05:00
|
|
|
$('.network-activity-indicator').css('visibility', 'hidden');
|
2011-04-12 02:13:30 -05:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-10-27 22:32:30 -05:00
|
|
|
return that;
|
2010-11-01 15:32:07 -05:00
|
|
|
}());
|
2010-08-06 09:01:44 -05:00
|
|
|
|
2011-04-12 02:13:30 -05:00
|
|
|
/**
|
|
|
|
* Call an IPA command over JSON-RPC.
|
|
|
|
*
|
|
|
|
* Arguments:
|
|
|
|
* name - command name (optional)
|
|
|
|
* entity - command entity (optional)
|
|
|
|
* method - command method
|
|
|
|
* args - list of arguments, e.g. [username]
|
|
|
|
* options - dict of options, e.g. {givenname: 'Pavel'}
|
|
|
|
* on_success - callback function if command succeeds
|
|
|
|
* on_error - callback function if command fails
|
|
|
|
*/
|
2011-02-16 12:46:59 -06:00
|
|
|
IPA.command = function(spec) {
|
2010-11-04 21:42:37 -05:00
|
|
|
|
|
|
|
spec = spec || {};
|
|
|
|
|
|
|
|
var that = {};
|
2010-11-15 11:10:55 -06:00
|
|
|
|
2010-11-18 20:59:08 -06:00
|
|
|
that.name = spec.name;
|
2011-04-12 02:13:30 -05:00
|
|
|
|
|
|
|
that.entity = spec.entity;
|
2010-11-04 21:42:37 -05:00
|
|
|
that.method = spec.method;
|
|
|
|
|
2010-11-15 11:10:55 -06:00
|
|
|
that.args = $.merge([], spec.args || []);
|
|
|
|
that.options = $.extend({}, spec.options || {});
|
2010-11-04 21:42:37 -05:00
|
|
|
|
2010-11-15 11:10:55 -06:00
|
|
|
that.on_success = spec.on_success;
|
|
|
|
that.on_error = spec.on_error;
|
2010-11-04 21:42:37 -05:00
|
|
|
|
2011-04-11 20:22:38 -05:00
|
|
|
that.retry = typeof spec.retry == 'undefined' ? true : spec.retry;
|
|
|
|
|
2011-04-12 02:13:30 -05:00
|
|
|
that.get_command = function() {
|
|
|
|
return (that.entity ? that.entity+'_' : '') + that.method;
|
|
|
|
};
|
|
|
|
|
2010-11-15 11:10:55 -06:00
|
|
|
that.add_arg = function(arg) {
|
|
|
|
that.args.push(arg);
|
2010-11-04 21:42:37 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
that.set_option = function(name, value) {
|
2010-11-15 11:10:55 -06:00
|
|
|
that.options[name] = value;
|
2010-11-04 21:42:37 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
that.get_option = function(name) {
|
2010-11-15 11:10:55 -06:00
|
|
|
return that.options[name];
|
2010-11-04 21:42:37 -05:00
|
|
|
};
|
|
|
|
|
2010-11-15 11:10:55 -06:00
|
|
|
that.execute = function() {
|
2011-04-12 02:13:30 -05:00
|
|
|
|
|
|
|
function dialog_open(xhr, text_status, error_thrown) {
|
|
|
|
|
|
|
|
IPA.error_dialog = $('<div/>', {
|
|
|
|
id: 'error_dialog'
|
|
|
|
});
|
|
|
|
|
|
|
|
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,
|
2011-05-20 11:27:58 -05:00
|
|
|
title: error_thrown.name,
|
2011-04-12 02:13:30 -05:00
|
|
|
width: 400,
|
|
|
|
buttons: buttons,
|
|
|
|
close: function() {
|
|
|
|
close();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function error_handler(xhr, text_status, error_thrown) {
|
|
|
|
|
|
|
|
IPA.hide_activity_icon();
|
|
|
|
|
|
|
|
if (!error_thrown) {
|
|
|
|
error_thrown = {
|
|
|
|
name: xhr.responseText || 'Unknown Error',
|
|
|
|
message: xhr.statusText || 'Unknown Error'
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (xhr.status === 401) {
|
2011-04-28 19:17:58 -05:00
|
|
|
error_thrown = {}; // error_thrown is string
|
2011-04-12 02:13:30 -05:00
|
|
|
error_thrown.name = 'Kerberos ticket no longer valid.';
|
|
|
|
if (IPA.messages && IPA.messages.ajax) {
|
|
|
|
error_thrown.message = IPA.messages.ajax["401"];
|
|
|
|
} else {
|
|
|
|
error_thrown.message =
|
|
|
|
"Your kerberos ticket is no longer valid. "+
|
|
|
|
"Please run kinit and then click 'Retry'. "+
|
|
|
|
"If this is your first time running the IPA Web UI "+
|
|
|
|
"<a href='/ipa/config/unauthorized.html'>"+
|
|
|
|
"follow these directions</a> to configure your browser.";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-11 20:22:38 -05:00
|
|
|
if (that.retry) {
|
|
|
|
dialog_open.call(this, xhr, text_status, error_thrown);
|
|
|
|
|
|
|
|
} else if (that.on_error) {
|
|
|
|
that.on_error.call(this, xhr, text_status, error_thrown);
|
|
|
|
}
|
2011-04-12 02:13:30 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
function success_handler(data, text_status, xhr) {
|
|
|
|
|
|
|
|
if (!data) {
|
2011-04-11 20:22:38 -05:00
|
|
|
IPA.hide_activity_icon();
|
2011-04-12 02:13:30 -05:00
|
|
|
var error_thrown = {
|
2011-05-20 11:27:58 -05:00
|
|
|
name: 'HTTP Error '+xhr.status,
|
2011-04-12 02:13:30 -05:00
|
|
|
url: this.url,
|
|
|
|
message: data ? xhr.statusText : "No response"
|
|
|
|
};
|
|
|
|
dialog_open.call(this, xhr, text_status, error_thrown);
|
|
|
|
|
|
|
|
} else if (data.error) {
|
2011-04-11 20:22:38 -05:00
|
|
|
// error_handler() calls IPA.hide_activity_icon()
|
2011-04-12 02:13:30 -05:00
|
|
|
error_handler.call(this, xhr, text_status, /* error_thrown */ {
|
2011-05-20 11:27:58 -05:00
|
|
|
name: 'IPA Error '+data.error.code,
|
2011-04-12 02:13:30 -05:00
|
|
|
message: data.error.message
|
|
|
|
});
|
|
|
|
|
|
|
|
} else if (that.on_success) {
|
2011-04-11 20:22:38 -05:00
|
|
|
IPA.hide_activity_icon();
|
2011-04-12 02:13:30 -05:00
|
|
|
that.on_success.call(this, data, text_status, xhr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var url = IPA.json_url;
|
|
|
|
|
|
|
|
var command = that.get_command();
|
|
|
|
|
|
|
|
if (IPA.use_static_files) {
|
|
|
|
url += '/' + (that.name ? that.name : command) + '.json';
|
|
|
|
}
|
|
|
|
|
|
|
|
var data = {
|
|
|
|
method: command,
|
|
|
|
params: [that.args, that.options]
|
|
|
|
};
|
|
|
|
|
|
|
|
var request = {
|
|
|
|
url: url,
|
|
|
|
data: JSON.stringify(data),
|
|
|
|
success: success_handler,
|
|
|
|
error: error_handler
|
|
|
|
};
|
|
|
|
|
|
|
|
IPA.display_activity_icon();
|
|
|
|
$.ajax(request);
|
2010-11-04 21:42:37 -05:00
|
|
|
};
|
|
|
|
|
2010-11-15 11:10:55 -06:00
|
|
|
that.to_json = function() {
|
|
|
|
var json = {};
|
|
|
|
|
2011-04-12 02:13:30 -05:00
|
|
|
json.method = that.get_command();
|
2010-11-15 11:10:55 -06:00
|
|
|
|
|
|
|
json.params = [];
|
|
|
|
json.params[0] = that.args || [];
|
|
|
|
json.params[1] = that.options || {};
|
|
|
|
|
|
|
|
return json;
|
|
|
|
};
|
|
|
|
|
2010-11-04 21:42:37 -05:00
|
|
|
that.to_string = function() {
|
2011-04-12 02:13:30 -05:00
|
|
|
var string = that.get_command().replace(/_/g, '-');
|
2010-11-04 21:42:37 -05:00
|
|
|
|
2010-11-15 11:10:55 -06:00
|
|
|
for (var i=0; i<that.args.length; i++) {
|
|
|
|
string += ' '+that.args[i];
|
2010-11-04 21:42:37 -05:00
|
|
|
}
|
|
|
|
|
2010-11-15 11:10:55 -06:00
|
|
|
for (var name in that.options) {
|
|
|
|
string += ' --'+name+'=\''+that.options[name]+'\'';
|
2010-11-04 21:42:37 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return string;
|
|
|
|
};
|
|
|
|
|
|
|
|
return that;
|
2011-01-14 11:16:25 -06:00
|
|
|
};
|
|
|
|
|
2011-01-12 18:51:22 -06:00
|
|
|
IPA.batch_command = function (spec) {
|
2010-11-04 21:42:37 -05:00
|
|
|
|
|
|
|
spec = spec || {};
|
|
|
|
|
|
|
|
spec.method = 'batch';
|
|
|
|
|
2011-01-12 18:51:22 -06:00
|
|
|
var that = IPA.command(spec);
|
2010-11-04 21:42:37 -05:00
|
|
|
|
2010-11-15 11:10:55 -06:00
|
|
|
that.commands = [];
|
|
|
|
|
2010-11-04 21:42:37 -05:00
|
|
|
that.add_command = function(command) {
|
2010-11-15 11:10:55 -06:00
|
|
|
that.commands.push(command);
|
|
|
|
that.add_arg(command.to_json());
|
|
|
|
};
|
|
|
|
|
|
|
|
that.add_commands = function(commands) {
|
|
|
|
for (var i=0; i<commands.length; i++) {
|
|
|
|
that.add_command(commands[i]);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
that.execute = function() {
|
2011-04-12 02:13:30 -05:00
|
|
|
|
|
|
|
IPA.command({
|
|
|
|
name: that.name,
|
|
|
|
entity: that.entity,
|
|
|
|
method: that.method,
|
|
|
|
args: that.args,
|
|
|
|
options: that.options,
|
|
|
|
on_success: function(data, text_status, xhr) {
|
2011-01-10 20:14:51 -06:00
|
|
|
|
2010-11-15 11:10:55 -06:00
|
|
|
for (var i=0; i<that.commands.length; i++) {
|
|
|
|
var command = that.commands[i];
|
|
|
|
var result = data.result.results[i];
|
|
|
|
|
|
|
|
if (!result) {
|
|
|
|
if (command.on_error) command.on_error(
|
|
|
|
xhr, text_status,
|
|
|
|
{
|
2011-05-20 11:27:58 -05:00
|
|
|
name: 'Internal Error '+xhr.status,
|
2010-11-15 11:10:55 -06:00
|
|
|
message: result ? xhr.statusText : "Internal error"
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
} else if (result.error) {
|
|
|
|
if (command.on_error) command.on_error(
|
|
|
|
xhr,
|
|
|
|
text_status,
|
|
|
|
{
|
2011-05-20 11:27:58 -05:00
|
|
|
name: 'IPA Error '+result.error.code,
|
2010-11-15 11:10:55 -06:00
|
|
|
message: result.error.message
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
if (command.on_success) command.on_success(result, text_status, xhr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (that.on_success) that.on_success(data, text_status, xhr);
|
|
|
|
},
|
2011-04-12 02:13:30 -05:00
|
|
|
on_error: function(xhr, text_status, error_thrown) {
|
2010-11-15 11:10:55 -06:00
|
|
|
// TODO: undefined behavior
|
2011-01-12 13:47:29 -06:00
|
|
|
if (that.on_error) {
|
|
|
|
that.on_error(xhr, text_status, error_thrown);
|
|
|
|
}
|
2011-02-21 18:36:42 -06:00
|
|
|
}
|
2011-04-12 02:13:30 -05:00
|
|
|
}).execute();
|
2010-08-06 09:01:44 -05:00
|
|
|
};
|
|
|
|
|
2011-04-12 02:13:30 -05:00
|
|
|
return that;
|
2011-01-14 11:16:25 -06:00
|
|
|
};
|
2010-08-06 09:01:44 -05:00
|
|
|
|
|
|
|
/* helper function used to retrieve information about an attribute */
|
2011-02-16 12:46:59 -06:00
|
|
|
IPA.get_entity_param = function(entity_name, name) {
|
|
|
|
|
|
|
|
var metadata = IPA.metadata.objects[entity_name];
|
|
|
|
if (!metadata) {
|
2010-11-01 15:32:07 -05:00
|
|
|
return null;
|
|
|
|
}
|
2010-09-24 18:50:29 -05:00
|
|
|
|
2011-02-16 12:46:59 -06:00
|
|
|
var params = metadata.takes_params;
|
|
|
|
if (!params) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (var i=0; i<params.length; i++) {
|
|
|
|
if (params[i].name === name) {
|
|
|
|
return params[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
};
|
|
|
|
|
2011-04-26 16:21:25 -05:00
|
|
|
IPA.get_method_arg = function(method_name, name) {
|
|
|
|
|
|
|
|
var metadata = IPA.metadata.methods[method_name];
|
|
|
|
if (!metadata) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
var args = metadata.takes_args;
|
|
|
|
if (!args) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (var i=0; i<args.length; i++) {
|
|
|
|
if (args[i].name === name) {
|
|
|
|
return args[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
};
|
|
|
|
|
|
|
|
IPA.get_method_option = function(method_name, name) {
|
2010-08-06 09:01:44 -05:00
|
|
|
|
2011-02-16 12:46:59 -06:00
|
|
|
var metadata = IPA.metadata.methods[method_name];
|
|
|
|
if (!metadata) {
|
|
|
|
return null;
|
2010-11-01 15:32:07 -05:00
|
|
|
}
|
2011-02-16 12:46:59 -06:00
|
|
|
|
|
|
|
var options = metadata.takes_options;
|
|
|
|
if (!options) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (var i=0; i<options.length; i++) {
|
|
|
|
if (options[i].name === name) {
|
|
|
|
return options[i];
|
2010-11-01 15:32:07 -05:00
|
|
|
}
|
2010-08-06 09:01:44 -05:00
|
|
|
}
|
|
|
|
|
2011-02-16 12:46:59 -06:00
|
|
|
return null;
|
2011-01-14 11:16:25 -06:00
|
|
|
};
|
2010-09-16 09:28:07 -05:00
|
|
|
|
|
|
|
/* helper function used to retrieve attr name with members of type `member` */
|
2011-02-16 12:46:59 -06:00
|
|
|
IPA.get_member_attribute = function(obj_name, member) {
|
|
|
|
|
|
|
|
var obj = IPA.metadata.objects[obj_name];
|
2011-01-12 18:51:22 -06:00
|
|
|
if (!obj) {
|
2010-11-01 15:32:07 -05:00
|
|
|
return null;
|
|
|
|
}
|
2011-02-16 12:46:59 -06:00
|
|
|
|
2011-01-12 18:51:22 -06:00
|
|
|
var attribute_members = obj.attribute_members;
|
2010-09-16 09:28:07 -05:00
|
|
|
for (var a in attribute_members) {
|
|
|
|
var objs = attribute_members[a];
|
2010-11-01 15:32:07 -05:00
|
|
|
for (var i = 0; i < objs.length; i += 1) {
|
|
|
|
if (objs[i] === member){
|
2010-09-16 09:28:07 -05:00
|
|
|
return a;
|
2010-11-01 15:32:07 -05:00
|
|
|
}
|
2010-09-16 09:28:07 -05:00
|
|
|
}
|
|
|
|
}
|
2011-01-14 11:16:25 -06:00
|
|
|
|
2011-02-16 12:46:59 -06:00
|
|
|
return null;
|
2011-01-17 09:10:00 -06:00
|
|
|
};
|
|
|
|
|
2011-01-10 20:14:51 -06:00
|
|
|
IPA.create_network_spinner = function(){
|
|
|
|
return $('<span />',{
|
|
|
|
'class':'network-activity-indicator',
|
|
|
|
html: '<img src="spinner_small.gif" />'});
|
2011-01-14 11:16:25 -06:00
|
|
|
};
|