Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[VIVO-1915] i18n - Adding a label with language tag through the "new" manageLabelsForindividualAddForm.ftl does not take the setting for language tag #184

Merged
merged 4 commits into from
Sep 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,6 @@ protected void subInValuesToN3(
/*
* do it only if aLiteral are xstring datatype
*/

if (XSD.xstring.getURI().equals(aLiteratDT) || RDF.dtLangString.getURI().equals(aLiteratDT)) {
String lang = vreq.getLocale().getLanguage();
if (!vreq.getLocale().getCountry().isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,20 @@ private void addFormSpecificData(EditConfigurationVTwo config,
config.addFormSpecificData("displayRemoveLink", (numberExistingLabels > 1));


// get current selected locale
String rangeLang = vreq.getLocale().getLanguage();
if (!vreq.getLocale().getCountry().isEmpty()) {
rangeLang += "-" + vreq.getLocale().getCountry();
}

// check if locale already has an entry (label)
boolean localeEntryExisting = true;
for (HashMap<String, String> tmp : availableLocalesForAdd) {
if (tmp.get("code").equals(rangeLang)) localeEntryExisting = false;
}
config.addFormSpecificData("localeEntryExisting", localeEntryExisting);
config.addFormSpecificData("currentSelectedLocale", rangeLang);

//How do we edit? Will need to see
config.addFormSpecificData("deleteWebpageUrl", "/edit/primitiveDelete");

Expand Down
40 changes: 9 additions & 31 deletions webapp/src/main/webapp/js/individual/manageLabelsForIndividual.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ var manageLabels = {
// Initial page setup. Called only at page load.
initPage: function() {

var disableSubmit = true;
if(this.submissionErrorsExist == "false") {
//hide the form to add label
this.addLabelForm.hide();
Expand All @@ -44,7 +43,11 @@ var manageLabels = {
if(this.numberAvailableLocales == 0) {
manageLabels.showFormButtonWrapper.hide();
this.showCancelOnlyButton.show();
} else {
} else if(manageLabels.localeEntryExisting == "true") {
// if there is already an label for the selected langauge hide the add button
manageLabels.showFormButtonWrapper.hide();
this.showCancelOnlyButton.show();
} else{
//if the add label button is visible, don't need cancel only link
this.showCancelOnlyButton.hide();
}
Expand All @@ -53,19 +56,6 @@ var manageLabels = {
//Display the form
this.onShowAddForm();

//Also make sure the save button is enabled in case there is a value selected for the drop down
if(this.labelLanguage.val() != "") {
disableSubmit = false;
}

}



if(disableSubmit) {
//disable submit until user selects a language
this.submit.attr('disabled', 'disabled');
this.submit.addClass('disabledSubmit');
}

this.bindEventListeners();
Expand All @@ -74,18 +64,6 @@ var manageLabels = {

bindEventListeners: function() {

this.labelLanguage.change( function() {
//if language selected, allow submission, otherwise disallow
var selectedLanguage = manageLabels.labelLanguage.val();
if(selectedLanguage != "") {
manageLabels.submit.attr('disabled', false);
manageLabels.submit.removeClass('disabledSubmit');
} else {
manageLabels.submit.attr('disabled', 'disabled');
manageLabels.submit.addClass('disabledSubmit');
}
});

//enable form to add label to be displayed or hidden
this.showFormButton.click(function() {
//clear the inputs for the label if the button is being clicked
Expand Down Expand Up @@ -123,9 +101,6 @@ var manageLabels = {
clearAddForm:function() {
//clear inputs and select
manageLabels.addLabelForm.find("input[type='text'],select").val("");
//set the button for save to be disabled again
manageLabels.submit.attr('disabled', 'disabled');
manageLabels.submit.addClass('disabledSubmit');
},
onShowAddForm:function() {
manageLabels.addLabelForm.show();
Expand Down Expand Up @@ -226,12 +201,14 @@ var manageLabels = {
var availableLocalesList = [];
var listLen = selectLocalesFullList.length;
var i;
var showAddButton = false;
for(i = 0; i < listLen; i++) {
var possibleLanguageInfo = selectLocalesFullList[i];
var possibleLanguageCode = possibleLanguageInfo["code"];
var possibleLangaugeLabel = possibleLanguageInfo["label"];
if(!(possibleLanguageCode in existingLanguages)) {
//manageLabels.addLanguageCode(possibleLanguageCode, possibleLanguageLabel);
if (possibleLanguageCode == manageLabels.currentSelectedLocale) showAddButton = true;
availableLocalesList.push(possibleLanguageInfo);
}
}
Expand All @@ -242,8 +219,9 @@ var manageLabels = {
var compB = b["label"];
return compA < compB ? -1 : 1;
});

//Re-show the add button and the form if they were hidden before
if(availableLocalesList.length > 0 && manageLabels.showFormButtonWrapper.is(":hidden")) {
if(availableLocalesList.length > 0 && manageLabels.showFormButtonWrapper.is(":hidden") && showAddButton) {
manageLabels.showFormButtonWrapper.show();
//hide the cancel only button
manageLabels.showCancelOnlyButton.hide();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@
<#else>
<h2>${i18n().manage_labels_capitalized}</h2>
</#if>
<#assign localeEntryExisting = true />
<#if editConfiguration.pageData.localeEntryExisting?has_content>
<#assign localeEntryExisting = editConfiguration.pageData.localeEntryExisting />
</#if>
<#assign currentSelectedLocale =" " />
<#if editConfiguration.pageData.currentSelectedLocale?has_content>
<#assign currentSelectedLocale = editConfiguration.pageData.currentSelectedLocale />
</#if>



Expand Down Expand Up @@ -94,7 +102,9 @@ var customFormData = {
individualUri: '${subjectUri!}',
submissionErrorsExist: '${submissionErrorsExist}',
selectLocalesFullList: selectLocalesFullList,
numberAvailableLocales:${availableLocalesNumber}
numberAvailableLocales:${availableLocalesNumber},
localeEntryExisting : '${localeEntryExisting?c}',
currentSelectedLocale: '${currentSelectedLocale}'
};
var i18nStrings = {
errorProcessingLabels: '${i18n().error_processing_labels?js_string}',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,6 @@
<label for="name">${i18n().name} ${requiredHint}</label>
<input size="30" type="text" id="label" name="label" value="" />
</p>
<label for="newLabelLanguage">${i18n().add_label_for_language}</label>
<select name="newLabelLanguage" id="newLabelLanguage" >
<option value=""<#if !newLabelLanguageValue?has_content> selected="selected"</#if>>${i18n().select_locale}</option>
<#if editConfiguration.pageData.selectLocale?has_content>
<#assign selectLocale = editConfiguration.pageData.selectLocale />
<#--Use the list of names because that is the order we want displayed-->

<#list selectLocale as locale>

<option value="${locale.code}"<#if newLabelLanguageValue?has_content && locale.code == newLabelLanguageValue> selected="selected"</#if>>${locale.label}</option>
</#list>
</#if>
</select>

<input type="hidden" name="editKey" id="editKey" value="${editKey}"/>

Expand Down