ItEr23S08CUEdicionCalendarioLaboral: Adding button to create a new version.
This commit is contained in:
parent
7d7b105554
commit
bdb94ab049
7 changed files with 91 additions and 0 deletions
|
|
@ -154,6 +154,10 @@ public class BaseCalendar extends BaseEntity implements IValidable {
|
|||
"Can not set the expiring date "
|
||||
+ "because of it does not have a next calendar");
|
||||
}
|
||||
if (expiringDate.compareTo(new LocalDate()) <= 0) {
|
||||
throw new IllegalArgumentException(
|
||||
"Expering date must be greater than current date");
|
||||
}
|
||||
if (previousCalendar != null) {
|
||||
if (expiringDate.compareTo(previousCalendar.getExpiringDate()) <= 0) {
|
||||
throw new IllegalArgumentException(
|
||||
|
|
|
|||
|
|
@ -628,4 +628,20 @@ public class BaseCalendarTest {
|
|||
calendar.removeExceptionDay(pastMonth);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNotAllowSetExpiringDateInThePast() {
|
||||
BaseCalendar calendar = createBasicCalendar();
|
||||
|
||||
LocalDate pastMonth = (new LocalDate()).minusMonths(1);
|
||||
calendar.newVersion(pastMonth);
|
||||
|
||||
LocalDate pastWeek = (new LocalDate()).minusWeeks(1);
|
||||
try {
|
||||
calendar.setExpiringDate(pastWeek);
|
||||
fail("It should throw an exception");
|
||||
} catch (IllegalArgumentException e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -60,8 +60,12 @@ public class BaseCalendarCRUDController extends GenericForwardComposer {
|
|||
|
||||
private Window confirmRemove;
|
||||
|
||||
private Window createNewVersion;
|
||||
|
||||
private boolean confirmingRemove = false;
|
||||
|
||||
private boolean creatingNewVersion = false;
|
||||
|
||||
private OnlyOneVisible visibility;
|
||||
|
||||
private IMessagesForUser messagesForUser;
|
||||
|
|
@ -751,4 +755,42 @@ public class BaseCalendarCRUDController extends GenericForwardComposer {
|
|||
|
||||
}
|
||||
|
||||
public Date getDateValidFromNewVersion() {
|
||||
return new Date();
|
||||
}
|
||||
|
||||
public void setDateValidFromNewVersion(Date date) {
|
||||
// Just for ZK binding not needed
|
||||
}
|
||||
|
||||
public boolean isCreatingNewVersion() {
|
||||
return creatingNewVersion;
|
||||
}
|
||||
|
||||
public void createNewVersion() {
|
||||
creatingNewVersion = true;
|
||||
try {
|
||||
Util.reloadBindings(createNewVersion);
|
||||
createNewVersion.doModal();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void aceptCreateNewVersion(Date date) {
|
||||
// TODO manage errors if date is current date or date is not greater
|
||||
// than last expiring date
|
||||
baseCalendarModel.createNewVersion(date);
|
||||
|
||||
creatingNewVersion = false;
|
||||
Util.reloadBindings(createNewVersion);
|
||||
setSelectedDay(date);
|
||||
Util.reloadBindings(editWindow);
|
||||
}
|
||||
|
||||
public void cancelNewVersion() {
|
||||
creatingNewVersion = false;
|
||||
Util.reloadBindings(createNewVersion);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -405,6 +405,13 @@ public class BaseCalendarModel implements IBaseCalendarModel {
|
|||
return history;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createNewVersion(Date date) {
|
||||
if (getBaseCalendar() != null) {
|
||||
this.baseCalendar = getBaseCalendar().newVersion(date);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Final conversation steps
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -114,6 +114,8 @@ public interface IBaseCalendarModel {
|
|||
|
||||
List<BaseCalendar> getHistoryVersions();
|
||||
|
||||
void createNewVersion(Date date);
|
||||
|
||||
/*
|
||||
* Final conversation steps
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -93,6 +93,9 @@
|
|||
label="${arg.save_button_label}" />
|
||||
<button onClick="controller.cancel();"
|
||||
label="${arg.cancel_button_label}" />
|
||||
<button onClick="controller.createNewVersion();"
|
||||
label="${i18n:_('Create new version')}"
|
||||
visible="@{controller.isEditing}" />
|
||||
</hbox>
|
||||
|
||||
</vbox>
|
||||
|
|
|
|||
|
|
@ -37,6 +37,23 @@
|
|||
</hbox>
|
||||
</vbox>
|
||||
</window>
|
||||
<window visible="@{controller.creatingNewVersion}"
|
||||
id="createNewVersion" title="${i18n:_('Create new version')}" >
|
||||
<vbox>
|
||||
<label value="${i18n:_('Select the date from which the new version will be valid')}" />
|
||||
<hbox>
|
||||
<label value="${i18n:_('Valid from')}" />
|
||||
<datebox id="dateValidFromNewVersion"
|
||||
value="@{controller.dateValidFromNewVersion}"/>
|
||||
</hbox>
|
||||
<hbox>
|
||||
<button label="${i18n:_('Create')}"
|
||||
onClick="controller.aceptCreateNewVersion(dateValidFromNewVersion.value);" />
|
||||
<button label="${i18n:_('Cancel')}"
|
||||
onClick="controller.cancelNewVersion();" />
|
||||
</hbox>
|
||||
</vbox>
|
||||
</window>
|
||||
</window>
|
||||
|
||||
</zk>
|
||||
Loading…
Add table
Reference in a new issue