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
@@ -37,80 +37,84 | |||
|
37 | 37 | end |
|
38 | 38 | else |
|
39 | 39 | @description = nil |
|
40 | 40 | end |
|
41 | 41 | @problem.description = @description |
|
42 | 42 | if @problem.save |
|
43 | 43 | flash[:notice] = 'Problem was successfully created.' |
|
44 | 44 | redirect_to :action => 'list' |
|
45 | 45 | else |
|
46 | 46 | render :action => 'new' |
|
47 | 47 | end |
|
48 | 48 | end |
|
49 | 49 | |
|
50 | 50 | def edit |
|
51 | 51 | @problem = Problem.find(params[:id]) |
|
52 | 52 | @description = @problem.description |
|
53 | 53 | end |
|
54 | 54 | |
|
55 | 55 | def update |
|
56 | 56 | @problem = Problem.find(params[:id]) |
|
57 | 57 | @description = @problem.description |
|
58 | 58 | if @description == nil and params[:description][:body]!='' |
|
59 | 59 | @description = Description.new(params[:description]) |
|
60 | 60 | if !@description.save |
|
61 | 61 | flash[:notice] = 'Error saving description' |
|
62 | 62 | render :action => 'edit' and return |
|
63 | 63 | end |
|
64 | 64 | @problem.description = @description |
|
65 | 65 | elsif @description!=nil |
|
66 | 66 | if !@description.update_attributes(params[:description]) |
|
67 | 67 | flash[:notice] = 'Error saving description' |
|
68 | 68 | render :action => 'edit' and return |
|
69 | 69 | end |
|
70 | 70 | end |
|
71 | 71 | if @problem.update_attributes(params[:problem]) |
|
72 | 72 | flash[:notice] = 'Problem was successfully updated.' |
|
73 | 73 | redirect_to :action => 'show', :id => @problem |
|
74 | 74 | else |
|
75 | 75 | render :action => 'edit' |
|
76 | 76 | end |
|
77 | 77 | end |
|
78 | 78 | |
|
79 | 79 | def destroy |
|
80 | 80 | Problem.find(params[:id]).destroy |
|
81 | 81 | redirect_to :action => 'list' |
|
82 | 82 | end |
|
83 | 83 | |
|
84 | 84 | def toggle |
|
85 | - @problem = Problem.find(params[:id]) | |
|
86 | - @problem.available = !(@problem.available) | |
|
87 | - @problem.save | |
|
85 | + respond_to do |wants| | |
|
86 | + wants.js { | |
|
87 | + @problem = Problem.find(params[:id]) | |
|
88 | + @problem.available = !(@problem.available) | |
|
89 | + @problem.save | |
|
90 | + } | |
|
91 | + end | |
|
88 | 92 | end |
|
89 | 93 | |
|
90 | 94 | def turn_all_off |
|
91 | 95 | Problem.find(:all, |
|
92 | 96 | :conditions => "available = 1").each do |problem| |
|
93 | 97 | problem.available = false |
|
94 | 98 | problem.save |
|
95 | 99 | end |
|
96 | 100 | redirect_to :action => 'list' |
|
97 | 101 | end |
|
98 | 102 | |
|
99 | 103 | def turn_all_on |
|
100 | 104 | Problem.find(:all, |
|
101 | 105 | :conditions => "available = 0").each do |problem| |
|
102 | 106 | problem.available = true |
|
103 | 107 | problem.save |
|
104 | 108 | end |
|
105 | 109 | redirect_to :action => 'list' |
|
106 | 110 | end |
|
107 | 111 | |
|
108 | 112 | def stat |
|
109 | 113 | @problem = Problem.find(params[:id]) |
|
110 | 114 | if !@problem.available |
|
111 | 115 | redirect_to :controller => 'main', :action => 'list' |
|
112 | 116 | else |
|
113 | 117 | @submissions = Submission.find_all_last_by_problem(params[:id]) |
|
114 | 118 | end |
|
115 | 119 | end |
|
116 | 120 | end |
@@ -1,46 +1,46 | |||
|
1 | 1 | <% content_for :head do %> |
|
2 | 2 | <%= stylesheet_link_tag 'scaffold' %> |
|
3 | 3 | <%= stylesheet_link_tag 'problems' %> |
|
4 | 4 | <%= javascript_include_tag :defaults %> |
|
5 | 5 | <% end %> |
|
6 | 6 | |
|
7 | 7 | <h1>Listing problems</h1> |
|
8 | 8 | |
|
9 | 9 | <p> |
|
10 | 10 | <%= link_to 'New problem', :action => 'new' %> |
|
11 | 11 | <%= link_to 'Turn off all problems', :action => 'turn_all_off' %> |
|
12 | 12 | <%= link_to 'Turn on all problems', :action => 'turn_all_on' %> |
|
13 | 13 | </p> |
|
14 | 14 | |
|
15 | 15 | <table> |
|
16 | 16 | <tr> |
|
17 | 17 | <th>Name</th> |
|
18 | 18 | <th>Full name</th> |
|
19 | 19 | <th>Full score</th> |
|
20 | 20 | <th>Date added</th> |
|
21 | 21 | <th>Avail?</th> |
|
22 | 22 | <th>Test?</th> |
|
23 | 23 | </tr> |
|
24 | 24 | |
|
25 | 25 | <% for problem in @problems %> |
|
26 | 26 | <tr id="prob-<%= problem.id %>" name="prob-<%= problem.id %>" class="<%= (problem.available) ? "available" : "not-available" %>"> |
|
27 | 27 | <% @problem=problem %> |
|
28 | 28 | <td><%= in_place_editor_field :problem, :name, {}, :rows=>1 %></td> |
|
29 | 29 | <td><%= in_place_editor_field :problem, :full_name, {}, :rows=>1 %></td> |
|
30 | 30 | <td><%= in_place_editor_field :problem, :full_score, {}, :rows=>1 %></td> |
|
31 | 31 | <td><%= problem.date_added %></td> |
|
32 | - <td><%= problem.available %></td> | |
|
32 | + <td id="prob-<%= problem.id %>-avail"><%= problem.available %></td> | |
|
33 | 33 | <td><%= problem.test_allowed %></td> |
|
34 | 34 | |
|
35 | 35 | <td><%= link_to_remote '[Toggle]', :url => {:action => 'toggle', :id => problem.id } %></td> |
|
36 | 36 | <td><%= link_to '[Stat]', :action => 'stat', :id => problem.id %></td> |
|
37 | 37 | <td><%= link_to '[Show]', :action => 'show', :id => problem %></td> |
|
38 | 38 | <td><%= link_to '[Edit]', :action => 'edit', :id => problem %></td> |
|
39 | 39 | <td><%= link_to '[Destroy]', { :action => 'destroy', :id => problem }, :confirm => 'Are you sure?', :method => :post %></td> |
|
40 | 40 | </tr> |
|
41 | 41 | <% end %> |
|
42 | 42 | </table> |
|
43 | 43 | |
|
44 | 44 | <br /> |
|
45 | 45 | |
|
46 | 46 | <%= link_to 'New problem', :action => 'new' %> |
You need to be logged in to leave comments.
Login now