ItEr53S10AdaptacionServiciosRESTItEr52S10: Added the checkbox 'generate code' to the Work Report administration page.

Code fields are enabled/disabled when the checkbox changes.
Codes for unsaved entities are re-generated when the checkbox is activated.
The value of the checkbox is persistent (as an attribute of WorkReport).
This commit is contained in:
Jacobo Aragunde Pérez 2010-04-12 13:59:39 +02:00 committed by Javier Moran Rua
parent 3899010e16
commit 2f0208a0bd
5 changed files with 50 additions and 2 deletions

View file

@ -74,6 +74,8 @@ public class WorkReport extends IntegrationEntity {
private OrderElement orderElement;
private Boolean generateCode = false;
private Set<Label> labels = new HashSet<Label>();
private Set<WorkReportLine> workReportLines = new HashSet<WorkReportLine>();
@ -197,6 +199,14 @@ public class WorkReport extends IntegrationEntity {
}
}
public Boolean getGenerateCode() {
return generateCode;
}
public void setGenerateCode(Boolean generateCode) {
this.generateCode = generateCode;
}
@SuppressWarnings("unused")
@AssertTrue(message = "date:the date must be not null if is shared by lines")
public boolean checkConstraintDateMustBeNotNullIfIsSharedByLines() {

View file

@ -61,6 +61,8 @@
<property name="date"/>
<property name="generateCode" not-null="true" />
<many-to-one name="workReportType" class="WorkReportType" column="WORK_REPORT_TYPE_ID" not-null="true"/>
<many-to-one name="resource" class="org.navalplanner.business.resources.entities.Resource" column="RESOURCE_ID"/>

View file

@ -57,6 +57,7 @@ import org.navalplanner.web.common.entrypoints.URLHandler;
import org.zkoss.ganttz.IPredicate;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.WrongValueException;
import org.zkoss.zk.ui.event.CheckEvent;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zk.ui.event.Events;
@ -1119,6 +1120,7 @@ public class WorkReportCRUDController extends GenericForwardComposer implements
final WorkReportLine line = (WorkReportLine) row.getValue();
final Textbox code = new Textbox();
code.setWidth("150px");
code.setDisabled(getWorkReport().getGenerateCode());
code.applyProperties();
if (line.getCode() != null) {
@ -1672,4 +1674,21 @@ public class WorkReportCRUDController extends GenericForwardComposer implements
}
}
public void onCheckGenerateCode(Event e) {
CheckEvent ce = (CheckEvent) e;
if(ce.isChecked()) {
//we have to auto-generate the code for new objects
if(getWorkReport().isNewObject()) {
getWorkReport().setCodeAutogenerated();
Util.reloadBindings(createWindow);
}
for(WorkReportLine line : getWorkReportLines()) {
if(line.isNewObject()) {
line.setCodeAutogenerated();
}
}
}
reloadWorkReportLines();
}
}

View file

@ -28,6 +28,7 @@ import java.util.List;
import java.util.Map;
import org.apache.commons.lang.Validate;
import org.navalplanner.business.common.daos.IConfigurationDAO;
import org.navalplanner.business.common.exceptions.InstanceNotFoundException;
import org.navalplanner.business.common.exceptions.ValidationException;
import org.navalplanner.business.labels.daos.ILabelDAO;
@ -79,6 +80,9 @@ public class WorkReportModel implements IWorkReportModel {
@Autowired
private ILabelDAO labelDAO;
@Autowired
private IConfigurationDAO configurationDAO;
private WorkReportType workReportType;
private WorkReport workReport;
@ -113,6 +117,10 @@ public class WorkReportModel implements IWorkReportModel {
editing = false;
forceLoadWorkReportTypeFromDB(workReportType);
workReport = WorkReport.create(this.workReportType);
workReport.setGenerateCode(configurationDAO.getConfiguration().getGenerateCodeForWorkReport());
if(!workReport.getGenerateCode()) {
workReport.setCode("");
}
loadMaps();
}
@ -334,6 +342,9 @@ public class WorkReportModel implements IWorkReportModel {
public WorkReportLine addWorkReportLine() {
if (workReport != null) {
WorkReportLine workReportLine = WorkReportLine.create(workReport);
if(!workReport.getGenerateCode()) {
workReportLine.setCode("");
}
workReport.addWorkReportLine(workReportLine);
return workReportLine;
}

View file

@ -128,8 +128,14 @@
</row>
<row>
<label value="${i18n:_('Code')}:" />
<textbox value="@{controller.workReport.code}" width="500px"
constraint="no empty:${i18n:_('cannot be null or empty')}" />
<hbox>
<textbox width="350px" value="@{controller.workReport.code}"
constraint="no empty:${i18n:_('cannot be null or empty')}"
disabled="@{controller.workReport.generateCode}" />
<checkbox id="generateCode" label="${i18n:_('Generate code')}"
onCheck="controller.onCheckGenerateCode(event)"
checked="@{controller.workReport.generateCode}" />
</hbox>
</row>
</rows>
</grid>