diff --git a/.gitignore b/.gitignore --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,2 @@ *~ log -config/environment.rb -config/database.yml diff --git a/app/controllers/main_controller.rb b/app/controllers/main_controller.rb --- a/app/controllers/main_controller.rb +++ b/app/controllers/main_controller.rb @@ -163,7 +163,33 @@ @user = User.find(session[:user_id]) end + # announcement refreshing and hiding methods + + def announcements + if params.has_key? 'recent' + prepare_announcements(params[:recent]) + else + prepare_announcements + end + render(:partial => 'announcement', + :collection => @announcements, + :locals => {:announcement_effect => true}) + end + protected + + def prepare_announcements(recent=nil) + if Configuration.show_tasks_to?(@user) + @announcements = Announcement.find_published(true) + else + @announcements = Announcement.find_published + end + if recent!=nil + recent_id = recent.to_i + @announcements = @announcements.find_all { |a| a.id > recent_id } + end + end + def prepare_list_information @problems = Problem.find_available_problems @prob_submissions = Array.new @@ -176,11 +202,7 @@ @prob_submissions << { :count => 0, :submission => nil } end end - if Configuration.show_tasks_to?(@user) - @announcements = Announcement.find_published(true) - else - @announcements = Announcement.find_published - end + prepare_announcements end def check_viewability diff --git a/app/views/main/_announcement.html.haml b/app/views/main/_announcement.html.haml --- a/app/views/main/_announcement.html.haml +++ b/app/views/main/_announcement.html.haml @@ -1,4 +1,17 @@ -.announcement - = markdown(announcement.body) - -#.pub-info - -# %p= "#{announcement.author}, #{announcement.created_at}" +.announcement{:id => "announcement-#{announcement.id}", :style => "#{'opacity: 0;' if (defined? announcement_effect) and announcement_effect }"} + -# .announcement-title + -# .toggles + -# %a{:href => '#', :onclick => "$(\"announcement-body-#{announcement.id}\").hide(); return false;"} + -# [hide] + -# %a{:href => '#', :onclick => "$(\"announcement-body-#{announcement.id}\").show(); return false;"} + -# [show] + -# Announcement Title + .announcement-body{:id => "announcement-body-#{announcement.id}"} + = markdown(announcement.body) + -#.pub-info + -# %p= "#{announcement.author}, #{announcement.created_at}" + :javascript + Announcement.updateRecentId(#{announcement.id}); + - if (defined? announcement_effect) and announcement_effect + :javascript + $("announcement-#{announcement.id}").appear(); diff --git a/app/views/main/list.html.haml b/app/views/main/list.html.haml --- a/app/views/main/list.html.haml +++ b/app/views/main/list.html.haml @@ -1,10 +1,15 @@ +- content_for :head do + = javascript_include_tag :defaults + %script{:type => 'text/javascript', :src => '/javascripts/announcement_refresh.js'} + = user_title_bar(@user) - if @announcements.length!=0 .announcementbox %span{:class => 'title'} Announcements - = render :partial => 'announcement', :collection => @announcements + #announcementbox-body + = render :partial => 'announcement', :collection => @announcements - if Configuration.show_submitbox_to?(@user) .submitbox @@ -14,7 +19,8 @@ %hr/ -- if (Configuration.contest_mode) and (@user.site!=nil) and (@user.site.started!=true) +- if (Configuration.contest_mode) and (@user.site!=nil) | + and (@user.site.started!=true) %p=t 'main.start_soon' - if Configuration.show_tasks_to?(@user) @@ -28,3 +34,6 @@ %hr/ +:javascript + Announcement.registerRefreshEventTimer(); + diff --git a/config/.gitignore b/config/.gitignore new file mode 100644 --- /dev/null +++ b/config/.gitignore @@ -0,0 +1,4 @@ +environment.rb +database.yml +tasks.yml + diff --git a/public/javascripts/announcement_refresh.js b/public/javascripts/announcement_refresh.js new file mode 100644 --- /dev/null +++ b/public/javascripts/announcement_refresh.js @@ -0,0 +1,33 @@ + +var Announcement = { + + mostRecentId: 0, + + setMostRecentId: function(id) { + Announcement.mostRecentId = id; + }, + + updateRecentId: function(id) { + if(Announcement.mostRecentId < id) + Announcement.mostRecentId = id; + }, + + refreshAnnouncement: function() { + var url = '/main/announcements'; + new Ajax.Request(url, { + method: 'get', + parameters: { recent: Announcement.mostRecentId }, + onSuccess: function(transport) { + var announcementBody = $("announcementbox-body"); + announcementBody.insert({ top: transport.responseText }); + } + }); + Announcement.registerRefreshEventTimer(); + }, + + registerRefreshEventTimer: function() { + setTimeout(function () { + Announcement.refreshAnnouncement(); + }, 30000); + } +}; \ No newline at end of file diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css --- a/public/stylesheets/application.css +++ b/public/stylesheets/application.css @@ -237,10 +237,13 @@ padding: 1px; padding-left: 10px; padding-right: 10px; + padding-top: 5px; + padding-bottom: 5px; } -div.announcement p { +.announcement p { font-size: 12px; + margin: 2px; } div.pub-info, div.pub-info p { @@ -249,6 +252,16 @@ font-size: 9px; } +.announcement .toggles { + font-weight: normal; + float: right; + font-size: 80%; +} + +.announcement .announcement-title { + font-weight: bold; +} + /****************** Messages ******************/