/*global define */ define(['jquery', 'underscore', 'backbone', 'gmaps', 'models/SolrResult', 'views/DownloadButtonView', 'text!templates/loading.html', 'text!templates/alert.html', 'text!templates/attribute.html', 'text!templates/dataDisplay.html', ], function($, _, Backbone, gmaps, SolrResult, DownloadButtonView, LoadingTemplate, alertTemplate, AttributeTemplate, DataDisplayTemplate) { var MetadataIndexView = Backbone.View.extend({ type: "MetadataIndex", id: 'Metadata', className: "metadata-index container form-horizontal", tagName: 'article', template: null, loadingTemplate: _.template(LoadingTemplate), attributeTemplate: _.template(AttributeTemplate), alertTemplate: _.template(alertTemplate), dataDisplayTemplate: _.template(DataDisplayTemplate), semanticFields: null, events: { }, initialize: function (options) { this.pid = options.pid || null; //this.el.id = this.id + "-" + this.pid; //Give this element a specific ID in case multiple MetadataIndex views are on one page this.parentView = options.parentView || null; // use these to tailor the annotation ui widget this.semanticFields = { attribute: "sem_annotation", attributeName: "sem_annotation", attributeLabel: "sem_annotation", attributeDescription: "sem_annotation", attributeUnit: "sem_annotation", origin: "orcid_sm", investigator: "orcid_sm" } }, render: function(){ if(!this.pid) return false; var view = this; //Get all the fields from the Solr index var query = 'q=(id:"' + encodeURIComponent(this.pid) + '"+OR+seriesId:"'+ encodeURIComponent(this.pid)+'")&rows=1&start=0&fl=*&wt=json'; var requestSettings = { url: MetacatUI.appModel.get('queryServiceUrl') + query, success: function(data, textStatus, xhr){ if(data.response.numFound == 0){ if( view.parentView && view.parentView.model ){ //Show a "not indexed" message if there is system metadata but nothing in // the index if(view.parentView.model.get("systemMetadata")){ view.showNotIndexed(); } //Show a "not found" message if there is no system metadata and no results in the index else{ view.parentView.model.set("notFound", true); view.parentView.showNotFound(); } } view.flagComplete(); } else{ view.docs = data.response.docs; _.each(data.response.docs, function(doc, i, list){ //If this is a data object and there is a science metadata doc that describes it, then navigate to that Metadata View. if((doc.formatType == "DATA") && (doc.isDocumentedBy && doc.isDocumentedBy.length)){ view.onClose(); MetacatUI.uiRouter.navigate("view/" + doc.isDocumentedBy[0], true); return; } var metadataEl = $(document.createElement("section")).attr("id", "metadata-index-details"), id = doc.id, creator = doc.origin, title = doc.title, pubDate = doc.pubDate, dateUploaded = doc.dateUploaded, keys = Object.keys(doc), docModel = new SolrResult(doc); //Extract General Info details that we want to list first var generalInfoKeys = ["title", "id", "abstract", "pubDate", "keywords"]; keys = _.difference(keys, generalInfoKeys); $(metadataEl).append(view.formatAttributeSection(docModel, generalInfoKeys, "General")); //Extract Spatial details var spatialKeys = ["site", "southBoundCoord", "northBoundCoord", "westBoundCoord", "eastBoundCoord"]; keys = _.difference(keys, spatialKeys); $(metadataEl).append(view.formatAttributeSection(docModel, spatialKeys, "Geographic Region")); //Extract Temporal Coverage details var temporalKeys = ["beginDate", "endDate"]; keys = _.difference(keys, temporalKeys); $(metadataEl).append(view.formatAttributeSection(docModel, temporalKeys, "Temporal Coverage")); //Extract Taxonomic Coverage details var taxonKeys = ["order", "phylum", "family", "genus", "species", "scientificName"]; keys = _.difference(keys, taxonKeys); $(metadataEl).append(view.formatAttributeSection(docModel, taxonKeys, "Taxonomic Coverage")); //Extract People details var peopleKeys = ["origin", "investigator", "contactOrganization", "project"]; keys = _.difference(keys, peopleKeys); $(metadataEl).append(view.formatAttributeSection(docModel, peopleKeys, "People and Associated Parties")); //Extract Access Control details var accessKeys = ["isPublic", "submitter", "rightsHolder", "writePermission", "readPermission", "changePermission", "authoritativeMN"]; keys = _.difference(keys, accessKeys); $(metadataEl).append(view.formatAttributeSection(docModel, accessKeys, "Access Control")); //Add the rest of the metadata $(metadataEl).append(view.formatAttributeSection(docModel, keys, "Other")); view.$el.html(metadataEl); view.flagComplete(); }); } }, error: function(){ var msg = "
This data or science metadata is available to download, but " + "there seems to be an issue with displaying details on this webpage. " + "If this content was recently submitted, it may still be in the processing queue.
", includeEmail: true }); this.$el.append(message); //If this metadata doc is not indexed, we need to search the system metadata //to see if it is publicly accessible. if( this.parentView && this.parentView.model ){ //Get the system metadata string var sysMeta = this.parentView.model.get("systemMetadata"); if(sysMeta){ //Parse it into XML nodes sysMeta = $.parseXML(sysMeta); //Find the allow permission for the public var publicPermission = $(sysMeta).find("allow subject:contains('public')"); if( publicPermission.length ){ //Remove the "private" icon $("#metadata-controls-container .private").remove(); } } //If there is no system metadata, default to hiding the private icon else{ $("#metadata-controls-container .private").remove(); } } }, flagComplete: function(){ this.complete = true; this.trigger("complete"); }, onClose: function(){ this.$el.html(this.loadingTemplate()); this.pid = null; //Detach this view from its parent view this.parentView.subviews = _.without(this.parentView.subviews, this); this.parentView = null; //Remove listeners this.stopListening(); } }); return MetadataIndexView; });