Forms for Monograph
parent
af1964c745
commit
a298b0b299
|
|
@ -0,0 +1,48 @@
|
||||||
|
/*
|
||||||
|
* 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.Monograph;
|
||||||
|
import org.scientificcms.publications.PublicationRepository;
|
||||||
|
|
||||||
|
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 MonographController {
|
||||||
|
|
||||||
|
public static final String REVIEWED = "reviewed";
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private PublicationRepository publicationRepository;
|
||||||
|
|
||||||
|
public void saveMonograph(
|
||||||
|
final long monographId, final Map<String, Object> data
|
||||||
|
) {
|
||||||
|
final Monograph monograph = publicationRepository
|
||||||
|
.findByIdAndType(monographId, Monograph.class)
|
||||||
|
.orElseThrow(
|
||||||
|
() -> new IllegalArgumentException(
|
||||||
|
String.format(
|
||||||
|
"No Monograph with ID %d found.", monographId
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (data.containsKey(REVIEWED)) {
|
||||||
|
monograph.setReviewed((Boolean) data.get(REVIEWED));
|
||||||
|
}
|
||||||
|
|
||||||
|
publicationRepository.save(monograph);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,128 @@
|
||||||
|
/*
|
||||||
|
* 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.PageState;
|
||||||
|
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.domain.DomainService;
|
||||||
|
import com.arsdigita.globalization.GlobalizedMessage;
|
||||||
|
import com.arsdigita.toolbox.ui.DomainObjectPropertySheet;
|
||||||
|
|
||||||
|
import org.scientificcms.publications.SciPublicationsConstants;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
*/
|
||||||
|
public class MonographPropertiesStep
|
||||||
|
extends PublicationWithPublisherPropertiesStep {
|
||||||
|
|
||||||
|
private final StringParameter selectedLangParam;
|
||||||
|
|
||||||
|
public MonographPropertiesStep(
|
||||||
|
final ItemSelectionModel itemModel,
|
||||||
|
final AuthoringKitWizard parent,
|
||||||
|
final StringParameter selectedLangParam
|
||||||
|
) {
|
||||||
|
super(itemModel, parent, selectedLangParam);
|
||||||
|
this.selectedLangParam = selectedLangParam;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Component getMonographPropertySheet(
|
||||||
|
final ItemSelectionModel itemModel,
|
||||||
|
final StringParameter selectedLangParam
|
||||||
|
) {
|
||||||
|
DomainObjectPropertySheet sheet
|
||||||
|
= (DomainObjectPropertySheet) PublicationWithPublisherPropertiesStep
|
||||||
|
.getPublicationWithPublisherPropertySheet(
|
||||||
|
itemModel,
|
||||||
|
selectedLangParam
|
||||||
|
);
|
||||||
|
|
||||||
|
sheet.add(
|
||||||
|
new GlobalizedMessage(
|
||||||
|
"publications.ui.monograph.reviewed",
|
||||||
|
SciPublicationsConstants.BUNDLE
|
||||||
|
),
|
||||||
|
MonographController.REVIEWED,
|
||||||
|
new ReviewedFormatter()
|
||||||
|
);
|
||||||
|
|
||||||
|
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 MonographPropertyForm(
|
||||||
|
itemModel, this, selectedLangParam
|
||||||
|
);
|
||||||
|
|
||||||
|
basicProperties.add(
|
||||||
|
EDIT_SHEET_NAME,
|
||||||
|
new GlobalizedMessage(
|
||||||
|
"publications.ui.monograph.edit_basic_sheet",
|
||||||
|
SciPublicationsConstants.BUNDLE
|
||||||
|
),
|
||||||
|
new WorkflowLockedComponentAccess(editBasicSheet, itemModel),
|
||||||
|
editBasicSheet.getSaveCancelSection().getCancelButton()
|
||||||
|
);
|
||||||
|
|
||||||
|
basicProperties.setDisplayComponent(
|
||||||
|
getMonographPropertySheet(itemModel, selectedLangParam)
|
||||||
|
);
|
||||||
|
|
||||||
|
getSegmentedPanel().addSegment(
|
||||||
|
new Label(
|
||||||
|
new GlobalizedMessage(
|
||||||
|
"publications.ui.publication.basic_properties",
|
||||||
|
SciPublicationsConstants.BUNDLE
|
||||||
|
)
|
||||||
|
),
|
||||||
|
basicProperties);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class ReviewedFormatter
|
||||||
|
extends DomainService
|
||||||
|
implements DomainObjectPropertySheet.AttributeFormatter {
|
||||||
|
|
||||||
|
public ReviewedFormatter() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String format(
|
||||||
|
final Object obj, final String attribute, final PageState state
|
||||||
|
) {
|
||||||
|
if ((get(obj, attribute) != null)
|
||||||
|
&& (get(obj, attribute) instanceof Boolean)
|
||||||
|
&& ((Boolean) get(obj, attribute) == true)) {
|
||||||
|
return (String) new GlobalizedMessage(
|
||||||
|
"publications.ui.monograph.reviewed.yes",
|
||||||
|
SciPublicationsConstants.BUNDLE).localize();
|
||||||
|
} else {
|
||||||
|
return (String) new GlobalizedMessage(
|
||||||
|
"publications.ui.monograph.reviewed.no",
|
||||||
|
SciPublicationsConstants.BUNDLE).localize();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,133 @@
|
||||||
|
/*
|
||||||
|
* 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.Label;
|
||||||
|
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.CheckboxGroup;
|
||||||
|
import com.arsdigita.bebop.form.Option;
|
||||||
|
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.Monograph;
|
||||||
|
import org.scientificcms.publications.SciPublicationsConstants;
|
||||||
|
import org.scientificcms.publications.contenttypes.MonographItem;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
*/
|
||||||
|
public class MonographPropertyForm extends PublicationWithPublisherPropertyForm
|
||||||
|
implements FormProcessListener, FormInitListener, FormSubmissionListener {
|
||||||
|
|
||||||
|
public static final String ID = "MonographEdit";
|
||||||
|
|
||||||
|
|
||||||
|
private CheckboxGroup reviewed;
|
||||||
|
|
||||||
|
public MonographPropertyForm(
|
||||||
|
final ItemSelectionModel itemModel,
|
||||||
|
final StringParameter selectedLangParam
|
||||||
|
) {
|
||||||
|
this(itemModel, null, selectedLangParam);
|
||||||
|
}
|
||||||
|
|
||||||
|
public MonographPropertyForm(
|
||||||
|
final ItemSelectionModel itemModel,
|
||||||
|
final MonographPropertiesStep step,
|
||||||
|
final StringParameter selectedLangParam
|
||||||
|
) {
|
||||||
|
super(itemModel, step, selectedLangParam);
|
||||||
|
addSubmissionListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void addWidgets() {
|
||||||
|
|
||||||
|
super.addWidgets();
|
||||||
|
|
||||||
|
reviewed = new CheckboxGroup("reviewedGroup");
|
||||||
|
reviewed.addOption(
|
||||||
|
new Option(
|
||||||
|
MonographController.REVIEWED,
|
||||||
|
new Label(
|
||||||
|
new GlobalizedMessage(
|
||||||
|
"publications.ui.monograph.reviewed",
|
||||||
|
SciPublicationsConstants.BUNDLE
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
reviewed.setLabel(
|
||||||
|
new GlobalizedMessage(
|
||||||
|
"publications.ui.monograph.reviewed",
|
||||||
|
SciPublicationsConstants.BUNDLE
|
||||||
|
)
|
||||||
|
);
|
||||||
|
add(reviewed);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void init(final FormSectionEvent event) throws FormProcessException {
|
||||||
|
super.init(event);
|
||||||
|
|
||||||
|
final FormData data = event.getFormData();
|
||||||
|
final MonographItem monographItem = (MonographItem) super
|
||||||
|
.initBasicWidgets(event);
|
||||||
|
final Monograph monograph = monographItem.getPublication();
|
||||||
|
|
||||||
|
if ((monograph.getReviewed() != null) && (monograph.getReviewed())) {
|
||||||
|
reviewed.setValue(
|
||||||
|
event.getPageState(),
|
||||||
|
new String[]{MonographController.REVIEWED}
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
reviewed.setValue(event.getPageState(), null);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void process(final FormSectionEvent event)
|
||||||
|
throws FormProcessException {
|
||||||
|
super.process(event);
|
||||||
|
|
||||||
|
final PageState state = event.getPageState();
|
||||||
|
final MonographItem monographItem = (MonographItem) super
|
||||||
|
.processBasicWidgets(event);
|
||||||
|
|
||||||
|
if ((monographItem != null)
|
||||||
|
&& getSaveCancelSection().getSaveButton().isSelected(state)) {
|
||||||
|
|
||||||
|
final Map<String, Object> data = new HashMap<>();
|
||||||
|
if (reviewed.getValue(event.getPageState()) == null) {
|
||||||
|
data.put(MonographController.REVIEWED, false);
|
||||||
|
} else {
|
||||||
|
data.put(MonographController.REVIEWED, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
final MonographController controller = CdiUtil
|
||||||
|
.createCdiUtil()
|
||||||
|
.findBean(MonographController.class);
|
||||||
|
controller.saveMonograph(
|
||||||
|
monographItem.getPublication().getPublicationId(),
|
||||||
|
data
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue