import Ember from 'ember';


var range = function(start, stop) {
    var options = [];
    for (var i=start; i <= stop; i++) {
        options.push(i);
    }
    return options;
};

const questions = {
  q1: {
    question: 'Age',
    type: 'select',
    scale: range(16, 100),
    value: null
  },
  q2: {
    question: 'Gender',
    type: 'select',
    scale: ['Male', 'Female', 'Other', 'I\'d rather not state'],
    value: null
  },
  q3: {
    question: 'What is your ethnicity?',
    type: 'input',
    value: null
  },
  q4: {
    question: 'What was your first language?',
    type: 'input',
    value: null
  },
  q5: {
    question: 'On a scale from 1 to 10 with 10 being people that are the most well off in society, and 1 ' +
              'being the people who are the least well off, where would you describe your family\'s position?',
    type: 'radio',
    scale: range(1, 10),
    labelTop: true,
    value: null
  },
  q6: {
    question: 'Birth Country and City',
    type: 'input',
    value: null
  },
  q7: {
    question: 'Hometown residence',
    type: 'select',
    scale: ['remote rural', 'rural', 'suburban', 'urban'],
    value: null
  },
  q8: {
    question: 'Do you follow a religion?',
    type: 'radio',
    scale: ['Yes', 'No'],
    labelTop: true,
    value: null
  },
  q9: {
    question: 'If so, which one do you follow?',
    type: 'input',
    optional: true,
    value: null
  },
  q10: {
    question: 'On a scale from 1 to 10, how religious are you?',
    type: 'radio',
    scale: range(1, 10),
    labelTop: true,
    value: null
  }
};

export default Ember.Component.extend({
  questions: questions,
  actions: {
    nextSection() {
        var formData = {};
        var questions = this.get('questions');
        for (var question in questions) {
          formData[question] = questions[question]['value'];
        }
        this.sendAction('update', formData, 'overview');
        this.sendAction('nextSection');
      }
  }
});

@@ -20,16 +20,82 @@
 ember';%0A
+import %7Bvalidator, buildValidations%7D from 'ember-cp-validations';%0A
 %0A%0Avar ra
@@ -241,16 +241,473 @@
 ns;%0A%7D;%0A%0A
+var generateValidators = function(questions) %7B%0A  var validators = %7B%7D;%0A  var presence = validator('presence', %7B%0A      presence:true,%0A      message: 'This field is required'%0A  %7D);%0A  for (var question in questions) %7B%0A      var isOptional = 'optional' in questions%5Bquestion%5D && questions%5Bquestion%5D%5B'optional'%5D;%0A      if (!isOptional) %7B%0A        var key = 'questions.' + question + '.value';%0A        validators%5Bkey%5D = presence;%0A    %7D%0A  %7D%0A  return validators;%0A%7D;%0A%0A
 const qu
@@ -2099,16 +2099,86 @@
   %7D%0A%7D;%0A%0A
+const Validations = buildValidations(generateValidators(questions));%0A%0A
 export d
@@ -2207,16 +2207,29 @@
 .extend(
+Validations, 
 %7B%0A  ques
@@ -2275,24 +2275,69 @@
 Section() %7B%0A
+      if (this.get('validations.isValid')) %7B%0A
         var 
@@ -2612,20 +2612,26 @@
 ');%0A      %7D%0A
+    %7D%0A
   %7D%0A%7D);%0A

Add validation to overview form