]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Refs #2538. Loading js/configuration.js again. Only updating tokens on success and...
authorbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>
Tue, 15 Mar 2011 05:26:43 +0000 (05:26 +0000)
committerbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>
Tue, 15 Mar 2011 05:26:43 +0000 (05:26 +0000)
git-svn-id: http://code.elgg.org/elgg/trunk@8719 36083f99-b078-4883-b0ff-0f9b5a30f544

js/lib/ajax.js
js/lib/configuration.js
js/lib/security.js
languages/en.php
views/default/js/elgg.php

index 36f76b2c3fd8fdf10aad437063db6837b74c8b02..5e290df6fe1aa9c6ef711b5c58d73acd4ce0f0cb 100644 (file)
@@ -193,7 +193,7 @@ elgg.action = function(action, options) {
        //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);
                }
index d0c852bd08c8bf6da1bfa1a42028d70463b5f888..f724a2f01c328edf74fa682cc9a1f19a918a2902 100644 (file)
@@ -1,7 +1,10 @@
 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
index f88c6165d637d78a40c925513d1fd91f4a32f3fa..fa0a6f7efda4a3b2b96bd41a5bcb72ee4e0c323d 100644 (file)
@@ -5,13 +5,15 @@ elgg.provide('elgg.security');
 
 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;
 
@@ -34,6 +36,24 @@ elgg.security.setToken = function(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);
        });
 };
index 32a4cbb3dd976bed108f3ebe5a9def498cfa3577..375ba613510848f76939d58d0e50e30c21c6e690 100644 (file)
@@ -1098,6 +1098,13 @@ You cannot reply to this email.",
        '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
  */
index 018db79677f0a0f995c2b201ec9d16e4396eb08f..a434afc7d558b13a2d6b2fa77182bb80c9b7aa28 100644 (file)
@@ -34,6 +34,7 @@ $libs = array(
        'ajax',
        'session',
        'pageowner',
+       'configuration',
 
        //ui
        'ui',