Description:
added announcement refresh, more styling, prep for announcement hiding
git-svn-id: http://theory.cpe.ku.ac.th/grader/web/trunk@412 6386c4cd-e34a-4fa8-8920-d93eb39b512e
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r192:f7680fc5e3dd - - 7 files changed: 106 inserted, 14 deleted
@@ -0,0 +1,33 | |||
|
1 | + | |
|
2 | + var Announcement = { | |
|
3 | + | |
|
4 | + mostRecentId: 0, | |
|
5 | + | |
|
6 | + setMostRecentId: function(id) { | |
|
7 | + Announcement.mostRecentId = id; | |
|
8 | + }, | |
|
9 | + | |
|
10 | + updateRecentId: function(id) { | |
|
11 | + if(Announcement.mostRecentId < id) | |
|
12 | + Announcement.mostRecentId = id; | |
|
13 | + }, | |
|
14 | + | |
|
15 | + refreshAnnouncement: function() { | |
|
16 | + var url = '/main/announcements'; | |
|
17 | + new Ajax.Request(url, { | |
|
18 | + method: 'get', | |
|
19 | + parameters: { recent: Announcement.mostRecentId }, | |
|
20 | + onSuccess: function(transport) { | |
|
21 | + var announcementBody = $("announcementbox-body"); | |
|
22 | + announcementBody.insert({ top: transport.responseText }); | |
|
23 | + } | |
|
24 | + }); | |
|
25 | + Announcement.registerRefreshEventTimer(); | |
|
26 | + }, | |
|
27 | + | |
|
28 | + registerRefreshEventTimer: function() { | |
|
29 | + setTimeout(function () { | |
|
30 | + Announcement.refreshAnnouncement(); | |
|
31 | + }, 30000); | |
|
32 | + } | |
|
33 | + }; No newline at end of file |
@@ -163,7 +163,33 | |||
|
163 | 163 | @user = User.find(session[:user_id]) |
|
164 | 164 | end |
|
165 | 165 | |
|
166 | + # announcement refreshing and hiding methods | |
|
167 | + | |
|
168 | + def announcements | |
|
169 | + if params.has_key? 'recent' | |
|
170 | + prepare_announcements(params[:recent]) | |
|
171 | + else | |
|
172 | + prepare_announcements | |
|
173 | + end | |
|
174 | + render(:partial => 'announcement', | |
|
175 | + :collection => @announcements, | |
|
176 | + :locals => {:announcement_effect => true}) | |
|
177 | + end | |
|
178 | + | |
|
166 | 179 | protected |
|
180 | + | |
|
181 | + def prepare_announcements(recent=nil) | |
|
182 | + if Configuration.show_tasks_to?(@user) | |
|
183 | + @announcements = Announcement.find_published(true) | |
|
184 | + else | |
|
185 | + @announcements = Announcement.find_published | |
|
186 | + end | |
|
187 | + if recent!=nil | |
|
188 | + recent_id = recent.to_i | |
|
189 | + @announcements = @announcements.find_all { |a| a.id > recent_id } | |
|
190 | + end | |
|
191 | + end | |
|
192 | + | |
|
167 | 193 | def prepare_list_information |
|
168 | 194 | @problems = Problem.find_available_problems |
|
169 | 195 | @prob_submissions = Array.new |
@@ -176,11 +202,7 | |||
|
176 | 202 | @prob_submissions << { :count => 0, :submission => nil } |
|
177 | 203 | end |
|
178 | 204 | end |
|
179 | - if Configuration.show_tasks_to?(@user) | |
|
180 | - @announcements = Announcement.find_published(true) | |
|
181 | - else | |
|
182 | - @announcements = Announcement.find_published | |
|
183 | - end | |
|
205 | + prepare_announcements | |
|
184 | 206 | end |
|
185 | 207 | |
|
186 | 208 | def check_viewability |
@@ -1,4 +1,17 | |||
|
1 | - .announcement | |
|
2 | - = markdown(announcement.body) | |
|
3 | - -#.pub-info | |
|
4 | - -# %p= "#{announcement.author}, #{announcement.created_at}" | |
|
1 | + .announcement{:id => "announcement-#{announcement.id}", :style => "#{'opacity: 0;' if (defined? announcement_effect) and announcement_effect }"} | |
|
2 | + -# .announcement-title | |
|
3 | + -# .toggles | |
|
4 | + -# %a{:href => '#', :onclick => "$(\"announcement-body-#{announcement.id}\").hide(); return false;"} | |
|
5 | + -# [hide] | |
|
6 | + -# %a{:href => '#', :onclick => "$(\"announcement-body-#{announcement.id}\").show(); return false;"} | |
|
7 | + -# [show] | |
|
8 | + -# Announcement Title | |
|
9 | + .announcement-body{:id => "announcement-body-#{announcement.id}"} | |
|
10 | + = markdown(announcement.body) | |
|
11 | + -#.pub-info | |
|
12 | + -# %p= "#{announcement.author}, #{announcement.created_at}" | |
|
13 | + :javascript | |
|
14 | + Announcement.updateRecentId(#{announcement.id}); | |
|
15 | + - if (defined? announcement_effect) and announcement_effect | |
|
16 | + :javascript | |
|
17 | + $("announcement-#{announcement.id}").appear(); |
@@ -1,10 +1,15 | |||
|
1 | + - content_for :head do | |
|
2 | + = javascript_include_tag :defaults | |
|
3 | + %script{:type => 'text/javascript', :src => '/javascripts/announcement_refresh.js'} | |
|
4 | + | |
|
1 | 5 | = user_title_bar(@user) |
|
2 | 6 | |
|
3 | 7 | - if @announcements.length!=0 |
|
4 | 8 | .announcementbox |
|
5 | 9 | %span{:class => 'title'} |
|
6 | 10 | Announcements |
|
7 | - = render :partial => 'announcement', :collection => @announcements | |
|
11 | + #announcementbox-body | |
|
12 | + = render :partial => 'announcement', :collection => @announcements | |
|
8 | 13 | |
|
9 | 14 | - if Configuration.show_submitbox_to?(@user) |
|
10 | 15 | .submitbox |
@@ -14,7 +19,8 | |||
|
14 | 19 | |
|
15 | 20 | %hr/ |
|
16 | 21 | |
|
17 |
- - if (Configuration.contest_mode) and (@user.site!=nil) |
|
|
22 | + - if (Configuration.contest_mode) and (@user.site!=nil) | | |
|
23 | + and (@user.site.started!=true) | |
|
18 | 24 | %p=t 'main.start_soon' |
|
19 | 25 | |
|
20 | 26 | - if Configuration.show_tasks_to?(@user) |
@@ -28,3 +34,6 | |||
|
28 | 34 | |
|
29 | 35 | %hr/ |
|
30 | 36 | |
|
37 | + :javascript | |
|
38 | + Announcement.registerRefreshEventTimer(); | |
|
39 | + |
@@ -237,10 +237,13 | |||
|
237 | 237 | padding: 1px; |
|
238 | 238 | padding-left: 10px; |
|
239 | 239 | padding-right: 10px; |
|
240 | + padding-top: 5px; | |
|
241 | + padding-bottom: 5px; | |
|
240 | 242 | } |
|
241 | 243 | |
|
242 |
- |
|
|
244 | + .announcement p { | |
|
243 | 245 | font-size: 12px; |
|
246 | + margin: 2px; | |
|
244 | 247 | } |
|
245 | 248 | |
|
246 | 249 | div.pub-info, div.pub-info p { |
@@ -249,6 +252,16 | |||
|
249 | 252 | font-size: 9px; |
|
250 | 253 | } |
|
251 | 254 | |
|
255 | + .announcement .toggles { | |
|
256 | + font-weight: normal; | |
|
257 | + float: right; | |
|
258 | + font-size: 80%; | |
|
259 | + } | |
|
260 | + | |
|
261 | + .announcement .announcement-title { | |
|
262 | + font-weight: bold; | |
|
263 | + } | |
|
264 | + | |
|
252 | 265 | /****************** |
|
253 | 266 | Messages |
|
254 | 267 | ******************/ |
You need to be logged in to leave comments.
Login now