Skip to content
Snippets Groups Projects
Commit 82b4a4e1 authored by srosse's avatar srosse
Browse files

OO-1042: check the boundaries of the hibernate bag before add a checkpoint,...

OO-1042: check the boundaries of the hibernate bag before add a checkpoint, clean the velocity container and reload all data after a save...
parent af1ee7d5
No related branches found
No related tags found
No related merge requests found
...@@ -138,7 +138,11 @@ public class Checklist extends PersistentObject implements ModifiedInfo, Seriali ...@@ -138,7 +138,11 @@ public class Checklist extends PersistentObject implements ModifiedInfo, Seriali
* @param checkpoint * @param checkpoint
*/ */
public void addCheckpoint(int index, Checkpoint checkpoint) { public void addCheckpoint(int index, Checkpoint checkpoint) {
checkpoints.add(index, checkpoint); if(index >= 0 && index < checkpoints.size()) {
checkpoints.add(index, checkpoint);
} else {
checkpoints.add(checkpoint);
}
} }
/** /**
......
...@@ -127,9 +127,8 @@ public class ChecklistEditCheckpointsController extends FormBasicController { ...@@ -127,9 +127,8 @@ public class ChecklistEditCheckpointsController extends FormBasicController {
} }
checklist = checklistManager.updateChecklist(checklist); checklist = checklistManager.updateChecklist(checklist);
DBFactory.getInstance().commit(); DBFactory.getInstance().commit();
checkpointsInVc.clear(); loadCheckpointInVC();
checkpointsInVc.addAll(checklist.getCheckpointsSorted(checkpointComparator)); titleContainer.setDirty(true);
titleContainer.contextPut("checkpoints", checkpointsInVc);
// Inform all listeners about the changes // Inform all listeners about the changes
fireEvent(ureq, Event.CHANGED_EVENT); fireEvent(ureq, Event.CHANGED_EVENT);
} }
...@@ -223,27 +222,12 @@ public class ChecklistEditCheckpointsController extends FormBasicController { ...@@ -223,27 +222,12 @@ public class ChecklistEditCheckpointsController extends FormBasicController {
titleContainer = FormLayoutContainer.createCustomFormLayout("titleLayout", getTranslator(), velocity_root + "/edit.html"); titleContainer = FormLayoutContainer.createCustomFormLayout("titleLayout", getTranslator(), velocity_root + "/edit.html");
fic.add(titleContainer); fic.add(titleContainer);
// create gui elements for all checkpoints // create gui elements for all checkpoints
int numOfCheckpoints = checklist.getCheckpoints().size(); loadCheckpointInVC();
if(numOfCheckpoints == 0) {
Checkpoint newCheckpoint = new Checkpoint();
newCheckpoint.setChecklist(checklist);
newCheckpoint.setLastModified(new Date());
newCheckpoint.setTitle("");
newCheckpoint.setDescription("");
newCheckpoint.setMode(CheckpointMode.MODE_EDITABLE);
checklist.addCheckpoint(0, newCheckpoint);
addNewFormCheckpoint(0, newCheckpoint);
} else {
for (int i = 0; i<numOfCheckpoints; i++) {
Checkpoint checkpoint = checklist.getCheckpointsSorted(checkpointComparator).get(i);
addNewFormCheckpoint(i, checkpoint);
}
}
addButton = new FormLinkImpl("add" + counter, "add" + counter, "cl.table.add", Link.BUTTON_SMALL); addButton = new FormLinkImpl("add" + counter, "add" + counter, "cl.table.add", Link.BUTTON_SMALL);
addButton.setUserObject(checklist.getCheckpointsSorted(checkpointComparator).get(checklist.getCheckpoints().size() - 1)); addButton.setUserObject(checklist.getCheckpointsSorted(checkpointComparator).get(checklist.getCheckpoints().size() - 1));
titleContainer.add(addButton); titleContainer.add(addButton);
checkpointsInVc.addAll(checklist.getCheckpointsSorted(checkpointComparator));
titleContainer.contextPut("checkpoints", checkpointsInVc); titleContainer.contextPut("checkpoints", checkpointsInVc);
titleContainer.contextPut("titleInputList", titleInputList); titleContainer.contextPut("titleInputList", titleInputList);
titleContainer.contextPut("descriptionInputList", descriptionInputList); titleContainer.contextPut("descriptionInputList", descriptionInputList);
...@@ -258,6 +242,36 @@ public class ChecklistEditCheckpointsController extends FormBasicController { ...@@ -258,6 +242,36 @@ public class ChecklistEditCheckpointsController extends FormBasicController {
uifactory.addFormSubmitButton("subm", submitKey, buttonContainer); uifactory.addFormSubmitButton("subm", submitKey, buttonContainer);
} }
private void loadCheckpointInVC() {
checkpointsInVc.clear();
titleInputList.clear();
descriptionInputList.clear();
modeInputList.clear();
delButtonList.clear();
int numOfCheckpoints = checklist.getCheckpoints().size();
if(numOfCheckpoints == 0) {
Checkpoint newCheckpoint = new Checkpoint();
newCheckpoint.setChecklist(checklist);
newCheckpoint.setLastModified(new Date());
newCheckpoint.setTitle("");
newCheckpoint.setDescription("");
newCheckpoint.setMode(CheckpointMode.MODE_EDITABLE);
checklist.addCheckpoint(0, newCheckpoint);
addNewFormCheckpoint(0, newCheckpoint);
List<Checkpoint> checkpoints = checklist.getCheckpointsSorted(checkpointComparator);
checkpointsInVc.addAll(checkpoints);
} else {
List<Checkpoint> checkpoints = checklist.getCheckpointsSorted(checkpointComparator);
for (int i = 0; i<numOfCheckpoints; i++) {
Checkpoint checkpoint = checkpoints.get(i);
addNewFormCheckpoint(i, checkpoint);
}
checkpointsInVc.addAll(checkpoints);
}
}
@Override @Override
protected void event(UserRequest ureq, Controller source, Event event) { protected void event(UserRequest ureq, Controller source, Event event) {
if(source == yesNoController) { if(source == yesNoController) {
...@@ -290,7 +304,6 @@ public class ChecklistEditCheckpointsController extends FormBasicController { ...@@ -290,7 +304,6 @@ public class ChecklistEditCheckpointsController extends FormBasicController {
return isOk; return isOk;
} }
@Override @Override
protected void formCancelled(UserRequest ureq) { protected void formCancelled(UserRequest ureq) {
// reset complete form // reset complete form
...@@ -304,5 +317,4 @@ public class ChecklistEditCheckpointsController extends FormBasicController { ...@@ -304,5 +317,4 @@ public class ChecklistEditCheckpointsController extends FormBasicController {
initForm(flc, this, ureq); initForm(flc, this, ureq);
fireEvent(ureq, Event.CANCELLED_EVENT); fireEvent(ureq, Event.CANCELLED_EVENT);
} }
}
} \ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment