surveyor 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. data/CHANGELOG.md +26 -0
  2. data/README.md +67 -168
  3. data/app/models/survey_translation.rb +5 -0
  4. data/app/views/partials/_answer.html.haml +9 -5
  5. data/app/views/partials/_question.html.haml +3 -3
  6. data/app/views/partials/_question_group.html.haml +9 -8
  7. data/app/views/partials/_section.html.haml +1 -1
  8. data/app/views/surveyor/edit.html.haml +3 -3
  9. data/app/views/surveyor/export.json.rabl +12 -8
  10. data/app/views/surveyor/new.html.haml +9 -14
  11. data/app/views/surveyor/show.html.haml +2 -2
  12. data/doc/surveyor_models.png +0 -0
  13. data/doc/surveyor_models2.png +0 -0
  14. data/features/export_to_json.feature +97 -1
  15. data/features/internationalization.feature +55 -0
  16. data/features/step_definitions/parser_steps.rb +7 -0
  17. data/features/step_definitions/surveyor_steps.rb +43 -6
  18. data/features/step_definitions/ui_steps.rb +22 -0
  19. data/features/support/env.rb +2 -0
  20. data/features/support/hooks.rb +4 -0
  21. data/features/surveyor.feature +117 -1
  22. data/features/surveyor_dependencies.feature +56 -2
  23. data/features/surveyor_parser.feature +10 -10
  24. data/lib/assets/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  25. data/lib/assets/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
  26. data/lib/assets/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
  27. data/lib/assets/images/ui-bg_glass_75_dadada_1x400.png +0 -0
  28. data/lib/assets/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  29. data/lib/assets/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
  30. data/lib/assets/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
  31. data/lib/assets/images/{ui-icons_ef8c08_256x240.png → ui-icons_222222_256x240.png} +0 -0
  32. data/lib/assets/images/ui-icons_2e83ff_256x240.png +0 -0
  33. data/lib/assets/images/{ui-icons_ffffff_256x240.png → ui-icons_454545_256x240.png} +0 -0
  34. data/lib/assets/images/ui-icons_888888_256x240.png +0 -0
  35. data/lib/assets/images/ui-icons_cd0a0a_256x240.png +0 -0
  36. data/lib/assets/javascripts/surveyor/jquery-1.9.0.js +9555 -0
  37. data/lib/assets/javascripts/surveyor/jquery-ui-1.10.0.custom.js +14850 -0
  38. data/lib/assets/javascripts/surveyor/jquery-ui-timepicker-addon.js +1795 -1153
  39. data/lib/assets/javascripts/surveyor/jquery.maskedinput.js +338 -0
  40. data/lib/assets/javascripts/surveyor/jquery.surveyor.js +8 -0
  41. data/lib/assets/stylesheets/surveyor.sass +2 -2
  42. data/lib/assets/stylesheets/surveyor/jquery-ui-1.10.0.custom.css +1174 -0
  43. data/lib/assets/stylesheets/surveyor/jquery-ui-timepicker-addon.css +7 -2
  44. data/lib/assets/stylesheets/surveyor/reset.css +24 -26
  45. data/lib/generators/surveyor/install_generator.rb +4 -0
  46. data/lib/generators/surveyor/templates/app/assets/javascripts/surveyor_all.js +4 -3
  47. data/lib/generators/surveyor/templates/app/assets/stylesheets/surveyor_all.css +2 -2
  48. data/lib/generators/surveyor/templates/config/locales/surveyor_en.yml +1 -0
  49. data/lib/generators/surveyor/templates/config/locales/surveyor_he.yml +1 -1
  50. data/lib/generators/surveyor/templates/config/locales/surveyor_ko.yml +18 -0
  51. data/lib/generators/surveyor/templates/db/migrate/add_input_mask_attributes_to_answer.rb +12 -0
  52. data/lib/generators/surveyor/templates/db/migrate/create_survey_translations.rb +19 -0
  53. data/lib/generators/surveyor/templates/surveys/kitchen_sink_survey.rb +5 -0
  54. data/lib/generators/surveyor/templates/surveys/languages.rb +10 -0
  55. data/lib/generators/surveyor/templates/surveys/translations/languages.es.yml +14 -0
  56. data/lib/generators/surveyor/templates/surveys/translations/languages.he.yml +14 -0
  57. data/lib/generators/surveyor/templates/surveys/translations/languages.ko.yml +14 -0
  58. data/lib/surveyor/helpers/formtastic_custom_input.rb +4 -8
  59. data/lib/surveyor/helpers/surveyor_helper_methods.rb +22 -26
  60. data/lib/surveyor/models/answer_methods.rb +41 -10
  61. data/lib/surveyor/models/question_group_methods.rb +17 -3
  62. data/lib/surveyor/models/question_methods.rb +32 -5
  63. data/lib/surveyor/models/response_methods.rb +7 -7
  64. data/lib/surveyor/models/survey_methods.rb +20 -4
  65. data/lib/surveyor/models/survey_section_methods.rb +10 -5
  66. data/lib/surveyor/models/survey_translation_methods.rb +33 -0
  67. data/lib/surveyor/mustache_context.rb +11 -0
  68. data/lib/surveyor/parser.rb +15 -2
  69. data/lib/surveyor/surveyor_controller_methods.rb +19 -17
  70. data/lib/surveyor/version.rb +1 -1
  71. data/spec/controllers/surveyor_controller_spec.rb +3 -3
  72. data/spec/factories.rb +21 -7
  73. data/spec/helpers/formtastic_custom_input_spec.rb +2 -3
  74. data/spec/helpers/surveyor_helper_spec.rb +64 -100
  75. data/spec/models/answer_spec.rb +166 -58
  76. data/spec/models/question_group_spec.rb +84 -38
  77. data/spec/models/question_spec.rb +188 -116
  78. data/spec/models/survey_section_spec.rb +77 -40
  79. data/spec/models/survey_spec.rb +176 -145
  80. data/spec/spec_helper.rb +3 -0
  81. data/stacktests.sh +52 -0
  82. metadata +36 -18
  83. data/lib/assets/images/ui-bg_glass_100_f6f6f6_1x400.png +0 -0
  84. data/lib/assets/images/ui-bg_glass_100_fdf5ce_1x400.png +0 -0
  85. data/lib/assets/images/ui-bg_gloss-wave_35_f6a828_500x100.png +0 -0
  86. data/lib/assets/images/ui-bg_highlight-soft_100_eeeeee_1x100.png +0 -0
  87. data/lib/assets/images/ui-bg_highlight-soft_75_ffe45c_1x100.png +0 -0
  88. data/lib/assets/javascripts/surveyor/jquery-ui.js +0 -11729
  89. data/lib/assets/javascripts/surveyor/jquery.tools.min.js +0 -204
  90. data/lib/assets/stylesheets/surveyor/dateinput.css +0 -149
  91. data/lib/assets/stylesheets/surveyor/jquery-ui.custom.css +0 -572
  92. data/lib/surveyor/render_text.rb +0 -23
  93. data/lib/surveyor/surveyor_admin_controller_methods.rb +0 -55
