# Source: themes/ess-dive/config.js

    MetacatUI.theme = 'ess-dive';
    MetacatUI.themeTitle = 'ESS-DIVE Data Archive';

    MetacatUI.officialGroups = {
    	adminGroups: "adminGroups",
    	allowedToSubmitDataGroups: "allowedToSubmitDataGroups"
    };

    MetacatUI.themeMap =
    {
    	'*': {
    		'optional': MetacatUI.root + '/js/themes/' + MetacatUI.theme + '/loaders/optional.js',
    		'json': MetacatUI.root + '/js/themes/' + MetacatUI.theme + '/loaders/json.js',

            'FileSaver' : MetacatUI.root + '/js/themes/' + MetacatUI.theme + '/components/FileSaver.js',

    		// Templates include extension
    		'templates/altHeader.html' : MetacatUI.root + 'themes/arctic/templates/altHeader.html',
    		'templates/defaultHeader.html' : MetacatUI.root + 'themes/arctic/templates/defaultHeader.html',
    		'templates/dataItem.html' : MetacatUI.root + 'themes/' + MetacatUI.theme + '/templates/dataItem.html',
    		'templates/dataPackageStar.html' : MetacatUI.root + 'themes/' + MetacatUI.theme + '/templates/dataItem.html',
    		'templates/editor.html' : MetacatUI.root + 'themes/' + MetacatUI.theme + '/templates/editor.html',
    		'templates/editorSubmitMessage.html' : MetacatUI.root + 'themes/' + MetacatUI.theme + '/templates/editorSubmitMessage.html',
    		'templates/featuredData.html' : MetacatUI.root + 'themes/arctic/templates/featuredData.html',
    		'templates/footer.html' : MetacatUI.root + 'themes/' + MetacatUI.theme + '/templates/footer.html',
    		'templates/insertProgress.html' : MetacatUI.root + 'themes/arctic/templates/insertProgress.html',
    		'templates/loginButtons.html' : MetacatUI.root + 'themes/arctic/templates/loginButtons.html',
    		'templates/mainContent.html' : MetacatUI.root + 'themes/arctic/templates/mainContent.html',
    		'templates/metadata.html' : MetacatUI.root + 'themes/arctic/templates/metadata.html',
    		'templates/metadataControls.html': MetacatUI.root + 'themes/'+MetacatUI.theme + '/templates/metadataControls.html',
    		'templates/navbar.html' : MetacatUI.root + 'themes/' + MetacatUI.theme + '/templates/navbar.html',
    		'templates/noResults.html' : MetacatUI.root + 'themes/' + MetacatUI.theme + '/templates/noResults.html',
    		'templates/resultsItem.html' : MetacatUI.root + 'themes/' + MetacatUI.theme + '/templates/resultsItem.html',
    		'templates/userProfileMenu.html' : MetacatUI.root + 'themes/arctic/templates/userProfileMenu.html',
    		'templates/userSettings.html' : MetacatUI.root + 'themes/' + MetacatUI.theme + '/templates/userSettings.html',
    		'templates/search.html' : MetacatUI.root + 'themes/' + MetacatUI.theme + '/templates/search.html',
    		'templates/publishDOI.html' : MetacatUI.root + 'themes/' + MetacatUI.theme + '/templates/publishDOI.html',
            'templates/app.html' : MetacatUI.root + 'themes/' + MetacatUI.theme + '/templates/app.html',

    		// Metadata templates
    		'templates/metadata/eml.html': MetacatUI.root + 'themes/'+MetacatUI.theme + '/templates/metadata/eml.html',
    		'templates/metadata/dates.html': MetacatUI.root + 'themes/'+MetacatUI.theme + '/templates/metadata/dates.html',
    		'templates/metadata/EMLMethods.html' : MetacatUI.root + 'themes/' + MetacatUI.theme + '/templates/metadata/EMLMethods.html',
    		'templates/metadata/EMLParty.html' : MetacatUI.root + 'themes/' + MetacatUI.theme + '/templates/metadata/EMLParty.html',
    		'templates/metadata/EMLPartyCopyMenu.html': MetacatUI.root + 'themes/'+MetacatUI.theme + '/templates/metadata/EMLPartyCopyMenu.html',
    		'templates/metadata/locationsSection.html': MetacatUI.root + 'themes/'+MetacatUI.theme + '/templates/metadata/locationsSection.html',
    		'templates/metadata/metadataOverview.html': MetacatUI.root + 'themes/'+MetacatUI.theme + '/templates/metadata/metadataOverview.html',

    		// Collections
    		'collections/BaseDataPackage' : MetacatUI.root + '/js/collections/DataPackage.js',
    		'collections/DataPackage' : MetacatUI.root + '/js/themes/' + MetacatUI.theme + '/collections/DataPackage.js',

    		// Models
    		'models/BaseAppModel' : MetacatUI.root + '/js/themes/arctic/models/AppModel.js',
    		'models/AppModel' : MetacatUI.root + '/js/themes/' + MetacatUI.theme + '/models/AppModel.js',
    		'models/BaseDataONEObject' : MetacatUI.root + '/js/models/DataONEObject.js',
    		'models/DataONEObject' : MetacatUI.root + '/js/themes/' + MetacatUI.theme + '/models/DataONEObject.js',
    		'models/BaseSolrResult' : MetacatUI.root + '/js/models/SolrResult.js',
    		'models/SolrResult' : MetacatUI.root + '/js/themes/' + MetacatUI.theme + '/models/SolrResult.js',
    		'models/metadata/eml211/BaseEML211' : MetacatUI.root + '/js/models/metadata/eml211/EML211.js',
    		'models/metadata/eml211/EML211' : MetacatUI.root + '/js/themes/' + MetacatUI.theme + '/models/metadata/eml211/EML211.js',
    		'models/metadata/eml211/BaseEMLParty' : MetacatUI.root + '/js/models/metadata/eml211/EMLParty.js',
    		'models/metadata/eml211/EMLParty' : MetacatUI.root + '/js/themes/' + MetacatUI.theme + '/models/metadata/eml211/EMLParty.js',
    		'models/metadata/eml211/BaseEMLProject' : MetacatUI.root + '/js/models/metadata/eml211/EMLProject.js',
    		'models/metadata/eml211/EMLProject' : MetacatUI.root + '/js/themes/' + MetacatUI.theme + '/models/metadata/eml211/EMLProject.js',
    		'models/metadata/eml211/BaseEMLText' : MetacatUI.root + '/js/themes/' + MetacatUI.theme + '/models/metadata/eml211/BaseEMLText.js',
    		'models/metadata/eml211/EMLText' : MetacatUI.root + '/js/themes/' + MetacatUI.theme + '/models/metadata/eml211/EMLText.js',
    		'models/Map' : MetacatUI.root + '/js/themes/arctic/models/Map.js',
    		'routers/router' : MetacatUI.root + '/js/themes/arctic/routers/router.js',
    		'models/BasePackageModel' : MetacatUI.root + '/js/models/PackageModel.js',
    		'models/PackageModel' : MetacatUI.root + '/js/themes/' + MetacatUI.theme + '/models/PackageModel.js',

    		// Views to extend
    		'views/BaseCitationView' : MetacatUI.root + '/js/views/CitationView.js',
    		'views/CitationView' : MetacatUI.root + '/js/themes/' + MetacatUI.theme + '/views/CitationView.js',
    		'views/BaseDataCatalogView' : MetacatUI.root + '/js/views/DataCatalogView.js',
    		'views/DataCatalogView' : MetacatUI.root + '/js/themes/' + MetacatUI.theme + '/views/DataCatalogView.js',
    		'views/BaseDataItemView' : MetacatUI.root + '/js/views/DataItemView.js',
    		'views/DataItemView' : MetacatUI.root + '/js/themes/' + MetacatUI.theme + '/views/DataItemView.js',
    		'views/BaseDownloadButtonView' : MetacatUI.root + '/js/views/DownloadButtonView.js',
    		'views/DownloadButtonView' : MetacatUI.root + '/js/themes/' + MetacatUI.theme + '/views/DownloadButtonView.js',
    		'views/BaseEditorView' : MetacatUI.root + '/js/views/EditorView.js',
    		'views/EditorView' : MetacatUI.root + '/js/themes/' + MetacatUI.theme + '/views/EditorView.js',
    		'views/BaseMetadataView' : MetacatUI.root + '/js/views/MetadataView.js',
    		'views/MetadataView' : MetacatUI.root + '/js/themes/' + MetacatUI.theme + '/views/MetadataView.js',
    		'views/BaseMetricView' : MetacatUI.root + '/js/views/MetricView.js',
    		'views/MetricView' : MetacatUI.root + '/js/themes/' + MetacatUI.theme + '/views/MetricView.js',
    		'views/BaseUserView' : MetacatUI.root + '/js/views/UserView.js',
    		'views/UserView' : MetacatUI.root + '/js/themes/' + MetacatUI.theme + '/views/UserView.js',
    		'views/BaseNavbarView' : MetacatUI.root + '/js/views/NavbarView.js',
    		'views/NavbarView' : MetacatUI.root + '/js/themes/' + MetacatUI.theme + '/views/NavbarView.js',
    		'views/metadata/BaseEML211View' : MetacatUI.root + '/js/views/metadata/EML211View.js',
    		'views/metadata/EML211View' : MetacatUI.root + '/js/themes/' + MetacatUI.theme + '/views/metadata/EML211View.js',
    		'views/metadata/BaseEMLPartyView' : MetacatUI.root + '/js/views/metadata/EMLPartyView.js',
    		'views/metadata/EMLPartyView' : MetacatUI.root + '/js/themes/' + MetacatUI.theme + '/views/metadata/EMLPartyView.js'
    		}
    };

    MetacatUI.customMapModelOptions = {
    	tileHue: "231"
    }

    MetacatUI.regexPatterns = {
    	emails: /^([a-z\d!#$%&'*+\-\/=?^_`{|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+(\.[a-z\d!#$%&'*+\-\/=?^_`{|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+)*|"((([ \t]*\r\n)?[ \t]+)?([\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|\\[\x01-\x09\x0b\x0c\x0d-\x7f\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))*(([ \t]*\r\n)?[ \t]+)?")@(([a-z\d\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|[a-z\d\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF][a-z\d\-._~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]*[a-z\d\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])\.)+([a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|[a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF][a-z\d\-._~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]*[a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])\.?$/i
    }

    /**
     * Determine if the user is the member of a configured admin group
     *
     * @param {Array} isMemberOf - an array of groups (subject strings)
     * @returns {boolean}
     */
    MetacatUI.checkIfMemberOf = function(isMemberOf, chosenGroups){
    	// Get the chosen groups subjects
    	var retrievedChosenGroups = MetacatUI.appModel.get(chosenGroups);

    	// create a list of subject strings from the group objects
    	//    "groupId" is the subject
    	var userGroups = isMemberOf.map(function(x){return x.groupId;});

    	// is the user's groups in the chosen groups?
    	var userMemberOfChosenGroups = $(retrievedChosenGroups).not($(retrievedChosenGroups).not(userGroups));
    	return (userMemberOfChosenGroups.length > 0);
    };

    /**
     * Determine if the user is allowed to submit data to this archive
     *
     * If no allowedToSubmitDataGroups are specified then the user is allowed to submit. If
     * allowedToSubmitDataGroups are specified the user may only be allowed to submit data if they
     * belong to one of the listed groups.
     *
     * @param user - a UserModel
     * @returns {boolean}
     */
    MetacatUI.isAllowedtoSubmitData = function (user) {

    	return (!MetacatUI.appModel.get(MetacatUI.officialGroups.allowedToSubmitDataGroups) ||
    		MetacatUI.appModel.get(MetacatUI.officialGroups.allowedToSubmitDataGroups).length == 0) ||
    		MetacatUI.checkIfMemberOf(
    			user.get("isMemberOf"),
    			MetacatUI.officialGroups.allowedToSubmitDataGroups);
    };

    MetacatUI.customAppConfig = function(){
    	/** Load configuration file if it exists */

    	if(MetacatUI.appModel.get("baseUrl").indexOf("ess-dive.lbl.gov") > -1 && MetacatUI.appModel.get("baseUrl").indexOf("test") == -1){
    		MetacatUI.appModel.set("googleAnalyticsKey", null);
    	}
    };