Commit 64d0ae2868654ad922dea3ae23ad3ad7a0421903
1 parent
2bdb49ac
Exists in
master
and in
29 other branches
Save user_data and clear notice for reuse
Showing
1 changed file
with
24 additions
and
15 deletions
Show diff stats
public/javascripts/application.js
... | ... | @@ -518,6 +518,23 @@ function new_qualifier_row(selector, select_qualifiers, delete_button) { |
518 | 518 | jQuery(selector).append("<tr><td>" + select_qualifiers + "</td><td id='certifier-area-" + index + "'><select></select>" + delete_button + "</td></tr>"); |
519 | 519 | } |
520 | 520 | |
521 | +function userDataCallback(data) { | |
522 | + noosfero.user_data = data; | |
523 | + if (data.login) { | |
524 | + // logged in | |
525 | + if (data.chat_enabled) { | |
526 | + setInterval(function(){ $.getJSON(user_data, chatOnlineUsersDataCallBack)}, 10000); | |
527 | + } | |
528 | + } | |
529 | + if (data.notice) { | |
530 | + display_notice(data.notice); | |
531 | + // clear notice so that it is not display again in the case this function is called again. | |
532 | + data.notice = null; | |
533 | + } | |
534 | + // Bind this event to do more actions with the user data (for example, inside plugins) | |
535 | + jQuery(window).trigger("userDataLoaded", data); | |
536 | +}; | |
537 | + | |
521 | 538 | // controls the display of the login/logout stuff |
522 | 539 | jQuery(function($) { |
523 | 540 | $.ajaxSetup({ |
... | ... | @@ -528,21 +545,13 @@ jQuery(function($) { |
528 | 545 | }); |
529 | 546 | |
530 | 547 | var user_data = noosfero_root() + '/account/user_data'; |
531 | - $.getJSON(user_data, function userDataCallBack(data) { | |
532 | - if (data.login) { | |
533 | - // logged in | |
534 | - if (data.chat_enabled) { | |
535 | - setInterval(function(){ $.getJSON(user_data, chatOnlineUsersDataCallBack)}, 10000); | |
536 | - } | |
537 | - $('head').append('<meta content="authenticity_token" name="csrf-param" />'); | |
538 | - $('head').append('<meta content="'+$.cookie("_noosfero_.XSRF-TOKEN")+'" name="csrf-token" />'); | |
539 | - } | |
540 | - if (data.notice) { | |
541 | - display_notice(data.notice); | |
542 | - } | |
543 | - // Bind this event to do more actions with the user data (for example, inside plugins) | |
544 | - $(window).trigger("userDataLoaded", data); | |
545 | - }); | |
548 | + $.getJSON(user_data, userDataCallback) | |
549 | + if (user_data.login) { | |
550 | + $('head').append('<meta content="authenticity_token" name="csrf-param" />'); | |
551 | + $('head').append('<meta content="'+$.cookie("_noosfero_.XSRF-TOKEN")+'" name="csrf-token" />'); | |
552 | + } | |
553 | + | |
554 | + $.ajaxSetup({ cache: false }); | |
546 | 555 | |
547 | 556 | function chatOnlineUsersDataCallBack(data) { |
548 | 557 | if ($('#chat-online-users').length == 0) { | ... | ... |