@@ -1,6 +1,11 @@
1
+ /* css for timepicker */
1
2
  .ui-timepicker-div .ui-widget-header { margin-bottom: 8px; }
2
3
  .ui-timepicker-div dl { text-align: left; }
3
- .ui-timepicker-div dl dt { height: 25px; }
4
- .ui-timepicker-div dl dd { margin: -25px 10px 10px 65px; }
4
+ .ui-timepicker-div dl dt { height: 25px; margin-bottom: -25px; }
5
+ .ui-timepicker-div dl dd { margin: 0 10px 10px 65px; }
5
6
  .ui-timepicker-div td { font-size: 90%; }
6
7
  .ui-tpicker-grid-label { background: none; border: none; margin: 0; padding: 0; }
8
+
9
+ .ui-timepicker-rtl{ direction: rtl; }
10
+ .ui-timepicker-rtl dl { text-align: right; }
11
+ .ui-timepicker-rtl dl dd { margin: 0 65px 10px 10px; }
@@ -1,50 +1,48 @@
1
+ /* http://meyerweb.com/eric/tools/css/reset/
2
+ v2.0 | 20110126
3
+ License: none (public domain)
4
+ */
5
+
1
6
  html, body, div, span, applet, object, iframe,
2
7
  h1, h2, h3, h4, h5, h6, p, blockquote, pre,
3
8
  a, abbr, acronym, address, big, cite, code,
4
- del, dfn, em, font, img, ins, kbd, q, s, samp,
9
+ del, dfn, em, img, ins, kbd, q, s, samp,
5
10
  small, strike, strong, sub, sup, tt, var,
11
+ b, u, i, center,
6
12
  dl, dt, dd, ol, ul, li,
7
13
  fieldset, form, label, legend,
