aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorJoachim Filip Ignacy Bartosik <jbartosik@gmail.com>2010-07-20 18:14:17 +0200
committerJoachim Filip Ignacy Bartosik <jbartosik@gmail.com>2010-07-27 23:02:44 +0200
commit2099afae76ae1e8bdba495f1a996a3f5aab3fb0c (patch)
tree7d6aa8e2e530d41af70a8eb3a5d0f3b32648f543 /app
parentCleaned detailed tags (diff)
downloadrecruiting-webapp-2099afae76ae1e8bdba495f1a996a3f5aab3fb0c.tar.gz
recruiting-webapp-2099afae76ae1e8bdba495f1a996a3f5aab3fb0c.tar.bz2
recruiting-webapp-2099afae76ae1e8bdba495f1a996a3f5aab3fb0c.zip
Made Checklist a regular input
Previously it had to be handled separately. Updated Answer#update_from and Answer#new_from to work with it.
Diffstat (limited to 'app')
-rw-r--r--app/models/answer.rb31
-rw-r--r--app/views/taglibs/forms.dryml3
-rw-r--r--app/views/taglibs/inputs.dryml4
3 files changed, 10 insertions, 28 deletions
diff --git a/app/models/answer.rb b/app/models/answer.rb
index c4e8a93..4410980 100644
--- a/app/models/answer.rb
+++ b/app/models/answer.rb
@@ -76,36 +76,19 @@ class Answer < ActiveRecord::Base
end
def self.update_from(params)
- ans = Answer.find(params['id'])
-
- if ans.class == Answer
- update = params["answer"] || []
- elsif ans.class == MultipleChoiceAnswer
- params["multiple_choice_answer"] = {} unless params["multiple_choice_answer"]
- params["multiple_choice_answer"]["options"] = params["options"].inject(Array.new){ |a, cur| a.push cur.to_i }
- update = params["multiple_choice_answer"]
- end
-
- result = ans.attributes
+ ans = Answer.find(params['id'])
+ result = ans.attributes
- for u in update
- result[u[0]] = u[1]
- end
+ params[ans.class.to_s.underscore].try.each{ |u| result[u[0]] = u[1] }
- result
+ result
end
def self.new_from(params)
-
- if params.include? "answer"
- Answer.new params["answer"]
- elsif params.include? "multiple_choice_answer"
- ans_hash = params["multiple_choice_answer"]
- new_ans = MultipleChoiceAnswer.new ans_hash
- new_ans.options = params["options"].try.inject(Array.new){ |a, cur| a.push cur.to_i } || []
- return new_ans
+ for klass in [Answer, MultipleChoiceAnswer]
+ name = klass.to_s.underscore
+ return klass.new(params[name]) if params.include? name
end
-
end
def self.wrong_answers_of(uid)
diff --git a/app/views/taglibs/forms.dryml b/app/views/taglibs/forms.dryml
index 9f93b8a..eddfc0f 100644
--- a/app/views/taglibs/forms.dryml
+++ b/app/views/taglibs/forms.dryml
@@ -30,8 +30,7 @@
<table>
<input:question type="hidden"/>
<input:owner type="hidden"/>
- <input:options/>
- <field-list fields="reference, approved, feedback"/>
+ <field-list fields="reference, approved, feedback, options"/>
</table>
<div param="actions">
<submit label="#{ht 'answers.actions.save', :default=>['Save']}" param/><or-cancel param="cancel"/>
diff --git a/app/views/taglibs/inputs.dryml b/app/views/taglibs/inputs.dryml
index 18b1c59..66a8abd 100644
--- a/app/views/taglibs/inputs.dryml
+++ b/app/views/taglibs/inputs.dryml
@@ -1,9 +1,9 @@
-<def tag="input" for="RichTypes::CheckList" attrs="disabled">
+<def tag="input" for="RichTypes::CheckList" attrs="disabled, name">
<ul>
<repeat:options>
<li>
<%= %{
- <input name="options[]" type="checkbox" #{this[:checked]?'checked':''} value="#{this[:id]}" id="option-#{this[:id]}" #{'disabled' if disabled}/>
+ <input name="#{name}[]" type="checkbox" #{this[:checked]?'checked':''} value="#{this[:id]}" id="option-#{this[:id]}" #{'disabled' if disabled}/>
} %>
<label for="option-<%=this[:id]%>" >
<%= this[:content] %>