2010-08-06 09:01:44 -05:00
|
|
|
/* Authors:
|
|
|
|
* Pavel Zuna <pzuna@redhat.com>
|
|
|
|
*
|
|
|
|
* 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){
|
|
|
|
that.json_url = 'test/data'
|
|
|
|
}
|
|
|
|
|
2010-10-27 22:32:30 -05:00
|
|
|
that.ajax_options = {
|
|
|
|
type: 'POST',
|
|
|
|
contentType: 'application/json',
|
|
|
|
dataType: 'json',
|
|
|
|
async: true,
|
|
|
|
processData: false
|
|
|
|
};
|
|
|
|
|
|
|
|
that.messages = {};
|
|
|
|
that.metadata = {};
|
2010-11-17 21:15:09 -06:00
|
|
|
that.whoami = {};
|
|
|
|
|
2010-10-27 22:32:30 -05:00
|
|
|
|
|
|
|
that.entities = [];
|
|
|
|
that.entities_by_name = {};
|
|
|
|
|
|
|
|
that.error_dialog = $('<div/>', {
|
|
|
|
id: 'error_dialog'
|
|
|
|
});
|
|
|
|
|
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"}]},
|
|
|
|
{"method":"env","params":[[],{}]}
|
2010-11-17 21:15:09 -06:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
ipa_cmd('batch', startup_batch, {},
|
2010-11-01 15:32:07 -05:00
|
|
|
function (data, text_status, xhr) {
|
2010-11-17 21:15:09 -06:00
|
|
|
that.metadata = data.result.results[0].metadata;
|
|
|
|
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;
|
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,
|
|
|
|
'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];
|
|
|
|
};
|
|
|
|
|
2010-11-01 15:32:07 -05:00
|
|
|
that.add_entity = function (entity) {
|
2010-10-27 22:32:30 -05:00
|
|
|
that.entities.push(entity);
|
|
|
|
that.entities_by_name[entity.name] = entity;
|
|
|
|
};
|
|
|
|
|
2010-11-15 15:41:21 -06:00
|
|
|
|
2010-11-19 23:52:33 -06:00
|
|
|
that.show_page = function (entity_name, facet_name) {
|
2010-10-27 22:32:30 -05:00
|
|
|
|
|
|
|
var state = {};
|
|
|
|
state[entity_name + '-facet'] = facet_name;
|
|
|
|
$.bbq.pushState(state);
|
|
|
|
};
|
|
|
|
|
2010-11-19 23:52:33 -06:00
|
|
|
that.switch_and_show_page = function (this_entity, facet_name, pkey) {
|
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);
|
2010-11-15 15:41:21 -06:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
var state = {};
|
|
|
|
state[this_entity+'-pkey'] = pkey;
|
|
|
|
state[this_entity + '-facet'] = facet_name;
|
|
|
|
$.bbq.pushState(state);
|
|
|
|
};
|
|
|
|
|
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
|
|
|
|
2010-11-04 21:42:37 -05:00
|
|
|
function ipa_command(spec) {
|
|
|
|
|
|
|
|
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() {
|
2010-11-04 21:42:37 -05:00
|
|
|
ipa_cmd(
|
|
|
|
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,
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
function ipa_batch_command(spec) {
|
|
|
|
|
|
|
|
spec = spec || {};
|
|
|
|
|
|
|
|
spec.method = 'batch';
|
|
|
|
|
|
|
|
var that = ipa_command(spec);
|
|
|
|
|
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() {
|
|
|
|
ipa_cmd(
|
|
|
|
that.method,
|
|
|
|
that.args,
|
|
|
|
that.options,
|
|
|
|
function(data, text_status, xhr) {
|
|
|
|
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
|
|
|
|
if (that.on_error) that.on_error(xhr, text_status, error_thrown)
|
2010-11-19 23:52:33 -06:00
|
|
|
},
|
|
|
|
null,
|
|
|
|
that.name
|
2010-11-15 11:10:55 -06:00
|
|
|
);
|
2010-11-04 21:42:37 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
return that;
|
|
|
|
}
|
|
|
|
|
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) */
|
2010-11-18 20:59:08 -06:00
|
|
|
function ipa_cmd(name, args, options, win_callback, fail_callback, objname, command_name)
|
2010-08-06 09:01:44 -05:00
|
|
|
{
|
2010-11-05 18:48:42 -05:00
|
|
|
var default_json_url = '/ipa/json';
|
2010-11-01 15:32:07 -05:00
|
|
|
|
2010-10-28 09:50:34 -05:00
|
|
|
function dialog_open(xhr, text_status, error_thrown) {
|
|
|
|
var that = this;
|
|
|
|
|
|
|
|
IPA.error_dialog.dialog({
|
|
|
|
modal: true,
|
|
|
|
width: 400,
|
|
|
|
buttons: {
|
2010-11-01 15:32:07 -05:00
|
|
|
'Retry': function () {
|
2010-10-28 09:50:34 -05:00
|
|
|
IPA.error_dialog.dialog('close');
|
2010-11-19 23:52:33 -06:00
|
|
|
ipa_cmd(name, args, options, win_callback, fail_callback, objname, command_name);
|
2010-10-28 09:50:34 -05:00
|
|
|
},
|
2010-11-01 15:32:07 -05:00
|
|
|
'Cancel': function () {
|
2010-10-28 09:50:34 -05:00
|
|
|
IPA.error_dialog.dialog('close');
|
2010-11-15 11:10:55 -06:00
|
|
|
if (fail_callback) fail_callback.call(that, xhr, text_status, error_thrown);
|
2010-10-28 09:50:34 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2010-11-01 15:32:07 -05:00
|
|
|
function ajax_error_handler(xhr, text_status, error_thrown) {
|
|
|
|
IPA.error_dialog.empty();
|
|
|
|
IPA.error_dialog.attr('title', error_thrown.title);
|
2010-09-29 16:17:03 -05:00
|
|
|
|
2010-11-01 15:32:07 -05:00
|
|
|
IPA.error_dialog.append('<p>'+error_thrown.message+'</p>');
|
2010-10-01 16:33:57 -05:00
|
|
|
|
2010-11-01 15:32:07 -05:00
|
|
|
dialog_open.call(this, xhr, text_status, error_thrown);
|
2010-09-29 16:17:03 -05:00
|
|
|
}
|
|
|
|
|
2010-10-28 09:50:34 -05:00
|
|
|
function error_handler(xhr, text_status, error_thrown) {
|
2011-01-05 08:20:31 -06:00
|
|
|
|
|
|
|
if (!error_thrown) {
|
|
|
|
error_thrown = {
|
|
|
|
name: xhr.responseText || 'Unknown Error',
|
|
|
|
message: xhr.statusText || 'Unknown Error'
|
|
|
|
}
|
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-01-05 08:20:31 -06:00
|
|
|
"Your kerberos ticket 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."
|
2010-11-05 18:48:42 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-28 09:50:34 -05:00
|
|
|
error_thrown.title = 'AJAX Error: '+error_thrown.name;
|
|
|
|
ajax_error_handler.call(this, xhr, text_status, error_thrown);
|
|
|
|
}
|
|
|
|
|
2010-11-01 15:32:07 -05:00
|
|
|
|
|
|
|
function http_error_handler(xhr, text_status, error_thrown) {
|
2010-10-27 22:32:30 -05:00
|
|
|
IPA.error_dialog.empty();
|
2010-10-28 09:50:34 -05:00
|
|
|
IPA.error_dialog.attr('title', error_thrown.title);
|
2010-09-29 16:17:03 -05:00
|
|
|
|
2010-10-27 22:32:30 -05:00
|
|
|
IPA.error_dialog.append('<p>URL: '+this.url+'</p>');
|
2010-10-28 09:50:34 -05:00
|
|
|
IPA.error_dialog.append('<p>'+error_thrown.message+'</p>');
|
2010-09-29 00:52:56 -05:00
|
|
|
|
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 ipa_error_handler(xhr, text_status, error_thrown) {
|
2010-10-28 09:50:34 -05:00
|
|
|
IPA.error_dialog.empty();
|
|
|
|
IPA.error_dialog.attr('title', error_thrown.title);
|
|
|
|
|
|
|
|
IPA.error_dialog.append('<p>'+error_thrown.message+'</p>');
|
|
|
|
|
|
|
|
dialog_open.call(this, xhr, text_status, error_thrown);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-01 15:32:07 -05:00
|
|
|
function success_handler(data, text_status, xhr) {
|
|
|
|
if (!data) {
|
|
|
|
var error_thrown = {
|
|
|
|
title: 'HTTP Error '+xhr.status,
|
|
|
|
message: data ? xhr.statusText : "No response"
|
|
|
|
};
|
|
|
|
http_error_handler.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) {
|
|
|
|
ipa_error_handler.call(this, xhr, text_status, /* error_thrown */ {
|
|
|
|
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
|
|
|
};
|
|
|
|
|
|
|
|
$.ajax(request);
|
2010-08-06 09:01:44 -05:00
|
|
|
|
|
|
|
return (id);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* helper function used to retrieve information about an attribute */
|
2010-09-16 09:28:07 -05:00
|
|
|
function ipa_get_param_info(obj_name, attr)
|
2010-08-06 09:01:44 -05:00
|
|
|
{
|
2010-10-27 22:32:30 -05:00
|
|
|
var ipa_obj = IPA.metadata[obj_name];
|
2010-11-01 15:32:07 -05:00
|
|
|
if (!ipa_obj) {
|
|
|
|
return null;
|
|
|
|
}
|
2010-09-24 18:50:29 -05:00
|
|
|
|
|
|
|
var takes_params = ipa_obj.takes_params;
|
2010-11-01 15:32:07 -05:00
|
|
|
if (!takes_params) {
|
2010-09-16 09:28:07 -05:00
|
|
|
return (null);
|
2010-08-06 09:01:44 -05:00
|
|
|
|
2010-11-01 15:32:07 -05:00
|
|
|
}
|
|
|
|
for (var i = 0; i < takes_params.length; i += 1) {
|
|
|
|
if (takes_params[i].name === attr){
|
2010-09-16 09:28:07 -05:00
|
|
|
return (takes_params[i]);
|
2010-11-01 15:32:07 -05:00
|
|
|
}
|
2010-08-06 09:01:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return (null);
|
|
|
|
}
|
2010-09-16 09:28:07 -05:00
|
|
|
|
|
|
|
/* helper function used to retrieve attr name with members of type `member` */
|
|
|
|
function ipa_get_member_attribute(obj_name, member)
|
|
|
|
{
|
2010-10-27 22:32:30 -05:00
|
|
|
var ipa_obj = IPA.metadata[obj_name];
|
2010-11-01 15:32:07 -05:00
|
|
|
if (!ipa_obj) {
|
|
|
|
return null;
|
|
|
|
}
|
2010-10-27 22:32:30 -05:00
|
|
|
var attribute_members = ipa_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
|
|
|
}
|
|
|
|
}
|
2010-09-24 18:50:29 -05:00
|
|
|
return null;
|
2010-09-16 09:28:07 -05:00
|
|
|
}
|