{"size": 2650, "ext": "js", "max_stars_repo_path": "controllers/validate-parent-2-grandparents.js", "max_stars_repo_name": "versatil56/passports-prototype-v2", "max_stars_repo_stars_event_min_datetime": "2018-03-31T10:51:27.000Z", "max_stars_repo_stars_event_max_datetime": "2019-01-14T16:57:13.000Z", "max_issues_repo_path": "controllers/validate-parent-2-grandparents.js", "max_issues_repo_name": "versatil56/passports-prototype-v2", "max_issues_repo_issues_event_min_datetime": "2018-07-18T10:49:50.000Z", "max_issues_repo_issues_event_max_datetime": "2019-02-07T15:03:39.000Z", "max_forks_repo_path": "controllers/validate-parent-2-grandparents.js", "max_forks_repo_name": "versatil56/passports-prototype-v2", "max_forks_repo_forks_event_min_datetime": "2019-11-12T08:44:51.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-11T09:04:40.000Z"}
{"max_stars_count": 2, "max_issues_count": 9, "max_forks_count": 2, "avg_line_length": 41.40625, "max_line_length": 107, "alphanum_fraction": 0.6460377358}
var util = require('util')
var Base = require('hmpo-form-wizard').Controller

var Controller = function () {
    Base.apply(this, arguments)
}

util.inherits(Controller, Base)

Controller.prototype.process = function process(req, res, callback) {
    if ( // If ALL of the fields are EMPTY
        !req.form.values['parent2-parent1-additional-information'] &&
        !req.form.values['parent2-parent1-first-names'] &&
        !req.form.values['parent2-parent1-last-name'] &&
        !req.form.values['parent2-parent1-town-of-birth'] &&
        !req.form.values['parent2-parent1-country-of-birth'] &&
        (
            !req.form.values['parent2-parent1-age-day'] ||
            !req.form.values['parent2-parent1-age-month'] ||
            !req.form.values['parent2-parent1-age-year']
        )
    ) { // Run validation on additional info
        this.options.fields['parent2-parent1-additional-information'].validate = ['required'];
    } else {
        this.options.fields['parent2-parent1-additional-information'].validate = [];
    }


    if ( // If ALL of the fields are EMPTY
        !req.form.values['parent2-parent2-additional-information'] &&
        !req.form.values['parent2-parent2-first-names'] &&
        !req.form.values['parent2-parent2-last-name'] &&
        !req.form.values['parent2-parent2-town-of-birth'] &&
        !req.form.values['parent2-parent2-country-of-birth'] &&
        (
            !req.form.values['parent2-parent2-age-day'] ||
            !req.form.values['parent2-parent2-age-month'] ||
            !req.form.values['parent2-parent2-age-year']
        )
    ) { // Run validation on additional info
        this.options.fields['parent2-parent2-additional-information'].validate = ['required'];
    } else {
        this.options.fields['parent2-parent2-additional-information'].validate = [];
    }

    Base.prototype.process.call(this, req, res, callback);
}

Controller.prototype.getValues = function getValues(req, res, callback) {
    Base.prototype.getValues.call(this, req, res, (err, values) => {
        let errorParent2Parent1 = values.errors && values.errors['parent2-parent1-additional-information'];
        let errorParent2Parent2 = values.errors && values.errors['parent2-parent2-additional-information'];

        if (errorParent2Parent1 || values['parent2-parent1-additional-information']) {
            values.openParent2Parent1AdditionalInfo = 'open';
        }
        if (errorParent2Parent2 || values['parent2-parent2-additional-information']) {
            values.openParent2Parent2AdditionalInfo = 'open';
        }
        callback(err, values);
    });
}

module.exports = Controller;