*
* The action can be relative to the current site ('name/of/action') or
* the full URL of the action ('http://elgg.org/action/name/of/action').
*
* @example Usage 2:
* If you want to pass some data along with it, use the second parameter
*

* elgg.action('friend/add', { friend: some_guid });
*

*
* @example Usage 3:
* Of course, you will have no control over what happens when the request
* completes if you do it like that, so there's also the most verbose method
*

* You can pass any of your favorite $.ajax arguments into this second parameter.
*
* @note If you intend to use the second field in the "verbose" way, you must
* specify a callback method or the data parameter. If you do not, elgg.action
* will think you mean to send the second parameter as data.
*
* @note You do not have to add security tokens to this request. Elgg does that
* for you automatically.
*
* @see jQuery.ajax
*
* @param {String} action The action to call.
* @param {Object} options
* @return {XMLHttpRequest}
*/
elgg.action = function(action, options) {
elgg.assertTypeOf('string', action);
// support shortcut and full URLs
// this will mangle URLs that aren't elgg actions.
// Use post, get, or ajax for those.
if (action.indexOf('action/') < 0) {
action = 'action/' + action;
}
options = elgg.ajax.handleOptions(action, options);
// This is a misuse of elgg.security.addToken() because it is not always a
// full query string with a ?. As such we need a special check for the tokens.
if (!elgg.isString(options.data) || options.data.indexOf('__elgg_ts') == -1) {
options.data = elgg.security.addToken(options.data);
}
options.dataType = 'json';
//Always display system messages after actions
var custom_success = options.success || elgg.nullFunction;
options.success = function(json, two, three, four) {
if (json && json.system_messages) {
elgg.register_error(json.system_messages.error);
elgg.system_message(json.system_messages.success);
}
custom_success(json, two, three, four);
};
return elgg.post(options);
};
/**
* Make an API call
*
* @example Usage:
*