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
Story/cit 6 #14
Story/cit 6 #14
Changes from 23 commits
33880ed
1135d97
ed70252
1dcbf6f
6b4085e
a67c6ef
b6299aa
a922825
ea7fbd6
21204e5
9ea6711
1a8744f
ae50939
5b0bebe
9626306
3b9f155
59ad854
56c9f0f
4d14047
0227920
f25968b
740293f
ad64f52
633be1d
f724aa9
bed9012
ff43113
3e59c49
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,99 +26,67 @@ $(function() { | |
authorIdField.attr("type", "hidden"); | ||
authorIdField.attr("id", "authors" + idx + ".id"); | ||
authorIdField.attr("name", "authors[" + idx + "].id"); | ||
authorIdField.attr("value", $(author).data("author-id")); | ||
authorIdField.attr("value", $(author).attr("data-author-id")); | ||
$("#editForm").append(authorIdField); | ||
|
||
var authorFirstNameField = $("<input>"); | ||
authorFirstNameField.attr("type", "hidden"); | ||
authorFirstNameField.attr("id", "authors" + idx + ".firstName"); | ||
authorFirstNameField.attr("name", "authors[" + idx + "].firstName"); | ||
authorFirstNameField.attr("value", $(author).data("author-firstname")); | ||
authorFirstNameField.attr("value", $(author).attr("data-author-firstname")); | ||
$("#editForm").append(authorFirstNameField); | ||
|
||
var authorLastNameField = $("<input>"); | ||
authorLastNameField.attr("type", "hidden"); | ||
authorLastNameField.attr("id", "authors" + idx + ".lastName"); | ||
authorLastNameField.attr("name", "authors[" + idx + "].lastName"); | ||
authorLastNameField.attr("value", $(author).data("author-lastname")); | ||
authorLastNameField.attr("value", $(author).attr("data-author-lastname")); | ||
$("#editForm").append(authorLastNameField); | ||
|
||
var authorUriField = $("<input>"); | ||
authorUriField.attr("type", "hidden"); | ||
authorUriField.attr("id", "authors" + idx + ".uri"); | ||
authorUriField.attr("name", "authors[" + idx + "].uri"); | ||
authorUriField.attr("value", $(author).data("author-uri")); | ||
authorUriField.attr("value", $(author).attr("data-author-uri")); | ||
$("#editForm").append(authorUriField); | ||
|
||
var authorAuthorityField = $("<input>"); | ||
authorAuthorityField.attr("type", "hidden"); | ||
authorAuthorityField.attr("id", "authors" + idx + ".localAuthorityId"); | ||
authorAuthorityField.attr("name", "authors[" + idx + "].localAuthorityId"); | ||
authorAuthorityField.attr("value", $(author).data("author-authority-id")); | ||
authorAuthorityField.attr("value", $(author).attr("data-author-authority-id")); | ||
$("#editForm").append(authorAuthorityField); | ||
|
||
$(author).children("span").each(function(idx2, affiliation) { | ||
var affiliationField = $("<input>"); | ||
affiliationField.attr("type", "hidden"); | ||
affiliationField.attr("id", "authors" + idx + ".affiliations" + idx2 + ".name"); | ||
affiliationField.attr("name", "authors[" + idx + "].affiliations[" + idx2 + "].name"); | ||
affiliationField.attr("value", $(affiliation).data("affiliation-name")); | ||
affiliationField.attr("value", $(affiliation).attr("data-affiliation-name")); | ||
$("#editForm").append(affiliationField); | ||
|
||
var affiliationIdField = $("<input>"); | ||
affiliationIdField.attr("type", "hidden"); | ||
affiliationIdField.attr("id", "authors" + idx + ".affiliations" + idx2 + ".id"); | ||
affiliationIdField.attr("name", "authors[" + idx + "].affiliations[" + idx2 + "].id"); | ||
affiliationIdField.attr("value", $(affiliation).data("affiliation-id")); | ||
affiliationIdField.attr("value", $(affiliation).attr("data-affiliation-id")); | ||
$("#editForm").append(affiliationIdField); | ||
}); | ||
}); | ||
}); | ||
|
||
$("#addAuthorButton").click(function() { | ||
var firstname = $("#firstNameAuthor").val(); | ||
var lastname = $("#lastNameAuthor").val(); | ||
var uri = $("#uriAuthor").val(); | ||
var localAuthority = $("#uriAuthorLocalId").val(); | ||
|
||
var authorSpan = $("<span>"); | ||
authorSpan.attr("class", "label label-primary author-item"); | ||
authorSpan.attr("data-author-firstname", firstname); | ||
authorSpan.attr("data-author-lastname", lastname); | ||
authorSpan.attr("data-author-uri", uri); | ||
authorSpan.attr("data-author-authority-id", localAuthority); | ||
|
||
var affiliationsList = []; | ||
var affSpan = $("<span>"); | ||
$("#affiliations").children().each(function(idx, elem) { | ||
var affSpan = $("<span>"); | ||
var input = $(elem).find("input"); | ||
affSpan.attr("data-affiliation-name", input.val()); | ||
affiliationsList.push(input.val()); | ||
authorSpan.append(affSpan); | ||
}); | ||
|
||
var affiliationString = ""; | ||
if (affiliationsList) { | ||
affiliationString = " (" + affiliationsList.join(", ") + ")"; | ||
} | ||
|
||
authorSpan.append(lastname + ', ' + firstname + affiliationString + ' '); | ||
var deleteIcon = $('<i class="fas fa-times remove-author"></i>'); | ||
deleteIcon.click(removeAuthor); | ||
authorSpan.append(deleteIcon); | ||
$("#authorList").append(authorSpan); | ||
$("#authorList").append(" ") | ||
|
||
$("#authorModal").modal('hide'); | ||
resetAuthorCreationModal(); | ||
$(document).on('click', '#addAuthorButton', function() { | ||
saveAuthor(); | ||
}); | ||
|
||
$("#addAuthorModalCancel").click(function() { | ||
$("#authorModal").modal('hide'); | ||
resetAuthorCreationModal(); | ||
}); | ||
|
||
$(".edit-author").click(editAuthor); | ||
$(".edit-author").css('cursor', 'pointer'); | ||
|
||
$(".remove-author").click(removeAuthor); | ||
$(".remove-author").css('cursor', 'pointer'); | ||
|
||
|
@@ -160,11 +128,82 @@ $(function() { | |
}); | ||
}); | ||
|
||
function editAuthor(){ | ||
var authorItem = $(this).parent(); | ||
$("#firstNameAuthor").val(authorItem.attr("data-author-firstname")); | ||
$("#lastNameAuthor").val(authorItem.attr("data-author-lastname")); | ||
$("#uriAuthor").val(authorItem.attr("data-author-uri")); | ||
$("#idAuthor").attr("data-author-id", authorItem.attr("id")); | ||
|
||
authorItem.children("span").each(function(idx, elem){ | ||
var affInput = $("#affiliationTemplate").clone(); | ||
affInput.removeAttr("id"); | ||
affInput.attr("class", affInput.attr("class")+" aff-info"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just use 'addClass' function |
||
affInput.find("input").attr("data-affiliation-name", $(elem).data("affiliationName")); | ||
affInput.find("input").attr("data-affiliation-id", $(elem).data("affiliationId")); | ||
affInput.find("input").val($(elem).data("affiliationName")); | ||
$("#authorModal #affiliations").append(affInput); | ||
}); | ||
$("#addAuthorButton").text("Update Author"); | ||
$("#authorModal").modal('show'); | ||
} | ||
|
||
function saveAuthor() { | ||
if($("#idAuthor").attr("data-author-id")){ | ||
authorSpan = $('#'+$("#idAuthor").attr("data-author-id")); | ||
} else { | ||
$("#idAuthor").attr("data-author-id", $("#authorList").length); | ||
authorSpan = $('<span id="author'+$("#idAuthor").attr("data-author-id")+'">'); | ||
} | ||
authorSpan.html(""); | ||
var firstname = $("#firstNameAuthor").val(); | ||
var lastname = $("#lastNameAuthor").val(); | ||
var uri = $("#uriAuthor").val(); | ||
var localAuthority = $("#uriAuthorLocalId").val(); | ||
authorSpan.attr("class", "label label-primary author-item"); | ||
authorSpan.attr("data-author-firstname", firstname); | ||
authorSpan.attr("data-author-lastname", lastname); | ||
authorSpan.attr("data-author-uri", uri); | ||
authorSpan.attr("data-author-authority-id", localAuthority); | ||
|
||
var affiliationsList = []; | ||
$("#affiliations").children().each(function(idx, elem){ | ||
var input = $(elem).find("input"); | ||
if(input.val().length!=0){ | ||
var affSpan = $("<span>"); | ||
affSpan.attr("data-affiliation-id", input.attr("data-affiliation-id")); | ||
affSpan.attr("data-affiliation-name", input.val()); | ||
affSpan.val(input.val()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. isn't affSpan a span element? what does calling val() accomplish? form jquery documentation: "This method is typically used to set the values of form fields." |
||
affiliationsList.push(input.val()); | ||
authorSpan.append(affSpan); | ||
} | ||
}); | ||
|
||
var affiliationString = ""; | ||
if (affiliationsList.length!=0) { | ||
affiliationString = " (" + $.grep(affiliationsList, Boolean).join(", ") + ")"; | ||
} | ||
authorSpan.append(lastname + ', ' + firstname + affiliationString + ' '); | ||
var editIcon = $('<i class="far fa-edit edit-author"></i>') | ||
var deleteIcon = $('<i class="fas fa-times remove-author"></i>'); | ||
editIcon.click(editAuthor); | ||
deleteIcon.click(removeAuthor); | ||
authorSpan.append(editIcon); | ||
authorSpan.append(deleteIcon); | ||
$("#authorList").append(authorSpan); | ||
$("#authorList").append(" ") | ||
$("#authorModal").modal('hide'); | ||
resetAuthorCreationModal(); | ||
} | ||
function resetAuthorCreationModal() { | ||
$("#firstNameAuthor").val(""); | ||
$("#lastNameAuthor").val(""); | ||
$("#affiliationTemplate").find("input").val(""); | ||
$("#uriAuthor").val(""); | ||
$("#idAuthor").attr("data-author-id",""); | ||
$(".aff-info").find("input").val(""); | ||
$(".aff-info").remove(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why do you set the input to empty first, if you then remove the the elements? |
||
$("#addAuthorButton").text("Add Author"); | ||
resetAuthorAuthorityCreation(); | ||
} | ||
|
||
|
@@ -303,10 +342,12 @@ let removeAuthor = function removeAuthor(e) { | |
<td> | ||
<span id="authorList" style="font-size: 18px"> | ||
<c:forEach items="${citation.authors}" var="author" varStatus="status"> | ||
<span class="label label-primary author-item" data-author-id="${author.id}" data-author-firstname="${author.firstName}" data-author-lastname="${author.lastName}" data-author-uri="${author.uri}" data-author-authority-id="${author.localAuthorityId}"> | ||
<span id="author${status.index}" class="label label-primary author-item" data-author-id="${author.id}" data-author-firstname="${author.firstName}" data-author-lastname="${author.lastName}" data-author-uri="${author.uri}" data-author-authority-id="${author.localAuthorityId}"> | ||
<c:forEach items="${author.affiliations}" var="aff"> <span data-affiliation-name="${aff.name}" data-affiliation-id="${aff.id}"></span></c:forEach> | ||
${author.lastName}<c:if test="${not empty author.firstName}">, ${author.firstName}</c:if><c:forEach items="${author.affiliations}" var="aff"> (${aff.name})</c:forEach> | ||
| ||
${author.lastName}<c:if test="${not empty author.firstName}">, ${author.firstName}</c:if><c:forEach items="${author.affiliations}" var="aff"><c:if test="${not empty aff.name}"> (${aff.name})</c:if></c:forEach> | ||
| ||
<i class="far fa-edit edit-author"></i> | ||
| ||
<i class="fas fa-times remove-author"></i> | ||
</span> | ||
| ||
|
@@ -422,6 +463,9 @@ ${author.lastName}<c:if test="${not empty author.firstName}">, ${author.firstNam | |
<h4 class="modal-title" id="authorLabel">Enter Author Information</h4> | ||
</div> | ||
<div class="modal-body"> | ||
<div class="form-group"> | ||
<input type="hidden" class="form-control" id="idAuthor"> | ||
</div> | ||
<div class="form-group"> | ||
<label for="firstNameAuthor">First Name:</label> | ||
<input type="text" class="form-control" id="firstNameAuthor" placeholder="First Name"> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since this is basically the same code as for adding authors, let's reuse the existing code.