2011-07-21 20:31:36 +00:00
|
|
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
|
|
|
|
2013-06-07 11:59:14 -04:00
|
|
|
$.extend(this, i18nStrings);
|
|
|
|
|
2011-07-21 20:31:36 +00:00
|
|
|
var ErrorDisplayWidget = Class.extend({
|
|
|
|
|
|
|
|
container: '',
|
|
|
|
body: '',
|
|
|
|
bodyID: 'error-body',
|
|
|
|
messagePlaceholderID: 'variable-error-text',
|
|
|
|
|
|
|
|
init: function(opts) {
|
|
|
|
|
|
|
|
this.container = $("#" + opts.containerID);
|
|
|
|
this.body = this.container.find("#" + this.bodyID);
|
|
|
|
},
|
|
|
|
|
|
|
|
isErrorConditionTriggered: function(responseData) {
|
|
|
|
|
|
|
|
if (responseData.error) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (responseData[0].pubsMapped === 0) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
show: function(errorForType, responseData) {
|
|
|
|
|
|
|
|
var isZeroPublicationsCase = responseData.error ? true : false;
|
|
|
|
var newErrorMessage = "";
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This means that the organization or person has zero publications.
|
|
|
|
* */
|
|
|
|
if (isZeroPublicationsCase) {
|
|
|
|
|
2013-06-07 11:59:14 -04:00
|
|
|
newErrorMessage += i18nStrings.noAttributedPubs + " " + errorForType.toLowerCase() + ".";
|
2011-07-21 20:31:36 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* This means that the organization or person has publications but none of them are mapped.
|
|
|
|
* Change the default text.
|
|
|
|
* */
|
|
|
|
newErrorMessage += this._getUnScienceLocatedErrorMessage(errorForType, responseData[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Now replace the error message with the newly created one.
|
|
|
|
* */
|
|
|
|
this.body.find("#" + this.messagePlaceholderID).html(newErrorMessage);
|
|
|
|
|
|
|
|
this.container.show();
|
|
|
|
},
|
|
|
|
|
|
|
|
_getUnScienceLocatedErrorMessage: function(errorForType, responseData) {
|
|
|
|
|
|
|
|
var totalPublications = responseData.pubsWithNoJournals + responseData.pubsWithInvalidJournals;
|
|
|
|
var newErrorMessage = "";
|
|
|
|
|
|
|
|
if (totalPublications > 1) {
|
2013-06-07 11:59:14 -04:00
|
|
|
newErrorMessage = i18nStrings.noneOfThe + " " + totalPublications + " "
|
|
|
|
+ i18nStrings.pubsAttributedTo + " "
|
|
|
|
+ errorForType.toLowerCase()
|
|
|
|
+ " " + i18nStrings.beenScienceLocated;
|
2011-07-21 20:31:36 +00:00
|
|
|
|
|
|
|
} else {
|
2013-06-07 11:59:14 -04:00
|
|
|
newErrorMessage = i18nStrings.pubAttributedTo + " "
|
|
|
|
+ errorForType.toLowerCase() + " " + i18nStrings.notScienceLocated;
|
2011-07-21 20:31:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
newErrorMessage += "<ul class='error-list'>";
|
|
|
|
|
|
|
|
if (responseData.pubsWithNoJournals && responseData.pubsWithNoJournals > 0) {
|
|
|
|
|
2013-06-07 11:59:14 -04:00
|
|
|
var publicationsText = (responseData.pubsWithNoJournals > 1) ? i18nStrings.publicationsString : i18nStrings.publicationString;
|
2011-07-21 20:31:36 +00:00
|
|
|
|
2013-06-07 11:59:14 -04:00
|
|
|
newErrorMessage += "<li>" + responseData.pubsWithNoJournals + " " + publicationsText
|
|
|
|
+ " " + i18nStrings.noJournalInformation + "</li>"
|
2011-07-21 20:31:36 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (responseData.pubsWithInvalidJournals && responseData.pubsWithInvalidJournals > 0) {
|
|
|
|
|
2013-06-07 11:59:14 -04:00
|
|
|
var publicationsText = (responseData.pubsWithInvalidJournals > 1) ? i18nStrings.publicationsString : i18nStrings.publicationString;
|
2011-07-21 20:31:36 +00:00
|
|
|
|
|
|
|
newErrorMessage += "<li>" + responseData.pubsWithInvalidJournals + " " + publicationsText + " "
|
2013-06-07 11:59:14 -04:00
|
|
|
+ " " + i18nStrings.noMatchingMapLocation + "</li>"
|
2011-07-21 20:31:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
newErrorMessage += "</ul>";
|
|
|
|
|
|
|
|
return newErrorMessage;
|
|
|
|
},
|
|
|
|
|
|
|
|
hide: function() {
|
|
|
|
this.container.hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|