ask_it 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +11 -0
  3. data/LICENSE.md +21 -0
  4. data/README.md +287 -0
  5. data/Rakefile +29 -0
  6. data/app/controllers/ask_it/attempts_controller.rb +36 -0
  7. data/app/controllers/ask_it/surveys_controller.rb +58 -0
  8. data/app/models/ask_it/answer.rb +99 -0
  9. data/app/models/ask_it/attempt.rb +108 -0
  10. data/app/models/ask_it/option.rb +65 -0
  11. data/app/models/ask_it/options_type.rb +39 -0
  12. data/app/models/ask_it/predefined_value.rb +24 -0
  13. data/app/models/ask_it/question.rb +73 -0
  14. data/app/models/ask_it/question_type.rb +32 -0
  15. data/app/models/ask_it/section.rb +66 -0
  16. data/app/models/ask_it/survey.rb +77 -0
  17. data/config/locales/en.yml +54 -0
  18. data/config/locales/pt-PT.yml +48 -0
  19. data/config/locales/pt.yml +48 -0
  20. data/lib/ask_it/active_record.rb +25 -0
  21. data/lib/ask_it/engine.rb +8 -0
  22. data/lib/ask_it/railtie.rb +13 -0
  23. data/lib/ask_it/version.rb +5 -0
  24. data/lib/ask_it.rb +20 -0
  25. data/lib/generators/ask_it/install_generator.rb +57 -0
  26. data/lib/generators/ask_it/survey_generator.rb +117 -0
  27. data/lib/generators/templates/active_admin.rb +87 -0
  28. data/lib/generators/templates/controllers/attempts_controller.rb +11 -0
  29. data/lib/generators/templates/controllers/surveys_controller.rb +31 -0
  30. data/lib/generators/templates/helpers/ask_it/surveys_helper.rb +56 -0
  31. data/lib/generators/templates/migration.rb.tt +59 -0
  32. data/lib/generators/templates/migration_add_head_number_to_options_table.rb.tt +8 -0
  33. data/lib/generators/templates/migration_add_mandatory_to_questions_table.rb.tt +8 -0
  34. data/lib/generators/templates/migration_add_types_to_questions_and_options.rb.tt +15 -0
  35. data/lib/generators/templates/migration_create_predefined_values_table.rb.tt +16 -0
  36. data/lib/generators/templates/migration_section.rb.tt +24 -0
  37. data/lib/generators/templates/migration_update_survey_tables.rb.tt +24 -0
  38. data/lib/generators/templates/rails_admin.rb +10 -0
  39. data/lib/generators/templates/views/attempts/_form.html.erb +61 -0
  40. data/lib/generators/templates/views/attempts/new.html.erb +10 -0
  41. data/lib/generators/templates/views/surveys/_form.html.erb +78 -0
  42. data/lib/generators/templates/views/surveys/_option_fields.html.erb +26 -0
  43. data/lib/generators/templates/views/surveys/_question_fields.html.erb +42 -0
  44. data/lib/generators/templates/views/surveys/_section_fields.html.erb +29 -0
  45. data/lib/generators/templates/views/surveys/edit.html.erb +2 -0
  46. data/lib/generators/templates/views/surveys/index.html.erb +14 -0
  47. data/lib/generators/templates/views/surveys/new.html.erb +2 -0
  48. data/lib/survey.rb +7 -0
  49. data/lib/tasks/changelog.rake +10 -0
  50. metadata +372 -0
@@ -0,0 +1,117 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AskIt
4
+ class SurveyGenerator < Rails::Generators::Base
5
+ source_root File.expand_path('../templates', __dir__)
6
+
7
+ TEMPLATES = %w[active_admin rails_admin plain routes].freeze
8
+
9
+ argument :arguments,
10
+ type: :array,
11
+ default: [],
12
+ banner: "< #{TEMPLATES.join('|')} > [scope]"
13
+
14
+ def create_resolution
15
+ strategy = arguments.first
16
+ if TEMPLATES.include? strategy
17
+ send("generate_#{strategy}_resolution")
18
+ success_message(strategy)
19
+ else
20
+ error_message(strategy)
21
+ end
22
+ end
23
+
24
+ private
25
+
26
+ def generate_active_admin_resolution
27
+ copy_file 'active_admin.rb', 'app/admin/survey.rb'
28
+ end
29
+
30
+ def generate_rails_admin_resolution
31
+ copy_file 'rails_admin.rb', 'config/initializers/survey_rails_admin.rb'
32
+ end
33
+
34
+ def generate_plain_resolution
35
+ scope = get_scope
36
+ generate_controller(scope)
37
+ generate_views(scope)
38
+ generate_helpers(scope)
39
+ generate_routes_for(scope)
40
+ end
41
+
42
+ def generate_routes_resolution
43
+ generate_routes_for(get_scope)
44
+ end
45
+
46
+ def generate_controller(scope)
47
+ template 'controllers/surveys_controller.rb', controller_path(scope)
48
+ template 'controllers/attempts_controller.rb', attempts_controller_path(scope)
49
+ end
50
+
51
+ def generate_helpers(_scope)
52
+ survey_helper_path = 'app/helpers/ask_it/surveys_helper.rb'
53
+ template 'helpers/ask_it/surveys_helper.rb', survey_helper_path
54
+ end
55
+
56
+ def generate_views(scope)
57
+ view_path = scope.present? ? "app/views/#{scope}" : 'app/views'
58
+ directory 'views/surveys', "#{view_path}/surveys", recursive: true
59
+ directory 'views/attempts', "#{view_path}/attempts", recursive: true
60
+ end
61
+
62
+ def generate_routes_for(scope)
63
+ inject_into_file 'config/routes.rb',
64
+ after: 'Rails.application.routes.draw do' do
65
+ if scope.blank?
66
+ <<-CONTENT
67
+
68
+ resources :surveys
69
+ resources :attempts, only: %i[new create]
70
+ CONTENT
71
+ else
72
+ <<-CONTENT
73
+
74
+ namespace :#{scope} do
75
+ resources :surveys
76
+ resources :attempts, only: %i[new create]
77
+ end
78
+ CONTENT
79
+ end
80
+ end
81
+ end
82
+
83
+ def get_scope
84
+ arguments.size > 1 ? arguments[1] : nil
85
+ end
86
+
87
+ def get_scope_path
88
+ get_scope.present? ? "#{get_scope}_" : ''
89
+ end
90
+
91
+ def get_controller_scope
92
+ scope = get_scope
93
+ scope.present? ? "#{scope.capitalize}::" : ''
94
+ end
95
+
96
+ def controller_path(scope)
97
+ scope.present? ? "app/controllers/#{scope}/surveys_controller.rb" : 'app/controllers/surveys_controller.rb'
98
+ end
99
+
100
+ def attempts_controller_path(scope)
101
+ scope.present? ? "app/controllers/#{scope}/attempts_controller.rb" : 'app/controllers/attempts_controller.rb'
102
+ end
103
+
104
+ # Error Handlers
105
+ def error_message(argument)
106
+ error_message = <<-CONTENT
107
+ This Resolution: '#{argument}' is not supported by Survey:
108
+ We only support Active Admin, Rails Admin, Plain, and Routes
109
+ CONTENT
110
+ say error_message, :red
111
+ end
112
+
113
+ def success_message(argument)
114
+ say "Generation of #{argument.capitalize} Template Complete :) enjoy Survey", :green
115
+ end
116
+ end
117
+ end
@@ -0,0 +1,87 @@
1
+ # frozen_string_literal: true
2
+
3
+ ActiveAdmin.register AskIt::Survey do
4
+ menu label: I18n.t('surveys')
5
+
6
+ filter :name,
7
+ as: :select,
8
+ collection: proc {
9
+ AskIt::Survey.select('distinct(name)').collect do |c|
10
+ [c.name, c.name]
11
+ end
12
+ }
13
+ filter :active,
14
+ as: :select,
15
+ collection: %w[true false]
16
+
17
+ filter :created_at
18
+
19
+ index do
20
+ column :name
21
+ column :description
22
+ column :active
23
+ column :attempts_number
24
+ column :finished
25
+ column :created_at
26
+ default_actions
27
+ end
28
+
29
+ form do |f|
30
+ f.inputs I18n.t('survey_details') do
31
+ f.input :name
32
+ f.input :locale_name
33
+ f.input :description
34
+ f.input :locale_description
35
+ f.input :active, as: :select, collection: %w[true false]
36
+ f.input :attempts_number
37
+ end
38
+
39
+ f.inputs I18n.t('sections') do
40
+ f.has_many :sections do |s|
41
+ s.input :head_number
42
+ s.input :locale_head_number
43
+ s.input :name
44
+ s.input :locale_name
45
+ s.input :description
46
+ s.input :locale_description
47
+
48
+ s.has_many :questions do |q|
49
+ q.input :head_number
50
+ q.input :locale_head_number
51
+ q.input :text
52
+ q.input :locale_text
53
+ q.input :description
54
+ q.input :locale_description
55
+ q.input :questions_type_id, as: :select, collection: AskIt::QuestionType.questions_types_title
56
+ q.input :mandatory
57
+
58
+ q.inputs I18n.t('predefined_values') do
59
+ q.has_many :predefined_values do |p|
60
+ p.input :head_number
61
+ p.input :name
62
+ p.input :locale_name
63
+ end
64
+ end
65
+
66
+ q.has_many :options do |a|
67
+ a.input :head_number
68
+ a.input :text
69
+ a.input :locale_text
70
+ a.input :options_type_id, as: :select, collection: AskIt::OptionsType.options_types_title
71
+ a.input :correct
72
+ end
73
+ end
74
+ end
75
+ end
76
+
77
+ f.buttons
78
+ end
79
+
80
+ if Rails::VERSION::MAJOR >= 4
81
+ controller do
82
+ def permitted_params
83
+ params.permit!
84
+ end
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,11 @@
1
+ class <%= get_controller_scope %>AttemptsController < AskIt::AttemptsController
2
+ # GET /resource/attempts/new
3
+ # def new
4
+ # super
5
+ # end
6
+
7
+ # POST /resource/attempts
8
+ # def create
9
+ # super
10
+ # end
11
+ end
@@ -0,0 +1,31 @@
1
+ class <%= get_controller_scope %>SurveysController < AskIt::SurveysController
2
+ # GET /resource/surveys
3
+ # def index
4
+ # super
5
+ # end
6
+
7
+ # GET /resource/surveys/new
8
+ # def new
9
+ # super
10
+ # end
11
+
12
+ # POST /resource/surveys
13
+ # def create
14
+ # super
15
+ # end
16
+
17
+ # GET /resource/surveys/:id/edit
18
+ # def edit
19
+ # super
20
+ # end
21
+
22
+ # GET /resource/surveys/:id
23
+ # def show
24
+ # super
25
+ # end
26
+
27
+ # PATCH/PUT /resource/surveys/:id
28
+ # def update
29
+ # super
30
+ # end
31
+ end
@@ -0,0 +1,56 @@
1
+ module AskIt
2
+ module SurveysHelper
3
+ def link_to_remove_field(name, f)
4
+ f.hidden_field(:_destroy) +
5
+ link_to_function(raw(name), "removeField(this)", :id =>"remove-attach")
6
+ end
7
+
8
+ def new_attempt_path
9
+ new_<%= get_scope_path %>attempt_path
10
+ end
11
+
12
+ def new_survey_path
13
+ new_<%= get_scope_path %>survey_path
14
+ end
15
+
16
+ def edit_survey_path(resource)
17
+ edit_<%= get_scope_path %>survey_path(resource)
18
+ end
19
+
20
+ def attempt_scope(resource)
21
+ if action_name =~ /new|create/
22
+ <%= get_scope_path %>attempts_path(resource)
23
+ elsif action_name =~ /edit|update/
24
+ <%= get_scope_path %>attempt_path(resource)
25
+ end
26
+ end
27
+
28
+ def survey_scope(resource)
29
+ if action_name =~ /new|create/
30
+ <%= get_scope_path %>surveys_path(resource)
31
+ elsif action_name =~ /edit|update/
32
+ <%= get_scope_path %>survey_path(resource)
33
+ end
34
+ end
35
+
36
+ def link_to_add_field(name, f, association)
37
+ new_object = f.object.class.reflect_on_association(association).klass.new
38
+ fields = f.fields_for(association, new_object,:child_index => "new_#{association}") do |builder|
39
+ render(association.to_s.singularize + "_fields", :f => builder)
40
+ end
41
+ link_to_function(name, "addField(this, \"#{association}\", \"#{escape_javascript(fields)}\")",
42
+ id: "add-attach",
43
+ class: "btn btn-small btn-info")
44
+ end
45
+
46
+ def link_to_function(name, *args, &block)
47
+ html_options = args.extract_options!.symbolize_keys
48
+
49
+ function = block_given? ? update_page(&block) : args[0] || ''
50
+ onclick = "#{"#{html_options[:onclick]}; " if html_options[:onclick]}#{function}; return false;"
51
+ href = html_options[:href] || '#'
52
+
53
+ content_tag(:a, name, html_options.merge(:href => href, :onclick => onclick))
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ class CreateSurvey < ActiveRecord::Migration<%= migration_version %>
4
+ def self.up
5
+ # survey surveys logic
6
+ create_table :survey_surveys do |t|
7
+ t.string :name
8
+ t.text :description
9
+ t.integer :attempts_number, default: 0
10
+ t.boolean :finished, default: false
11
+ t.boolean :active, default: true
12
+
13
+ t.timestamps
14
+ end
15
+
16
+ create_table :survey_questions do |t|
17
+ t.integer :survey_id
18
+ t.string :text
19
+
20
+ t.timestamps
21
+ end
22
+
23
+ create_table :survey_options do |t|
24
+ t.integer :question_id
25
+ t.integer :weight, default: 0
26
+ t.string :text
27
+ t.boolean :correct
28
+
29
+ t.timestamps
30
+ end
31
+
32
+ # survey answer logic
33
+ create_table :survey_attempts do |t|
34
+ t.belongs_to :participant, polymorphic: true
35
+ t.integer :survey_id
36
+ t.boolean :winner, null: false, default: false
37
+ t.decimal :score
38
+
39
+ t.timestamps
40
+ end
41
+
42
+ create_table :survey_answers do |t|
43
+ t.integer :attempt_id
44
+ t.integer :question_id
45
+ t.integer :option_id
46
+ t.boolean :correct, null: false, default: false
47
+ t.timestamps
48
+ end
49
+ end
50
+
51
+ def self.down
52
+ drop_table :survey_surveys
53
+ drop_table :survey_questions
54
+ drop_table :survey_options
55
+
56
+ drop_table :survey_attempts
57
+ drop_table :survey_answers
58
+ end
59
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AddHeadNumberToOptionsTable < ActiveRecord::Migration<%= migration_version %>
4
+ def change
5
+ # Survey Options table
6
+ add_column :survey_options, :head_number, :string
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AddMandatoryToQuestionsTable < ActiveRecord::Migration<%= migration_version %>
4
+ def change
5
+ # Survey Questions table
6
+ add_column :survey_questions, :mandatory, :boolean, default: false
7
+ end
8
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AddTypesToQuestionsAndOptions < ActiveRecord::Migration<%= migration_version %>
4
+ def change
5
+ # Survey Questions table
6
+ add_column :survey_questions, :questions_type_id, :integer
7
+
8
+ # Survey Options table
9
+ add_column :survey_options, :options_type_id, :integer
10
+
11
+ # Survey Answers table
12
+ add_column :survey_answers, :option_text, :text
13
+ add_column :survey_answers, :option_number, :integer
14
+ end
15
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ class CreatePredefinedValuesTable < ActiveRecord::Migration<%= migration_version %>
4
+ def change
5
+ create_table :survey_predefined_values do |t|
6
+ t.string :head_number
7
+ t.string :name
8
+ t.string :locale_name
9
+ t.integer :question_id
10
+
11
+ t.timestamps
12
+ end
13
+
14
+ add_column :survey_answers, :predefined_value_id, :integer
15
+ end
16
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ class CreateSections < ActiveRecord::Migration<%= migration_version %>
4
+ def self.up
5
+ create_table :survey_sections do |t|
6
+ t.string :head_number
7
+ t.string :name
8
+ t.text :description
9
+ t.integer :survey_id
10
+
11
+ t.timestamps
12
+ end
13
+
14
+ remove_column :survey_questions, :survey_id
15
+ add_column :survey_questions, :section_id, :integer
16
+ end
17
+
18
+ def self.down
19
+ drop_table :survey_sections
20
+
21
+ remove_column :survey_questions, :section_id
22
+ add_column :survey_questions, :survey_id, :integer
23
+ end
24
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ class UpdateSurveyTables < ActiveRecord::Migration<%= migration_version %>
4
+ def change
5
+ # Survey Surveys table
6
+ add_column :survey_surveys, :locale_name, :string
7
+ add_column :survey_surveys, :locale_description, :text
8
+
9
+ # Survey Sections table
10
+ add_column :survey_sections, :locale_head_number, :string
11
+ add_column :survey_sections, :locale_name, :string
12
+ add_column :survey_sections, :locale_description, :text
13
+
14
+ # Survey Questions table
15
+ add_column :survey_questions, :head_number, :string
16
+ add_column :survey_questions, :description, :text
17
+ add_column :survey_questions, :locale_text, :string
18
+ add_column :survey_questions, :locale_head_number, :string
19
+ add_column :survey_questions, :locale_description, :text
20
+
21
+ # Survey Options table
22
+ add_column :survey_options, :locale_text, :string
23
+ end
24
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ RailsAdmin.config do |c|
4
+ c.excluded_models = [
5
+ AskIt::Answer,
6
+ AskIt::Option,
7
+ AskIt::Attempt,
8
+ AskIt::Question
9
+ ]
10
+ end
@@ -0,0 +1,61 @@
1
+ <h1><%= @survey.name %></h1>
2
+ <p><%= @survey.description %></p>
3
+ <%= form_for(@attempt, :url => attempt_scope(@attempt)) do |f| %>
4
+ <%= f.fields_for :answers do |builder| %>
5
+ <ul>
6
+ <% seq = 0 %>
7
+ <% @survey.sections.each do |section| %>
8
+ <p><span><%= "#{section.head_number} : " if section.head_number %></span><%= section.name%></p>
9
+ <p><%= section.description if section.description %></p>
10
+ <% section.questions.each do |question| %>
11
+ <% seq += 1 %>
12
+ <li>
13
+ <p><span><%= "#{question.head_number} : " if question.head_number %></span><%= question.text %></p>
14
+ <p><%= question.description if question.description %></p>
15
+ <% question.options.each do |option| %>
16
+
17
+ <% if [AskIt::OptionsType.multi_choices, AskIt::OptionsType.multi_choices_with_text, AskIt::OptionsType.multi_choices_with_number].include? option.options_type_id %>
18
+ <%= hidden_field_tag "survey_attempt[answers_attributes][#{seq}][question_id]", question.id %>
19
+ <%= check_box_tag "survey_attempt[answers_attributes][#{seq}][option_id]", option.id %>
20
+
21
+ <% if option.options_type_id == AskIt::OptionsType.multi_choices_with_text %>
22
+ <%= text_field_tag "survey_attempt[answers_attributes][#{seq}][option_text]", "" %>
23
+ <% elsif option.options_type_id == AskIt::OptionsType.multi_choices_with_number %>
24
+ <%= number_field_tag "survey_attempt[answers_attributes][#{seq}][option_number]", "", class: "form-control" %>
25
+ <% end %>
26
+ <% seq += 1 %>
27
+ <% elsif [AskIt::OptionsType.single_choice, AskIt::OptionsType.single_choice_with_text].include? option.options_type_id %>
28
+ <%= hidden_field_tag "survey_attempt[answers_attributes][#{seq}][question_id]", question.id %>
29
+ <%= radio_button_tag "survey_attempt[answers_attributes][#{seq}][option_id]", option.id %>
30
+
31
+ <% if option.options_type_id == AskIt::OptionsType.single_choice_with_text %>
32
+ <%= text_field_tag "survey_attempt[answers_attributes][#{seq}][option_text]", "" %>
33
+ <% elsif option.options_type_id == AskIt::OptionsType.single_choice_with_number %>
34
+ <%= number_field_tag "survey_attempt[answers_attributes][#{seq}][option_number]", "", class: "form-control" %>
35
+ <% end %>
36
+ <% elsif option.options_type_id == AskIt::OptionsType.number %>
37
+ <%= hidden_field_tag "survey_attempt[answers_attributes][#{seq}][question_id]", question.id %>
38
+ <%= hidden_field_tag "survey_attempt[answers_attributes][#{seq}][option_id]", option.id %>
39
+ <%= number_field_tag "survey_attempt[answers_attributes][#{seq}][option_number]", "", :style => "width: 40px;" %>
40
+ <% seq += 1 %>
41
+ <% elsif option.options_type_id == AskIt::OptionsType.text %>
42
+ <%= hidden_field_tag "survey_attempt[answers_attributes][#{seq}][question_id]", question.id %>
43
+ <%= hidden_field_tag "survey_attempt[answers_attributes][#{seq}][option_id]", option.id %>
44
+ <%= text_field_tag "survey_attempt[answers_attributes][#{seq}][option_text]", "" %>
45
+ <% seq += 1 %>
46
+ <% elsif option.options_type_id == AskIt::OptionsType.large_text %>
47
+ <%= hidden_field_tag "survey_attempt[answers_attributes][#{seq}][question_id]", question.id %>
48
+ <%= hidden_field_tag "survey_attempt[answers_attributes][#{seq}][option_id]", option.id %>
49
+ <%= text_area_tag "survey_attempt[answers_attributes][#{seq}][option_text]", "" %>
50
+ <% seq += 1 %>
51
+ <% end %>
52
+
53
+ <%= option.text %> <br/>
54
+ <% end -%>
55
+ </li>
56
+ <% end -%>
57
+ <% end -%>
58
+ </ul>
59
+ <% end -%>
60
+ <%= f.submit "Submit" %>
61
+ <% end -%>
@@ -0,0 +1,10 @@
1
+ <h3><%= flash[:alert]%></h3>
2
+ <h3><%= flash[:error]%></h3>
3
+
4
+ <% if @survey.avaliable_for_participant?(@participant) %>
5
+ <%= render 'form' %>
6
+ <% else %>
7
+ <p>
8
+ <%= @participant.name %> spent all the possible attempts to answer this Survey
9
+ </p>
10
+ <% end -%>
@@ -0,0 +1,78 @@
1
+ <%= form_for(@survey, :url => survey_scope(@survey)) do |f| %>
2
+
3
+ <%= f.error_messages %>
4
+
5
+ <div class="field">
6
+ <%= f.label :name %> <br />
7
+ <%= f.text_field :name %> <br />
8
+ </div>
9
+ <div class="field">
10
+ <%= f.label :locale_name %> <br />
11
+ <%= f.text_field :locale_name %> <br />
12
+ </div>
13
+ <div class="field">
14
+ <%= f.label :description %> <br />
15
+ <%= f.text_area :description, :size => "100x5" %> <br />
16
+ </div>
17
+ <div class="field">
18
+ <%= f.label :locale_description %> <br />
19
+ <%= f.text_area :locale_description %> <br />
20
+ </div>
21
+ <div class="field">
22
+ <%= f.label :attempts_number %> <br />
23
+ <%= f.text_field :attempts_number %> <br />
24
+ </div>
25
+ <div class="field">
26
+ <%= f.label :active %> <br />
27
+ <%= f.select :active, ["true", "false"] %>
28
+ </div>
29
+
30
+ <br/ >
31
+
32
+ <div class="field">
33
+ <ul>
34
+ <%= f.fields_for :sections do |builder| %>
35
+ <%= render "section_fields", :f => builder %>
36
+ <% end %>
37
+ </ul>
38
+ <br/ >
39
+ <%= link_to_add_field "Add a new Section", f, :sections %>
40
+ </div>
41
+
42
+ <br/ >
43
+
44
+ <div class="field">
45
+ <%= f.submit %>
46
+ </div>
47
+ <% end -%>
48
+
49
+ <script type="text/javascript">
50
+ // remove attachment field
51
+ function removeField(link) {
52
+ var hiddenField = link.previousElementSibling;
53
+ if (hiddenField && hiddenField.type === "hidden") {
54
+ hiddenField.value = "true";
55
+ }
56
+ var tag = link.closest("li");
57
+ if (tag) {
58
+ tag.style.display = "none";
59
+ tag.classList.add("deleted");
60
+ }
61
+ }
62
+
63
+ // add attachment field
64
+ function addField(link, association, content) {
65
+ var new_id = new Date().getTime();
66
+ var regexp = new RegExp("new_" + association, "g");
67
+ var html = content.replace(regexp, new_id);
68
+ var tempDiv = document.createElement("div");
69
+ tempDiv.innerHTML = html;
70
+ var newElement = tempDiv.firstElementChild;
71
+ newElement.style.display = "none";
72
+ var ul = link.closest("div.field").querySelector("ul");
73
+ if (ul) {
74
+ ul.appendChild(newElement);
75
+ newElement.style.display = "block";
76
+ }
77
+ }
78
+ </script>
@@ -0,0 +1,26 @@
1
+ <li>
2
+ <h2>Option</h2>
3
+ <div class="field">
4
+ <%= f.label :head_number %> <br/ >
5
+ <%= f.text_field :head_number %>
6
+ </div>
7
+ <div class="field">
8
+ <%= f.label :text %> <br/ >
9
+ <%= f.text_field :text %>
10
+ </div>
11
+ <div class="field">
12
+ <%= f.label :locale_text %> <br/ >
13
+ <%= f.text_field :locale_text %>
14
+ </div>
15
+ <div class="field">
16
+ <%= f.label :options_type_id %> <br />
17
+ <%= f.select :options_type_id, AskIt::OptionsType.options_types_title %>
18
+ </div>
19
+ <div class="field">
20
+ <%= f.check_box :correct %>
21
+ <%= f.label :correct %>
22
+ </div>
23
+ <div class="field">
24
+ <%= link_to_remove_field "Remove", f %>
25
+ </div>
26
+ </li>