8
- table, caption, tbody, tfoot, thead, tr, th, td {
14
+ table, caption, tbody, tfoot, thead, tr, th, td,
15
+ article, aside, canvas, details, embed,
16
+ figure, figcaption, footer, header, hgroup,
17
+ menu, nav, output, ruby, section, summary,
18
+ time, mark, audio, video {
9
19
  margin: 0;
10
20
  padding: 0;
11
21
  border: 0;
12
- outline: 0;
13
- font-weight: inherit;
14
- font-style: inherit;
15
22
  font-size: 100%;
16
- font-family: inherit;
23
+ font: inherit;
17
24
  vertical-align: baseline;
18
25
  }
19
- /* remember to define focus styles! */
20
- :focus {
21
- outline: 0;
26
+ /* HTML5 display-role reset for older browsers */
27
+ article, aside, details, figcaption, figure,
28
+ footer, header, hgroup, menu, nav, section {
29
+ display: block;
22
30
  }
23
31
  body {
24
32
  line-height: 1;
25
- color: black;
26
- background: white;
27
33
  }
28
34
  ol, ul {
29
35
  list-style: none;
30
36
  }
31
- /* tables still need 'cellspacing="0"' in the markup */
32
- table {
33
- border-collapse: separate;
34
- border-spacing: 0;
35
- }
36
- caption, th, td {
37
- text-align: left;
38
- font-weight: normal;
37
+ blockquote, q {
38
+ quotes: none;
39
39
  }
40
40
  blockquote:before, blockquote:after,
41
41
  q:before, q:after {
42
- content: "";
42
+ content: '';
43
+ content: none;
43
44
  }
44
- blockquote, q {
45
- quotes: "" "";
46
- }
47
- pre {
48
- background: #333333;
49
- color: #EFEFEF;
45
+ table {
46
+ border-collapse: collapse;
47
+ border-spacing: 0;
50
48
  }
@@ -38,6 +38,8 @@ module Surveyor
38
38
  add_unique_index_on_access_code_and_version_in_surveys
39
39
  update_blank_versions_on_surveys
40
40
  api_ids_must_be_unique
41
+ create_survey_translations
42
+ add_input_mask_attributes_to_answer
41
43
  )
42
44
 
43
45
  def readme
@@ -84,6 +86,8 @@ module Surveyor
84
86
  copy_file "surveys/kitchen_sink_survey.rb"
85
87
  copy_file "surveys/quiz.rb"
86
88
  copy_file "surveys/date_survey.rb"
89
+ copy_file "surveys/languages.rb"
90
+ directory "surveys/translations"
87
91
  end
88
92
 
89
93
  def locales
@@ -1,5 +1,6 @@
1
- //= require surveyor/jquery.tools.min
2
- //= require surveyor/jquery-ui
1
+ //= require surveyor/jquery-1.9.0
2
+ //= require surveyor/jquery-ui-1.10.0.custom
3
3
  //= require surveyor/jquery-ui-timepicker-addon
4
- //= require surveyor/jquery.surveyor
5
4
  //= require surveyor/jquery.selectToUISlider
5
+ //= require surveyor/jquery.surveyor
6
+ //= require surveyor/jquery.maskedinput
@@ -1,9 +1,9 @@
1
1
  /*
2
2
  *= require surveyor/reset
3
- *= require surveyor/dateinput
4
- *= require surveyor/jquery-ui.custom
3
+ *= require surveyor/jquery-ui-1.10.0.custom
5
4
  *= require surveyor/jquery-ui-timepicker-addon
6
5
  *= require surveyor/ui.slider.extras
6
+ *= require surveyor/results
7
7
  *= require surveyor
8
8
  *= require custom
9
9
  */
@@ -1,3 +1,4 @@
1
+ # encoding: UTF-8
1
2
  # Sample localization file for English. Add more files in this directory for other locales.
2
3
  # See http://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
3
4
 
@@ -14,5 +14,5 @@ he:
14
14
  click_here_to_finish: "לסיום"
15
15
  previous_section: "חזרה »"
16
16
  next_section: "« המשך"
17
- Select_one: "בחר/י"
17
+ select_one: "בחר/י"
18
18
  sections: "סעיפים"
@@ -0,0 +1,18 @@
1
+ # encoding: UTF-8
2
+ # Sample localization file for Korean. Add more files in this directory for other locales.
3
+ # See http://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
4
+
5
+ ko:
6
+ surveyor:
7
+ take_these_surveys: "설문에 답을 하셔도 좋습니다"
8
+ take_it: "답을 하십시요"
9
+ completed_survey: "완료된 설문"
10
+ unable_to_find_your_responses: "설문에 대한 답을 찾을 수 없습니다"
11
+ unable_to_update_survey: "설문을 업데이트 할 수 없습니다"
12
+ unable_to_find_that_survey: "이 설문을 찾을 수 없습니다"
13
+ survey_started_success: "설문 조사가 성공적으로 시작되었습니다"
14
+ click_here_to_finish: "종료 하려면 여기를 누르십시요"
15
+ previous_section: "« 이전 항목으로"
16
+ next_section: "다음 항목으로 »"
17
+ select_one: "하나를 선택하십시요"
18
+ sections: "항목"
@@ -0,0 +1,12 @@
1
+ # encoding: UTF-8
2
+ class AddInputMaskAttributesToAnswer < ActiveRecord::Migration
3
+ def self.up
4
+ add_column :answers, :input_mask, :string
5
+ add_column :answers, :input_mask_placeholder, :string
6
+ end
7
+
8
+ def self.down
9
+ remove_column :answers, :input_mask
10
+ remove_column :answers, :input_mask_placeholder
11
+ end
12
+ end
@@ -0,0 +1,19 @@
1
+ # encoding: UTF-8
2
+ class CreateSurveyTranslations < ActiveRecord::Migration
3
+ def self.up
4
+ create_table :survey_translations do |t|
5
+ # Content
6
+ t.integer :survey_id
7
+
8
+ # Reference
9
+ t.string :locale
10
+ t.text :translation
11
+
12
+ t.timestamps
13
+ end
14
+ end
15
+
16
+ def self.down
17
+ drop_table :surveys
18
+ end
19
+ end
@@ -175,6 +175,11 @@ survey "Kitchen Sink survey", :default_mandatory => false do
175
175
  a "maybe"
176
176
  a "no"
177
177
  a "I don't know"
178
+
179
+ # Questions may also have input masks with fancy placeholders
180
+ q "What is your phone number?"
181
+ a :string, :input_mask => '(999)999-9999', :input_mask_placeholder => '#'
182
+
178
183
  end
179
184
 
180
185
  section "Complicated questions" do
@@ -0,0 +1,10 @@
1
+ # encoding: UTF-8
2
+ survey "One language is never enough" do
3
+ translations :es => "translations/languages.es.yml", :he => "translations/languages.he.yml", :ko => "translations/languages.ko.yml"
4
+ section_one "One" do
5
+ g_hello "Hello" do
6
+ q_name "What is your name?"
7
+ a_name :string, :help_text => "My name is..."
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,14 @@
1
+ # encoding: UTF-8
2
+ title: "Un idioma nunca es suficiente"
3
+ survey_sections:
4
+ one:
5
+ title: "Uno"
6
+ question_groups:
7
+ hello:
8
+ text: "¡Hola!"
9
+ questions:
10
+ name:
11
+ text: "¿Cómo se llama Usted?"
12
+ answers:
13
+ name:
14
+ help_text: "Mi nombre es..."
@@ -0,0 +1,14 @@
1
+ # encoding: UTF-8
2
+ title: "ידיעת שפה אחת אינה מספיקה"
3
+ survey_sections:
4
+ one:
5
+ title: "אחת"
6
+ question_groups:
7
+ hello:
8
+ text: "שלום"
9
+ questions:
10
+ name:
11
+ text: "מה שמך?"
12
+ answers:
13
+ name:
14
+ help_text: "שמי..."
@@ -0,0 +1,14 @@
1
+ # encoding: UTF-8
2
+ title: "한가지 언어로는 충분치 않습니다."
3
+ survey_sections:
4
+ one:
5
+ title: "하나"
6
+ question_groups:
7
+ hello:
8
+ text: "안녕하십니까"
9
+ questions:
10
+ name:
11
+ text: "성함이 어떻게 되십니까?"
12
+ answers:
13
+ name:
14
+ help_text: "제 이름은 ... 입니다"
@@ -4,14 +4,10 @@ module Surveyor
4
4
  def input_html_options_with(choice, response_class)
5
5
  input_html_options.merge(choice_html_options(choice)).merge({:id => (input_html_options[:id] || "answer_id").gsub("answer_id", response_class_to_method(response_class).to_s), :class => [input_html_options[:class], response_class].join(" ")})
6
6
  end
7
- def response_class_to_method(response_class)
7
+ def response_class_to_method(type_sym)
8
8
  # doesn't handle response_class == answer, and doesn't have to
9
- case response_class.to_s
10
- when /^other_and_string$/ then :string_value
11
- when /^date|time$/ then :datetime_value
12
- else "#{response_class}_value".to_sym
13
- end
14
- end
9
+ "#{type_sym.to_s}_value".to_sym
10
+ end
15
11
  end
16
12
  end
17
- end
13
+ end
@@ -10,7 +10,19 @@ module Surveyor
10
10
  if asset_pipeline_enabled?
11
11
  stylesheet_link_tag('surveyor_all') + javascript_include_tag('surveyor_all')
12
12
  else
13
- stylesheet_link_tag('surveyor/reset', 'surveyor/dateinput', 'surveyor/jquery-ui.custom', 'surveyor/jquery-ui-timepicker-addon', 'surveyor', 'custom') + javascript_include_tag('surveyor/jquery.tools.min', 'surveyor/jquery-ui', 'surveyor/jquery-ui-timepicker-addon', 'surveyor/jquery.surveyor')
13
+ stylesheet_link_tag('surveyor/reset',
14
+ 'surveyor/jquery-ui-1.10.0.custom',
15
+ 'surveyor/jquery-ui-timepicker-addon',
16
+ 'surveyor/ui.slider.extras',
17
+ 'surveyor/results',
18
+ 'surveyor',
19
+ 'custom') +
20
+ javascript_include_tag('surveyor/jquery-1.9.0',
21
+ 'surveyor/jquery-ui-1.10.0.custom',
22
+ 'surveyor/jquery-ui-timepicker-addon',
23
+ 'surveyor/jquery.selectToUISlider',
24
+ 'surveyor/jquery.surveyor',
25
+ 'surveyor/jquery.maskedinput')
14
26
  end
15
27
  end
16
28
  # Helper for displaying warning/notice/error flash messages
@@ -28,7 +40,7 @@ module Surveyor
28
40
  "&nbsp;&nbsp;You answered &quot;#{trigger_responses.join("&quot; and &quot;")}&quot; to the question &quot;#{dependent_questions.map(&:text).join("&quot;,&quot;")}&quot;"
29
41
  end
30
42
  def menu_button_for(section)
31
- submit_tag(section.title, :name => "section[#{section.id}]")
43
+ submit_tag(section.translation(I18n.locale)[:title], :name => "section[#{section.id}]")
32
44
  end
33
45
  def previous_section
34
46
  # use copy in memory instead of making extra db calls
@@ -40,11 +52,8 @@ module Surveyor
40
52
  end
41
53
 
42
54
  # Questions
43
- def q_text(obj, context=nil)
44
-
45
- return image_tag(obj.text) if obj.is_a?(Question) and obj.display_type == "image"
46
- return obj.render_question_text(context) if obj.is_a?(Question) and (obj.dependent? or obj.display_type == "label" or obj.part_of_group?)
47
- "#{next_question_number(obj)}#{obj.render_question_text(context)}"
55
+ def q_text(q, context=nil, locale=nil)
56
+ "#{next_question_number(q) unless (q.dependent? or q.display_type == "label" or q.display_type == "image" or q.part_of_group?)}#{q.text_for(nil, context, locale)}"
48
57
  end
49
58
 
50
59
  def next_question_number(question)
@@ -52,24 +61,7 @@ module Surveyor
52
61
  "<span class='qnum'>#{@n += 1}) </span>"
53
62
  end
54
63
 
55
- # def split_text(text = "") # Split text into with "|" delimiter - parts to go before/after input element
56
- # {:prefix => text.split("|")[0].blank? ? "&nbsp;" : text.split("|")[0], :postfix => text.split("|")[1] || "&nbsp;"}
57
- # end
58
- # def question_help_helper(question)
59
- # question.help_text.blank? ? "" : %Q(<span class="question-help">#{question.help_text}</span>)
60
- # end
61
-
62
- # Help_text
63
- def render_help_text(obj, context=nil)
64
- obj.render_help_text(context)
65
- end
66
-
67
- # Answers
68
- def a_text(obj, pos=nil, context = nil)
69
- return image_tag(obj.text) if obj.is_a?(Answer) and obj.display_type == "image"
70
- obj.split_or_hidden_text(pos, context)
71
- end
72
-
64
+ # Responses
73
65
  def rc_to_attr(type_sym)
74
66
  case type_sym.to_s
75
67
  when /^answer$/ then :answer_id
@@ -84,11 +76,15 @@ module Surveyor
84
76
  end
85
77
  end
86
78
 
87
- def generate_pick_none_input_html(value, default_value, css_class, response_class, disabled)
79
+ def generate_pick_none_input_html(value, default_value, css_class, response_class, disabled, input_mask, input_mask_placeholder)
88
80
  html = {}
89
81
  html[:class] = [response_class,css_class].reject{ |c| c.blank? }
90
82
  html[:value] = default_value if value.blank?
91
83
  html[:disabled] = disabled unless disabled.blank?
84
+ if input_mask
85
+ html[:'data-input-mask'] = input_mask
86
+ html[:'data-input-mask-placeholder'] = input_mask_placeholder unless input_mask_placeholder.blank?
87
+ end
92
88
  html
93
89
  end
94
90
 
@@ -8,10 +8,13 @@ module Surveyor
8
8
  base.send :belongs_to, :question
9
9
  base.send :has_many, :responses
10
10
  base.send :has_many, :validations, :dependent => :destroy
11
-
11
+
12
12
  # Scopes
13
13
  base.send :default_scope, :order => "display_order ASC"
14
-
14
+
15
+ # Mustache
16
+ base.send :include, MustacheContext
17
+
15
18
  @@validations_already_included ||= nil
16
19
  unless @@validations_already_included
17
20
  # Validations
@@ -20,12 +23,10 @@ module Surveyor
20
23
  # base.send :validates_numericality_of, :question_id, :allow_nil => false, :only_integer => true
21
24
  @@validations_already_included = true
22
25
  end
23
-
26
+
24
27
  # Whitelisting attributes
25
- base.send :attr_accessible, :question, :question_id, :text, :short_text, :help_text, :weight, :response_class, :reference_identifier, :data_export_identifier, :common_namespace, :common_identifier, :display_order, :is_exclusive, :display_length, :custom_class, :custom_renderer, :default_value, :display_type
28
+ base.send :attr_accessible, :question, :question_id, :text, :short_text, :help_text, :weight, :response_class, :reference_identifier, :data_export_identifier, :common_namespace, :common_identifier, :display_order, :is_exclusive, :display_length, :custom_class, :custom_renderer, :default_value, :display_type, :input_mask, :input_mask_placeholder
26
29
  end
27
-
28
- include RenderText
29
30
 
30
31
  # Instance Methods
31
32
  def initialize(*args)
@@ -41,14 +42,44 @@ module Surveyor
41
42
  self.data_export_identifier ||= Surveyor::Common.normalize(text)
42
43
  self.api_id ||= Surveyor::Common.generate_api_id
43
44
  end
44
-
45
+ def display_type=(val)
46
+ write_attribute(:display_type, val.nil? ? nil : val.to_s)
47
+ end
48
+
45
49
  def css_class
46
50
  [(is_exclusive ? "exclusive" : nil), custom_class].compact.join(" ")
47
51
  end
48
-
49
- def split_or_hidden_text(part = nil, context = nil)
52
+
53
+ def text_for(position = nil, context = nil, locale = nil)
50
54
  return "" if display_type == "hidden_label"
51
- part == :pre ? self.render_answer_text(text.split("|",2)[0], context) : (part == :post ? self.render_answer_text(text.split("|",2)[1], context) : self.render_answer_text(text, context))
55
+ imaged(split(in_context(translation(locale)[:text], context), position))
56
+ end
57
+ def help_text_for(context = nil, locale = nil)
58
+ in_context(translation(locale)[:help_text], context)
59
+ end
60
+ def default_value_for(context = nil, locale = nil)
61
+ in_context(translation(locale)[:default_value], context)
62
+ end
63
+ def split(text, position=nil)
64
+ case position
65
+ when :pre
66
+ text.split("|",2)[0]
67
+ when :post
68
+ text.split("|",2)[1]
69
+ else
70
+ text
71
+ end.to_s
72
+ end
73
+ def translation(locale)
74
+ {:text => self.text, :help_text => self.help_text, :default_value => self.default_value}.with_indifferent_access.merge(
75
+ (self.question.translation(locale)[:answers] || {})[self.reference_identifier] || {}
76
+ )
77
+ end
78
+
79
+ private
80
+
81
+ def imaged(text)
82
+ self.display_type == "image" && !text.blank? ? ActionController::Base.helpers.image_tag(text) : text
52
83
  end
53
84
  end
54
85
  end