Skip to content

Commit

Permalink
SAK-47084 Discussions: Dates are on bad format when trying saving a n…
Browse files Browse the repository at this point in the history
…ew forum without title on "Specify dates to open (show) and/or close (hide)" option (sakaiproject#10405)

* SAK-47084 Discussions: Dates are on bad format when trying saving a new forum without title on "Specify dates to open (show) and/or close (hide)" option

* Minor improvements
  • Loading branch information
Fernando Alvarez-Castellanos Rojo authored Apr 25, 2022
1 parent 8e96a6f commit 7c2c2af
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.format.FormatStyle;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.function.Predicate;

import javax.faces.context.FacesContext;
import javax.faces.model.SelectItem;

import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -69,6 +69,8 @@ public class DiscussionForumBean

private SimpleDateFormat datetimeFormat;
private UserTimeService userTimeService;
private String openDateISO = "";
private String closeDateISO = "";

private static final String MESSAGECENTER_BUNDLE = "org.sakaiproject.api.app.messagecenter.bundle.Messages";
private static final ResourceLoader rb = new ResourceLoader(MESSAGECENTER_BUNDLE);
Expand Down Expand Up @@ -533,16 +535,14 @@ public String getOpenDate(){
if(forum == null || forum.getOpenDate() == null){
return "";
}else{
StringBuilder dateTimeOpenDate = new StringBuilder( datetimeFormat.format( forum.getOpenDate() ) );
return dateTimeOpenDate.toString();
return userTimeService.dateTimeFormat(forum.getOpenDate().toInstant(), FormatStyle.SHORT, null);
}
}
}

