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
|
|
|
*/
|
|
|
|
|
|
|
|
|
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 = {};
|
|
|
|
|
2010-10-27 22:32:30 -05:00
|
|
|
that.entities = [];
|
2011-01-19 20:10:18 -06:00
|
|
|
that.entity_factories = {};
|
|
|
|
|
2010-10-27 22:32:30 -05:00
|
|
|
that.entities_by_name = {};
|
|
|
|
|
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';
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2010-11-17 21:15:09 -06:00
|
|
|
|
2010-11-18 15:48:23 -06:00
|
|
|
var startup_batch =
|
2010-11-17 21:15:09 -06:00
|
|
|
[
|
|
|
|
{"method":"json_metadata","params":[[],{}]},
|
|
|
|
{"method":"i18n_messages","params":[[],{}]},
|
|
|
|
{"method":"user_find","params":[[],{
|
2010-11-18 15:48:23 -06:00
|
|
|
"whoami":"true","all":"true"}]},
|
2011-01-25 18:39:08 -06:00
|
|
|
{"method":"env","params":[[],{}]},
|
|
|
|
{"method":"dns_is_enabled","params":[[],{}]}
|
2010-11-17 21:15:09 -06:00
|
|
|
];
|
|
|
|
|
|
|
|
|
2011-01-12 18:51:22 -06:00
|
|
|
IPA.cmd('batch', startup_batch, {},
|
2010-11-01 15:32:07 -05:00
|
|
|
function (data, text_status, xhr) {
|
2011-02-16 12:46:59 -06:00
|
|
|
that.metadata = data.result.results[0];
|
2010-11-17 21:15:09 -06:00
|
|
|
that.messages = data.result.results[1].messages;
|
|
|
|
that.whoami = data.result.results[2].result[0];
|
2010-11-18 15:48:23 -06:00
|
|
|
that.env = data.result.results[3].result;
|
2011-01-25 20:58:49 -06:00
|
|
|
that.dns_enabled = data.result.results[4].result;
|
2011-02-16 12:46:59 -06:00
|
|
|
|
2010-11-01 15:32:07 -05:00
|
|
|
if (on_success) {
|
|
|
|
on_success(data, text_status, xhr);
|
|
|
|
}
|
2010-10-27 22:32:30 -05:00
|
|
|
},
|
2010-11-18 20:59:08 -06:00
|
|
|
on_error,
|
|
|
|
null,
|
2011-01-12 13:47:29 -06:00
|
|
|
'ipa_init');
|
2010-10-27 22:32:30 -05:00
|
|
|
};
|
|
|
|
|
2010-11-01 15:32:07 -05:00
|
|
|
that.get_entities = function () {
|
2010-10-27 22:32:30 -05:00
|
|
|
return that.entities;
|
|
|
|
};
|
|
|
|
|
2010-11-01 15:32:07 -05:00
|
|
|
that.get_entity = function (name) {
|
2010-10-27 22:32:30 -05:00
|
|
|
return that.entities_by_name[name];
|
|
|
|
};
|
|
|
|
|
2011-01-19 20:10:18 -06:00
|
|
|
function add_entity(entity) {
|
2010-10-27 22:32:30 -05:00
|
|
|
that.entities.push(entity);
|
|
|
|
that.entities_by_name[entity.name] = entity;
|
2011-01-19 20:10:18 -06:00
|
|
|
}
|
2010-10-27 22:32:30 -05:00
|
|
|
|
2011-01-19 20:10:18 -06:00
|
|
|
that.start_entities = function(){
|
|
|
|
var factory;
|
|
|
|
var name ;
|
|
|
|
for (name in that.entity_factories){
|
|
|
|
factory = that.entity_factories[name];
|
|
|
|
var entity = factory();
|
|
|
|
add_entity(entity);
|
|
|
|
entity.init();
|
|
|
|
}
|
|
|
|
};
|
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);
|
|
|
|
var facet = IPA.current_entity.facets_by_name[facet_name];
|
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
|
|
|
|
2010-11-19 23:52:33 -06:00
|
|
|
that.show_page = function (entity_name, facet_name) {
|
2011-01-26 19:58:06 -06:00
|
|
|
if (!IPA.test_dirty()){
|
|
|
|
return false;
|
|
|
|
}
|
2010-10-27 22:32:30 -05:00
|
|
|
|
|
|
|
var state = {};
|
|
|
|
state[entity_name + '-facet'] = facet_name;
|
|
|
|
$.bbq.pushState(state);
|
2011-01-28 09:21:30 -06:00
|
|
|
return true;
|
2010-10-27 22:32:30 -05:00
|
|
|
};
|
|
|
|
|
2010-11-19 23:52:33 -06:00
|
|
|
that.switch_and_show_page = function (this_entity, facet_name, pkey) {
|
2011-01-26 19:58:06 -06:00
|
|
|
if (!IPA.test_dirty()){
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-11-15 15:41:21 -06:00
|
|
|
if (!pkey){
|
2010-11-19 23:52:33 -06:00
|
|
|
that.show_page(this_entity, facet_name);
|
2011-01-27 19:30:22 -06:00
|
|
|
return false;
|
2010-11-15 15:41:21 -06:00
|
|
|
}
|
|
|
|
var state = {};
|
|
|
|
state[this_entity+'-pkey'] = pkey;
|
|
|
|
state[this_entity + '-facet'] = facet_name;
|
|
|
|
$.bbq.pushState(state);
|
2011-01-27 19:30:22 -06:00
|
|
|
return true;
|
2010-11-15 15:41:21 -06: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-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;
|
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
|
|
|
|
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-01-12 18:51:22 -06:00
|
|
|
IPA.cmd(
|
2010-11-04 21:42:37 -05:00
|
|
|
that.method,
|
2010-11-15 11:10:55 -06:00
|
|
|
that.args,
|
|
|
|
that.options,
|
|
|
|
that.on_success,
|
2010-11-18 20:59:08 -06:00
|
|
|
that.on_error,
|
|
|
|
null,
|
2011-01-12 13:47:29 -06:00
|
|
|
that.name);
|
2010-11-04 21:42:37 -05:00
|
|
|
};
|
|
|
|
|
2010-11-15 11:10:55 -06:00
|
|
|
that.to_json = function() {
|
|
|
|
var json = {};
|
|
|
|
|
|
|
|
json.method = that.method;
|
|
|
|
|
|
|
|
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() {
|
|
|
|
var string = that.method.replace(/_/g, '-');
|
|
|
|
|
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-01-12 18:51:22 -06:00
|
|
|
IPA.cmd(
|
2010-11-15 11:10:55 -06:00
|
|
|
that.method,
|
|
|
|
that.args,
|
|
|
|
that.options,
|
|
|
|
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,
|
|
|
|
{
|
|
|
|
title: 'Internal Error '+xhr.status,
|
|
|
|
message: result ? xhr.statusText : "Internal error"
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
} else if (result.error) {
|
|
|
|
if (command.on_error) command.on_error(
|
|
|
|
xhr,
|
|
|
|
text_status,
|
|
|
|
{
|
|
|
|
title: 'IPA Error '+result.error.code,
|
|
|
|
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);
|
|
|
|
},
|
|
|
|
function(xhr, text_status, error_thrown) {
|
|
|
|
// TODO: undefined behavior
|
2011-01-12 13:47:29 -06:00
|
|
|
if (that.on_error) {
|
|
|
|
that.on_error(xhr, text_status, error_thrown);
|
|
|
|
}
|
2010-11-19 23:52:33 -06:00
|
|
|
},
|
|
|
|
null,
|
2011-01-12 13:47:29 -06:00
|
|
|
that.name);
|
2010-11-04 21:42:37 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
return that;
|
2011-01-14 11:16:25 -06:00
|
|
|
};
|
2010-11-04 21:42:37 -05:00
|
|
|
|
2010-08-06 09:01:44 -05:00
|
|
|
/* call an IPA command over JSON-RPC
|
|
|
|
* arguments:
|
|
|
|
* name - name of the command or method if objname is set
|
|
|
|
* args - list of positional arguments, e.g. [username]
|
|
|
|
* options - dict of options, e.g. {givenname: 'Pavel'}
|
|
|
|
* win_callback - function to call if the JSON request succeeds
|
|
|
|
* fail_callback - function to call if the JSON request fails
|
|
|
|
* objname - name of an IPA object (optional) */
|
2011-02-16 07:26:35 -06:00
|
|
|
IPA.cmd = function (name, args, options, win_callback, fail_callback, objname, command_name) {
|
2010-11-05 18:48:42 -05:00
|
|
|
var default_json_url = '/ipa/json';
|
2010-11-01 15:32:07 -05:00
|
|
|
|
2011-01-10 20:14:51 -06:00
|
|
|
var network_call_count = 0;
|
|
|
|
function display_activity_icon(){
|
|
|
|
network_call_count += 1;
|
|
|
|
$('.network-activity-indicator').css('display','inline');
|
|
|
|
}
|
|
|
|
|
|
|
|
function hide_activity_icon(){
|
|
|
|
network_call_count -= 1;
|
|
|
|
|
|
|
|
if (0 === network_call_count){
|
|
|
|
$('.network-activity-indicator').css('display','none');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-28 09:50:34 -05:00
|
|
|
function dialog_open(xhr, text_status, error_thrown) {
|
|
|
|
var that = this;
|
|
|
|
|
2011-03-05 00:21:49 -06:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2011-02-21 18:36:42 -06:00
|
|
|
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() {
|
2011-03-05 00:21:49 -06:00
|
|
|
close();
|
2011-02-21 18:36:42 -06:00
|
|
|
IPA.cmd(name, args, options, win_callback, fail_callback,
|
|
|
|
objname, command_name);
|
|
|
|
};
|
|
|
|
|
|
|
|
label = IPA.messages.buttons ? IPA.messages.buttons.cancel : 'Cancel';
|
|
|
|
buttons[label] = function() {
|
2011-03-05 00:21:49 -06:00
|
|
|
close();
|
2011-02-21 18:36:42 -06:00
|
|
|
if (fail_callback) {
|
|
|
|
fail_callback.call(that, xhr, text_status, error_thrown);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-10-28 09:50:34 -05:00
|
|
|
IPA.error_dialog.dialog({
|
|
|
|
modal: true,
|
2011-02-21 15:42:53 -06:00
|
|
|
title: error_thrown.title,
|
2010-10-28 09:50:34 -05:00
|
|
|
width: 400,
|
2011-03-05 00:21:49 -06:00
|
|
|
buttons: buttons,
|
|
|
|
close: function() {
|
|
|
|
close();
|
|
|
|
}
|
2010-10-28 09:50:34 -05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function error_handler(xhr, text_status, error_thrown) {
|
2011-01-10 20:14:51 -06:00
|
|
|
hide_activity_icon();
|
2011-01-05 08:20:31 -06:00
|
|
|
if (!error_thrown) {
|
|
|
|
error_thrown = {
|
|
|
|
name: xhr.responseText || 'Unknown Error',
|
|
|
|
message: xhr.statusText || 'Unknown Error'
|
2011-01-12 13:47:29 -06:00
|
|
|
};
|
2010-11-05 18:48:42 -05:00
|
|
|
}
|
|
|
|
|
2011-01-05 08:20:31 -06:00
|
|
|
if (xhr.status === 401) {
|
|
|
|
error_thrown.name = 'Kerberos ticket no longer valid.';
|
2010-11-05 18:48:42 -05:00
|
|
|
if (IPA.messages && IPA.messages.ajax){
|
2011-01-05 08:20:31 -06:00
|
|
|
error_thrown.message = IPA.messages.ajax["401"];
|
|
|
|
} else {
|
2010-11-05 18:48:42 -05:00
|
|
|
error_thrown.message =
|
2011-02-16 12:46:59 -06:00
|
|
|
"Your kerberos ticket is no longer valid. "+
|
2011-02-21 18:36:42 -06:00
|
|
|
"Please run kinit and then click 'Retry'. "+
|
2011-01-05 08:20:31 -06:00
|
|
|
"If this is your first time running the IPA Web UI "+
|
|
|
|
"<a href='/ipa/config/unauthorized.html'>"+
|
2011-01-12 13:47:29 -06:00
|
|
|
"follow these directions</a> to configure your browser.";
|
2010-11-05 18:48:42 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-21 15:42:53 -06:00
|
|
|
if (!error_thrown.title) {
|
|
|
|
error_thrown.title = 'AJAX Error: '+error_thrown.name;
|
|
|
|
}
|
2010-10-28 09:50:34 -05:00
|
|
|
dialog_open.call(this, xhr, text_status, error_thrown);
|
|
|
|
}
|
2010-10-06 15:09:14 -05:00
|
|
|
|
2010-11-01 15:32:07 -05:00
|
|
|
function success_handler(data, text_status, xhr) {
|
2011-01-10 20:14:51 -06:00
|
|
|
hide_activity_icon();
|
2010-11-01 15:32:07 -05:00
|
|
|
if (!data) {
|
|
|
|
var error_thrown = {
|
|
|
|
title: 'HTTP Error '+xhr.status,
|
2011-03-05 00:21:49 -06:00
|
|
|
url: this.url,
|
2010-11-01 15:32:07 -05:00
|
|
|
message: data ? xhr.statusText : "No response"
|
|
|
|
};
|
2011-03-05 00:21:49 -06:00
|
|
|
dialog_open.call(this, xhr, text_status, error_thrown);
|
2010-10-28 09:50:34 -05:00
|
|
|
|
2010-11-01 15:32:07 -05:00
|
|
|
} else if (data.error) {
|
2011-01-12 18:51:22 -06:00
|
|
|
error_handler.call(this, xhr, text_status, /* error_thrown */ {
|
2010-11-01 15:32:07 -05:00
|
|
|
title: 'IPA Error '+data.error.code,
|
|
|
|
message: data.error.message
|
|
|
|
});
|
|
|
|
|
|
|
|
} else if (win_callback) {
|
|
|
|
win_callback.call(this, data, text_status, xhr);
|
|
|
|
}
|
2010-10-06 15:09:14 -05:00
|
|
|
}
|
2010-09-29 00:52:56 -05:00
|
|
|
|
2010-11-01 15:32:07 -05:00
|
|
|
IPA.jsonrpc_id += 1;
|
|
|
|
var id = IPA.jsonrpc_id;
|
2010-09-29 00:52:56 -05:00
|
|
|
|
|
|
|
var method_name = name;
|
|
|
|
|
2010-11-01 15:32:07 -05:00
|
|
|
if (objname){
|
2010-09-29 00:52:56 -05:00
|
|
|
method_name = objname + '_' + name;
|
2010-11-01 15:32:07 -05:00
|
|
|
}
|
2010-09-16 09:28:07 -05:00
|
|
|
|
2010-10-27 22:32:30 -05:00
|
|
|
var url = IPA.json_url;
|
2010-09-24 18:50:29 -05:00
|
|
|
|
2010-11-01 15:32:07 -05:00
|
|
|
if (IPA.use_static_files){
|
2010-11-18 20:59:08 -06:00
|
|
|
if (command_name) {
|
|
|
|
url += '/' + command_name + '.json';
|
|
|
|
} else {
|
|
|
|
url += '/' + method_name + '.json';
|
|
|
|
}
|
2010-11-01 15:32:07 -05:00
|
|
|
}
|
2010-08-06 09:01:44 -05:00
|
|
|
var data = {
|
2010-09-29 00:52:56 -05:00
|
|
|
method: method_name,
|
2010-09-16 09:28:07 -05:00
|
|
|
params: [args, options],
|
2010-09-29 00:52:56 -05:00
|
|
|
id: id
|
2010-08-06 09:01:44 -05:00
|
|
|
};
|
|
|
|
|
2010-08-17 13:26:36 -05:00
|
|
|
var request = {
|
2010-09-16 09:28:07 -05:00
|
|
|
url: url,
|
|
|
|
data: JSON.stringify(data),
|
2010-10-28 09:50:34 -05:00
|
|
|
success: success_handler,
|
|
|
|
error: error_handler
|
2010-08-17 13:26:36 -05:00
|
|
|
};
|
2011-01-10 20:14:51 -06:00
|
|
|
display_activity_icon();
|
2010-08-17 13:26:36 -05:00
|
|
|
$.ajax(request);
|
2010-08-06 09:01:44 -05:00
|
|
|
|
|
|
|
return (id);
|
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;
|
|
|
|
};
|
|
|
|
|
|
|
|
IPA.get_method_param = 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
|
|
|
};
|