Description:
fixed announcement refresh bug when initially there was no announcement
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r226:4488d204f427 - - 2 files changed: 8 inserted, 4 deleted

@@ -1,38 +1,37
1 - content_for :head do
1 - content_for :head do
2 = javascript_include_tag :defaults
2 = javascript_include_tag :defaults
3 - %script{:type => 'text/javascript', :src => '/javascripts/announcement_refresh.js'}
3 + = javascript_include_tag 'announcement_refresh.js'
4
4
5 = user_title_bar(@user)
5 = user_title_bar(@user)
6
6
7 - - if @announcements.length!=0
7 + .announcementbox{:style => (@announcements.length==0 ? "display:none" : "")}
8 - .announcementbox
9 %span{:class => 'title'}
8 %span{:class => 'title'}
10 Announcements
9 Announcements
11 #announcementbox-body
10 #announcementbox-body
12 = render :partial => 'announcement', :collection => @announcements
11 = render :partial => 'announcement', :collection => @announcements
13
12
14 - if Configuration.show_submitbox_to?(@user)
13 - if Configuration.show_submitbox_to?(@user)
15 .submitbox
14 .submitbox
16 = error_messages_for 'submission'
15 = error_messages_for 'submission'
17 = render :partial => 'submission_box'
16 = render :partial => 'submission_box'
18
17
19
18
20 %hr/
19 %hr/
21
20
22 - if (Configuration.contest_mode?) and (@user.site!=nil) and (@user.site.started!=true)
21 - if (Configuration.contest_mode?) and (@user.site!=nil) and (@user.site.started!=true)
23 %p=t 'main.start_soon'
22 %p=t 'main.start_soon'
24
23
25 - if Configuration.show_tasks_to?(@user)
24 - if Configuration.show_tasks_to?(@user)
26 %table.info
25 %table.info
27 %tr.info-head
26 %tr.info-head
28 %th
27 %th
29 %th Tasks
28 %th Tasks
30 %th # of sub(s)
29 %th # of sub(s)
31 %th Results
30 %th Results
32 = render :partial => 'problem', :collection => @problems
31 = render :partial => 'problem', :collection => @problems
33
32
34 %hr/
33 %hr/
35
34
36 :javascript
35 :javascript
37 Announcement.registerRefreshEventTimer();
36 Announcement.registerRefreshEventTimer();
38
37
@@ -1,33 +1,38
1
1
2 var Announcement = {
2 var Announcement = {
3
3
4 mostRecentId: 0,
4 mostRecentId: 0,
5
5
6 setMostRecentId: function(id) {
6 setMostRecentId: function(id) {
7 Announcement.mostRecentId = id;
7 Announcement.mostRecentId = id;
8 },
8 },
9
9
10 updateRecentId: function(id) {
10 updateRecentId: function(id) {
11 if(Announcement.mostRecentId < id)
11 if(Announcement.mostRecentId < id)
12 Announcement.mostRecentId = id;
12 Announcement.mostRecentId = id;
13 },
13 },
14
14
15 refreshAnnouncement: function() {
15 refreshAnnouncement: function() {
16 var url = '/main/announcements';
16 var url = '/main/announcements';
17 new Ajax.Request(url, {
17 new Ajax.Request(url, {
18 method: 'get',
18 method: 'get',
19 parameters: { recent: Announcement.mostRecentId },
19 parameters: { recent: Announcement.mostRecentId },
20 onSuccess: function(transport) {
20 onSuccess: function(transport) {
21 + if(transport.responseText.match(/\S/)!=null) {
21 var announcementBody = $("announcementbox-body");
22 var announcementBody = $("announcementbox-body");
22 announcementBody.insert({ top: transport.responseText });
23 announcementBody.insert({ top: transport.responseText });
24 + var announcementBoxes = $$(".announcementbox");
25 + if(announcementBoxes.length!=0)
26 + announcementBoxes[0].show();
27 + }
23 }
28 }
24 });
29 });
25 Announcement.registerRefreshEventTimer();
30 Announcement.registerRefreshEventTimer();
26 },
31 },
27
32
28 registerRefreshEventTimer: function() {
33 registerRefreshEventTimer: function() {
29 setTimeout(function () {
34 setTimeout(function () {
30 Announcement.refreshAnnouncement();
35 Announcement.refreshAnnouncement();
31 }, 30000);
36 }, 30000);
32 }
37 }
33 - }; No newline at end of file
38 + };
You need to be logged in to leave comments. Login now