Source: themes/ess-dive/models/metadata/eml211/EMLParty.js

/* global define */
define(['jquery', 'underscore', 'backbone', 'models/metadata/eml211/BaseEMLParty'],
    function($, _, Backbone,  BaseEMLParty) {

        var EMLParty = BaseEMLParty.extend({

            /**
             * Override the defaults function
             *
             * Add additional roleOptions for associatedParty type
             * @returns {*}
             */
            defaults: function(){
                // Call the base class function
                var super_defaults = BaseEMLParty.prototype.defaults.apply(this);
                super_defaults["roleOptions"].push("acknowledgement");
                super_defaults["roleOptions"].push("contributor");
                super_defaults["roleOptions"].push("fundingOrganization");
                return super_defaults;

            },
            /*
             * Extend person validation to require email address for contact types
             */
            validate: function(){
                // Exit if this is not a contact type
                if ( this.get("type") != "contact" &&
                        this.get("type") != "creator") return;

                var errors = {
                    errorMessage: null
                };

                //The EMLParty must have an organization name, firstname, surname. It must ALSO have a type or role.
                if (  (!this.get("individualName") || 
                            (this.get("individualName") && !this.get("individualName").givenName) ||
                            (this.get("individualName") && !this.get("individualName").surName)) ||
                            (this.get("type") == "contact" && 
                                (!this.get("email") || this.get("email").length == 0 || this.get("email") == ""))) {
                    //The contact must have an email address
                    if (this.get("type") == "contact") {
                        errors.errorMessage = "Required fields: First Name, Last Name, Email";
                    } else {
                        errors.errorMessage = "Required fields: First Name, Last Name";
                    }
                }

                if (errors.errorMessage){
                    return errors;
                }
            }
        });


        return EMLParty;
    });