Forms for Talk
parent
7acb09ccf4
commit
0d30b98253
|
|
@ -27,6 +27,7 @@ import org.scientificcms.publications.Proceedings;
|
||||||
import org.scientificcms.publications.SciPublicationsConstants;
|
import org.scientificcms.publications.SciPublicationsConstants;
|
||||||
import org.scientificcms.publications.contenttypes.ProceedingsItem;
|
import org.scientificcms.publications.contenttypes.ProceedingsItem;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
import java.time.ZoneId;
|
import java.time.ZoneId;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.GregorianCalendar;
|
import java.util.GregorianCalendar;
|
||||||
|
|
@ -137,14 +138,18 @@ public class ProceedingsPropertyForm
|
||||||
ProceedingsController.PLACE_OF_CONFERENCE,
|
ProceedingsController.PLACE_OF_CONFERENCE,
|
||||||
proceedings.getPlaceOfConference()
|
proceedings.getPlaceOfConference()
|
||||||
);
|
);
|
||||||
data.put(
|
final LocalDate localStartDate = proceedings.getStartDate();
|
||||||
ProceedingsController.START_DATE,
|
final java.util.Date startDate = java.util.Date.from(
|
||||||
proceedings.getStartDate()
|
localStartDate.atStartOfDay().atZone(
|
||||||
);
|
ZoneId.systemDefault()
|
||||||
data.put(
|
).toInstant());
|
||||||
ProceedingsController.END_DATE,
|
data.put(ProceedingsController.START_DATE, startDate);
|
||||||
proceedings.getEndDate()
|
final LocalDate localEndDate = proceedings.getEndDate();
|
||||||
);
|
final java.util.Date endDate = java.util.Date.from(
|
||||||
|
localEndDate.atStartOfDay().atZone(
|
||||||
|
ZoneId.systemDefault()
|
||||||
|
).toInstant());
|
||||||
|
data.put(ProceedingsController.END_DATE, endDate);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,59 @@
|
||||||
|
/*
|
||||||
|
* To change this license header, choose License Headers in Project Properties.
|
||||||
|
* To change this template file, choose Tools | Templates
|
||||||
|
* and open the template in the editor.
|
||||||
|
*/
|
||||||
|
package com.arsdigita.cms.contenttypes.ui;
|
||||||
|
|
||||||
|
import org.scientificcms.publications.PublicationRepository;
|
||||||
|
import org.scientificcms.publications.Talk;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import javax.enterprise.context.RequestScoped;
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
*/
|
||||||
|
@RequestScoped
|
||||||
|
public class TalkController {
|
||||||
|
|
||||||
|
public static final String PLACE = "place";
|
||||||
|
|
||||||
|
public static final String DATE_OF_TALK = "dateOfTalk";
|
||||||
|
|
||||||
|
public static final String EVENT = "event";
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private PublicationRepository publicationRepository;
|
||||||
|
|
||||||
|
public void saveTalk(final long talkId, final Map<String, Object> data) {
|
||||||
|
|
||||||
|
final Talk talk = publicationRepository
|
||||||
|
.findByIdAndType(talkId, Talk.class)
|
||||||
|
.orElseThrow(
|
||||||
|
() -> new IllegalArgumentException(
|
||||||
|
String.format(
|
||||||
|
"No Talk with ID %d found.", talkId
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (data.containsKey(PLACE)) {
|
||||||
|
talk.setPlace((String) data.get(PLACE));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.containsKey(DATE_OF_TALK)) {
|
||||||
|
talk.setDateOfTalk((LocalDate) data.get(DATE_OF_TALK));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.containsKey(EVENT)) {
|
||||||
|
talk.setEvent((String) data.get(EVENT));
|
||||||
|
}
|
||||||
|
|
||||||
|
publicationRepository.save(talk);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,109 @@
|
||||||
|
/*
|
||||||
|
* To change this license header, choose License Headers in Project Properties.
|
||||||
|
* To change this template file, choose Tools | Templates
|
||||||
|
* and open the template in the editor.
|
||||||
|
*/
|
||||||
|
package com.arsdigita.cms.contenttypes.ui;
|
||||||
|
|
||||||
|
import com.arsdigita.bebop.Component;
|
||||||
|
import com.arsdigita.bebop.Label;
|
||||||
|
import com.arsdigita.bebop.parameters.StringParameter;
|
||||||
|
import com.arsdigita.cms.ItemSelectionModel;
|
||||||
|
import com.arsdigita.cms.ui.authoring.AuthoringKitWizard;
|
||||||
|
import com.arsdigita.cms.ui.authoring.BasicPageForm;
|
||||||
|
import com.arsdigita.cms.ui.authoring.SimpleEditStep;
|
||||||
|
import com.arsdigita.cms.ui.workflow.WorkflowLockedComponentAccess;
|
||||||
|
import com.arsdigita.globalization.GlobalizedMessage;
|
||||||
|
import com.arsdigita.toolbox.ui.DomainObjectPropertySheet;
|
||||||
|
|
||||||
|
import org.scientificcms.publications.SciPublicationsConstants;
|
||||||
|
import org.scientificcms.publications.Talk;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
*/
|
||||||
|
public class TalkPropertiesStep extends PublicationPropertiesStep {
|
||||||
|
|
||||||
|
private final StringParameter selectedLangParam;
|
||||||
|
|
||||||
|
public TalkPropertiesStep(
|
||||||
|
final ItemSelectionModel itemModel,
|
||||||
|
final AuthoringKitWizard parent,
|
||||||
|
final StringParameter selectedLangParam
|
||||||
|
) {
|
||||||
|
super(itemModel, parent, selectedLangParam);
|
||||||
|
this.selectedLangParam = selectedLangParam;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Component getTalkPropertiesSheet(
|
||||||
|
final ItemSelectionModel itemModel,
|
||||||
|
final StringParameter selectedLangParam
|
||||||
|
) {
|
||||||
|
|
||||||
|
final DomainObjectPropertySheet sheet
|
||||||
|
= (DomainObjectPropertySheet) getPublicationPropertySheet(
|
||||||
|
itemModel, selectedLangParam);
|
||||||
|
|
||||||
|
sheet.add(
|
||||||
|
new GlobalizedMessage(
|
||||||
|
"publications.ui.talk.place",
|
||||||
|
SciPublicationsConstants.BUNDLE
|
||||||
|
),
|
||||||
|
TalkController.PLACE
|
||||||
|
);
|
||||||
|
sheet.add(
|
||||||
|
new GlobalizedMessage(
|
||||||
|
"publications.ui.talk.date",
|
||||||
|
SciPublicationsConstants.BUNDLE
|
||||||
|
),
|
||||||
|
TalkController.DATE_OF_TALK
|
||||||
|
);
|
||||||
|
sheet.add(
|
||||||
|
new GlobalizedMessage(
|
||||||
|
"publications.ui.talk.event",
|
||||||
|
SciPublicationsConstants.BUNDLE
|
||||||
|
),
|
||||||
|
TalkController.EVENT
|
||||||
|
);
|
||||||
|
|
||||||
|
return sheet;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void addBasicProperties(
|
||||||
|
final ItemSelectionModel itemModel,
|
||||||
|
final AuthoringKitWizard parent
|
||||||
|
) {
|
||||||
|
|
||||||
|
final SimpleEditStep basicProperties = new SimpleEditStep(
|
||||||
|
itemModel, parent, selectedLangParam, EDIT_SHEET_NAME);
|
||||||
|
|
||||||
|
final BasicPageForm editBasicSheet = new TalkPropertyForm(
|
||||||
|
itemModel, this, selectedLangParam
|
||||||
|
);
|
||||||
|
|
||||||
|
basicProperties.add(
|
||||||
|
EDIT_SHEET_NAME,
|
||||||
|
new GlobalizedMessage(
|
||||||
|
"publications.ui.talk.edit_basic_sheet",
|
||||||
|
SciPublicationsConstants.BUNDLE
|
||||||
|
),
|
||||||
|
new WorkflowLockedComponentAccess(editBasicSheet, itemModel),
|
||||||
|
editBasicSheet.getSaveCancelSection().getCancelButton());
|
||||||
|
|
||||||
|
basicProperties.setDisplayComponent(
|
||||||
|
getTalkPropertiesSheet(itemModel, selectedLangParam)
|
||||||
|
);
|
||||||
|
|
||||||
|
getSegmentedPanel().addSegment(
|
||||||
|
new Label(
|
||||||
|
new GlobalizedMessage(
|
||||||
|
"publications.ui.talk.basic_properties",
|
||||||
|
SciPublicationsConstants.BUNDLE
|
||||||
|
)
|
||||||
|
),
|
||||||
|
basicProperties);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,168 @@
|
||||||
|
/*
|
||||||
|
* To change this license header, choose License Headers in Project Properties.
|
||||||
|
* To change this template file, choose Tools | Templates
|
||||||
|
* and open the template in the editor.
|
||||||
|
*/
|
||||||
|
package com.arsdigita.cms.contenttypes.ui;
|
||||||
|
|
||||||
|
import com.arsdigita.bebop.FormData;
|
||||||
|
import com.arsdigita.bebop.FormProcessException;
|
||||||
|
import com.arsdigita.bebop.PageState;
|
||||||
|
import com.arsdigita.bebop.event.FormInitListener;
|
||||||
|
import com.arsdigita.bebop.event.FormProcessListener;
|
||||||
|
import com.arsdigita.bebop.event.FormSectionEvent;
|
||||||
|
import com.arsdigita.bebop.event.FormSubmissionListener;
|
||||||
|
import com.arsdigita.bebop.form.Date;
|
||||||
|
import com.arsdigita.bebop.form.TextField;
|
||||||
|
import com.arsdigita.bebop.parameters.DateParameter;
|
||||||
|
import com.arsdigita.bebop.parameters.ParameterModel;
|
||||||
|
import com.arsdigita.bebop.parameters.StringParameter;
|
||||||
|
import com.arsdigita.cms.ItemSelectionModel;
|
||||||
|
import com.arsdigita.globalization.GlobalizedMessage;
|
||||||
|
|
||||||
|
import org.libreccm.cdi.utils.CdiUtil;
|
||||||
|
import org.scientificcms.publications.SciPublicationsConstants;
|
||||||
|
import org.scientificcms.publications.Talk;
|
||||||
|
import org.scientificcms.publications.contenttypes.TalkItem;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.time.ZoneId;
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
*/
|
||||||
|
public class TalkPropertyForm extends PublicationPropertyForm
|
||||||
|
implements FormInitListener, FormProcessListener, FormSubmissionListener {
|
||||||
|
|
||||||
|
private static final String ID = "TaskEdit";
|
||||||
|
|
||||||
|
public TalkPropertyForm(
|
||||||
|
final ItemSelectionModel itemModel,
|
||||||
|
final StringParameter selectedLangParameter
|
||||||
|
) {
|
||||||
|
this(itemModel, null, selectedLangParameter);
|
||||||
|
}
|
||||||
|
|
||||||
|
public TalkPropertyForm(
|
||||||
|
final ItemSelectionModel itemModel,
|
||||||
|
final TalkPropertiesStep step,
|
||||||
|
final StringParameter selectedLangParam
|
||||||
|
) {
|
||||||
|
super(itemModel, step, selectedLangParam);
|
||||||
|
addSubmissionListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addWidgets() {
|
||||||
|
|
||||||
|
super.addWidgets();
|
||||||
|
|
||||||
|
final ParameterModel placeParameter = new StringParameter(
|
||||||
|
TalkController.PLACE
|
||||||
|
);
|
||||||
|
final TextField placeField = new TextField(placeParameter);
|
||||||
|
placeField
|
||||||
|
.setLabel(
|
||||||
|
new GlobalizedMessage(
|
||||||
|
"publications.ui.talk.place",
|
||||||
|
SciPublicationsConstants.BUNDLE
|
||||||
|
)
|
||||||
|
);
|
||||||
|
add(placeField);
|
||||||
|
|
||||||
|
final ParameterModel dateParameter = new DateParameter(
|
||||||
|
TalkController.DATE_OF_TALK
|
||||||
|
);
|
||||||
|
final Date dateField = new Date(dateParameter);
|
||||||
|
final Calendar calendar = Calendar.getInstance();
|
||||||
|
final int currentYear = calendar.get(Calendar.YEAR);
|
||||||
|
dateField.setYearRange(currentYear - 10, currentYear + 1);
|
||||||
|
dateField
|
||||||
|
.setLabel(
|
||||||
|
new GlobalizedMessage(
|
||||||
|
"publications.ui.talk.date",
|
||||||
|
SciPublicationsConstants.BUNDLE
|
||||||
|
)
|
||||||
|
);
|
||||||
|
add(dateField);
|
||||||
|
|
||||||
|
final ParameterModel eventParameter = new StringParameter(
|
||||||
|
TalkController.EVENT
|
||||||
|
);
|
||||||
|
final TextField eventField = new TextField(eventParameter);
|
||||||
|
eventField
|
||||||
|
.setLabel(
|
||||||
|
new GlobalizedMessage(
|
||||||
|
"publications.ui.talk.event",
|
||||||
|
SciPublicationsConstants.BUNDLE
|
||||||
|
)
|
||||||
|
);
|
||||||
|
add(eventField);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void init(final FormSectionEvent event) throws FormProcessException {
|
||||||
|
|
||||||
|
super.init(event);
|
||||||
|
|
||||||
|
final FormData data = event.getFormData();
|
||||||
|
final TalkItem talkItem = (TalkItem) initBasicWidgets(event);
|
||||||
|
final Talk talk = talkItem.getPublication();
|
||||||
|
|
||||||
|
data.put(
|
||||||
|
TalkController.EVENT,
|
||||||
|
talk.getEvent()
|
||||||
|
);
|
||||||
|
final LocalDate localDateOfTalk = talk.getDateOfTalk();
|
||||||
|
final java.util.Date dateOfTalk = java.util.Date.from(
|
||||||
|
localDateOfTalk.atStartOfDay().atZone(
|
||||||
|
ZoneId.systemDefault()
|
||||||
|
).toInstant()
|
||||||
|
);
|
||||||
|
data.put(TalkController.DATE_OF_TALK, dateOfTalk);
|
||||||
|
data.put(TalkController.PLACE, talk.getPlace());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void process(final FormSectionEvent event)
|
||||||
|
throws FormProcessException {
|
||||||
|
|
||||||
|
super.process(event);
|
||||||
|
|
||||||
|
final FormData formData = event.getFormData();
|
||||||
|
final PageState state = event.getPageState();
|
||||||
|
final TalkItem talkItem = (TalkItem) processBasicWidgets(event);
|
||||||
|
|
||||||
|
if (talkItem != null
|
||||||
|
&& getSaveCancelSection().getSaveButton().isSelected(state)) {
|
||||||
|
|
||||||
|
final Map<String, Object> data = new HashMap<>();
|
||||||
|
|
||||||
|
final java.util.Date dateOfTalk = (java.util.Date) data.get(
|
||||||
|
TalkController.DATE_OF_TALK
|
||||||
|
);
|
||||||
|
final LocalDate localDateOfTalk = dateOfTalk
|
||||||
|
.toInstant().atZone(
|
||||||
|
ZoneId.systemDefault()
|
||||||
|
).toLocalDate();
|
||||||
|
data.put(TalkController.DATE_OF_TALK, localDateOfTalk);
|
||||||
|
|
||||||
|
data.put(TalkController.EVENT, data.get(TalkController.EVENT));
|
||||||
|
data.put(TalkController.PLACE, data.get(TalkController.PLACE));
|
||||||
|
|
||||||
|
final TalkController controller = CdiUtil
|
||||||
|
.createCdiUtil()
|
||||||
|
.findBean(TalkController.class);
|
||||||
|
|
||||||
|
controller.saveTalk(
|
||||||
|
talkItem.getPublication().getPublicationId(),
|
||||||
|
data
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue