Description:
change problem toggle to ajax git-svn-id: http://theory.cpe.ku.ac.th/grader/web/trunk@286 6386c4cd-e34a-4fa8-8920-d93eb39b512e
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r147:b29d8a0527ac - - 3 files changed: 11 inserted, 8 deleted

@@ -0,0 +1,5
1 + if @problem.available
2 + page["prob-#{@problem.id}"].className = "available"
3 + else
4 + page["prob-#{@problem.id}"].className = "not-available"
5 + end No newline at end of file
@@ -60,53 +60,52
60 if !@description.save
60 if !@description.save
61 flash[:notice] = 'Error saving description'
61 flash[:notice] = 'Error saving description'
62 render :action => 'edit' and return
62 render :action => 'edit' and return
63 end
63 end
64 @problem.description = @description
64 @problem.description = @description
65 elsif @description!=nil
65 elsif @description!=nil
66 if !@description.update_attributes(params[:description])
66 if !@description.update_attributes(params[:description])
67 flash[:notice] = 'Error saving description'
67 flash[:notice] = 'Error saving description'
68 render :action => 'edit' and return
68 render :action => 'edit' and return
69 end
69 end
70 end
70 end
71 if @problem.update_attributes(params[:problem])
71 if @problem.update_attributes(params[:problem])
72 flash[:notice] = 'Problem was successfully updated.'
72 flash[:notice] = 'Problem was successfully updated.'
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_avail
84 + def toggle
85 - problem = Problem.find(params[:id])
85 + @problem = Problem.find(params[:id])
86 - problem.available = !(problem.available)
86 + @problem.available = !(@problem.available)
87 - problem.save
87 + @problem.save
88 - redirect_to :action => 'list'
89 end
88 end
90
89
91 def turn_all_off
90 def turn_all_off
92 Problem.find(:all,
91 Problem.find(:all,
93 :conditions => "available = 1").each do |problem|
92 :conditions => "available = 1").each do |problem|
94 problem.available = false
93 problem.available = false
95 problem.save
94 problem.save
96 end
95 end
97 redirect_to :action => 'list'
96 redirect_to :action => 'list'
98 end
97 end
99
98
100 def turn_all_on
99 def turn_all_on
101 Problem.find(:all,
100 Problem.find(:all,
102 :conditions => "available = 0").each do |problem|
101 :conditions => "available = 0").each do |problem|
103 problem.available = true
102 problem.available = true
104 problem.save
103 problem.save
105 end
104 end
106 redirect_to :action => 'list'
105 redirect_to :action => 'list'
107 end
106 end
108
107
109 def stat
108 def stat
110 @problem = Problem.find(params[:id])
109 @problem = Problem.find(params[:id])
111 if !@problem.available
110 if !@problem.available
112 redirect_to :controller => 'main', :action => 'list'
111 redirect_to :controller => 'main', :action => 'list'
@@ -2,46 +2,45
2 <%= stylesheet_link_tag 'scaffold' %>
2 <%= stylesheet_link_tag 'scaffold' %>
3 <%= stylesheet_link_tag 'problems' %>
3 <%= stylesheet_link_tag 'problems' %>
4 <%= javascript_include_tag :defaults %>
4 <%= javascript_include_tag :defaults %>
5 <% end %>
5 <% end %>
6
6
7 <h1>Listing problems</h1>
7 <h1>Listing problems</h1>
8
8
9 <p>
9 <p>
10 <%= link_to 'New problem', :action => 'new' %>
10 <%= link_to 'New problem', :action => 'new' %>
11 <%= link_to 'Turn off all problems', :action => 'turn_all_off' %>
11 <%= link_to 'Turn off all problems', :action => 'turn_all_off' %>
12 <%= link_to 'Turn on all problems', :action => 'turn_all_on' %>
12 <%= link_to 'Turn on all problems', :action => 'turn_all_on' %>
13 </p>
13 </p>
14
14
15 <table>
15 <table>
16 <tr>
16 <tr>
17 <th>Name</th>
17 <th>Name</th>
18 <th>Full name</th>
18 <th>Full name</th>
19 <th>Full score</th>
19 <th>Full score</th>
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 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><%= problem.available %></td>
33 <td><%= problem.test_allowed %></td>
33 <td><%= problem.test_allowed %></td>
34
34
35 - <td><%= link_to '[Toggle]', :action => 'toggle_avail', :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 -
45 <br />
44 <br />
46
45
47 <%= link_to 'New problem', :action => 'new' %>
46 <%= link_to 'New problem', :action => 'new' %>
You need to be logged in to leave comments. Login now