Commit ecd518a5 authored by Maxime Chaillet's avatar Maxime Chaillet

Move global function which handles dates to the jsonExtractor. Move the code...

Move global function which handles dates to the jsonExtractor. Move the code which handles the display of the message above the access data button to the DOIView class.
parent 14cd3832
This diff is collapsed.
......@@ -29,15 +29,15 @@ DOIController.prototype.getData = function(doi) {
success : function(doiData) {
if (doiData) {
var jsonExtractor = new JsonExtractor();
// extract dates for doi landing page
extractDates(doiData);
jsonExtractor.extractDates(doiData);
jsonExtractor.extractFromSubject("Proposal Type Description",doiData,"proposalType");
jsonExtractor.extractFromSubject("Proposal",doiData,"proposalNumber");
jsonExtractor.extractFromSubject("instrument",doiData,"beamline");
jsonExtractor.extractInvestigationId(doiData);
jsonExtractor.extractInvestigationId(doiData);
_this.view.setDataAccessMessage(doiData);
_this.createCitation(doiData);
// Retrieve the URL corresponding to the beamline name.
// Set the URL corresponding to the beamline name.
var experimentalDate = new Date(doiData.date_collected + "T00:00+00:00");
doiData.beamlineUrl = _this.findsUrl(doiData.beamline, experimentalDate);
......@@ -170,31 +170,6 @@ data.citation = citation;
//HELPER FUNCTIONS
// extract dates as required for the DOI landing page
function extractDates(data){
// publication Year in doi landing page is the minting year
data.mintingYear = new Date(data.date_registered).getFullYear();
// session date is the date the experiment for the session was performed
var experimentDate = new Date(data.date_collected);
data.sessionDate = experimentDate.getFullYear() + "-" + experimentDate.getMonth() + "-" + experimentDate.getDate();
// Setup access message which is displayed above the button to access the data
var publicationDate = new Date(data.publication_year + "-01-01T00:00+00:00");
var now = new Date();
if (now > publicationDate ) {
data.accessMessage = "The data can be downloaded by clicking on the link below" ;
} else {
data.accessMessage = "The data is under embargo until <b>" + data.publication_year + "</b> but could be released earlier. It is currently only available to download if you are a member of the proposal team.";
}
}
......
......@@ -25,4 +25,20 @@ DOIView.prototype.displayMessage = function(template, message, id){
$("#" + id).html(out);
}
);
};
\ No newline at end of file
};
/**
* Set the message which is displayed just above the "Access data button"
* @param {object} data The json object reference.
*/
DOIView.prototype.setDataAccessMessage = function(data){
var publicationDate = new Date(data.publication_year + "-01-01T00:00+00:00");
var now = new Date();
if (now > publicationDate) {
data.accessMessage = "The data can be downloaded by clicking on the link below";
} else {
data.accessMessage = "The data is under embargo until <b>" + data.publication_year + "</b> but could be released earlier. It is currently only available to download if you are a member of the proposal team.";
}
};
......@@ -40,4 +40,29 @@ JsonExtractor.prototype.extractFromSubject = function(field, data, newField) {
if (!found) {
data[newField] = "Not available";
}
};
\ No newline at end of file
};
/**
* Extract useful dates from the data object. Handles the possibility that these
* dates do not exist.
*
* @param {object}
* data The data object reference which is sent to the dustjs
* template
*/
JsonExtractor.prototype.extractDates = function(data) {
// Displayed publication Year in doi landing page is the minting year
if (data.date_registered && data.date_registered != null) {
data.mintingYear = new Date(data.date_registered).getFullYear();
} else {
data.mintingYear = "Not available";
}
// Session date is the date the experiment for the session was performed
if (data.date_collected && data.date_registered != null) {
date = new Date(data.date_collected);
data.sessionDate = date.getFullYear() + "-" + date.getMonth() + "-" + date.getDate();
} else {
data.sessionDate = "Not available";
}
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment