bitzesty/qae — pull request #15 by RuslanHamidullin (2014-11-27 09:12:15+00:00)
Title: [Form DB Structure] candidate V1

So, here is the db structure candidate.

Form ("innovation award" etc)
1) has_many :form_steps

FormStep ("Step 1 of 5: Company Information" etc)
1) has_many :questions

Question
1) can have following possible element types (list can be extended in future):
[
'text_input',
'text_area',
'radio',
'complex_radio', # Radio buttons with advanced questions
'checkbox',
'complex_checkbox', # Checkbox with advanced questions
'select',
'complex_select', # Select with advanced questions
'group', # complex question with couple inputs,
'date',
'file'
]

2) question can belongs to another question via 'question_id'.
For example:
```
11 Head of your business*
11.1 Job title / Role in the organisation*
11.2 Email address*
```
3) each question has 'placement' column, so that we can order them

4) Questions can be simple and complex.

Simple question:
```
9. Website URL* (here just one field)
```
Simple questions are presented with same number of html tags, but here can be 3 customization metrics:
4.1 ) css_class - can be in small / medium / large (in future can be extended)
4.2 ) css_size
4.3 ) chars_limited (boolean) - some textareas and inputs will have limited js counters.
The value of top limit, can be fetched from object's backend validation and then passed as tag attribute
```

# <= css_size (4)
Country
# <= css_class ('medium')

```
So, simple questions can be presented as universal with ability to set custom ops above ^.

More complex question blocks will has many children questions like:
```
11. Head of your business*

Title
First name
Last name
Personal Honours
Email address
```

In case if we need to use something specific on view - we do not need to add hard conditions - we just can use 'view_template_path' column (custom_partial_path).

5) "is_subquestion" boolean field means that question is advanced question on for example selected specific radio button value.
For example "Step 1 of 5: Company Information" -> "Are you a current Queen’s Award holder (2010-2014)? *". If you select "Yes" => then 3 extra questions will be shown.
So, these 3 extra questions will be "is_subquestion"

6) "visible" boolean. Some questions can be hidden by default and will be displayed only after selecting specific radio or checkbox value.

7) Custom texts between questions, like we have on "Step 3 of 5: Commercial Performance " before "21. Number of units/contracts/quantity sold" can be presented via "note_above" or "note_below" text fields.

8) Specific hints can also be presented via "hint_above" or "hint_below" text fileds.

9) Question can have many question_options (like checkboxes, radio buttons)

QuestionOption
- has name, input and area fields (as for some selected options can be extra "Specify" field, which can be input or textarea).
- display or not "Specify" advanced fields can be handled via "with_input" boolean field

FormResponse
- has many answers and belongs to user and form
- 'state' column (maybe for state machine or some own implementation)
- 'devise_type' can be used for tracking (Tablet/Mobile/Desktop)

Answer
- belongs to form response, question and also can be belongs_to question_option (in case of checkboxes or radio buttons)
- has 4 basic type columns:
- input
- area
- date_value
- file