Description:
fixed avail bug for ajax toggle
git-svn-id: http://theory.cpe.ku.ac.th/grader/web/trunk@287 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
r148:5e03edcd8c25 - - 3 files changed: 10 inserted, 5 deleted
@@ -73,27 +73,31 | |||||
|
73 | redirect_to :action => 'show', :id => @problem |
|
73 | redirect_to :action => 'show', :id => @problem |
|
74 | else |
|
74 | else |
|
75 | render :action => 'edit' |
|
75 | render :action => 'edit' |
|
76 | end |
|
76 | end |
|
77 | end |
|
77 | end |
|
78 |
|
78 | ||
|
79 | def destroy |
|
79 | def destroy |
|
80 | Problem.find(params[:id]).destroy |
|
80 | Problem.find(params[:id]).destroy |
|
81 | redirect_to :action => 'list' |
|
81 | redirect_to :action => 'list' |
|
82 | end |
|
82 | end |
|
83 |
|
83 | ||
|
84 | def toggle |
|
84 | def toggle |
|
85 | - @problem = Problem.find(params[:id]) |
|
85 | + respond_to do |wants| |
|
86 | - @problem.available = !(@problem.available) |
|
86 | + wants.js { |
|
87 | - @problem.save |
|
87 | + @problem = Problem.find(params[:id]) |
|
|
88 | + @problem.available = !(@problem.available) | ||
|
|
89 | + @problem.save | ||
|
|
90 | + } | ||
|
|
91 | + end | ||
|
88 | end |
|
92 | end |
|
89 |
|
93 | ||
|
90 | def turn_all_off |
|
94 | def turn_all_off |
|
91 | Problem.find(:all, |
|
95 | Problem.find(:all, |
|
92 | :conditions => "available = 1").each do |problem| |
|
96 | :conditions => "available = 1").each do |problem| |
|
93 | problem.available = false |
|
97 | problem.available = false |
|
94 | problem.save |
|
98 | problem.save |
|
95 | end |
|
99 | end |
|
96 | redirect_to :action => 'list' |
|
100 | redirect_to :action => 'list' |
|
97 | end |
|
101 | end |
|
98 |
|
102 | ||
|
99 | def turn_all_on |
|
103 | def turn_all_on |
@@ -20,25 +20,25 | |||||
|
20 | <th>Date added</th> |
|
20 | <th>Date added</th> |
|
21 | <th>Avail?</th> |
|
21 | <th>Avail?</th> |
|
22 | <th>Test?</th> |
|
22 | <th>Test?</th> |
|
23 | </tr> |
|
23 | </tr> |
|
24 |
|
24 | ||
|
25 | <% for problem in @problems %> |
|
25 | <% for problem in @problems %> |
|
26 | <tr id="prob-<%= problem.id %>" name="prob-<%= problem.id %>" class="<%= (problem.available) ? "available" : "not-available" %>"> |
|
26 | <tr id="prob-<%= problem.id %>" name="prob-<%= problem.id %>" class="<%= (problem.available) ? "available" : "not-available" %>"> |
|
27 | <% @problem=problem %> |
|
27 | <% @problem=problem %> |
|
28 | <td><%= in_place_editor_field :problem, :name, {}, :rows=>1 %></td> |
|
28 | <td><%= in_place_editor_field :problem, :name, {}, :rows=>1 %></td> |
|
29 | <td><%= in_place_editor_field :problem, :full_name, {}, :rows=>1 %></td> |
|
29 | <td><%= in_place_editor_field :problem, :full_name, {}, :rows=>1 %></td> |
|
30 | <td><%= in_place_editor_field :problem, :full_score, {}, :rows=>1 %></td> |
|
30 | <td><%= in_place_editor_field :problem, :full_score, {}, :rows=>1 %></td> |
|
31 | <td><%= problem.date_added %></td> |
|
31 | <td><%= problem.date_added %></td> |
|
32 | - <td><%= problem.available %></td> |
|
32 | + <td id="prob-<%= problem.id %>-avail"><%= problem.available %></td> |
|
33 | <td><%= problem.test_allowed %></td> |
|
33 | <td><%= problem.test_allowed %></td> |
|
34 |
|
34 | ||
|
35 | <td><%= link_to_remote '[Toggle]', :url => {:action => 'toggle', :id => problem.id } %></td> |
|
35 | <td><%= link_to_remote '[Toggle]', :url => {:action => 'toggle', :id => problem.id } %></td> |
|
36 | <td><%= link_to '[Stat]', :action => 'stat', :id => problem.id %></td> |
|
36 | <td><%= link_to '[Stat]', :action => 'stat', :id => problem.id %></td> |
|
37 | <td><%= link_to '[Show]', :action => 'show', :id => problem %></td> |
|
37 | <td><%= link_to '[Show]', :action => 'show', :id => problem %></td> |
|
38 | <td><%= link_to '[Edit]', :action => 'edit', :id => problem %></td> |
|
38 | <td><%= link_to '[Edit]', :action => 'edit', :id => problem %></td> |
|
39 | <td><%= link_to '[Destroy]', { :action => 'destroy', :id => problem }, :confirm => 'Are you sure?', :method => :post %></td> |
|
39 | <td><%= link_to '[Destroy]', { :action => 'destroy', :id => problem }, :confirm => 'Are you sure?', :method => :post %></td> |
|
40 | </tr> |
|
40 | </tr> |
|
41 | <% end %> |
|
41 | <% end %> |
|
42 | </table> |
|
42 | </table> |
|
43 |
|
43 | ||
|
44 | <br /> |
|
44 | <br /> |
@@ -1,5 +1,6 | |||||
|
1 | if @problem.available |
|
1 | if @problem.available |
|
2 | page["prob-#{@problem.id}"].className = "available" |
|
2 | page["prob-#{@problem.id}"].className = "available" |
|
3 | else |
|
3 | else |
|
4 | page["prob-#{@problem.id}"].className = "not-available" |
|
4 | page["prob-#{@problem.id}"].className = "not-available" |
|
5 | - end No newline at end of file |
|
5 | + end |
|
|
6 | + page["prob-#{@problem.id}-avail"].innerHTML = @problem.available.to_s |
You need to be logged in to leave comments.
Login now