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
@@ -38,24 +38,41 | |||
|
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 | + 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 | 67 | def edit |
|
51 | 68 | @problem = Problem.find(params[:id]) |
|
52 | 69 | @description = @problem.description |
|
53 | 70 | end |
|
54 | 71 | |
|
55 | 72 | def update |
|
56 | 73 | @problem = Problem.find(params[:id]) |
|
57 | 74 | @description = @problem.description |
|
58 | 75 | if @description == nil and params[:description][:body]!='' |
|
59 | 76 | @description = Description.new(params[:description]) |
|
60 | 77 | if !@description.save |
|
61 | 78 | flash[:notice] = 'Error saving description' |
@@ -1,9 +1,12 | |||
|
1 | 1 | class Problem < ActiveRecord::Base |
|
2 | 2 | |
|
3 | 3 | belongs_to :description |
|
4 | 4 | |
|
5 | + validates_presence_of :name | |
|
6 | + validates_presence_of :full_name | |
|
7 | + | |
|
5 | 8 | def self.find_available_problems |
|
6 | 9 | find(:all, :conditions => {:available => true}, :order => "date_added DESC") |
|
7 | 10 | end |
|
8 | 11 | |
|
9 | 12 | end |
@@ -2,24 +2,35 | |||
|
2 | 2 | <%= stylesheet_link_tag 'problems' %> |
|
3 | 3 | <%= javascript_include_tag :defaults %> |
|
4 | 4 | <% end %> |
|
5 | 5 | |
|
6 | 6 | <h1>Listing problems</h1> |
|
7 | 7 | |
|
8 | 8 | <p> |
|
9 | 9 | <%= link_to 'New problem', :action => 'new' %> |
|
10 | 10 | <%= link_to 'Turn off all problems', :action => 'turn_all_off' %> |
|
11 | 11 | <%= link_to 'Turn on all problems', :action => 'turn_all_on' %> |
|
12 | 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 | 25 | <table> |
|
15 | 26 | <tr> |
|
16 | 27 | <th>Name</th> |
|
17 | 28 | <th>Full name</th> |
|
18 | 29 | <th>Full score</th> |
|
19 | 30 | <th>Date added</th> |
|
20 | 31 | <th>Avail?</th> |
|
21 | 32 | <th>Test?</th> |
|
22 | 33 | </tr> |
|
23 | 34 | |
|
24 | 35 | <% for problem in @problems %> |
|
25 | 36 | <tr id="prob-<%= problem.id %>" name="prob-<%= problem.id %>" class="<%= (problem.available) ? "available" : "not-available" %>"> |
You need to be logged in to leave comments.
Login now