//Always display system messages after actions
var custom_success = options.success || elgg.nullFunction;
options.success = function(json, two, three, four) {
- if (json.system_messages) {
+ if (json && json.system_messages) {
elgg.register_error(json.system_messages.errors);
elgg.system_message(json.system_messages.success);
}
elgg.provide('elgg.config');
-elgg.config.wwwroot = '/';
-
+/**
+ * Returns the current site URL
+ *
+ * @return {String} The site URL.
+ */
elgg.get_site_url = function() {
return elgg.config.wwwroot;
}
\ No newline at end of file
elgg.security.token = {};
+elgg.security.tokenRefreshFailed = false;
+
/**
* Sets the currently active security token and updates all forms and links on the current page.
*
* @param {Object} json The json representation of a token containing __elgg_ts and __elgg_token
* @return {Void}
*/
-elgg.security.setToken = function(json) {
+elgg.security.setToken = function(json) {
//update the convenience object
elgg.security.token = json;
*/
elgg.security.refreshToken = function() {
elgg.action('security/refreshtoken', function(data) {
+
+ // @todo might want to move this to setToken() once http://trac.elgg.org/ticket/3127
+ // is implemented. It's here right now to avoid soggy code.
+ if (!data || !(data.output.__elgg_ts && data.output.__elgg_token)) {
+ elgg.register_error(elgg.echo('js:security:token_refresh_failed', [elgg.get_site_url()]));
+ elgg.security.tokenRefreshFailed = true;
+
+ // don't setToken because we refresh every 5 minutes and tokens are good for 1
+ // hour by default
+ return;
+ }
+
+ // if had problems last time, let them know it's working now
+ if (elgg.security.tokenRefreshFailed) {
+ elgg.system_message(elgg.echo('js:security:token_refreshed', [elgg.get_site_url()]));
+ elgg.security.tokenRefreshFailed = false;
+ }
+
elgg.security.setToken(data.output);
});
};
'tag_names:tags' => 'Tags',
'tags:site_cloud' => 'Site Tag Cloud',
+/**
+ * Javascript
+ */
+
+ 'js:security:token_refresh_failed' => 'Cannot contact %s. You may experience problems saving content.',
+ 'js:security:token_refreshed' => 'Connection to %s restored!',
+
/**
* Languages according to ISO 639-1
*/