define(['jquery', 'underscore', 'backbone', 'models/SolrResult'],
function($, _, Backbone, SolrResult, template) {
'use strict'
/**
* Button to the data package editor
*
* @type {void|*}
*/
var SubmitDataButtonView = Backbone.View.extend({
tagName: "a",
className: "btn btn-primary",
/**
* Initialize the button. Specify parent element for tool tips
* @param options
*/
initialize: function (options) {
if (!options) var options = {};
this.parent = options.parent
},
/**
* Render the submit data button. Tool tips are added if a parent element is specified
* during initialization.
*
* Checks that the user is logged in and has permission to submit data.
*
* @type {boolean}
*/
render: function(){
var ifUserHasPerm = MetacatUI.isAllowedtoSubmitData(MetacatUI.appUserModel);
if (!ifUserHasPerm) {
// Setup the parent element for tooltips
if (this.parent)
$(this.parent).addClass("tooltip-this")
.attr("data-placement", "bottom")
.attr("data-trigger", "hover");
// Determine if the user is allowed to submit data
if (!MetacatUI.appUserModel.get("loggedIn")) {
this.$el.addClass("btn-secondary disabled").removeClass('btn-primary');
this.$el.text("Submit Data");
if (this.parent)
$(this.parent)
.attr("disabled", "disabled")
.attr("data-title", "Login with your Orcid to submit data." +
" If you do not have an Orcid, click 'Sign in with Orcid' " +
"and follow the registration instructions.");
} else if (!ifUserHasPerm) {
this.$el.attr("href", MetacatUI.appModel.get("userRegistrationUrl"));
this.$el.attr("target", "_blank");
this.$el.text("Request Upload Access");
if (this.parent)
$(this.parent)
.attr("data-title", "You don't have permission to Submit Data." +
" Click here to request submit access.");
}
}
else{
this.$el.removeClass("btn-secondary disabled").addClass("btn-primary");
this.$el.removeProp("disable");
this.$el.removeProp("target");
this.$el.attr("href", "/submit");
this.$el.text("Submit Data");
if (this.parent)
$(this.parent).removeClass("tooltip-this")
.removeProp("data-placement", "bottom")
.removeProp("data-trigger", "hover");
}
return this;
}
});
return SubmitDataButtonView;
}
);