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

Story/cit 6 #14

Merged
merged 28 commits into from Mar 8, 2019
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
33880ed
[CIT-5] Merge develop to branch.
Jan 25, 2019
1135d97
Merge branch 'develop' of https://github.com/diging/citesphere into d…
Jan 29, 2019
ed70252
[CIT-6] Saving changes in edit author.
Jan 29, 2019
1dcbf6f
Merge remote-tracking branch 'origin/develop' into story/CIT-6
Jan 30, 2019
6b4085e
Merge remote-tracking branch 'origin/develop' into story/CIT-6
Jan 30, 2019
a67c6ef
[CIT-6] Changes in edit author on edit page.
Jan 30, 2019
b6299aa
[CIT-6] Saving changes in edit author.
Jan 31, 2019
a922825
[CIT-6] Saving changes in retaining affiliations.
Feb 4, 2019
ea7fbd6
[CIT-6] Added update affiliations in edit author modal.
Feb 5, 2019
21204e5
[CIT-6] Merge remote-tracking branch 'origin/develop' into story/CIT-6
Feb 5, 2019
9ea6711
[CIT-6] Null pointer fix in title sort comparator.
Feb 5, 2019
1a8744f
[CIT-6] Reverting Cit-5 changes.
Feb 5, 2019
ae50939
[CIT-6] Changes in formatting.
Feb 5, 2019
5b0bebe
[CIT-6] Removing unused library.
Feb 5, 2019
9626306
Merge remote-tracking branch 'origin/develop' into story/CIT-6
Feb 6, 2019
3b9f155
[CIT-6] Saving work.
Feb 6, 2019
59ad854
[CIT-6] Changes in edit author.
Feb 7, 2019
56c9f0f
[CIT-6] Saving work in edit authors.
Feb 11, 2019
4d14047
[CIT-6] Saving work in edit author.
Feb 13, 2019
0227920
[CIT-6] Changes in edit author.
Feb 14, 2019
f25968b
[CIT-6] Minor fixes.
Feb 14, 2019
740293f
[CIT-6] Merge remote-tracking branch 'origin/develop' into story/CIT-6
Feb 14, 2019
ad64f52
[CIT-6] Minor fixes in formatting in JSP.
Feb 14, 2019
633be1d
[CIT-6] Refactored code.
Feb 15, 2019
f724aa9
[CIT-6] Minor changes in affiliation field in modal.
Feb 18, 2019
bed9012
[CIT-6] Merge remote-tracking branch 'origin/develop' into story/CIT-6
Mar 7, 2019
ff43113
[CIT-6] Ability to edit authors and editors.
Mar 7, 2019
3e59c49
[CIT-6] Fixed the exception in citation factory for jsonnull.
Mar 8, 2019
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
Expand Up @@ -79,7 +79,6 @@ public void init() {
sortFunctions.put("title", ((o1, o2) -> {
String o1Title = o1 != null && o1.getTitle() != null ? o1.getTitle() : "";
String o2Title = o2 != null && o2.getTitle() != null ? o2.getTitle() : "";

return o1Title.toLowerCase().compareTo(o2Title.toLowerCase());
}));
}
Expand Down
138 changes: 91 additions & 47 deletions citesphere/src/main/webapp/WEB-INF/views/auth/group/editItem.jsp
Expand Up @@ -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 + '&nbsp;&nbsp; ');
var deleteIcon = $('<i class="fas fa-times remove-author"></i>');
deleteIcon.click(removeAuthor);
authorSpan.append(deleteIcon);
$("#authorList").append(authorSpan);
$("#authorList").append("&nbsp;&nbsp; ")

$("#authorModal").modal('hide');
resetAuthorCreationModal();
$(document).on('click', '#addAuthorButton', function() {
saveAuthor();
});
Copy link
Member

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.


$("#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');

Expand Down Expand Up @@ -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");
Copy link
Member

Choose a reason for hiding this comment

The 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());
Copy link
Member

Choose a reason for hiding this comment

The 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 + '&nbsp;&nbsp; ');
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("&nbsp;&nbsp; ")
$("#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();
Copy link
Member

Choose a reason for hiding this comment

The 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();
}

Expand Down Expand Up @@ -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>
&nbsp;&nbsp;
${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>
&nbsp;
<i class="far fa-edit edit-author"></i>
&nbsp;
<i class="fas fa-times remove-author"></i>
</span>
&nbsp;&nbsp;
Expand Down Expand Up @@ -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">
Expand Down