public void setOpenDate(String openDateStr){
if (StringUtils.isNotBlank(openDateStr)) {
if (StringUtils.isNoneBlank(openDateStr, openDateISO)) {
try{
String hiddenOpenDate = (String)FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("openDateISO8601");
Date openDate = (Date) datetimeFormat.parse(hiddenOpenDate);
Date openDate = (Date) datetimeFormat.parse(openDateISO);
forum.setOpenDate(openDate);
}catch (ParseException e) {
log.error("Couldn't convert open date", e);
Expand All @@ -556,25 +556,23 @@ public String getCloseDate(){
if(forum == null || forum.getCloseDate() == null){
return "";
}else{
StringBuilder dateTimeCloseDate = new StringBuilder( datetimeFormat.format( forum.getCloseDate() ) );
return dateTimeCloseDate.toString();
return userTimeService.dateTimeFormat(forum.getCloseDate().toInstant(), FormatStyle.SHORT, null);
}
}
}

public void setCloseDate(String closeDateStr){
if (StringUtils.isNotBlank(closeDateStr)) {
if (StringUtils.isNoneBlank(closeDateStr, closeDateISO)) {
try{
String hiddenCloseDate = (String)FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("closeDateISO8601");
Date CloseDate = (Date) datetimeFormat.parse(hiddenCloseDate);
forum.setCloseDate(CloseDate);
Date closeDate = (Date) datetimeFormat.parse(closeDateISO);
forum.setCloseDate(closeDate);
}catch (ParseException e) {
log.error("Couldn't convert Close date", e);
}
}else{
forum.setCloseDate(null);
}
}

public String getFormattedCloseDate(){
if(forum == null || forum.getCloseDate() == null){
return "";
Expand All @@ -598,4 +596,14 @@ public String getFormattedOpenDate(){
public String getHasRubric(){
return rubricsService.hasAssociatedRubric(RubricsConstants.RBCS_TOOL_GRADEBOOKNG, forum.getDefaultAssignName()) ? Boolean.TRUE.toString() : Boolean.FALSE.toString();
}

public void setOpenDateISO(String openDateISO) {
this.openDateISO = openDateISO;
setOpenDate(this.openDateISO);
}

public void setCloseDateISO(String closeDateISO) {
this.closeDateISO = closeDateISO;
setCloseDate(this.closeDateISO);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
<script src="/messageforums-tool/js/forum.js"></script>
<script src="/messageforums-tool/js/messages.js"></script>
<script src="/messageforums-tool/js/permissions_header.js"></script>
<script src="/messageforums-tool/js/datetimepicker.js"></script>
<script src="/library/js/lang-datepicker/lang-datepicker.js"></script>
<script src="/webcomponents/rubrics/sakai-rubrics-utils.js<h:outputText value="#{ForumTool.CDNQuery}" />"></script>
<script type="module" src="/webcomponents/rubrics/rubric-association-requirements.js<h:outputText value="#{ForumTool.CDNQuery}" />"></script>
Expand All @@ -34,18 +33,17 @@
}
</script>
<script>
$(document).ready(function() {
const radioButtonRestrictedAvailability = document.getElementById('revise:availabilityRestricted:1');
if (radioButtonRestrictedAvailability.checked && $(".calWidget")[0].style['display'] === 'none') {
setDatesEnabled(radioButtonRestrictedAvailability);
}
});
function setDatesEnabled(radioButton){
$(".calWidget").fadeToggle('slow');
}
function openDateCal(){
NewCal('revise:openDate','MMDDYYYY',true,12, '<h:outputText value="#{ForumTool.defaultAvailabilityTime}"/>');
}
function closeDateCal(){
NewCal('revise:closeDate','MMDDYYYY',true,12, '<h:outputText value="#{ForumTool.defaultAvailabilityTime}"/>');
}
function updateGradeAssignment(){
var elems = document.getElementsByTagName('sakai-rubric-association');
var forumAssignments = document.getElementById("revise:forum_assignments");
Expand Down Expand Up @@ -283,36 +281,51 @@
</h:selectOneRadio>
</h:panelGroup>
<h:panelGroup id="openDateSpan" styleClass="indnt2 openDateSpan calWidget" style="display: #{ForumTool.selectedForum.availabilityRestricted ? 'block' : 'none'}">
<h:outputLabel value="#{msgs.openDate}: " for="openDate"/>
<h:outputLabel value="#{msgs.openDate}: " for="openDate"/>
<h:inputText id="openDate" styleClass="openDate" value="#{ForumTool.selectedForum.openDate}" onchange="storeOpenDateISO(event)"/>
<h:inputText id="openDateISO" styleClass="openDateISO hidden" value="#{ForumTool.selectedForum.openDateISO}"></h:inputText>
</h:panelGroup>
<h:panelGroup id="closeDateSpan" styleClass="indnt2 closeDateSpan calWidget" style="display: #{ForumTool.selectedForum.availabilityRestricted ? 'block' : 'none'}">
<h:outputLabel value="#{msgs.closeDate}: " for="closeDate" />
<h:inputText id="closeDate" styleClass="closeDate" value="#{ForumTool.selectedForum.closeDate}" onchange="storeCloseDateISO(event)"/>
<h:inputText id="closeDateISO" styleClass="closeDateISO hidden" value="#{ForumTool.selectedForum.closeDateISO}"></h:inputText>
</h:panelGroup>
</h:panelGroup>
<h:inputText id="openDate" styleClass="openDate" value="#{ForumTool.selectedForum.openDate}"/>
<script>
function storeOpenDateISO(e) {
e.preventDefault();
document.getElementsByClassName("openDateISO")[0].value = document.getElementById("openDateISO8601").value;
}
</h:panelGroup>
<h:panelGroup id="closeDateSpan" styleClass="indnt2 closeDateSpan calWidget" style="display: #{ForumTool.selectedForum.availabilityRestricted ? '' : 'none'}">
<h:outputLabel value="#{msgs.closeDate}: " for="closeDate" />
<h:inputText id="closeDate" styleClass="closeDate" value="#{ForumTool.selectedForum.closeDate}"/>
function storeCloseDateISO(e) {
e.preventDefault();
document.getElementsByClassName("closeDateISO")[0].value = document.getElementById("closeDateISO8601").value;
}
</h:panelGroup>
<%-- </h:panelGrid> --%>
</h:panelGroup>
$(document).ready(function() {
if (document.getElementById("openDateISO8601").value != null) {
document.getElementsByClassName("openDateISO")[0].value = document.getElementById("openDateISO8601").value;
document.getElementsByClassName("closeDateISO")[0].value = document.getElementById("closeDateISO8601").value;
}
});
<script>
localDatePicker({
input:'.openDate',
allowEmptyDate:true,
ashidden: { iso8601: 'openDateISO8601' },
getval:'.openDate',
useTime:1
});
localDatePicker({
input: '.openDate',
allowEmptyDate: true,
ashidden: { iso8601: 'openDateISO8601' },
value: '.openDate',
useTime: 1
});
localDatePicker({
input:'.closeDate',
allowEmptyDate:true,
ashidden: { iso8601: 'closeDateISO8601' },
getval:'.closeDate',
useTime:1
});
</script>
localDatePicker({
input: '.closeDate',
allowEmptyDate: true,
ashidden: { iso8601: 'closeDateISO8601' },
value: '.closeDate',
useTime: 1
});
</script>
<h2><h:outputText value="#{msgs.cdfm_forum_mark_read}"/></h2>
Expand Down

0 comments on commit 7c2c2af

Please sign in to comment.