Description:
added quick new problem
git-svn-id: http://theory.cpe.ku.ac.th/grader/web/trunk@369 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
r171:1a5685d096bd - - 3 files changed: 31 inserted, 0 deleted
@@ -26,48 +26,65 | |||||
|
26 | def new |
|
26 | def new |
|
27 | @problem = Problem.new |
|
27 | @problem = Problem.new |
|
28 | @description = nil |
|
28 | @description = nil |
|
29 | end |
|
29 | end |
|
30 |
|
30 | ||
|
31 | def create |
|
31 | def create |
|
32 | @problem = Problem.new(params[:problem]) |
|
32 | @problem = Problem.new(params[:problem]) |
|
33 | @description = Description.new(params[:description]) |
|
33 | @description = Description.new(params[:description]) |
|
34 | if @description.body!='' |
|
34 | if @description.body!='' |
|
35 | if !@description.save |
|
35 | if !@description.save |
|
36 | render :action => new and return |
|
36 | render :action => new and return |
|
37 | end |
|
37 | end |
|
38 | else |
|
38 | else |
|
39 | @description = nil |
|
39 | @description = nil |
|
40 | end |
|
40 | end |
|
41 | @problem.description = @description |
|
41 | @problem.description = @description |
|
42 | if @problem.save |
|
42 | if @problem.save |
|
43 | flash[:notice] = 'Problem was successfully created.' |
|
43 | flash[:notice] = 'Problem was successfully created.' |
|
44 | redirect_to :action => 'list' |
|
44 | redirect_to :action => 'list' |
|
45 | else |
|
45 | else |
|
46 | render :action => 'new' |
|
46 | render :action => 'new' |
|
47 | end |
|
47 | end |
|
48 | end |
|
48 | end |
|
49 |
|
49 | ||
|
|
50 | + def quick_create | ||
|
|
51 | + @problem = Problem.new(params[:problem]) | ||
|
|
52 | + @problem.full_name = @problem.name if @problem.full_name == '' | ||
|
|
53 | + @problem.full_score = 100 | ||
|
|
54 | + @problem.available = false | ||
|
|
55 | + @problem.test_allowed = true | ||
|
|
56 | + @problem.output_only = false | ||
|
|
57 | + @problem.date_added = Time.new | ||
|
|
58 | + if @problem.save | ||
|
|
59 | + flash[:notice] = 'Problem was successfully created.' | ||
|
|
60 | + redirect_to :action => 'list' | ||
|
|
61 | + else | ||
|
|
62 | + flash[:notice] = 'Error saving problem' | ||
|
|
63 | + redirect_to :action => 'list' | ||
|
|
64 | + end | ||
|
|
65 | + end | ||
|
|
66 | + | ||
|
50 | def edit |
|
67 | def edit |
|
51 | @problem = Problem.find(params[:id]) |
|
68 | @problem = Problem.find(params[:id]) |
|
52 | @description = @problem.description |
|
69 | @description = @problem.description |
|
53 | end |
|
70 | end |
|
54 |
|
71 | ||
|
55 | def update |
|
72 | def update |
|
56 | @problem = Problem.find(params[:id]) |
|
73 | @problem = Problem.find(params[:id]) |
|
57 | @description = @problem.description |
|
74 | @description = @problem.description |
|
58 | if @description == nil and params[:description][:body]!='' |
|
75 | if @description == nil and params[:description][:body]!='' |
|
59 | @description = Description.new(params[:description]) |
|
76 | @description = Description.new(params[:description]) |
|
60 | if !@description.save |
|
77 | if !@description.save |
|
61 | flash[:notice] = 'Error saving description' |
|
78 | flash[:notice] = 'Error saving description' |
|
62 | render :action => 'edit' and return |
|
79 | render :action => 'edit' and return |
|
63 | end |
|
80 | end |
|
64 | @problem.description = @description |
|
81 | @problem.description = @description |
|
65 | elsif @description!=nil |
|
82 | elsif @description!=nil |
|
66 | if !@description.update_attributes(params[:description]) |
|
83 | if !@description.update_attributes(params[:description]) |
|
67 | flash[:notice] = 'Error saving description' |
|
84 | flash[:notice] = 'Error saving description' |
|
68 | render :action => 'edit' and return |
|
85 | render :action => 'edit' and return |
|
69 | end |
|
86 | end |
|
70 | end |
|
87 | end |
|
71 | if @problem.update_attributes(params[:problem]) |
|
88 | if @problem.update_attributes(params[:problem]) |
|
72 | flash[:notice] = 'Problem was successfully updated.' |
|
89 | flash[:notice] = 'Problem was successfully updated.' |
|
73 | redirect_to :action => 'show', :id => @problem |
|
90 | redirect_to :action => 'show', :id => @problem |
@@ -1,9 +1,12 | |||||
|
1 | class Problem < ActiveRecord::Base |
|
1 | class Problem < ActiveRecord::Base |
|
2 |
|
2 | ||
|
3 | belongs_to :description |
|
3 | belongs_to :description |
|
4 |
|
4 | ||
|
|
5 | + validates_presence_of :name | ||
|
|
6 | + validates_presence_of :full_name | ||
|
|
7 | + | ||
|
5 | def self.find_available_problems |
|
8 | def self.find_available_problems |
|
6 | find(:all, :conditions => {:available => true}, :order => "date_added DESC") |
|
9 | find(:all, :conditions => {:available => true}, :order => "date_added DESC") |
|
7 | end |
|
10 | end |
|
8 |
|
11 | ||
|
9 | end |
|
12 | end |
@@ -1,37 +1,48 | |||||
|
1 | <% content_for :head do %> |
|
1 | <% content_for :head do %> |
|
2 | <%= stylesheet_link_tag 'problems' %> |
|
2 | <%= stylesheet_link_tag 'problems' %> |
|
3 | <%= javascript_include_tag :defaults %> |
|
3 | <%= javascript_include_tag :defaults %> |
|
4 | <% end %> |
|
4 | <% end %> |
|
5 |
|
5 | ||
|
6 | <h1>Listing problems</h1> |
|
6 | <h1>Listing problems</h1> |
|
7 |
|
7 | ||
|
8 | <p> |
|
8 | <p> |
|
9 | <%= link_to 'New problem', :action => 'new' %> |
|
9 | <%= link_to 'New problem', :action => 'new' %> |
|
10 | <%= link_to 'Turn off all problems', :action => 'turn_all_off' %> |
|
10 | <%= link_to 'Turn off all problems', :action => 'turn_all_off' %> |
|
11 | <%= link_to 'Turn on all problems', :action => 'turn_all_on' %> |
|
11 | <%= link_to 'Turn on all problems', :action => 'turn_all_on' %> |
|
12 | </p> |
|
12 | </p> |
|
13 |
|
13 | ||
|
|
14 | + <div class="submitbox"> | ||
|
|
15 | + <% form_tag :action => 'quick_create' do %> | ||
|
|
16 | + <b>Quick New:</b> | ||
|
|
17 | + <label for="problem_name">Name</label> | ||
|
|
18 | + <%= text_field 'problem', 'name' %> | | ||
|
|
19 | + <label for="problem_full_name">Full name</label> | ||
|
|
20 | + <%= text_field 'problem', 'full_name' %> | ||
|
|
21 | + <%= submit_tag "Create" %> | ||
|
|
22 | + <% end %> | ||
|
|
23 | + </div> | ||
|
|
24 | + | ||
|
14 | <table> |
|
25 | <table> |
|
15 | <tr> |
|
26 | <tr> |
|
16 | <th>Name</th> |
|
27 | <th>Name</th> |
|
17 | <th>Full name</th> |
|
28 | <th>Full name</th> |
|
18 | <th>Full score</th> |
|
29 | <th>Full score</th> |
|
19 | <th>Date added</th> |
|
30 | <th>Date added</th> |
|
20 | <th>Avail?</th> |
|
31 | <th>Avail?</th> |
|
21 | <th>Test?</th> |
|
32 | <th>Test?</th> |
|
22 | </tr> |
|
33 | </tr> |
|
23 |
|
34 | ||
|
24 | <% for problem in @problems %> |
|
35 | <% for problem in @problems %> |
|
25 | <tr id="prob-<%= problem.id %>" name="prob-<%= problem.id %>" class="<%= (problem.available) ? "available" : "not-available" %>"> |
|
36 | <tr id="prob-<%= problem.id %>" name="prob-<%= problem.id %>" class="<%= (problem.available) ? "available" : "not-available" %>"> |
|
26 | <% @problem=problem %> |
|
37 | <% @problem=problem %> |
|
27 | <td><%= in_place_editor_field :problem, :name, {}, :rows=>1 %></td> |
|
38 | <td><%= in_place_editor_field :problem, :name, {}, :rows=>1 %></td> |
|
28 | <td><%= in_place_editor_field :problem, :full_name, {}, :rows=>1 %></td> |
|
39 | <td><%= in_place_editor_field :problem, :full_name, {}, :rows=>1 %></td> |
|
29 | <td><%= in_place_editor_field :problem, :full_score, {}, :rows=>1 %></td> |
|
40 | <td><%= in_place_editor_field :problem, :full_score, {}, :rows=>1 %></td> |
|
30 | <td><%= problem.date_added %></td> |
|
41 | <td><%= problem.date_added %></td> |
|
31 | <td id="prob-<%= problem.id %>-avail"><%= problem.available %></td> |
|
42 | <td id="prob-<%= problem.id %>-avail"><%= problem.available %></td> |
|
32 | <td><%= problem.test_allowed %></td> |
|
43 | <td><%= problem.test_allowed %></td> |
|
33 |
|
44 | ||
|
34 | <td><%= link_to_remote '[Toggle]', :url => {:action => 'toggle', :id => problem.id } %></td> |
|
45 | <td><%= link_to_remote '[Toggle]', :url => {:action => 'toggle', :id => problem.id } %></td> |
|
35 | <td><%= link_to '[Stat]', :action => 'stat', :id => problem.id %></td> |
|
46 | <td><%= link_to '[Stat]', :action => 'stat', :id => problem.id %></td> |
|
36 | <td><%= link_to '[Show]', :action => 'show', :id => problem %></td> |
|
47 | <td><%= link_to '[Show]', :action => 'show', :id => problem %></td> |
|
37 | <td><%= link_to '[Edit]', :action => 'edit', :id => problem %></td> |
|
48 | <td><%= link_to '[Edit]', :action => 'edit', :id => problem %></td> |
You need to be logged in to leave comments.
Login now