Skip to content

Commit

Permalink
Fix some documentation for the new RegisterCitationView view
Browse files Browse the repository at this point in the history
  • Loading branch information
laurenwalker committed Jul 28, 2020
1 parent b1814e6 commit 02c9504
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 39 deletions.
27 changes: 17 additions & 10 deletions src/js/views/MetricModalView.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@ define(['jquery', 'underscore', 'backbone', 'MetricsChart', 'text!templates/metr
function($, _, Backbone, MetricsChart, MetricModalTemplate, Citations, CitationList) {
'use strict';

var MetricModalView = Backbone.View.extend({
/**
* @class MetricModalView
* @classdesc A Bootstrap Modal that displays a DataONE dataset usage metric,
* such as downloads, views, or citations.
* @extends Backbone.View
*/
var MetricModalView = Backbone.View.extend(
/** @lends MetricModalView.prototype */ {

id: 'metric-modal',
className: 'modal fade hide',
Expand Down Expand Up @@ -33,21 +40,21 @@ define(['jquery', 'underscore', 'backbone', 'MetricsChart', 'text!templates/metr
this.pid = options.pid;

},

getPreviousMetric : function(currentMetricName) {
if(currentMetricName != 'undefined') {
this.metricIndex = this.metrics.indexOf(currentMetricName);
}

// Implementing a circular queue to get the previous metric
return(this.metrics[((this.metricIndex + this.metrics.length - 1) % this.metrics.length)]);
},

getNextMetric : function(currentMetricName) {
if(currentMetricName != 'undefined') {
this.metricIndex = this.metrics.indexOf(currentMetricName);
}

// Implementing a circular queue to get the next metric
return(this.metrics[((this.metricIndex + this.metrics.length + 1) % this.metrics.length)]);
},
Expand Down Expand Up @@ -105,11 +112,11 @@ define(['jquery', 'underscore', 'backbone', 'MetricsChart', 'text!templates/metr
},

showPreviousMetricModal: function() {

this.nextMetricName = this.metricName;
this.metricName = this.getPreviousMetric(this.metricName);
this.nextMetricName = this.getPreviousMetric(this.metricName);


this.metricNameLemma = this.metricName.toLowerCase().substring(0, this.metricName.length - 1);
if ( this.metricName === "Citations") {
Expand All @@ -125,7 +132,7 @@ define(['jquery', 'underscore', 'backbone', 'MetricsChart', 'text!templates/metr
else {
var citationList = new CitationList({citations: this.citationCollection, citationsForDataCatalogView: true});
}

this.citationList = citationList;

this.$el.html(this.template({metricName:this.metricName, metricNameLemma:this.metricNameLemma, metricValue: this.metricsModel.get("totalCitations"), metricBody:this.citationList.render().$el.html()}));
Expand Down Expand Up @@ -160,7 +167,7 @@ define(['jquery', 'underscore', 'backbone', 'MetricsChart', 'text!templates/metr
this.prevMetricName = this.metricName;
this.metricName = this.getNextMetric(this.metricName);
this.nextMetricName = this.getNextMetric(this.metricName);


this.metricNameLemma = this.metricName.toLowerCase().substring(0, this.metricName.length - 1);
if ( this.metricName === "Citations") {
Expand All @@ -176,7 +183,7 @@ define(['jquery', 'underscore', 'backbone', 'MetricsChart', 'text!templates/metr
else {
var citationList = new CitationList({citations: this.citationCollection, citationsForDataCatalogView: true});
}

this.citationList = citationList;

this.$el.html(this.template({metricName:this.metricName, metricNameLemma:this.metricNameLemma, metricValue: this.metricsModel.get("totalCitations"), metricBody:this.citationList.render().$el.html()}));
Expand Down
77 changes: 48 additions & 29 deletions src/js/views/RegisterCitationView.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,32 @@ define(['jquery', 'underscore', 'backbone', 'text!templates/registerCitation.htm
function($, _, Backbone, RegisterCitationTemplate, AlertTemplate) {
'use strict';

var RegisterCitationView = Backbone.View.extend({
/**
* @class RegisterCitationView
* @classdesc A simple form for a user to input a DOI that cites or uses a dataset in DataONE.
* When the form is submitted, the citation is registered with the DataONE Metrics service.
* @extends Backbone.View
*/
var RegisterCitationView = Backbone.View.extend(
/** @lends RegisterCitationView.prototype */ {

id: 'citation-modal',
className: 'modal fade hide',

/**
* The URL to save the citation to
* @type {string}
*/
citationUrl: "",

template: _.template(RegisterCitationTemplate),
alertTemplate: _.template(AlertTemplate),
successFooterTemplate: _.template("<button class='btn btn-indigo'" +
successFooterTemplate: _.template("<button class='btn btn-indigo'" +
" data-dismiss='modal'" +
">Done</button>"),

events: {
'hidden' : 'teardown',
'hidden' : 'teardown',
'click .btn-register-citation' : 'registerCitation'
},

Expand All @@ -28,29 +42,34 @@ define(['jquery', 'underscore', 'backbone', 'text!templates/registerCitation.htm

},

/**
* Shows this view on the page.
*/
show: function() {
this.$el.modal('show');
},

/**
* Hides and removes this view from the page.
*/
teardown: function() {
this.$el.modal('hide');
this.$el.data('modal', null);
this.remove();
},

/**
* Renders the submission form and creates a Bootstrap modal for this view
*/
render: function() {
this.renderView();
return this;
},

renderView: function(){
this.$el.html(this.template());
this.$el.modal({show:false}); // dont show modal on instantiation

this.$el.html(this.template());
this.$el.modal({show:false}); // dont show modal on instantiation
return this;
},

/**
* Get inputs from the modal and sends it to the Metrics Service
* Get inputs from the modal and sends it to the DataONE Metrics Service
*/
registerCitation: function() {

Expand All @@ -60,15 +79,15 @@ define(['jquery', 'underscore', 'backbone', 'text!templates/registerCitation.htm
var citationType = this.$("#citationTypeCustomSelect").val();
var relation_type = null;

// If the user has not selected a valid
// If the user has not selected a valid
if (citationType != 0) {
relation_type = citationType == 1 ? "isCitedBy" : "isReferencedBy";
}
else {
relation_type = "isCitedBy";
}

// create a request object
// create a request object
var citationsUrl = MetacatUI.appModel.get("d1CitationUrl");
this.citationsUrl = citationsUrl;

Expand All @@ -82,38 +101,38 @@ define(['jquery', 'underscore', 'backbone', 'text!templates/registerCitation.htm
citationRegisterObject["source_id"] = publicationIdentifier;
citationRegisterObject["relation_type"] = relation_type;
formData["metadata"].push(citationRegisterObject);
// ajax call to submit the given form and then render the results in the content area
var viewRef = this;
var requestSettings = {
type: "POST",
url: this.citationsUrl,
contentType: false,

// ajax call to submit the given form and then render the results in the content area
var viewRef = this;

var requestSettings = {
type: "POST",
url: this.citationsUrl,
contentType: false,
processData: false,
data: JSON.stringify(formData),
dataType: "json",
success: function(data, textStatus, jqXHR) {
var successMessage = $.parseHTML(viewRef.alertTemplate({
success: function(data, textStatus, jqXHR) {
var successMessage = $.parseHTML(viewRef.alertTemplate({
msg: 'Thank you! Your citation has been successfully submitted to DataONE. It may take upto 24 hours to display the citation.',
classes: "alert-success"
}));


viewRef.$(".modal-body").html(successMessage);
viewRef.$(".modal-footer").html(viewRef.successFooterTemplate());
},
error: function(){
var errorMessage = $.parseHTML(viewRef.alertTemplate({
msg: 'Sorry! We encountered an error while registering citation to DataONE.',
var errorMessage = $.parseHTML(viewRef.alertTemplate({
msg: 'Sorry! We encountered an error while registering that citation to DataONE.',
classes: "alert-error"
}));


viewRef.$(".modal-body").html(errorMessage);
}
}
}

$.ajax(_.extend(requestSettings, MetacatUI.appUserModel.createAjaxSettings()));

}
Expand Down

0 comments on commit 02c9504

Please sign in to comment.