From a374186e869aca5d44e3a352222ab13be2ab5206 Mon Sep 17 00:00:00 2001 From: Seal98 Date: Fri, 9 Jun 2017 16:18:22 +0300 Subject: [PATCH 01/39] [WIP] Advanced calendar component (issue#852) Resolves #852 --- .../calendar/CalendarEventPresenter.java | 138 ++++- .../ui/view/calendar/CalendarEventView.java | 585 ++++++++++++++---- .../sigmah/client/i18n/UIConstants.properties | 8 + 3 files changed, 580 insertions(+), 151 deletions(-) diff --git a/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java b/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java index 00f3847f9..63631ba56 100644 --- a/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java +++ b/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java @@ -55,7 +55,11 @@ import com.allen_sauer.gwt.log.client.Log; import com.extjs.gxt.ui.client.event.ButtonEvent; import com.extjs.gxt.ui.client.event.SelectionListener; +import com.extjs.gxt.ui.client.widget.form.CheckBox; import com.extjs.gxt.ui.client.widget.form.DateField; +import com.extjs.gxt.ui.client.widget.form.FieldSet; +import com.extjs.gxt.ui.client.widget.form.Radio; +import com.extjs.gxt.ui.client.widget.form.RadioGroup; import com.extjs.gxt.ui.client.widget.form.TextArea; import com.extjs.gxt.ui.client.widget.form.TextField; import com.extjs.gxt.ui.client.widget.form.Time; @@ -78,22 +82,53 @@ public class CalendarEventPresenter extends AbstractPagePresenter getEventSummaryField(); + TextField getEventSummaryField(); - DateField getEventDateField(); + DateField getEventDateStartField(); - TimeField getEventStartTimeField(); + DateField getEventDateEndField(); - TimeField getEventEndTimeField(); + TimeField getEventStartTimeField(); - TextArea getEventDescriptionField(); + TimeField getEventEndTimeField(); - Button getSaveButton(); + TextArea getEventDescriptionField(); - Button getCancelButton(); + Button getSaveButton(); + Button getCancelButton(); + + CheckBox getIsAllDayCheckbox(); + + FieldSet getPanelYearly(); + + FieldSet getPanelMonthly(); + + Radio getOnceRepeatRB(); + + Radio getDailyRepeatRB(); + + Radio getWeeklyRepeatRB(); + + Radio getMonthlyRepeatRB(); + + Radio getYearlyRepeatRB(); + + RadioGroup getYearlyVariantRG(); + + RadioGroup getMontlyVariantRG(); + + Radio getYearlySameDayOfWeekRB(); + + Radio getYearlySameDateRB(); + + RadioGroup getRepeatEventPeriodRG(); + + Radio getRadioMonthlySameDate(); + + Radio getRadioMonthlySameDayOfWeek(); } /** @@ -101,13 +136,13 @@ public static interface View extends ViewInterface { */ private Event event; - private CalendarWrapper calendarWrapper; - + private CalendarWrapper calendarWrapper; + /** * Presenters's initialization. * - * @param view Presenter's view interface. - * @param injector Injected client injector. + * @param view Presenter's view interface. + * @param injector Injected client injector. */ @Inject public CalendarEventPresenter(final View view, final Injector injector) { @@ -179,7 +214,7 @@ public void onPageRequest(final PageRequest request) { // -- for (final CalendarWrapper calendarWrapper : calendars) { if (calendarWrapper.getCalendar().isEditable()) { - this.calendarWrapper = calendarWrapper; + this.calendarWrapper = calendarWrapper; } } @@ -187,12 +222,20 @@ public void onPageRequest(final PageRequest request) { // Loading event on view (if edition). // -- if (creation) { + view.getRepeatEventPeriodRG().show(); return; - } + } else {// CREATE NEW EVENT NEW BELOW + view.getRepeatEventPeriodRG().hide(); + } - this.calendarWrapper = new CalendarWrapper(event.getParent()); + this.calendarWrapper = new CalendarWrapper(event.getParent()); view.getEventSummaryField().setValue(event.getSummary()); - view.getEventDateField().setValue(event.getKey()); + view.getEventDateStartField().setValue(event.getKey()); +// if(creation) { +// view.getIsAllDayCheckbox().hide(); +// } else {// CREATE NEW EVENT NEW BELOW +// view.getRepeatEventPeriodRG().hide(); +// } if (!isFullDayEvent(event)) { @@ -226,13 +269,20 @@ private void onSaveAction() { // Building properties map. // -- final Map properties = new HashMap(); - properties.put(Event.CALENDAR_ID, calendarWrapper); + properties.put(Event.CALENDAR_ID, calendarWrapper); properties.put(Event.SUMMARY, view.getEventSummaryField().getValue()); - final Date date = view.getEventDateField().getValue(); + final Date date = view.getEventDateStartField().getValue(); properties.put(Event.DATE, date); - - final Date startDate = view.getEventStartTimeField().getDateValue(); +// properties.put("YYYYYYY", (view.getMontlyVariantRG().getValue().toString()?"true":"false")); +// Radio getMontlyVariantRG = view.getMontlyVariantRG()!=null? view.getMontlyVariantRG().getValue():null; +// Boolean getDailyRepeatRB = view.getDailyRepeatRB()!=null? view.getDailyRepeatRB().getValue(): Boolean.FALSE; +// Boolean getOnceRepeatRB = view.getOnceRepeatRB().getValue(); +// Boolean getYearlyRepeatRB = view.getYearlyRepeatRB().getValue(); +// //properties.put("getYearlyRepeatRB", (view.getYearlyRepeatRB().getValue()?"true":"false")); +// Boolean getYearlySameDayOfWeekRB = view.getYearlySameDayOfWeekRB().getValue(); + + final Date startDate = view.getEventStartTimeField().getDateValue(); if (startDate != null) { startDate.setYear(date.getYear()); startDate.setMonth(date.getMonth()); @@ -254,18 +304,49 @@ private void onSaveAction() { properties.put(Event.DESCRIPTION, view.getEventDescriptionField().getValue()); - if (event == null) { + if (event == null) { addPersonalEvent(properties); - + //Here process properties and define repetable events dates + /*take parameters from View + Start Date, get End date, period settings like Once, Daily, Monthly etc + process values to prepare new properties for new event + if needed calculate same day of week for Monthly or Yearly + if needed compare if the Date exist in Month (like 29 30 31 Febr etc) + if needed define weekends + after that in cycle add new events + */ + + Date theDate = (Date) properties.get(Event.DATE); +// long theStartTime = ((Long)properties.get(Event.START_TIME)).longValue(); +// long theEndTime = ((Long) properties.get(Event.END_TIME)).longValue(); + Date dayAfter = new Date(theDate.getTime()+(24*60*60*1000)); + long theStartTimeNext = startDate.getTime()+(24*60*60*1000); + long theEndTimeNext = endDate.getTime()+(24*60*60*1000); + //LocalDateTime.from(theDate.toInstant().atZone(ZoneId.of("UTC"))).plusDays(1); + properties.put(Event.DATE, dayAfter); + properties.put(Event.START_TIME, theStartTimeNext); + properties.put(Event.END_TIME, theEndTimeNext); + String newSummary = (String) properties.get(Event.SUMMARY); + newSummary += " (repeat + 1 day)"; + properties.put(Event.SUMMARY, newSummary); + properties.put(Event.SUMMARY,properties.get(Event.SUMMARY)+" (This is repeated Daily event.)" ); + addPersonalEvent(properties); +//Here process properties and define repetable events dates } else { editPersonalEvent(event, properties); } +// if (event == null) { +// addPersonalEvent(properties); +// +// } else { +// editPersonalEvent(event, properties); +// } } /** * Creates a new "Personal" calendar event. * - * @param properties Properties of the new event. + * @param properties Properties of the new event. */ private void addPersonalEvent(final Map properties) { @@ -296,7 +377,7 @@ public void onCommandSuccess(final CreateResult result) { /** * Edits the events. * - * @param properties Properties of the new event. + * @param properties Properties of the new event. */ private void editPersonalEvent(final Event event, final Map properties) { @@ -318,8 +399,7 @@ public void onCommandSuccess(final VoidResult result) { final Calendar calendar = event.getParent(); - final List oldEventList = - calendar.getEvents().get(event.getKey()); + final List oldEventList = calendar.getEvents().get(event.getKey()); oldEventList.remove(event); updateEvent(event, properties); @@ -330,8 +410,8 @@ public void onCommandSuccess(final VoidResult result) { /** * Updates the given {@code event} with the given {@code properties}. * - * @param event The event to update. - * @param properties The properties. + * @param event The event to update. + * @param properties The properties. */ @SuppressWarnings("deprecation") private void updateEvent(final Event event, final Map properties) { @@ -389,7 +469,7 @@ private void updateEvent(final Event event, final Map properties) { /** * Returns if the given {@code event} is a full day event. * - * @param event The event. + * @param event The event. * @return {@code true} if the given {@code event} is a full day event. */ @SuppressWarnings("deprecation") diff --git a/src/main/java/org/sigmah/client/ui/view/calendar/CalendarEventView.java b/src/main/java/org/sigmah/client/ui/view/calendar/CalendarEventView.java index 85cf61775..503c1bc84 100644 --- a/src/main/java/org/sigmah/client/ui/view/calendar/CalendarEventView.java +++ b/src/main/java/org/sigmah/client/ui/view/calendar/CalendarEventView.java @@ -21,7 +21,10 @@ * . * #L% */ - +import com.extjs.gxt.ui.client.Style; +import com.extjs.gxt.ui.client.event.Events; +import com.extjs.gxt.ui.client.event.FieldEvent; +import com.extjs.gxt.ui.client.event.Listener; import org.sigmah.client.i18n.I18N; import org.sigmah.client.ui.presenter.calendar.CalendarEventPresenter; import org.sigmah.client.ui.res.icon.IconImageBundle; @@ -34,138 +37,476 @@ import com.extjs.gxt.ui.client.widget.form.ComboBox.TriggerAction; import com.extjs.gxt.ui.client.widget.form.DateField; +import com.extjs.gxt.ui.client.widget.form.Radio; +import com.extjs.gxt.ui.client.widget.form.RadioGroup; import com.extjs.gxt.ui.client.widget.form.TextArea; import com.extjs.gxt.ui.client.widget.form.TextField; import com.extjs.gxt.ui.client.widget.form.TimeField; +import com.extjs.gxt.ui.client.widget.form.CheckBox; +import com.extjs.gxt.ui.client.widget.form.CheckBoxGroup; +import com.extjs.gxt.ui.client.widget.form.FieldSet; import com.google.inject.Singleton; +import com.google.gwt.user.client.Window; /** * Calendar event edit frame view used to create/edit a calendar event. - * + * * @author Denis Colliot (dcolliot@ideia.fr) */ @Singleton public class CalendarEventView extends AbstractPopupView implements CalendarEventPresenter.View { - private FormPanel form; - private TextField eventSummaryField; - private DateField eventDateField; - private TimeField eventStartTimeField; - private TimeField eventEndTimeField; - private TextArea eventDescriptionField; - - private Button saveButton; - private Button cancelButton; - - /** - * Builds the view. - */ - public CalendarEventView() { - super(new PopupWidget(true), 500); - } - - /** - * {@inheritDoc} - */ - @Override - public void initialize() { - - form = Forms.panel(); - - eventSummaryField = Forms.text(I18N.CONSTANTS.calendarEventObject(), true); - eventSummaryField.setName(Event.SUMMARY); - - eventDateField = Forms.date(I18N.CONSTANTS.calendarEventDate(), true); - eventDateField.setName(Event.DATE); - - eventStartTimeField = Forms.time(I18N.CONSTANTS.calendarEventStartHour(), false); - eventStartTimeField.setName(Event.START_TIME); - eventStartTimeField.setTriggerAction(TriggerAction.ALL); - - eventEndTimeField = Forms.time(I18N.CONSTANTS.calendarEventEndHour(), false); - eventEndTimeField.setName(Event.END_TIME); - eventEndTimeField.setTriggerAction(TriggerAction.ALL); - - eventDescriptionField = Forms.textarea(I18N.CONSTANTS.calendarEventDescription(), false); - eventDescriptionField.setName(Event.DESCRIPTION); - - saveButton = Forms.button(I18N.CONSTANTS.formWindowSubmitAction(), IconImageBundle.ICONS.save()); - cancelButton = Forms.button(I18N.CONSTANTS.cancel()); - - form.add(eventSummaryField); - form.add(eventDateField); - form.add(eventStartTimeField); - form.add(eventEndTimeField); - form.add(eventDescriptionField); - - form.addButton(cancelButton); - form.addButton(saveButton); - - initPopup(form); - } - - /** - * {@inheritDoc} - */ - @Override - public FormPanel getForm() { - return form; - } - - /** - * {@inheritDoc} - */ - @Override - public TextField getEventSummaryField() { - return eventSummaryField; - } - - /** - * {@inheritDoc} - */ - @Override - public DateField getEventDateField() { - return eventDateField; - } - - /** - * {@inheritDoc} - */ - @Override - public TimeField getEventStartTimeField() { - return eventStartTimeField; - } - - /** - * {@inheritDoc} - */ - @Override - public TimeField getEventEndTimeField() { - return eventEndTimeField; - } - - /** - * {@inheritDoc} - */ - @Override - public TextArea getEventDescriptionField() { - return eventDescriptionField; - } - - /** - * {@inheritDoc} - */ - @Override - public Button getSaveButton() { - return saveButton; - } - - /** - * {@inheritDoc} - */ - @Override - public Button getCancelButton() { - return cancelButton; - } + private FormPanel form; + private TextField eventSummaryField; + private DateField eventDateStartField; + private DateField eventDateEndField; + private TimeField eventStartTimeField; + private TimeField eventEndTimeField; + private TextArea eventDescriptionField; + + private Button saveButton; + private Button cancelButton; + + private CheckBox isAllDayCheckbox; + private RadioGroup yearlyVariantRG; + private RadioGroup montlyVariantRG; + private FieldSet panelYearly; + private FieldSet panelMonthly; + + private Radio yearlySameDayOfWeekRB; + private Radio yearlySameDateRB; + + private Radio onceRepeatRB; + private Radio dailyRepeatRB; + private Radio weeklyRepeatRB; + private Radio monthlyRepeatRB; + private Radio yearlyRepeatRB; + private Radio radioMonthlySameDate; + private Radio radioMonthlySameDayOfWeek; + + private RadioGroup RepeatEventPeriodRG; + + /** + * Builds the view. + */ + public CalendarEventView() { + super(new PopupWidget(true), 500); + } + + /** + * {@inheritDoc} + */ + @Override + public void initialize() { + form = Forms.panel(); + createYearlyPanel(); + createMonthlyPanel(); + + eventSummaryField = Forms.text(I18N.CONSTANTS.calendarEventObject(), true); + eventSummaryField.setName(Event.SUMMARY); + + eventDateStartField = Forms.date(I18N.CONSTANTS.calendarEventDate(), true); + eventDateStartField.setName(Event.DATE); + + CheckBoxGroup allDayCheckboxGr = createAllDayCheckboxGroup(); + + eventStartTimeField = Forms.time(I18N.CONSTANTS.calendarEventStartHour(), false); + eventStartTimeField.setName(Event.START_TIME); + eventStartTimeField.setTriggerAction(TriggerAction.ALL); + + eventEndTimeField = Forms.time(I18N.CONSTANTS.calendarEventEndHour(), false); + eventEndTimeField.setName(Event.END_TIME); + eventEndTimeField.setTriggerAction(TriggerAction.ALL); + + eventDateEndField = Forms.date(I18N.CONSTANTS.calendarEventDate(), false); + eventDateEndField.setName(Event.DATE + "888end"); + + eventDescriptionField = Forms.textarea(I18N.CONSTANTS.calendarEventDescription(), false); + eventDescriptionField.setName(Event.DESCRIPTION); + eventDescriptionField.setId(Event.DESCRIPTION); + eventDescriptionField.setMaxLength(255); + + saveButton = Forms.button(I18N.CONSTANTS.formWindowSubmitAction(), IconImageBundle.ICONS.save()); + cancelButton = Forms.button(I18N.CONSTANTS.cancel()); + + form.add(eventSummaryField); + form.add(eventDateStartField); + form.add(eventDateEndField); + //form.add(isAllDayCheckbox); + form.add(allDayCheckboxGr); + + form.add(eventStartTimeField); + form.add(eventEndTimeField); + + createRepeatEventPeriodRadioGroup(); + + + form.add(RepeatEventPeriodRG); + form.add(panelYearly); + form.add(panelMonthly); + form.add(eventDescriptionField); + + form.addButton(cancelButton); + form.addButton(saveButton); + + initPopup(form); + } + + private CheckBoxGroup createAllDayCheckboxGroup() { + isAllDayCheckbox = Forms.checkbox("All day lab", "All day name", false); + isAllDayCheckbox.setFieldLabel("setFieldLabel"); + isAllDayCheckbox.setBoxLabel(I18N.CONSTANTS.calendar_addEvent_isAllDayCB_boxLabel()); + isAllDayCheckbox.addListener(Events.OnChange, new Listener() { + @Override + public void handleEvent(FieldEvent event) { +// eventStartTimeField.setVisible(((Boolean) event.getValue()).booleanValue()); +// eventEndTimeField.setVisible(((Boolean) event.getValue()).booleanValue()); +//checkbox.getValue() + eventStartTimeField.setVisible(!isAllDayCheckbox.getValue()); + eventEndTimeField.setVisible(!isAllDayCheckbox.getValue()); + Window.alert(getIsAllDayCheckbox().getBoxLabel() + " is checked"); + } + }); + CheckBoxGroup allDayCheckboxGr = Forms.checkBoxGroup(I18N.CONSTANTS.calendar_addEvent_allDayCbGr_label(), isAllDayCheckbox); +// isAllDayCheckbox.addHandler(new ValueChangeHandler() { +// @Override +// public void onValueChange(ValueChangeEvent event) { +// eventStartTimeField.setVisible(event.getValue()); +// eventEndTimeField.setVisible(event.getValue()); +// } +// }, ValueChangeEvent.getType()); + return allDayCheckboxGr; + } + + private void createRepeatEventPeriodRadioGroup() { + //final Radio + onceRepeatRB = Forms.radio("once", "onceRepeatRBname", Boolean.TRUE); + onceRepeatRB.setOriginalValue(Boolean.TRUE); + onceRepeatRB.setToolTip(I18N.CONSTANTS.calendar_addEvent_repeatOnceRB_toolTip()); + //onceRepeatRB = new Radio(); +// onceRepeatRB.setBoxLabel("once"); +// onceRepeatRB.setName("once"); +// onceRepeatRB.setValue(true); +// onceRepeatRB.focus(); + onceRepeatRB.addListener(Events.OnChange, new Listener() { + @Override + public void handleEvent(FieldEvent event) { + + getPanelYearly().setVisible(!onceRepeatRB.getValue()); + getPanelMonthly().setVisible(!onceRepeatRB.getValue()); + ((TextArea)form.getItemByItemId(Event.DESCRIPTION)).setValue(" The Once event."); + Window.alert(getOnceRepeatRB().getBoxLabel() + " is checked Listener OnChange on ONCE radio"); + } + }); + +//final Radio +//dailyRepeatRB = new Radio(); + dailyRepeatRB = Forms.radio("daily", "daily", Boolean.FALSE); +// dailyRepeatRB.setBoxLabel("daily"); +// dailyRepeatRB.setName("daily"); +// dailyRepeatRB.setValue(false); + + dailyRepeatRB.addListener(Events.OnChange, new Listener() { + @Override + public void handleEvent(FieldEvent event) { + ((TextArea)form.getItemByItemId(Event.DESCRIPTION)).setValue(" The Daily event."); + eventStartTimeField.setVisible(!dailyRepeatRB.getValue()); + eventEndTimeField.setVisible(!dailyRepeatRB.getValue()); + getPanelYearly().setVisible(!dailyRepeatRB.getValue()); + getPanelMonthly().setVisible(!dailyRepeatRB.getValue()); + Window.alert(getDailyRepeatRB().getBoxLabel() + " is checked Listener OnChange on DAILY radio"); + } + }); + +//final Radio +// weeklyRepeatRB = new Radio(); + weeklyRepeatRB = Forms.radio("weekly", "weekly", Boolean.FALSE); + weeklyRepeatRB.setToolTip(I18N.CONSTANTS.calendar_addEvent_repeatWeeklyRB_toolTip()); +// weeklyRepeatRB.setBoxLabel("weekly"); +// weeklyRepeatRB.setName("weekly"); +// weeklyRepeatRB.setValue(false); + weeklyRepeatRB.addListener(Events.OnChange, new Listener() { + @Override + public void handleEvent(FieldEvent event) { + //eventStartTimeField.setVisible(!yearlyRepeatRB.getValue()); + // eventEndTimeField.setVisible(!yearlyRepeatRB.getValue()); + ((TextArea)form.getItemByItemId(Event.DESCRIPTION)).setValue(" The Weekly event."); + getPanelYearly().setVisible(!weeklyRepeatRB.getValue()); + getPanelMonthly().setVisible(!weeklyRepeatRB.getValue()); + Window.alert(getWeeklyRepeatRB().getBoxLabel() + " is checked Listener OnChange on weekly radio"); + } + }); + +//final Radio +// monthlyRepeatRB = new Radio(); + monthlyRepeatRB = Forms.radio("monthly", "monthly", Boolean.FALSE); + monthlyRepeatRB.setToolTip(I18N.CONSTANTS.calendar_addEvent_repeatMonthlyRB_toolTip()); +// monthlyRepeatRB.setBoxLabel("monthly"); +// monthlyRepeatRB.setName("monthly"); +// monthlyRepeatRB.setValue(false); + monthlyRepeatRB.addListener(Events.OnChange, new Listener() { + @Override + public void handleEvent(FieldEvent event) { + //eventStartTimeField.setVisible(!yearlyRepeatRB.getValue()); + // eventEndTimeField.setVisible(!yearlyRepeatRB.getValue()); + ((TextArea)form.getItemByItemId(Event.DESCRIPTION)).setValue(" The Monthly event."); + getPanelYearly().setVisible(!monthlyRepeatRB.getValue()); + getPanelMonthly().setVisible(getMonthlyRepeatRB().getValue()); + Window.alert(getMonthlyRepeatRB().getBoxLabel() + " is checked Listener OnChange on monthly radio"); + } + }); + +//final Radio +// yearlyRepeatRB = Forms.radio("yearlyRepeatRB label", "yearlyRepeatRB name", Boolean.FALSE); +//yearlyRepeatRB = new Radio(); + yearlyRepeatRB = Forms.radio("yearly", "yearly", Boolean.FALSE); + yearlyRepeatRB.setToolTip(I18N.CONSTANTS.calendar_addEvent_repeatYearlyRB_toolTip()); +// yearlyRepeatRB.setBoxLabel("yearly"); +// yearlyRepeatRB.setName("yearly"); +// yearlyRepeatRB.setValue(false); + yearlyRepeatRB.addListener(Events.OnChange, new Listener() { + @Override + public void handleEvent(FieldEvent event) { + //eventStartTimeField.setVisible(!yearlyRepeatRB.getValue()); + // eventEndTimeField.setVisible(!yearlyRepeatRB.getValue()); + ((TextArea)form.getItemByItemId(Event.DESCRIPTION)).setValue(" The Yearly event."); + getPanelYearly().setVisible(getYearlyRepeatRB().getValue()); + getPanelMonthly().setVisible(!yearlyRepeatRB.getValue()); + Window.alert(getYearlyRepeatRB().getBoxLabel() + " is checked Listener OnChange on Yearly radio"); + } + }); +//YEARLY END +//final RadioGroup + RepeatEventPeriodRG = Forms.radioGroup(I18N.CONSTANTS.calendar_addEvent_repeatPeriodRG_label(), + "Repeat event 999", + Style.Orientation.HORIZONTAL, + onceRepeatRB, + dailyRepeatRB, + weeklyRepeatRB, + monthlyRepeatRB, + yearlyRepeatRB); + RepeatEventPeriodRG.setSelectionRequired(Boolean.TRUE); + } + + private void createMonthlyPanel() { + panelMonthly = new FieldSet(); + panelMonthly.setExpanded(true); + //panelMonthly.setTitle("Montly panel title"); + panelMonthly.setBorders(true); + panelMonthly.setHeadingHtml("Montly repeats settings"); + panelMonthly.setCollapsible(true); + panelMonthly.setAutoHeight(true); + //panelMonthly.setToolTip("Set Monthly event repeats options."); + panelMonthly.setVisible(false); + + //Radio radioMonthlySameDayOfWeek = new Radio(); + //Radio + radioMonthlySameDayOfWeek = Forms.radio("Same day of week"); + //radioMonthlySameDayOfWeek.setBoxLabel("Same day of week"); + radioMonthlySameDayOfWeek.setName("radioMonthlySameDayOfWeek"); + radioMonthlySameDayOfWeek.setValue(Boolean.TRUE); + radioMonthlySameDayOfWeek.setOriginalValue(Boolean.TRUE); + + + //Radio radioMonthlySameDate = new Radio(); + //Radio + radioMonthlySameDate = Forms.radio("Same date"); + radioMonthlySameDate.setBoxLabel("Same date"); + radioMonthlySameDate.setName("radioMonthlySameDate"); + radioMonthlySameDate.setValue(Boolean.FALSE); + + //montlyVariantRG= new RadioGroup(); + montlyVariantRG = Forms.radioGroup("Montly settings 999"); + montlyVariantRG.setSelectionRequired(Boolean.TRUE); + // montlyVariantRG.setSelectionRequired(Boolean.FALSE); + montlyVariantRG.setOrientation(Style.Orientation.HORIZONTAL); + //montlyVariantRG.setFieldLabel("Montly settings 999"); + montlyVariantRG.add(radioMonthlySameDayOfWeek); + montlyVariantRG.add(radioMonthlySameDate); + + panelMonthly.add(montlyVariantRG); + } + + private void createYearlyPanel() { + panelYearly = new FieldSet(); + panelYearly.setExpanded(true); + //panelYearly.setTitle("Yearly panel title"); + panelYearly.setBorders(true); + panelYearly.setHeadingHtml("Yearly repeats settings"); + panelYearly.setCollapsible(true); + panelYearly.setAutoHeight(true); + // panelYearly.setToolTip("Set Yearly event repeats options"); + panelYearly.setVisible(false); + + yearlySameDayOfWeekRB = Forms.radio("Same day of week", Boolean.TRUE); + yearlySameDayOfWeekRB.setToolTip("Repeat Calendar event at the same DAY of week annually"); + yearlySameDayOfWeekRB.setOriginalValue(Boolean.TRUE); + //yearlySameDayOfWeekRB.setBoxLabel("Same day of week"); + yearlySameDayOfWeekRB.setName("radioYearlySameDayOfWeek"); + yearlySameDayOfWeekRB.setValue(Boolean.TRUE); + + //yearlySameDateRB = new Radio(); + yearlySameDateRB = Forms.radio("Same date", Boolean.FALSE); + //yearlySameDateRB.setBoxLabel("Same date"); + yearlySameDateRB.setName("radioYearlySameDate"); + //yearlySameDateRB.setValue(false); + + yearlyVariantRG = Forms.radioGroup("Yearly settings 888", "Yearly settings name", + Style.Orientation.HORIZONTAL, + yearlySameDayOfWeekRB, + yearlySameDateRB); + yearlyVariantRG.setSelectionRequired(Boolean.FALSE); + + panelYearly.add(yearlyVariantRG); + } + + /** + * {@inheritDoc} + */ + @Override + public FormPanel getForm() { + return form; + } + + /** + * {@inheritDoc} + */ + @Override + public TextField getEventSummaryField() { + return eventSummaryField; + } + + /** + * {@inheritDoc} + */ + @Override + public DateField getEventDateStartField() { + return eventDateStartField; + } + + /** + * {@inheritDoc} + */ + @Override + public DateField getEventDateEndField() { + return eventDateEndField; + } + + /** + * {@inheritDoc} + */ + @Override + public TimeField getEventStartTimeField() { + return eventStartTimeField; + } + + /** + * {@inheritDoc} + */ + @Override + public TimeField getEventEndTimeField() { + return eventEndTimeField; + } + + /** + * {@inheritDoc} + */ + @Override + public TextArea getEventDescriptionField() { + return eventDescriptionField; + } + + /** + * {@inheritDoc} + */ + @Override + public Button getSaveButton() { + return saveButton; + } + + /** + * {@inheritDoc} + */ + @Override + public Button getCancelButton() { + return cancelButton; + } + + @Override + public CheckBox getIsAllDayCheckbox() { + return isAllDayCheckbox; + } + + @Override + public FieldSet getPanelYearly() { + return panelYearly; + } + + @Override + public FieldSet getPanelMonthly() { + return panelMonthly; + } + + /** + * + * @return + */ + @Override + public Radio getOnceRepeatRB() { + return onceRepeatRB; + } + + @Override + public Radio getDailyRepeatRB() { + return dailyRepeatRB; + } + + @Override + public Radio getWeeklyRepeatRB() { + return weeklyRepeatRB; + } + + @Override + public Radio getMonthlyRepeatRB() { + return monthlyRepeatRB; + } + + @Override + public Radio getYearlyRepeatRB() { + return yearlyRepeatRB; + } + + @Override + public RadioGroup getYearlyVariantRG() { + return yearlyVariantRG; + } + + @Override + public RadioGroup getMontlyVariantRG() { + return montlyVariantRG; + } + + @Override + public Radio getYearlySameDayOfWeekRB() { + return yearlySameDayOfWeekRB; + } + + @Override + public Radio getYearlySameDateRB() { + return yearlySameDateRB; + } + + @Override + public RadioGroup getRepeatEventPeriodRG() { + return RepeatEventPeriodRG; + } + + public Radio getRadioMonthlySameDate() { + return radioMonthlySameDate; + } + + public Radio getRadioMonthlySameDayOfWeek() { + return radioMonthlySameDayOfWeek; + } } diff --git a/src/main/resources/org/sigmah/client/i18n/UIConstants.properties b/src/main/resources/org/sigmah/client/i18n/UIConstants.properties index 603a1a054..401da775d 100644 --- a/src/main/resources/org/sigmah/client/i18n/UIConstants.properties +++ b/src/main/resources/org/sigmah/client/i18n/UIConstants.properties @@ -480,6 +480,14 @@ calendarEventObject=Object calendarEventStartHour=Start hour calendarNoCalendarSelected=No calendar selected calendar.addEvent.noCalendar.ko=You cannot add an event without a calendar. +# New Calnedar Event View +calendar.addEvent.repeatOnceRB.toolTip=Create single Calendar event. +calendar.addEvent.repeatWeeklyRB.toolTip=Create a recurring weekly Calendar events. +calendar.addEvent.repeatMonthlyRB.toolTip=Create a recurring monthly Calendar events. +calendar.addEvent.repeatYearlyRB.toolTip=Create a recurring yearly Calendar events. +calendar.addEvent.repeatPeriodRG.label=Repeats +calendar.addEvent.isAllDayCB.boxLabel=All day +calendar.addEvent.allDayCbGr.label=Duration cancel=Cancel cancelled=Cancelled cannotLoadMap=Google Maps could not be loaded. Please check your internet connection. From e1e6b6c0df059170a480a33fdc05f77fa7190ffd Mon Sep 17 00:00:00 2001 From: Seal98 Date: Mon, 12 Jun 2017 07:50:25 +0300 Subject: [PATCH 02/39] [WIP] Advanced calendar component (issue#852) removed one alert from calendar view Pom xml changed for local rub --- pom.xml | 23 +-- .../ui/view/calendar/CalendarEventView.java | 146 ++++++++++++------ 2 files changed, 112 insertions(+), 57 deletions(-) diff --git a/pom.xml b/pom.xml index ca9fefbba..bcdebf2f1 100644 --- a/pom.xml +++ b/pom.xml @@ -156,8 +156,8 @@ 1.8 - INFO - OBFUSCATED + ALL + DETAILED 9 true true @@ -201,13 +201,13 @@ [%-5level] {%d{dd/MM/yyyy HH:mm:ss.SSS}} [%thread] %logger{35} - %msg%n - ERROR + ALL jdbc:postgresql://localhost:5432/sigmah - sigmah - sigmah + postgres + admin @@ -885,7 +885,8 @@ org.jacoco jacoco-maven-plugin - 0.7.4.201502262128 + 0.7.9 + @@ -932,7 +933,7 @@ / org.sigmah.Sigmah - -Xmx1G -Xss256M -XX:PermSize=256M -Djava.io.tmpdir=${project.build.directory} + -Xmx1G -Xss128M -Djava.io.tmpdir=${project.build.directory} @@ -1058,7 +1059,11 @@ - + jdbc:postgresql://localhost:5432/sigmah + postgres + admin + C:\\Users\\1\\Documents\\GitHub\\sigmah + C:\\Users\\1\\Documents\\GitHub\\sigmah\\archives @@ -1222,4 +1227,4 @@ - + \ No newline at end of file diff --git a/src/main/java/org/sigmah/client/ui/view/calendar/CalendarEventView.java b/src/main/java/org/sigmah/client/ui/view/calendar/CalendarEventView.java index 503c1bc84..a07a9dbfc 100644 --- a/src/main/java/org/sigmah/client/ui/view/calendar/CalendarEventView.java +++ b/src/main/java/org/sigmah/client/ui/view/calendar/CalendarEventView.java @@ -67,7 +67,7 @@ public class CalendarEventView extends AbstractPopupView implements private Button saveButton; private Button cancelButton; - private CheckBox isAllDayCheckbox; + private CheckBox allDayCheckbox; private RadioGroup yearlyVariantRG; private RadioGroup montlyVariantRG; private FieldSet panelYearly; @@ -83,8 +83,22 @@ public class CalendarEventView extends AbstractPopupView implements private Radio yearlyRepeatRB; private Radio radioMonthlySameDate; private Radio radioMonthlySameDayOfWeek; + // private CheckBoxGroup allDayCheckboxGr; private RadioGroup RepeatEventPeriodRG; + private boolean showAddEventView = true; + + public boolean isShowAddEventView() { + return showAddEventView; + } + + /** + * {@inheritDoc} + */ + // @Override + public void setShowAddEventView(boolean showAddEventView) { + this.showAddEventView = showAddEventView; + } /** * Builds the view. @@ -99,16 +113,30 @@ public CalendarEventView() { @Override public void initialize() { form = Forms.panel(); + //setShowAddEventView(Forms.panel().getTitle().equalsIgnoreCase(I18N.CONSTANTS.calendarAddEvent())); + if (form.getTitle() != null) { + // Window.alert( form.getTitle()+ " !!"); + setShowAddEventView(Forms.panel().getTitle().equalsIgnoreCase(I18N.CONSTANTS.calendarAddEvent())); + } else { + Window.alert("setShowAddEventView(false)"); + setShowAddEventView(false); + } + // Window.alert("111"); + // if(isShowAddEventView()){ + // Window.alert(isShowAddEventView() + "isShowAddEventView 3"); createYearlyPanel(); createMonthlyPanel(); - + createRepeatEventPeriodRadioGroup(); + // } + +// CheckBoxGroup allDayCheckboxGr = +// createAllDayCheckboxGroup(); eventSummaryField = Forms.text(I18N.CONSTANTS.calendarEventObject(), true); eventSummaryField.setName(Event.SUMMARY); eventDateStartField = Forms.date(I18N.CONSTANTS.calendarEventDate(), true); eventDateStartField.setName(Event.DATE); - - CheckBoxGroup allDayCheckboxGr = createAllDayCheckboxGroup(); + //eventDateStartField.setAllowBlank(true); eventStartTimeField = Forms.time(I18N.CONSTANTS.calendarEventStartHour(), false); eventStartTimeField.setName(Event.START_TIME); @@ -132,18 +160,17 @@ public void initialize() { form.add(eventSummaryField); form.add(eventDateStartField); form.add(eventDateEndField); - //form.add(isAllDayCheckbox); - form.add(allDayCheckboxGr); + //form.add(allDayCheckbox); + form.add(createAllDayCheckbox()); + //form.add(allDayCheckboxGr); form.add(eventStartTimeField); form.add(eventEndTimeField); - - createRepeatEventPeriodRadioGroup(); - - +//if(isShowAddEventView()){ form.add(RepeatEventPeriodRG); form.add(panelYearly); form.add(panelMonthly); +//} form.add(eventDescriptionField); form.addButton(cancelButton); @@ -152,35 +179,39 @@ public void initialize() { initPopup(form); } - private CheckBoxGroup createAllDayCheckboxGroup() { - isAllDayCheckbox = Forms.checkbox("All day lab", "All day name", false); - isAllDayCheckbox.setFieldLabel("setFieldLabel"); - isAllDayCheckbox.setBoxLabel(I18N.CONSTANTS.calendar_addEvent_isAllDayCB_boxLabel()); - isAllDayCheckbox.addListener(Events.OnChange, new Listener() { + private CheckBox createAllDayCheckbox() { + // private CheckBoxGroup createAllDayCheckboxGroup() { + allDayCheckbox = Forms.checkbox(I18N.CONSTANTS.calendar_addEvent_isAllDayCB_boxLabel(), "All day name", false); + allDayCheckbox.setFieldLabel(I18N.CONSTANTS.calendar_addEvent_allDayCbGr_label()); + // allDayCheckbox.setBoxLabel(I18N.CONSTANTS.calendar_addEvent_isAllDayCB_boxLabel()); + allDayCheckbox.validate(false); + allDayCheckbox.addListener(Events.OnChange, new Listener() { @Override public void handleEvent(FieldEvent event) { // eventStartTimeField.setVisible(((Boolean) event.getValue()).booleanValue()); // eventEndTimeField.setVisible(((Boolean) event.getValue()).booleanValue()); //checkbox.getValue() - eventStartTimeField.setVisible(!isAllDayCheckbox.getValue()); - eventEndTimeField.setVisible(!isAllDayCheckbox.getValue()); - Window.alert(getIsAllDayCheckbox().getBoxLabel() + " is checked"); + eventStartTimeField.setVisible(!allDayCheckbox.getValue()); + eventEndTimeField.setVisible(!allDayCheckbox.getValue()); + Window.alert(getAllDayCheckbox().getBoxLabel() + " is checked"); } }); - CheckBoxGroup allDayCheckboxGr = Forms.checkBoxGroup(I18N.CONSTANTS.calendar_addEvent_allDayCbGr_label(), isAllDayCheckbox); -// isAllDayCheckbox.addHandler(new ValueChangeHandler() { -// @Override -// public void onValueChange(ValueChangeEvent event) { -// eventStartTimeField.setVisible(event.getValue()); -// eventEndTimeField.setVisible(event.getValue()); -// } -// }, ValueChangeEvent.getType()); - return allDayCheckboxGr; +// CheckBoxGroup allDayCheckboxGr = Forms.checkBoxGroup(I18N.CONSTANTS.calendar_addEvent_allDayCbGr_label(), allDayCheckbox); +//// allDayCheckbox.addHandler(new ValueChangeHandler() { +//// @Override +//// public void onValueChange(ValueChangeEvent event) { +//// eventStartTimeField.setVisible(event.getValue()); +//// eventEndTimeField.setVisible(event.getValue()); +//// } +//// }, ValueChangeEvent.getType()); +// return allDayCheckboxGr; +// } + return allDayCheckbox; } private void createRepeatEventPeriodRadioGroup() { //final Radio - onceRepeatRB = Forms.radio("once", "onceRepeatRBname", Boolean.TRUE); + onceRepeatRB = Forms.radio("once", "onceRepeatRBname", Boolean.FALSE); onceRepeatRB.setOriginalValue(Boolean.TRUE); onceRepeatRB.setToolTip(I18N.CONSTANTS.calendar_addEvent_repeatOnceRB_toolTip()); //onceRepeatRB = new Radio(); @@ -188,16 +219,19 @@ private void createRepeatEventPeriodRadioGroup() { // onceRepeatRB.setName("once"); // onceRepeatRB.setValue(true); // onceRepeatRB.focus(); +//if(isShowAddEventView()){ onceRepeatRB.addListener(Events.OnChange, new Listener() { @Override public void handleEvent(FieldEvent event) { getPanelYearly().setVisible(!onceRepeatRB.getValue()); getPanelMonthly().setVisible(!onceRepeatRB.getValue()); - ((TextArea)form.getItemByItemId(Event.DESCRIPTION)).setValue(" The Once event."); + eventDateStartField.setAllowBlank(true); + ((TextArea) form.getItemByItemId(Event.DESCRIPTION)).setValue(" The Once event."); Window.alert(getOnceRepeatRB().getBoxLabel() + " is checked Listener OnChange on ONCE radio"); } }); +//} //final Radio //dailyRepeatRB = new Radio(); @@ -205,19 +239,20 @@ public void handleEvent(FieldEvent event) { // dailyRepeatRB.setBoxLabel("daily"); // dailyRepeatRB.setName("daily"); // dailyRepeatRB.setValue(false); - +//if(isShowAddEventView()){ dailyRepeatRB.addListener(Events.OnChange, new Listener() { @Override public void handleEvent(FieldEvent event) { - ((TextArea)form.getItemByItemId(Event.DESCRIPTION)).setValue(" The Daily event."); + ((TextArea) form.getItemByItemId(Event.DESCRIPTION)).setValue(" The Daily event."); eventStartTimeField.setVisible(!dailyRepeatRB.getValue()); eventEndTimeField.setVisible(!dailyRepeatRB.getValue()); + eventDateStartField.setAllowBlank(false); getPanelYearly().setVisible(!dailyRepeatRB.getValue()); getPanelMonthly().setVisible(!dailyRepeatRB.getValue()); Window.alert(getDailyRepeatRB().getBoxLabel() + " is checked Listener OnChange on DAILY radio"); } }); - +//} //final Radio // weeklyRepeatRB = new Radio(); weeklyRepeatRB = Forms.radio("weekly", "weekly", Boolean.FALSE); @@ -225,18 +260,21 @@ public void handleEvent(FieldEvent event) { // weeklyRepeatRB.setBoxLabel("weekly"); // weeklyRepeatRB.setName("weekly"); // weeklyRepeatRB.setValue(false); +//if(isShowAddEventView()){ weeklyRepeatRB.addListener(Events.OnChange, new Listener() { @Override public void handleEvent(FieldEvent event) { //eventStartTimeField.setVisible(!yearlyRepeatRB.getValue()); // eventEndTimeField.setVisible(!yearlyRepeatRB.getValue()); - ((TextArea)form.getItemByItemId(Event.DESCRIPTION)).setValue(" The Weekly event."); + ((TextArea) form.getItemByItemId(Event.DESCRIPTION)).setValue(" The Weekly event."); getPanelYearly().setVisible(!weeklyRepeatRB.getValue()); getPanelMonthly().setVisible(!weeklyRepeatRB.getValue()); + + eventDateStartField.setAllowBlank(false); Window.alert(getWeeklyRepeatRB().getBoxLabel() + " is checked Listener OnChange on weekly radio"); } }); - +//} //final Radio // monthlyRepeatRB = new Radio(); monthlyRepeatRB = Forms.radio("monthly", "monthly", Boolean.FALSE); @@ -244,18 +282,23 @@ public void handleEvent(FieldEvent event) { // monthlyRepeatRB.setBoxLabel("monthly"); // monthlyRepeatRB.setName("monthly"); // monthlyRepeatRB.setValue(false); +//if(isShowAddEventView()){ monthlyRepeatRB.addListener(Events.OnChange, new Listener() { @Override public void handleEvent(FieldEvent event) { //eventStartTimeField.setVisible(!yearlyRepeatRB.getValue()); // eventEndTimeField.setVisible(!yearlyRepeatRB.getValue()); - ((TextArea)form.getItemByItemId(Event.DESCRIPTION)).setValue(" The Monthly event."); + ((TextArea) form.getItemByItemId(Event.DESCRIPTION)).setValue(" The Monthly event."); getPanelYearly().setVisible(!monthlyRepeatRB.getValue()); getPanelMonthly().setVisible(getMonthlyRepeatRB().getValue()); + eventDateStartField.setAllowBlank(false); + getRadioMonthlySameDate().show(); + getRadioMonthlySameDayOfWeek().show(); + getRadioMonthlySameDayOfWeek().setValue(true); Window.alert(getMonthlyRepeatRB().getBoxLabel() + " is checked Listener OnChange on monthly radio"); } }); - +//} //final Radio // yearlyRepeatRB = Forms.radio("yearlyRepeatRB label", "yearlyRepeatRB name", Boolean.FALSE); //yearlyRepeatRB = new Radio(); @@ -264,17 +307,24 @@ public void handleEvent(FieldEvent event) { // yearlyRepeatRB.setBoxLabel("yearly"); // yearlyRepeatRB.setName("yearly"); // yearlyRepeatRB.setValue(false); +//if(isShowAddEventView()){ yearlyRepeatRB.addListener(Events.OnChange, new Listener() { @Override public void handleEvent(FieldEvent event) { //eventStartTimeField.setVisible(!yearlyRepeatRB.getValue()); // eventEndTimeField.setVisible(!yearlyRepeatRB.getValue()); - ((TextArea)form.getItemByItemId(Event.DESCRIPTION)).setValue(" The Yearly event."); + ((TextArea) form.getItemByItemId(Event.DESCRIPTION)).setValue(" The Yearly event."); getPanelYearly().setVisible(getYearlyRepeatRB().getValue()); getPanelMonthly().setVisible(!yearlyRepeatRB.getValue()); + + getYearlySameDateRB().show(); + getYearlySameDayOfWeekRB().show(); + getYearlySameDateRB().setValue(true); + eventDateStartField.setAllowBlank(false); Window.alert(getYearlyRepeatRB().getBoxLabel() + " is checked Listener OnChange on Yearly radio"); } }); +//} //YEARLY END //final RadioGroup RepeatEventPeriodRG = Forms.radioGroup(I18N.CONSTANTS.calendar_addEvent_repeatPeriodRG_label(), @@ -286,6 +336,7 @@ public void handleEvent(FieldEvent event) { monthlyRepeatRB, yearlyRepeatRB); RepeatEventPeriodRG.setSelectionRequired(Boolean.TRUE); + RepeatEventPeriodRG.enable(); } private void createMonthlyPanel() { @@ -294,7 +345,7 @@ private void createMonthlyPanel() { //panelMonthly.setTitle("Montly panel title"); panelMonthly.setBorders(true); panelMonthly.setHeadingHtml("Montly repeats settings"); - panelMonthly.setCollapsible(true); + // panelMonthly.setCollapsible(true); panelMonthly.setAutoHeight(true); //panelMonthly.setToolTip("Set Monthly event repeats options."); panelMonthly.setVisible(false); @@ -304,9 +355,8 @@ private void createMonthlyPanel() { radioMonthlySameDayOfWeek = Forms.radio("Same day of week"); //radioMonthlySameDayOfWeek.setBoxLabel("Same day of week"); radioMonthlySameDayOfWeek.setName("radioMonthlySameDayOfWeek"); - radioMonthlySameDayOfWeek.setValue(Boolean.TRUE); - radioMonthlySameDayOfWeek.setOriginalValue(Boolean.TRUE); - + radioMonthlySameDayOfWeek.setValue(Boolean.FALSE); + radioMonthlySameDayOfWeek.setOriginalValue(Boolean.FALSE); //Radio radioMonthlySameDate = new Radio(); //Radio @@ -317,8 +367,8 @@ private void createMonthlyPanel() { //montlyVariantRG= new RadioGroup(); montlyVariantRG = Forms.radioGroup("Montly settings 999"); - montlyVariantRG.setSelectionRequired(Boolean.TRUE); - // montlyVariantRG.setSelectionRequired(Boolean.FALSE); + //montlyVariantRG.setSelectionRequired(Boolean.TRUE); + montlyVariantRG.setSelectionRequired(Boolean.FALSE); montlyVariantRG.setOrientation(Style.Orientation.HORIZONTAL); //montlyVariantRG.setFieldLabel("Montly settings 999"); montlyVariantRG.add(radioMonthlySameDayOfWeek); @@ -333,12 +383,12 @@ private void createYearlyPanel() { //panelYearly.setTitle("Yearly panel title"); panelYearly.setBorders(true); panelYearly.setHeadingHtml("Yearly repeats settings"); - panelYearly.setCollapsible(true); + // panelYearly.setCollapsible(true); panelYearly.setAutoHeight(true); // panelYearly.setToolTip("Set Yearly event repeats options"); panelYearly.setVisible(false); - yearlySameDayOfWeekRB = Forms.radio("Same day of week", Boolean.TRUE); + yearlySameDayOfWeekRB = Forms.radio("Same day of week", Boolean.FALSE); yearlySameDayOfWeekRB.setToolTip("Repeat Calendar event at the same DAY of week annually"); yearlySameDayOfWeekRB.setOriginalValue(Boolean.TRUE); //yearlySameDayOfWeekRB.setBoxLabel("Same day of week"); @@ -433,8 +483,8 @@ public Button getCancelButton() { } @Override - public CheckBox getIsAllDayCheckbox() { - return isAllDayCheckbox; + public CheckBox getAllDayCheckbox() { + return allDayCheckbox; } @Override @@ -509,4 +559,4 @@ public Radio getRadioMonthlySameDayOfWeek() { return radioMonthlySameDayOfWeek; } -} +} \ No newline at end of file From ff1a7c6bb22de4e25ca45426ee3347306f0df8e0 Mon Sep 17 00:00:00 2001 From: Seal98 Date: Mon, 12 Jun 2017 08:03:45 +0300 Subject: [PATCH 03/39] [WIP] Advanced calendar component (issue#852) Added to commit 2 files CalendarEventPresenter and PersonalEventService. Changes for correct work Add new Event and Edit existing event Views. Early were issues with correct showing radiogroups in Create new Event after some event was edited. As well as was issue field validation on GUI when saving edited event and error from backend due to null values start and end event time fields. --- .../calendar/CalendarEventPresenter.java | 748 ++++++++++-------- .../server/service/PersonalEventService.java | 6 +- 2 files changed, 410 insertions(+), 344 deletions(-) diff --git a/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java b/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java index 63631ba56..fb7d6d424 100644 --- a/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java +++ b/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java @@ -21,7 +21,6 @@ * . * #L% */ - import java.io.Serializable; import java.util.ArrayList; import java.util.Date; @@ -70,210 +69,274 @@ /** * Calendar event presenter which manages the {@link CalendarEventView}. - * + * * @author Denis Colliot (dcolliot@ideia.fr) */ @Singleton public class CalendarEventPresenter extends AbstractPagePresenter { - /** - * Description of the view managed by this presenter. - */ - @ImplementedBy(CalendarEventView.class) - public static interface View extends ViewInterface { + /** + * Description of the view managed by this presenter. + */ + @ImplementedBy(CalendarEventView.class) + public static interface View extends ViewInterface { - FormPanel getForm(); + FormPanel getForm(); - TextField getEventSummaryField(); + TextField getEventSummaryField(); - DateField getEventDateStartField(); + DateField getEventDateStartField(); - DateField getEventDateEndField(); + DateField getEventDateEndField(); - TimeField getEventStartTimeField(); + TimeField getEventStartTimeField(); - TimeField getEventEndTimeField(); + TimeField getEventEndTimeField(); - TextArea getEventDescriptionField(); + TextArea getEventDescriptionField(); - Button getSaveButton(); + Button getSaveButton(); - Button getCancelButton(); - - CheckBox getIsAllDayCheckbox(); + Button getCancelButton(); - FieldSet getPanelYearly(); + CheckBox getAllDayCheckbox(); - FieldSet getPanelMonthly(); + FieldSet getPanelYearly(); - Radio getOnceRepeatRB(); + FieldSet getPanelMonthly(); - Radio getDailyRepeatRB(); + Radio getOnceRepeatRB(); - Radio getWeeklyRepeatRB(); + Radio getDailyRepeatRB(); - Radio getMonthlyRepeatRB(); + Radio getWeeklyRepeatRB(); - Radio getYearlyRepeatRB(); + Radio getMonthlyRepeatRB(); - RadioGroup getYearlyVariantRG(); + Radio getYearlyRepeatRB(); - RadioGroup getMontlyVariantRG(); + RadioGroup getYearlyVariantRG(); - Radio getYearlySameDayOfWeekRB(); + RadioGroup getMontlyVariantRG(); - Radio getYearlySameDateRB(); + Radio getYearlySameDayOfWeekRB(); - RadioGroup getRepeatEventPeriodRG(); - - Radio getRadioMonthlySameDate(); - - Radio getRadioMonthlySameDayOfWeek(); - } + Radio getYearlySameDateRB(); + + RadioGroup getRepeatEventPeriodRG(); + + Radio getRadioMonthlySameDate(); + + Radio getRadioMonthlySameDayOfWeek(); + + void setShowAddEventView(boolean showAddEventView); + } - /** - * The edited calendar event, or {@code null} if creation. - */ - private Event event; + /** + * The edited calendar event, or {@code null} if creation. + */ + private Event event; private CalendarWrapper calendarWrapper; - /** - * Presenters's initialization. - * + /** + * Presenters's initialization. + * * @param view Presenter's view interface. * @param injector Injected client injector. - */ - @Inject - public CalendarEventPresenter(final View view, final Injector injector) { - super(view, injector); - } - - /** - * {@inheritDoc} - */ - @Override - public Page getPage() { - return Page.CALENDAR_EVENT; - } - - /** - * {@inheritDoc} - */ - @Override - public void onBind() { - - // -- - // Cancel button listener. - // -- - view.getCancelButton().addSelectionListener(new SelectionListener() { - - @Override - public void componentSelected(final ButtonEvent ce) { - hideView(); - } - }); - - // -- - // Save button listener. - // -- - view.getSaveButton().addSelectionListener(new SelectionListener() { - - @Override - public void componentSelected(final ButtonEvent ce) { - onSaveAction(); - } - }); - } - - /** - * {@inheritDoc} - */ - @Override - public void onPageRequest(final PageRequest request) { - - view.getForm().clearAll(); - - // -- - // Reading inputs into request. - // -- - event = request.getData(RequestParameter.DTO); - final boolean creation = event == null; - - final List calendars = request.getData(RequestParameter.CONTENT); - - if (ClientUtils.isEmpty(calendars)) { - hideView(); - throw new IllegalArgumentException("Provided calendars list is invalid."); - } - - setPageTitle(creation ? I18N.CONSTANTS.calendarAddEvent() : I18N.CONSTANTS.calendarEditEvent()); - - // -- - // Loading received calendars. - // -- - for (final CalendarWrapper calendarWrapper : calendars) { - if (calendarWrapper.getCalendar().isEditable()) { + */ + @Inject + public CalendarEventPresenter(final View view, final Injector injector) { + super(view, injector); + } + + /** + * {@inheritDoc} + */ + @Override + public Page getPage() { + return Page.CALENDAR_EVENT; + } + + /** + * {@inheritDoc} + */ + @Override + public void onBind() { + + // -- + // Cancel button listener. + // -- + view.getCancelButton().addSelectionListener(new SelectionListener() { + + @Override + public void componentSelected(final ButtonEvent ce) { + hideView(); + } + }); + + // -- + // Save button listener. + // -- + view.getSaveButton().addSelectionListener(new SelectionListener() { + + @Override + public void componentSelected(final ButtonEvent ce) { + onSaveAction(); + } + }); + } + + /** + * {@inheritDoc} + */ + @Override + public void onPageRequest(final PageRequest request) { + + view.getForm().clearAll(); + + // -- + // Reading inputs into request. + // -- + event = request.getData(RequestParameter.DTO); + final boolean creation = event == null; + + final List calendars = request.getData(RequestParameter.CONTENT); + + if (ClientUtils.isEmpty(calendars)) { + hideView(); + throw new IllegalArgumentException("Provided calendars list is invalid."); + } + + setPageTitle(creation ? I18N.CONSTANTS.calendarAddEvent() : I18N.CONSTANTS.calendarEditEvent()); + + // -- + // Loading received calendars. + // -- + for (final CalendarWrapper calendarWrapper : calendars) { + if (calendarWrapper.getCalendar().isEditable()) { this.calendarWrapper = calendarWrapper; - } - } - - // -- - // Loading event on view (if edition). - // -- - if (creation) { - view.getRepeatEventPeriodRG().show(); - return; - } else {// CREATE NEW EVENT NEW BELOW - view.getRepeatEventPeriodRG().hide(); - } - - this.calendarWrapper = new CalendarWrapper(event.getParent()); - view.getEventSummaryField().setValue(event.getSummary()); - view.getEventDateStartField().setValue(event.getKey()); + } + } + + // -- + // Loading event on view (if edition). + // -- + if (creation) { + // view.getForm().clearState(); + // view.initialize(); + view.setShowAddEventView(true); + if (view.getRepeatEventPeriodRG() != null) { + view.getRepeatEventPeriodRG().enable(); + view.getRepeatEventPeriodRG().show(); + view.getOnceRepeatRB().setValue(true); + view.getPanelMonthly().hide(); + view.getPanelYearly().hide(); + //view.getMontlyVariantRG().show(); + //view.getYearlyVariantRG().show(); + } + view.getEventStartTimeField().show(); + view.getEventEndTimeField().show(); + + view.getYearlyVariantRG().enable(); + view.getMontlyVariantRG().enable(); + view.getRepeatEventPeriodRG().enable(); + view.getMonthlyRepeatRB().enable(); + view.getYearlySameDateRB().enable(); + view.getYearlySameDayOfWeekRB().enable(); + view.getRadioMonthlySameDate().enable(); + view.getRadioMonthlySameDayOfWeek().enable(); + + view.getYearlyVariantRG().show(); + view.getMontlyVariantRG().show(); + view.getRepeatEventPeriodRG().show(); + view.getMonthlyRepeatRB().show(); + view.getYearlySameDateRB().show(); + view.getYearlySameDayOfWeekRB().show(); + view.getRadioMonthlySameDate().show(); + view.getRadioMonthlySameDayOfWeek().show(); + // view.getRepeatEventPeriodRG().show(); + // return; + //view.getRepeatEventPeriodRG().show(); + } else {// EDIST EXISTING EVENT + //view.setShowAddEventView(false); + //view.getRepeatEventPeriodRG().hide(); + //--->> } + + this.calendarWrapper = new CalendarWrapper(event.getParent()); + view.setShowAddEventView(false); + view.getForm().clearState(); + view.getEventSummaryField().setValue(event.getSummary()); + view.getEventDateStartField().setValue(event.getKey()); + if (view.getRepeatEventPeriodRG() != null) { + view.getRepeatEventPeriodRG().clear(); + view.getRepeatEventPeriodRG().clearInvalid(); + view.getRepeatEventPeriodRG().clearState(); + view.getRepeatEventPeriodRG().setSelectionRequired(false); + view.getRepeatEventPeriodRG().hide(); + + view.getPanelMonthly().hide(); + view.getMontlyVariantRG().hide(); + + view.getPanelYearly().hide(); + view.getYearlyVariantRG().hide(); + + view.getYearlyVariantRG().hide(); + view.getMontlyVariantRG().hide(); + view.getRepeatEventPeriodRG().hide(); + view.getMonthlyRepeatRB().hide(); + view.getYearlySameDateRB().hide(); + view.getYearlySameDayOfWeekRB().hide(); + view.getRadioMonthlySameDate().hide(); + view.getRadioMonthlySameDayOfWeek().hide(); + + } // if(creation) { // view.getIsAllDayCheckbox().hide(); // } else {// CREATE NEW EVENT NEW BELOW // view.getRepeatEventPeriodRG().hide(); // } - - if (!isFullDayEvent(event)) { - - final Time startTime = event.getDtstart() != null ? view.getEventStartTimeField().findModel(event.getDtstart()) : null; - view.getEventStartTimeField().setValue(startTime); - - final Time endTime = event.getDtend() != null ? view.getEventEndTimeField().findModel(event.getDtend()) : null; - view.getEventEndTimeField().setValue(endTime); - - } - - view.getEventDescriptionField().setValue(event.getDescription()); - } - - // --------------------------------------------------------------------------------------------------------------- - // - // UTILITY METHODS. - // - // --------------------------------------------------------------------------------------------------------------- - /** - * Method executed on save button action. - */ - @SuppressWarnings("deprecation") - private void onSaveAction() { - - if (!view.getForm().isValid()) { - return; - } - - // -- - // Building properties map. - // -- - final Map properties = new HashMap(); - properties.put(Event.CALENDAR_ID, calendarWrapper); - properties.put(Event.SUMMARY, view.getEventSummaryField().getValue()); - - final Date date = view.getEventDateStartField().getValue(); - properties.put(Event.DATE, date); + view.getEventStartTimeField().show(); + view.getEventEndTimeField().show(); + + if (!isFullDayEvent(event)) { + + final Time startTime = event.getDtstart() != null ? view.getEventStartTimeField().findModel(event.getDtstart()) : null; + view.getEventStartTimeField().setValue(startTime); + + final Time endTime = event.getDtend() != null ? view.getEventEndTimeField().findModel(event.getDtend()) : null; + view.getEventEndTimeField().setValue(endTime); + + } + + view.getEventDescriptionField().setValue(event.getDescription()); + } + } + + // --------------------------------------------------------------------------------------------------------------- + // + // UTILITY METHODS. + // + // --------------------------------------------------------------------------------------------------------------- + /** + * Method executed on save button action. + */ + @SuppressWarnings("deprecation") + private void onSaveAction() { + + if (!view.getForm().isValid()) { + return; + } + + // -- + // Building properties map. + // -- + final Map properties = new HashMap(); + properties.put(Event.CALENDAR_ID, calendarWrapper); + properties.put(Event.SUMMARY, view.getEventSummaryField().getValue()); + + final Date date = view.getEventDateStartField().getValue(); + properties.put(Event.DATE, date); // properties.put("YYYYYYY", (view.getMontlyVariantRG().getValue().toString()?"true":"false")); // Radio getMontlyVariantRG = view.getMontlyVariantRG()!=null? view.getMontlyVariantRG().getValue():null; // Boolean getDailyRepeatRB = view.getDailyRepeatRB()!=null? view.getDailyRepeatRB().getValue(): Boolean.FALSE; @@ -281,207 +344,210 @@ private void onSaveAction() { // Boolean getYearlyRepeatRB = view.getYearlyRepeatRB().getValue(); // //properties.put("getYearlyRepeatRB", (view.getYearlyRepeatRB().getValue()?"true":"false")); // Boolean getYearlySameDayOfWeekRB = view.getYearlySameDayOfWeekRB().getValue(); - - final Date startDate = view.getEventStartTimeField().getDateValue(); - if (startDate != null) { - startDate.setYear(date.getYear()); - startDate.setMonth(date.getMonth()); - startDate.setDate(date.getDate()); - properties.put(Event.START_TIME, startDate.getTime()); - } else { - properties.put(Event.START_TIME, null); - } - - final Date endDate = view.getEventEndTimeField().getDateValue(); - if (endDate != null) { - endDate.setYear(date.getYear()); - endDate.setMonth(date.getMonth()); - endDate.setDate(date.getDate()); - properties.put(Event.END_TIME, endDate.getTime()); - } else { - properties.put(Event.END_TIME, null); - } - - properties.put(Event.DESCRIPTION, view.getEventDescriptionField().getValue()); - - if (event == null) { - addPersonalEvent(properties); - //Here process properties and define repetable events dates - /*take parameters from View + + final Date startDate = view.getEventStartTimeField().getDateValue(); + if (startDate != null) { + startDate.setYear(date.getYear()); + startDate.setMonth(date.getMonth()); + startDate.setDate(date.getDate()); + properties.put(Event.START_TIME, startDate.getTime()); + } else { + properties.put(Event.START_TIME, null); + } + + final Date endDate = view.getEventEndTimeField().getDateValue(); + if (endDate != null) { + endDate.setYear(date.getYear()); + endDate.setMonth(date.getMonth()); + endDate.setDate(date.getDate()); + properties.put(Event.END_TIME, endDate.getTime()); + } else { + properties.put(Event.END_TIME, null); + } + + properties.put(Event.DESCRIPTION, view.getEventDescriptionField().getValue()); + + if (event == null) { + addPersonalEvent(properties); + //Here process properties and define repetable events dates + /*take parameters from View Start Date, get End date, period settings like Once, Daily, Monthly etc process values to prepare new properties for new event if needed calculate same day of week for Monthly or Yearly if needed compare if the Date exist in Month (like 29 30 31 Febr etc) if needed define weekends after that in cycle add new events - */ - - Date theDate = (Date) properties.get(Event.DATE); + */ + + Date theDate = (Date) properties.get(Event.DATE); // long theStartTime = ((Long)properties.get(Event.START_TIME)).longValue(); // long theEndTime = ((Long) properties.get(Event.END_TIME)).longValue(); - Date dayAfter = new Date(theDate.getTime()+(24*60*60*1000)); - long theStartTimeNext = startDate.getTime()+(24*60*60*1000); - long theEndTimeNext = endDate.getTime()+(24*60*60*1000); - //LocalDateTime.from(theDate.toInstant().atZone(ZoneId.of("UTC"))).plusDays(1); - properties.put(Event.DATE, dayAfter); - properties.put(Event.START_TIME, theStartTimeNext); - properties.put(Event.END_TIME, theEndTimeNext); - String newSummary = (String) properties.get(Event.SUMMARY); - newSummary += " (repeat + 1 day)"; - properties.put(Event.SUMMARY, newSummary); - properties.put(Event.SUMMARY,properties.get(Event.SUMMARY)+" (This is repeated Daily event.)" ); - addPersonalEvent(properties); + Date dayAfter = new Date(theDate.getTime() + (24 * 60 * 60 * 1000)); + long theStartTimeNext = startDate.getTime() + (24 * 60 * 60 * 1000); + long theEndTimeNext = endDate.getTime() + (24 * 60 * 60 * 1000); + //LocalDateTime.from(theDate.toInstant().atZone(ZoneId.of("UTC"))).plusDays(1); + properties.put(Event.DATE, dayAfter); + properties.put(Event.START_TIME, theStartTimeNext); + properties.put(Event.END_TIME, theEndTimeNext); + String newSummary = (String) properties.get(Event.SUMMARY); + newSummary += " (repeat + 1 day)"; + properties.put(Event.SUMMARY, newSummary); + properties.put(Event.SUMMARY, properties.get(Event.SUMMARY) + " (This is repeated Daily event.)"); + addPersonalEvent(properties); //Here process properties and define repetable events dates - } else { - editPersonalEvent(event, properties); - } + } else { + editPersonalEvent(event, properties); +// properties.remove(Event.START_TIME); +// properties.remove(Event.END_TIME); + //properties.remove(Event.DATE); + } // if (event == null) { // addPersonalEvent(properties); // // } else { // editPersonalEvent(event, properties); // } - } - - /** - * Creates a new "Personal" calendar event. - * - * @param properties Properties of the new event. - */ - private void addPersonalEvent(final Map properties) { - - final CreateEntity createEntity = new CreateEntity(PersonalEventDTO.ENTITY_NAME, properties); - - dispatch.execute(createEntity, new CommandResultHandler() { - - @Override - public void onCommandFailure(final Throwable caught) { - if (Log.isErrorEnabled()) { - Log.error(I18N.CONSTANTS.calendarAddEventError(), caught); - } - N10N.error(I18N.CONSTANTS.error(), I18N.CONSTANTS.calendarAddEventError()); - } - - @Override - public void onCommandSuccess(final CreateResult result) { - - // Creating events. - final Event event = new Event(); - event.setIdentifier((Integer) result.getEntity().getId()); - - updateEvent(event, properties); - } - }, view.getCancelButton(), view.getSaveButton()); - } - - /** - * Edits the events. - * + } + + /** + * Creates a new "Personal" calendar event. + * + * @param properties Properties of the new event. + */ + private void addPersonalEvent(final Map properties) { + + final CreateEntity createEntity = new CreateEntity(PersonalEventDTO.ENTITY_NAME, properties); + + dispatch.execute(createEntity, new CommandResultHandler() { + + @Override + public void onCommandFailure(final Throwable caught) { + if (Log.isErrorEnabled()) { + Log.error(I18N.CONSTANTS.calendarAddEventError(), caught); + } + N10N.error(I18N.CONSTANTS.error(), I18N.CONSTANTS.calendarAddEventError()); + } + + @Override + public void onCommandSuccess(final CreateResult result) { + + // Creating events. + final Event event = new Event(); + event.setIdentifier((Integer) result.getEntity().getId()); + + updateEvent(event, properties); + } + }, view.getCancelButton(), view.getSaveButton()); + } + + /** + * Edits the events. + * * @param properties Properties of the new event. - */ - private void editPersonalEvent(final Event event, final Map properties) { + */ + private void editPersonalEvent(final Event event, final Map properties) { - @SuppressWarnings("unchecked") - final UpdateEntity updateEntity = new UpdateEntity(PersonalEventDTO.ENTITY_NAME, event.getIdentifier(), (Map) properties); + @SuppressWarnings("unchecked") + final UpdateEntity updateEntity = new UpdateEntity(PersonalEventDTO.ENTITY_NAME, event.getIdentifier(), (Map) properties); - dispatch.execute(updateEntity, new CommandResultHandler() { + dispatch.execute(updateEntity, new CommandResultHandler() { - @Override - public void onCommandFailure(final Throwable caught) { - if (Log.isErrorEnabled()) { - Log.error(I18N.CONSTANTS.calendarAddEventError(), caught); - } - N10N.error(I18N.CONSTANTS.error(), I18N.CONSTANTS.calendarAddEventError()); - } + @Override + public void onCommandFailure(final Throwable caught) { + if (Log.isErrorEnabled()) { + Log.error(I18N.CONSTANTS.calendarAddEventError(), caught); + } + N10N.error(I18N.CONSTANTS.error(), I18N.CONSTANTS.calendarAddEventError()); + } - @Override - public void onCommandSuccess(final VoidResult result) { + @Override + public void onCommandSuccess(final VoidResult result) { - final Calendar calendar = event.getParent(); + final Calendar calendar = event.getParent(); - final List oldEventList = calendar.getEvents().get(event.getKey()); - oldEventList.remove(event); + final List oldEventList = calendar.getEvents().get(event.getKey()); + oldEventList.remove(event); - updateEvent(event, properties); - } - }, view.getCancelButton(), view.getSaveButton()); - } + updateEvent(event, properties); + } + }, view.getCancelButton(), view.getSaveButton()); + } - /** - * Updates the given {@code event} with the given {@code properties}. - * + /** + * Updates the given {@code event} with the given {@code properties}. + * * @param event The event to update. * @param properties The properties. - */ - @SuppressWarnings("deprecation") - private void updateEvent(final Event event, final Map properties) { - - // -- - // Updates the event. - // -- - event.setSummary((String) properties.get(Event.SUMMARY)); - event.setDescription((String) properties.get(Event.DESCRIPTION)); - - final Date day = (Date) properties.get(Event.DATE); - final Object startHourSerialized = properties.get(Event.START_TIME); - final Object endHourSerialized = properties.get(Event.END_TIME); - - if (startHourSerialized != null) { - final Date startHour = new Date((Long) startHourSerialized); - event.setDtstart(startHour); - if (endHourSerialized != null) { - final Date endHour = new Date((Long) endHourSerialized); - event.setDtend(endHour); - } else { - event.setDtend(null); - } - - } else { - event.setDtstart(new Date(day.getYear(), day.getMonth(), day.getDate())); - event.setDtend(new Date(day.getYear(), day.getMonth(), day.getDate() + 1)); - } - - // Adding the new event to the calendar - final CalendarWrapper wrapper = (CalendarWrapper) properties.get(Event.CALENDAR_ID); - final Calendar calendar = wrapper.getCalendar(); - - event.setParent(calendar); - - List events = calendar.getEvents().get(day); - if (events == null) { - events = new ArrayList(); - calendar.getEvents().put(day, events); - } - events.add(event); - - // -- - // Sends an update event on the event bus. - // -- - eventBus.fireEvent(new UpdateEvent(UpdateEvent.CALENDAR_EVENT_UPDATE, event)); - // calendarWidget.refresh(); - - // -- - // Hides the view. - // -- - hideView(); - } - - /** - * Returns if the given {@code event} is a full day event. - * + */ + @SuppressWarnings("deprecation") + private void updateEvent(final Event event, final Map properties) { + + // -- + // Updates the event. + // -- + event.setSummary((String) properties.get(Event.SUMMARY)); + event.setDescription((String) properties.get(Event.DESCRIPTION)); + + final Date day = (Date) properties.get(Event.DATE); + final Object startHourSerialized = properties.get(Event.START_TIME); + final Object endHourSerialized = properties.get(Event.END_TIME); + + if (startHourSerialized != null) { + final Date startHour = new Date((Long) startHourSerialized); + event.setDtstart(startHour); + if (endHourSerialized != null) { + final Date endHour = new Date((Long) endHourSerialized); + event.setDtend(endHour); + } else { + event.setDtend(null); + } + + } else { + event.setDtstart(new Date(day.getYear(), day.getMonth(), day.getDate())); + event.setDtend(new Date(day.getYear(), day.getMonth(), day.getDate() + 1)); + } + + // Adding the new event to the calendar + final CalendarWrapper wrapper = (CalendarWrapper) properties.get(Event.CALENDAR_ID); + final Calendar calendar = wrapper.getCalendar(); + + event.setParent(calendar); + + List events = calendar.getEvents().get(day); + if (events == null) { + events = new ArrayList(); + calendar.getEvents().put(day, events); + } + events.add(event); + + // -- + // Sends an update event on the event bus. + // -- + eventBus.fireEvent(new UpdateEvent(UpdateEvent.CALENDAR_EVENT_UPDATE, event)); + // calendarWidget.refresh(); + + // -- + // Hides the view. + // -- + hideView(); + } + + /** + * Returns if the given {@code event} is a full day event. + * * @param event The event. - * @return {@code true} if the given {@code event} is a full day event. - */ - @SuppressWarnings("deprecation") - private static boolean isFullDayEvent(final Event event) { + * @return {@code true} if the given {@code event} is a full day event. + */ + @SuppressWarnings("deprecation") + private static boolean isFullDayEvent(final Event event) { - if (event == null) { - return false; - } + if (event == null) { + return false; + } - return event.getDtend() != null - && (event.getDtstart().getDate() != event.getDtend().getDate() || event.getDtstart().getMonth() != event.getDtend().getMonth() || event.getDtstart() - .getYear() != event.getDtend().getYear()); - } + return event.getDtend() != null + && (event.getDtstart().getDate() != event.getDtend().getDate() || event.getDtstart().getMonth() != event.getDtend().getMonth() || event.getDtstart() + .getYear() != event.getDtend().getYear()); + } -} +} \ No newline at end of file diff --git a/src/main/java/org/sigmah/server/service/PersonalEventService.java b/src/main/java/org/sigmah/server/service/PersonalEventService.java index 59496b0d1..1859e9727 100644 --- a/src/main/java/org/sigmah/server/service/PersonalEventService.java +++ b/src/main/java/org/sigmah/server/service/PersonalEventService.java @@ -41,7 +41,7 @@ /** * {@link PersonalEvent} policy implementation. * - * @author Raphaël Calabro (rcalabro@ideia.fr) + * @author RaphaГ«l Calabro (rcalabro@ideia.fr) * @author Denis Colliot (dcolliot@ideia.fr) */ @Singleton @@ -96,11 +96,11 @@ private static void fillEvent(PersonalEvent event, PropertyMap properties) { final Serializable startHourSerialized = properties.get(Event.START_TIME); final Serializable endHourSerialized = properties.get(Event.END_TIME); - if (startHourSerialized instanceof Long) { + if (startHourSerialized != null && startHourSerialized instanceof Long) { final Date startHour = new Date((Long) startHourSerialized); event.setStartDate(startHour); - if (endHourSerialized instanceof Long) { + if (endHourSerialized != null && endHourSerialized instanceof Long) { final Date endHour = new Date((Long) endHourSerialized); event.setEndDate(endHour); } else { From 1e91db64d19e42076c147d426efb15c2b951a927 Mon Sep 17 00:00:00 2001 From: Seal98 Date: Tue, 13 Jun 2017 10:30:42 +0300 Subject: [PATCH 04/39] [WIP] Advanced calendar component (issue#852) Changes in 2 files: CalendarEventPresenter and CalendarEventView Implemented functionality 'Add daily events' - now repeating daily events can be created. --- .../calendar/CalendarEventPresenter.java | 193 ++++++++++++------ .../ui/view/calendar/CalendarEventView.java | 52 ++--- 2 files changed, 160 insertions(+), 85 deletions(-) diff --git a/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java b/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java index fb7d6d424..ab2e3432e 100644 --- a/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java +++ b/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java @@ -129,7 +129,7 @@ public static interface View extends ViewInterface { Radio getRadioMonthlySameDayOfWeek(); - void setShowAddEventView(boolean showAddEventView); + // void setShowAddEventView(boolean showAddEventView); } /** @@ -225,7 +225,7 @@ public void onPageRequest(final PageRequest request) { if (creation) { // view.getForm().clearState(); // view.initialize(); - view.setShowAddEventView(true); + //view.setShowAddEventView(true); if (view.getRepeatEventPeriodRG() != null) { view.getRepeatEventPeriodRG().enable(); view.getRepeatEventPeriodRG().show(); @@ -237,24 +237,24 @@ public void onPageRequest(final PageRequest request) { } view.getEventStartTimeField().show(); view.getEventEndTimeField().show(); - - view.getYearlyVariantRG().enable(); - view.getMontlyVariantRG().enable(); - view.getRepeatEventPeriodRG().enable(); - view.getMonthlyRepeatRB().enable(); - view.getYearlySameDateRB().enable(); - view.getYearlySameDayOfWeekRB().enable(); - view.getRadioMonthlySameDate().enable(); - view.getRadioMonthlySameDayOfWeek().enable(); - - view.getYearlyVariantRG().show(); - view.getMontlyVariantRG().show(); - view.getRepeatEventPeriodRG().show(); - view.getMonthlyRepeatRB().show(); - view.getYearlySameDateRB().show(); - view.getYearlySameDayOfWeekRB().show(); - view.getRadioMonthlySameDate().show(); - view.getRadioMonthlySameDayOfWeek().show(); + + view.getYearlyVariantRG().enable(); + view.getMontlyVariantRG().enable(); + view.getRepeatEventPeriodRG().enable(); + view.getMonthlyRepeatRB().enable(); + view.getYearlySameDateRB().enable(); + view.getYearlySameDayOfWeekRB().enable(); + view.getRadioMonthlySameDate().enable(); + view.getRadioMonthlySameDayOfWeek().enable(); + + view.getYearlyVariantRG().show(); + view.getMontlyVariantRG().show(); + view.getRepeatEventPeriodRG().show(); + view.getMonthlyRepeatRB().show(); + view.getYearlySameDateRB().show(); + view.getYearlySameDayOfWeekRB().show(); + view.getRadioMonthlySameDate().show(); + view.getRadioMonthlySameDayOfWeek().show(); // view.getRepeatEventPeriodRG().show(); // return; //view.getRepeatEventPeriodRG().show(); @@ -264,7 +264,7 @@ public void onPageRequest(final PageRequest request) { //--->> } this.calendarWrapper = new CalendarWrapper(event.getParent()); - view.setShowAddEventView(false); + //view.setShowAddEventView(false); view.getForm().clearState(); view.getEventSummaryField().setValue(event.getSummary()); view.getEventDateStartField().setValue(event.getKey()); @@ -289,7 +289,6 @@ public void onPageRequest(final PageRequest request) { view.getYearlySameDayOfWeekRB().hide(); view.getRadioMonthlySameDate().hide(); view.getRadioMonthlySameDayOfWeek().hide(); - } // if(creation) { // view.getIsAllDayCheckbox().hide(); @@ -334,22 +333,20 @@ private void onSaveAction() { final Map properties = new HashMap(); properties.put(Event.CALENDAR_ID, calendarWrapper); properties.put(Event.SUMMARY, view.getEventSummaryField().getValue()); - - final Date date = view.getEventDateStartField().getValue(); - properties.put(Event.DATE, date); -// properties.put("YYYYYYY", (view.getMontlyVariantRG().getValue().toString()?"true":"false")); -// Radio getMontlyVariantRG = view.getMontlyVariantRG()!=null? view.getMontlyVariantRG().getValue():null; -// Boolean getDailyRepeatRB = view.getDailyRepeatRB()!=null? view.getDailyRepeatRB().getValue(): Boolean.FALSE; -// Boolean getOnceRepeatRB = view.getOnceRepeatRB().getValue(); -// Boolean getYearlyRepeatRB = view.getYearlyRepeatRB().getValue(); -// //properties.put("getYearlyRepeatRB", (view.getYearlyRepeatRB().getValue()?"true":"false")); -// Boolean getYearlySameDayOfWeekRB = view.getYearlySameDayOfWeekRB().getValue(); - + + String eventSummary = view.getEventSummaryField().getValue(); + String eventDescription = view.getEventDescriptionField().getValue(); + + final Date beginEventIntervalDate = view.getEventDateStartField().getValue(); + properties.put(Event.DATE, beginEventIntervalDate); + + final Date endEventIntervalDate = view.getEventDateEndField().getValue(); + final Date startDate = view.getEventStartTimeField().getDateValue(); if (startDate != null) { - startDate.setYear(date.getYear()); - startDate.setMonth(date.getMonth()); - startDate.setDate(date.getDate()); + startDate.setYear(beginEventIntervalDate.getYear()); + startDate.setMonth(beginEventIntervalDate.getMonth()); + startDate.setDate(beginEventIntervalDate.getDate()); properties.put(Event.START_TIME, startDate.getTime()); } else { properties.put(Event.START_TIME, null); @@ -357,9 +354,9 @@ private void onSaveAction() { final Date endDate = view.getEventEndTimeField().getDateValue(); if (endDate != null) { - endDate.setYear(date.getYear()); - endDate.setMonth(date.getMonth()); - endDate.setDate(date.getDate()); + endDate.setYear(beginEventIntervalDate.getYear()); + endDate.setMonth(beginEventIntervalDate.getMonth()); + endDate.setDate(beginEventIntervalDate.getDate()); properties.put(Event.END_TIME, endDate.getTime()); } else { properties.put(Event.END_TIME, null); @@ -368,31 +365,107 @@ private void onSaveAction() { properties.put(Event.DESCRIPTION, view.getEventDescriptionField().getValue()); if (event == null) { - addPersonalEvent(properties); + Boolean isOnceRepeatEvent = view.getOnceRepeatRB().getValue(); + if(!isOnceRepeatEvent.booleanValue()){ //Here process properties and define repetable events dates /*take parameters from View - Start Date, get End date, period settings like Once, Daily, Monthly etc - process values to prepare new properties for new event - if needed calculate same day of week for Monthly or Yearly - if needed compare if the Date exist in Month (like 29 30 31 Febr etc) - if needed define weekends - after that in cycle add new events + Start Date, get End beginEventIntervalDate, period settings like Once, Daily, Monthly etc + process values to prepare new properties for new event + if needed calculate same day of week for Monthly or Yearly + if needed compare if the Date exist in Month (like 29 30 31 Febr etc) + if needed define weekends + after that in cycle add new events */ - Date theDate = (Date) properties.get(Event.DATE); -// long theStartTime = ((Long)properties.get(Event.START_TIME)).longValue(); -// long theEndTime = ((Long) properties.get(Event.END_TIME)).longValue(); - Date dayAfter = new Date(theDate.getTime() + (24 * 60 * 60 * 1000)); - long theStartTimeNext = startDate.getTime() + (24 * 60 * 60 * 1000); - long theEndTimeNext = endDate.getTime() + (24 * 60 * 60 * 1000); - //LocalDateTime.from(theDate.toInstant().atZone(ZoneId.of("UTC"))).plusDays(1); - properties.put(Event.DATE, dayAfter); - properties.put(Event.START_TIME, theStartTimeNext); - properties.put(Event.END_TIME, theEndTimeNext); - String newSummary = (String) properties.get(Event.SUMMARY); - newSummary += " (repeat + 1 day)"; - properties.put(Event.SUMMARY, newSummary); - properties.put(Event.SUMMARY, properties.get(Event.SUMMARY) + " (This is repeated Daily event.)"); + Boolean isAllDayEvent = view.getAllDayCheckbox().getValue(); + Boolean isDailyRepeatEvent = view.getDailyRepeatRB() != null ? view.getDailyRepeatRB().getValue() : Boolean.FALSE; + Boolean isWeeklyRepeatEvent = view.getWeeklyRepeatRB().getValue(); + Boolean isMonthlyRepeatEvent = view.getMonthlyRepeatRB().getValue(); + Boolean isYearlyRepeatEvent = view.getYearlyRepeatRB().getValue(); + + Boolean isMonthlySameDayOfWeek = view.getRadioMonthlySameDayOfWeek().getValue(); + Boolean isMonthlySameDate = view.getRadioMonthlySameDate().getValue(); + + Boolean isYearlySameDayOfWeek = view.getYearlySameDayOfWeekRB().getValue(); + Boolean isYearlySameDate = view.getYearlySameDateRB().getValue(); + + if(isDailyRepeatEvent.booleanValue()){ +// Map dailyProperties = new HashMap(); +// dailyProperties.put(Event.CALENDAR_ID, calendarWrapper); +// dailyProperties.put(Event.SUMMARY, view.getEventSummaryField().getValue()); +/// + /* + 1. find number of days between start and end + 2. in cycle create new event + */ + int daysInterval = 0; + + long milisPerDay = 86400000; //24 * 60 * 60 * 1000) + long diff = endEventIntervalDate.getTime() - beginEventIntervalDate.getTime(); + + long daysDiff = diff / milisPerDay + 1; + daysInterval = (int) daysDiff; +// java.util.Calendar is not supported by GWT !!! +// java.util.Calendar calNextEventDate = java.util.Calendar.getInstance(); +// calNextEventDate.setTime(beginEventIntervalDate); +// +// java.util.Calendar calNextEventStartTime = java.util.Calendar.getInstance(); +// calNextEventStartTime.setTime(startDate); +// +// java.util.Calendar calNextEventEndTime = java.util.Calendar.getInstance(); +// calNextEventEndTime.setTime(endDate); + + long calBeginNextEventDateLong = beginEventIntervalDate.getTime(); + Date calBeginNextEventDate = beginEventIntervalDate; + long calNextEventStartTime = startDate.getTime(); + long calNextEventEndTime = endDate.getTime(); + + if(daysInterval>1){ + properties.put(Event.SUMMARY, (String)properties.get(Event.SUMMARY)+ " (Daily event 1 of " + daysInterval + ")"); + properties.put(Event.DESCRIPTION, (String)properties.get(Event.DESCRIPTION)+ " (Daily event 1 of " + daysInterval + ")"); + } + + for (int i = 1; i < daysInterval; i++) { + + calBeginNextEventDateLong += milisPerDay; + calBeginNextEventDate = new Date(calBeginNextEventDateLong); + calNextEventStartTime += milisPerDay; + calNextEventEndTime += milisPerDay; + + Map dailyProperties = new HashMap(); + dailyProperties.put(Event.CALENDAR_ID, calendarWrapper); + dailyProperties.put(Event.SUMMARY, view.getEventSummaryField().getValue()); + + dailyProperties.put(Event.DATE, calBeginNextEventDate); + dailyProperties.put(Event.START_TIME, calNextEventStartTime); + dailyProperties.put(Event.END_TIME, calNextEventEndTime); +// java.util.Calendar is not supported by GWT !!! +// calNextEventDate.add(java.util.Calendar.DATE, 1); +// nextEventDate = calNextEventDate.getTime(); +// +// calNextEventStartTime.add(java.util.Calendar.DATE, 1); +// nextEventStartTime = calNextEventStartTime.getTime(); +// +// calNextEventEndTime.add(java.util.Calendar.DATE, 1); +// nextEventEndTime = calNextEventEndTime.getTime(); +// +// //Date beginEventIntervalDate = view.getEventDateStartField().getValue(); +// dailyProperties.put(Event.DATE, nextEventDate); +// dailyProperties.put(Event.START_TIME, nextEventStartTime); +// dailyProperties.put(Event.END_TIME, nextEventEndTime); + + String newSummary = eventSummary; + String newDescription = eventDescription; + newSummary += " (Daily event " + (i+1) + " of " + daysInterval + ")"; + newDescription += " (Daily event " + (i+1) + " of " + daysInterval + ")"; + dailyProperties.put(Event.SUMMARY, newSummary); + dailyProperties.put(Event.DESCRIPTION, newDescription); + + addPersonalEvent(dailyProperties); + } + } + } + //add first event addPersonalEvent(properties); //Here process properties and define repetable events dates } else { diff --git a/src/main/java/org/sigmah/client/ui/view/calendar/CalendarEventView.java b/src/main/java/org/sigmah/client/ui/view/calendar/CalendarEventView.java index a07a9dbfc..b9362b695 100644 --- a/src/main/java/org/sigmah/client/ui/view/calendar/CalendarEventView.java +++ b/src/main/java/org/sigmah/client/ui/view/calendar/CalendarEventView.java @@ -43,7 +43,6 @@ import com.extjs.gxt.ui.client.widget.form.TextField; import com.extjs.gxt.ui.client.widget.form.TimeField; import com.extjs.gxt.ui.client.widget.form.CheckBox; -import com.extjs.gxt.ui.client.widget.form.CheckBoxGroup; import com.extjs.gxt.ui.client.widget.form.FieldSet; import com.google.inject.Singleton; import com.google.gwt.user.client.Window; @@ -86,19 +85,19 @@ public class CalendarEventView extends AbstractPopupView implements // private CheckBoxGroup allDayCheckboxGr; private RadioGroup RepeatEventPeriodRG; - private boolean showAddEventView = true; + //private boolean showAddEventView = true; - public boolean isShowAddEventView() { - return showAddEventView; - } +// public boolean isShowAddEventView() { +// return showAddEventView; +// } - /** - * {@inheritDoc} - */ - // @Override - public void setShowAddEventView(boolean showAddEventView) { - this.showAddEventView = showAddEventView; - } +// /** +// * {@inheritDoc} +// */ +// // @Override +// public void setShowAddEventView(boolean showAddEventView) { +// this.showAddEventView = showAddEventView; +// } /** * Builds the view. @@ -114,13 +113,13 @@ public CalendarEventView() { public void initialize() { form = Forms.panel(); //setShowAddEventView(Forms.panel().getTitle().equalsIgnoreCase(I18N.CONSTANTS.calendarAddEvent())); - if (form.getTitle() != null) { - // Window.alert( form.getTitle()+ " !!"); - setShowAddEventView(Forms.panel().getTitle().equalsIgnoreCase(I18N.CONSTANTS.calendarAddEvent())); - } else { - Window.alert("setShowAddEventView(false)"); - setShowAddEventView(false); - } +// if (form.getTitle() != null) { +// // Window.alert( form.getTitle()+ " !!"); +// setShowAddEventView(Forms.panel().getTitle().equalsIgnoreCase(I18N.CONSTANTS.calendarAddEvent())); +// } else { +// Window.alert("setShowAddEventView(false)"); +// setShowAddEventView(false); +// } // Window.alert("111"); // if(isShowAddEventView()){ // Window.alert(isShowAddEventView() + "isShowAddEventView 3"); @@ -134,7 +133,7 @@ public void initialize() { eventSummaryField = Forms.text(I18N.CONSTANTS.calendarEventObject(), true); eventSummaryField.setName(Event.SUMMARY); - eventDateStartField = Forms.date(I18N.CONSTANTS.calendarEventDate(), true); + eventDateStartField = Forms.date(I18N.CONSTANTS.calendarEventDate()+ " start", true); eventDateStartField.setName(Event.DATE); //eventDateStartField.setAllowBlank(true); @@ -146,7 +145,7 @@ public void initialize() { eventEndTimeField.setName(Event.END_TIME); eventEndTimeField.setTriggerAction(TriggerAction.ALL); - eventDateEndField = Forms.date(I18N.CONSTANTS.calendarEventDate(), false); + eventDateEndField = Forms.date(I18N.CONSTANTS.calendarEventDate() + " end", false); eventDateEndField.setName(Event.DATE + "888end"); eventDescriptionField = Forms.textarea(I18N.CONSTANTS.calendarEventDescription(), false); @@ -226,7 +225,10 @@ public void handleEvent(FieldEvent event) { getPanelYearly().setVisible(!onceRepeatRB.getValue()); getPanelMonthly().setVisible(!onceRepeatRB.getValue()); - eventDateStartField.setAllowBlank(true); + eventStartTimeField.setVisible(!dailyRepeatRB.getValue()); + eventEndTimeField.setVisible(!dailyRepeatRB.getValue()); +// eventDateStartField.setAllowBlank(false); +// eventDateStartField.setAllowBlank(true); ((TextArea) form.getItemByItemId(Event.DESCRIPTION)).setValue(" The Once event."); Window.alert(getOnceRepeatRB().getBoxLabel() + " is checked Listener OnChange on ONCE radio"); } @@ -244,9 +246,9 @@ public void handleEvent(FieldEvent event) { @Override public void handleEvent(FieldEvent event) { ((TextArea) form.getItemByItemId(Event.DESCRIPTION)).setValue(" The Daily event."); - eventStartTimeField.setVisible(!dailyRepeatRB.getValue()); - eventEndTimeField.setVisible(!dailyRepeatRB.getValue()); - eventDateStartField.setAllowBlank(false); +// eventStartTimeField.setVisible(!dailyRepeatRB.getValue()); +// eventEndTimeField.setVisible(!dailyRepeatRB.getValue()); +// eventDateStartField.setAllowBlank(false); getPanelYearly().setVisible(!dailyRepeatRB.getValue()); getPanelMonthly().setVisible(!dailyRepeatRB.getValue()); Window.alert(getDailyRepeatRB().getBoxLabel() + " is checked Listener OnChange on DAILY radio"); From 6ea5bca2de766977b6c29c961491fc07fe3a8c2f Mon Sep 17 00:00:00 2001 From: Seal98 Date: Thu, 15 Jun 2017 09:39:01 +0300 Subject: [PATCH 05/39] [WIP] Advanced calendar component (issue#852) Changes in 1 file: CalendarEventPresenter. Implemented functionality 'Add weekly events' - now repeating weekly events can be created. --- .../calendar/CalendarEventPresenter.java | 123 +++++++++++++++++- 1 file changed, 116 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java b/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java index ab2e3432e..c98469de5 100644 --- a/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java +++ b/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java @@ -129,6 +129,7 @@ public static interface View extends ViewInterface { Radio getRadioMonthlySameDayOfWeek(); + // void setShowAddEventView(boolean showAddEventView); } @@ -388,8 +389,14 @@ private void onSaveAction() { Boolean isYearlySameDayOfWeek = view.getYearlySameDayOfWeekRB().getValue(); Boolean isYearlySameDate = view.getYearlySameDateRB().getValue(); + + long milisPerDay = 86400000; //24 * 60 * 60 * 1000) + long milisPerWeek = 7* milisPerDay; //7 days * (24hour * 60minutes * 60seconds * 1000mili seconds) + long diffInMilis = endEventIntervalDate.getTime() - beginEventIntervalDate.getTime(); + + - if(isDailyRepeatEvent.booleanValue()){ + if(isDailyRepeatEvent){ // Map dailyProperties = new HashMap(); // dailyProperties.put(Event.CALENDAR_ID, calendarWrapper); // dailyProperties.put(Event.SUMMARY, view.getEventSummaryField().getValue()); @@ -400,10 +407,10 @@ private void onSaveAction() { */ int daysInterval = 0; - long milisPerDay = 86400000; //24 * 60 * 60 * 1000) - long diff = endEventIntervalDate.getTime() - beginEventIntervalDate.getTime(); +// long milisPerDay = 86400000; //24 * 60 * 60 * 1000) +// long diffInMilis = endEventIntervalDate.getTime() - beginEventIntervalDate.getTime(); - long daysDiff = diff / milisPerDay + 1; + long daysDiff = diffInMilis / milisPerDay + 1; daysInterval = (int) daysDiff; // java.util.Calendar is not supported by GWT !!! // java.util.Calendar calNextEventDate = java.util.Calendar.getInstance(); @@ -463,10 +470,111 @@ private void onSaveAction() { addPersonalEvent(dailyProperties); } - } - } + }else if(isWeeklyRepeatEvent){ + // long diffInMilis = endEventIntervalDate.getTime() - beginEventIntervalDate.getTime(); + long weekDiff = diffInMilis / milisPerWeek + 1; + int weeksInterval = (int) weekDiff; + + long calBeginNextEventDateLong = beginEventIntervalDate.getTime(); + Date calBeginNextEventDate = beginEventIntervalDate; + long calNextEventStartTime = startDate.getTime(); + long calNextEventEndTime = endDate.getTime(); + + if(weeksInterval>1){ + properties.put(Event.SUMMARY, (String)properties.get(Event.SUMMARY)+ " (Weekly event 1 of " + weeksInterval + ")"); + properties.put(Event.DESCRIPTION, (String)properties.get(Event.DESCRIPTION)+ " (Weekly event 1 of " + weeksInterval + ")"); + } + + for (int i = 1; i < weeksInterval; i++) { + + calBeginNextEventDateLong += milisPerWeek; + calBeginNextEventDate = new Date(calBeginNextEventDateLong); + calNextEventStartTime += milisPerWeek; + calNextEventEndTime += milisPerWeek; + + Map weeklyProperties = new HashMap(); + weeklyProperties.put(Event.CALENDAR_ID, calendarWrapper); + weeklyProperties.put(Event.SUMMARY, view.getEventSummaryField().getValue()); + + weeklyProperties.put(Event.DATE, calBeginNextEventDate); + weeklyProperties.put(Event.START_TIME, calNextEventStartTime); + weeklyProperties.put(Event.END_TIME, calNextEventEndTime); + + String newSummary = eventSummary; + String newDescription = eventDescription; + newSummary += " (Weekly event " + (i+1) + " of " + weeksInterval + ")"; + newDescription += " (Weekly event " + (i+1) + " of " + weeksInterval + ")"; + weeklyProperties.put(Event.SUMMARY, newSummary); + weeklyProperties.put(Event.DESCRIPTION, newDescription); + + addPersonalEvent(weeklyProperties); + } + } /*else if (isMonthlyRepeatEvent){ + + int yearStart = beginEventIntervalDate.getYear(); + int yearEnd = endEventIntervalDate.getYear(); + int yearInterval = yearEnd - yearStart; + + int monthStart = beginEventIntervalDate.getMonth();//0 Jan 11 Dec + int monthEnd = endEventIntervalDate.getMonth(); + int monthInterval = 0; + if (yearInterval > 0){ + monthInterval = (yearInterval-1)*12 + (11-monthStart) + (monthEnd + 0); + }else{ + monthInterval = monthEnd - monthStart; + } + + + int dateStart = beginEventIntervalDate.getDate(); + int dateEnd = endEventIntervalDate.getDate(); + + int dayStart = beginEventIntervalDate.getDay();//day of week + int dayEnd = endEventIntervalDate.getDay(); + + + if(monthInterval>1){ + properties.put(Event.SUMMARY, (String)properties.get(Event.SUMMARY)+ " (Monthly event 1 of " + monthInterval + ")"); + properties.put(Event.DESCRIPTION, (String)properties.get(Event.DESCRIPTION)+ " (Monthly event 1 of " + monthInterval + ")"); + } + + long calBeginNextEventDateLong = beginEventIntervalDate.getTime(); + Date calBeginNextEventDate = beginEventIntervalDate; + long calNextEventStartTime = startDate.getTime(); + long calNextEventEndTime = endDate.getTime(); + + for (int i = 1; i < monthInterval; i++) { + ////////////////////////////////// + if (calBeginNextEventDate.getMonth()) + calBeginNextEventDateLong += milisPerWeek; + calBeginNextEventDate = new Date(calBeginNextEventDateLong); + calNextEventStartTime += milisPerWeek; + calNextEventEndTime += milisPerWeek; + + Map monthlyProperties = new HashMap(); + monthlyProperties.put(Event.CALENDAR_ID, calendarWrapper); + monthlyProperties.put(Event.SUMMARY, view.getEventSummaryField().getValue()); + + monthlyProperties.put(Event.DATE, calBeginNextEventDate); + monthlyProperties.put(Event.START_TIME, calNextEventStartTime); + monthlyProperties.put(Event.END_TIME, calNextEventEndTime); + + String newSummary = eventSummary; + String newDescription = eventDescription; + newSummary += " (Monthly event " + (i + 1) + " of " + monthInterval + ")"; + newDescription += " (Monthly event " + (i + 1) + " of " + monthInterval + ")"; + monthlyProperties.put(Event.SUMMARY, newSummary); + monthlyProperties.put(Event.DESCRIPTION, newDescription); + + addPersonalEvent(monthlyProperties); + ////////////////////////////////// + } + + }////////////ELSE IF MONTHLY + */ //add first event addPersonalEvent(properties); + } + //Here process properties and define repetable events dates } else { editPersonalEvent(event, properties); @@ -474,13 +582,14 @@ private void onSaveAction() { // properties.remove(Event.END_TIME); //properties.remove(Event.DATE); } + // if (event == null) { // addPersonalEvent(properties); // // } else { // editPersonalEvent(event, properties); // } - } +} /** * Creates a new "Personal" calendar event. From c0a328ccd13a1b4db9ccd8865da12a913ebf1467 Mon Sep 17 00:00:00 2001 From: Seal98 Date: Wed, 21 Jun 2017 22:01:08 +0300 Subject: [PATCH 06/39] [WIP] Advanced calendar component (issue#852) Implemented functionality 'Add monthly events' 'Same date'. With next event date correction if last date of next month less than date of first event (f.e. first event is 31st January next will be 28th February and next 31st March --- .../calendar/CalendarEventPresenter.java | 199 ++++++++++++++---- .../ui/view/calendar/CalendarEventView.java | 3 +- 2 files changed, 158 insertions(+), 44 deletions(-) diff --git a/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java b/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java index c98469de5..bff055050 100644 --- a/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java +++ b/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java @@ -54,6 +54,8 @@ import com.allen_sauer.gwt.log.client.Log; import com.extjs.gxt.ui.client.event.ButtonEvent; import com.extjs.gxt.ui.client.event.SelectionListener; +//import com.extjs.gxt.ui.client.widget.Window; +import com.google.gwt.user.client.Window; import com.extjs.gxt.ui.client.widget.form.CheckBox; import com.extjs.gxt.ui.client.widget.form.DateField; import com.extjs.gxt.ui.client.widget.form.FieldSet; @@ -413,15 +415,7 @@ private void onSaveAction() { long daysDiff = diffInMilis / milisPerDay + 1; daysInterval = (int) daysDiff; // java.util.Calendar is not supported by GWT !!! -// java.util.Calendar calNextEventDate = java.util.Calendar.getInstance(); -// calNextEventDate.setTime(beginEventIntervalDate); -// -// java.util.Calendar calNextEventStartTime = java.util.Calendar.getInstance(); -// calNextEventStartTime.setTime(startDate); -// -// java.util.Calendar calNextEventEndTime = java.util.Calendar.getInstance(); -// calNextEventEndTime.setTime(endDate); - + long calBeginNextEventDateLong = beginEventIntervalDate.getTime(); Date calBeginNextEventDate = beginEventIntervalDate; long calNextEventStartTime = startDate.getTime(); @@ -446,20 +440,6 @@ private void onSaveAction() { dailyProperties.put(Event.DATE, calBeginNextEventDate); dailyProperties.put(Event.START_TIME, calNextEventStartTime); dailyProperties.put(Event.END_TIME, calNextEventEndTime); -// java.util.Calendar is not supported by GWT !!! -// calNextEventDate.add(java.util.Calendar.DATE, 1); -// nextEventDate = calNextEventDate.getTime(); -// -// calNextEventStartTime.add(java.util.Calendar.DATE, 1); -// nextEventStartTime = calNextEventStartTime.getTime(); -// -// calNextEventEndTime.add(java.util.Calendar.DATE, 1); -// nextEventEndTime = calNextEventEndTime.getTime(); -// -// //Date beginEventIntervalDate = view.getEventDateStartField().getValue(); -// dailyProperties.put(Event.DATE, nextEventDate); -// dailyProperties.put(Event.START_TIME, nextEventStartTime); -// dailyProperties.put(Event.END_TIME, nextEventEndTime); String newSummary = eventSummary; String newDescription = eventDescription; @@ -509,8 +489,10 @@ private void onSaveAction() { addPersonalEvent(weeklyProperties); } - } /*else if (isMonthlyRepeatEvent){ + } else if (isMonthlyRepeatEvent){ +Window.alert("MONTHLY : " + (isMonthlySameDayOfWeek?"Same Day of Week":"")+(isMonthlySameDate?"Sane DATE":"")); + int yearStart = beginEventIntervalDate.getYear(); int yearEnd = endEventIntervalDate.getYear(); int yearInterval = yearEnd - yearStart; @@ -519,17 +501,17 @@ private void onSaveAction() { int monthEnd = endEventIntervalDate.getMonth(); int monthInterval = 0; if (yearInterval > 0){ - monthInterval = (yearInterval-1)*12 + (11-monthStart) + (monthEnd + 0); + monthInterval = (yearInterval-1)*12 + (12-monthStart) + (monthEnd + 1); }else{ - monthInterval = monthEnd - monthStart; + monthInterval = monthEnd - monthStart + 1; } - int dateStart = beginEventIntervalDate.getDate(); - int dateEnd = endEventIntervalDate.getDate(); + //int dateStart = beginEventIntervalDate.getDate(); + // int dateEnd = endEventIntervalDate.getDate(); - int dayStart = beginEventIntervalDate.getDay();//day of week - int dayEnd = endEventIntervalDate.getDay(); + //int dayStart = beginEventIntervalDate.getDay();//day of week + // int dayEnd = endEventIntervalDate.getDay(); if(monthInterval>1){ @@ -537,27 +519,58 @@ private void onSaveAction() { properties.put(Event.DESCRIPTION, (String)properties.get(Event.DESCRIPTION)+ " (Monthly event 1 of " + monthInterval + ")"); } - long calBeginNextEventDateLong = beginEventIntervalDate.getTime(); + + //long calBeginNextEventDateLong = beginEventIntervalDate.getTime(); Date calBeginNextEventDate = beginEventIntervalDate; - long calNextEventStartTime = startDate.getTime(); - long calNextEventEndTime = endDate.getTime(); + // long calNextEventStartTime = startDate.getTime(); + // long calNextEventEndTime = endDate.getTime(); for (int i = 1; i < monthInterval; i++) { - ////////////////////////////////// - if (calBeginNextEventDate.getMonth()) - calBeginNextEventDateLong += milisPerWeek; - calBeginNextEventDate = new Date(calBeginNextEventDateLong); - calNextEventStartTime += milisPerWeek; - calNextEventEndTime += milisPerWeek; + calBeginNextEventDate = getMonthlySameDate(beginEventIntervalDate, calBeginNextEventDate, i); Map monthlyProperties = new HashMap(); monthlyProperties.put(Event.CALENDAR_ID, calendarWrapper); monthlyProperties.put(Event.SUMMARY, view.getEventSummaryField().getValue()); monthlyProperties.put(Event.DATE, calBeginNextEventDate); - monthlyProperties.put(Event.START_TIME, calNextEventStartTime); - monthlyProperties.put(Event.END_TIME, calNextEventEndTime); +// if (startDate != null) { +// startDate.setYear(calBeginNextEventDate.getYear()); +// startDate.setDate(10);// to prevent month slip past (f.e. 31 jan -> 3 march instead of 29 febr) +// startDate.setMonth(calBeginNextEventDate.getMonth()); +// startDate.setDate(calBeginNextEventDate.getDate()); +// monthlyProperties.put(Event.START_TIME, startDate.getTime()); +// } else { +// monthlyProperties.put(Event.START_TIME, null); +// } + if (startDate != null) { + calBeginNextEventDate.setHours(startDate.getHours()); + calBeginNextEventDate.setMinutes(startDate.getMinutes()); + monthlyProperties.put(Event.START_TIME, calBeginNextEventDate.getTime()); + }else{ + monthlyProperties.put(Event.START_TIME, null); + } + + + if (endDate != null) { + calBeginNextEventDate.setHours(endDate.getHours()); + calBeginNextEventDate.setMinutes(endDate.getMinutes()); + monthlyProperties.put(Event.END_TIME, calBeginNextEventDate.getTime()); + }else{ + monthlyProperties.put(Event.END_TIME, null); + } + + +// if (endDate != null) { +// endDate.setYear(calBeginNextEventDate.getYear()); +// endDate.setDate(10);// to prevent month slip past (f.e. 31 jan -> 3 march instead of 29 febr) +// endDate.setMonth(calBeginNextEventDate.getMonth()); +// endDate.setDate(calBeginNextEventDate.getDate()); +// monthlyProperties.put(Event.END_TIME, endDate.getTime()); +// } else { +// monthlyProperties.put(Event.END_TIME, null); +// } + String newSummary = eventSummary; String newDescription = eventDescription; newSummary += " (Monthly event " + (i + 1) + " of " + monthInterval + ")"; @@ -566,11 +579,10 @@ private void onSaveAction() { monthlyProperties.put(Event.DESCRIPTION, newDescription); addPersonalEvent(monthlyProperties); - ////////////////////////////////// } }////////////ELSE IF MONTHLY - */ + //add first event addPersonalEvent(properties); } @@ -732,4 +744,105 @@ private static boolean isFullDayEvent(final Event event) { .getYear() != event.getDtend().getYear()); } + @SuppressWarnings({"deprecation"}) + private Date getMonthlySameDayOfWeek(Date dateObject, int numberMonths) { + Date firstDate = new Date(); + firstDate.setYear(dateObject.getYear()); + firstDate.setMonth(dateObject.getMonth()); + firstDate.setDate(dateObject.getDate()); + +// int n = dateObject.getDate(); + dateObject.setDate(10);// to prevent month slip past (f.e. 31 jan -> 3 march instead of 29 febr) +// dateObject.setMonth(dateObject.getMonth() + numberMonths); + dateObject.setMonth(dateObject.getMonth() + 1); + //dateObject.setDate(Math.min(n, getDaysInMonth(dateObject.getYear(), dateObject.getMonth()))); + + int daysInStartDate = getDaysInMonth(firstDate.getYear(), firstDate.getMonth()); + //&& daysInStartDate >= getDaysInMonth(dateObject.getYear(),dateObject.getMonth()) + if (firstDate.getDate() == daysInStartDate) {//if last day of the month + dateObject.setDate(getDaysInMonth(dateObject.getYear(), dateObject.getMonth())); +// dateObject.setMonth(dateObject.getMonth() + 1); + } else { +// dateObject.setMonth(dateObject.getMonth() + 1); + //dateObject.setDate(dateObject.getDate());//?? + dateObject.setDate(firstDate.getDate());//?? + + } + + //Calculate same day of week + int dayOfFirst = firstDate.getDay(); + + int dayOfCurrent = dateObject.getDay(); + + Date newDate = new Date(); + Date curDate = dateObject; + int mil = 86400000; + + if (dayOfFirst > dayOfCurrent) { + newDate = new Date(curDate.getTime() + (dayOfFirst - dayOfCurrent) * mil); + if (newDate.getMonth() != curDate.getMonth()) { //> + newDate = new Date(curDate.getTime() - (7 - (dayOfFirst - dayOfCurrent)) * mil); + } + + } else if (dayOfFirst < dayOfCurrent) {//< + newDate = new Date(curDate.getTime() - (dayOfCurrent - dayOfFirst) * mil); + if (newDate.getMonth() != curDate.getMonth()) { + newDate = new Date(curDate.getTime() + (7 - (dayOfFirst - dayOfCurrent)) * mil); + } + } else { + newDate = new Date(curDate.getTime()); + } + + Window.alert("Date start: Month:" + firstDate.getMonth() + " | " + firstDate.getDay() + "| Date:" + getDaysInMonth(firstDate.getYear(), firstDate.getMonth()) + " ; " + firstDate.toLocaleString() + " : month " + numberMonths + ": Result " + " | " + dateObject.getDay() + " | " + dateObject.toLocaleString() + + " || " + newDate.getDay() + " || " + newDate.toLocaleString()); + + return newDate; + } + + @SuppressWarnings({"deprecation", "empty-statement"}) + public Date getMonthlySameDate(Date firstDate, Date dateObject, int numberMonths) { + Date nextDate = new Date(); + Date newDate = new Date(); + nextDate.setYear(dateObject.getYear()); + nextDate.setMonth(dateObject.getMonth() + 1); + nextDate.setDate(1);// to prevent month slip past (f.e. 31 jan -> 3 march instead of 29 febr) + newDate.setYear(dateObject.getYear()); + + int daysInNextDate = getDaysInMonth(nextDate.getYear(), nextDate.getMonth()); + + if (firstDate.getDate() <= daysInNextDate) {//if last day of the month + newDate.setMonth(0); + newDate.setDate(firstDate.getDate()); + newDate.setMonth(dateObject.getMonth() + 1); + + } else { + newDate.setDate(daysInNextDate); + newDate.setMonth(dateObject.getMonth() + 1); + + } + + Window.alert("Date start: Month:" + firstDate.getMonth() + + " | " + firstDate.getDay() + "| Date:" + getDaysInMonth(nextDate.getYear(), nextDate.getMonth()) + + " ; " + firstDate.toLocaleString() + " : month " + numberMonths + + ": Result " + " | " + newDate.getDay() + " | " + newDate.toLocaleString()); + + return newDate; + } + + private int getDaysInMonth(int year, int month) { + int daysInMonth; + + if (month == 3 || month == 5 || month == 8 || month == 10) { + return daysInMonth = 30; + } else if (month == 1) { + + return daysInMonth = (isLeapYear(year)) ? 29 : 28; + } else { + return daysInMonth = 31; + } + } + + private boolean isLeapYear(int year) { + return (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)); + } } \ No newline at end of file diff --git a/src/main/java/org/sigmah/client/ui/view/calendar/CalendarEventView.java b/src/main/java/org/sigmah/client/ui/view/calendar/CalendarEventView.java index b9362b695..c27cc53e9 100644 --- a/src/main/java/org/sigmah/client/ui/view/calendar/CalendarEventView.java +++ b/src/main/java/org/sigmah/client/ui/view/calendar/CalendarEventView.java @@ -359,13 +359,14 @@ private void createMonthlyPanel() { radioMonthlySameDayOfWeek.setName("radioMonthlySameDayOfWeek"); radioMonthlySameDayOfWeek.setValue(Boolean.FALSE); radioMonthlySameDayOfWeek.setOriginalValue(Boolean.FALSE); + radioMonthlySameDayOfWeek.setToolTip("Every next month at the same day of week. (with autochange to ...h)"); //Radio radioMonthlySameDate = new Radio(); - //Radio radioMonthlySameDate = Forms.radio("Same date"); radioMonthlySameDate.setBoxLabel("Same date"); radioMonthlySameDate.setName("radioMonthlySameDate"); radioMonthlySameDate.setValue(Boolean.FALSE); + radioMonthlySameDate.setToolTip("Every next month at the same date. (with autochange to last day of month)"); //montlyVariantRG= new RadioGroup(); montlyVariantRG = Forms.radioGroup("Montly settings 999"); From 239850f0694be947c6bd4d8a5ae8276b241e3d56 Mon Sep 17 00:00:00 2001 From: Seal98 Date: Thu, 22 Jun 2017 09:36:43 +0300 Subject: [PATCH 07/39] [WIP] Advanced calendar component (issue#852) Changed pom.xml to avoid too big log --- pom.xml | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/pom.xml b/pom.xml index bcdebf2f1..cd2c2e4c0 100644 --- a/pom.xml +++ b/pom.xml @@ -156,8 +156,8 @@ 1.8 - ALL - DETAILED + INFO + OBFUSCATED 9 true true @@ -201,13 +201,13 @@ [%-5level] {%d{dd/MM/yyyy HH:mm:ss.SSS}} [%thread] %logger{35} - %msg%n - ALL + ERROR jdbc:postgresql://localhost:5432/sigmah - postgres - admin + sigmah + sigmah @@ -885,8 +885,7 @@ org.jacoco jacoco-maven-plugin - 0.7.9 - + 0.7.4.201502262128 @@ -1059,11 +1058,6 @@ - jdbc:postgresql://localhost:5432/sigmah - postgres - admin - C:\\Users\\1\\Documents\\GitHub\\sigmah - C:\\Users\\1\\Documents\\GitHub\\sigmah\\archives @@ -1227,4 +1221,4 @@ - \ No newline at end of file + From 2927edcf437f02ccc1665e5a33a7717735636cb1 Mon Sep 17 00:00:00 2001 From: Seal98 Date: Thu, 22 Jun 2017 11:00:49 +0300 Subject: [PATCH 08/39] [WIP] Advanced calendar component (issue#852) Implemented functionality 'Add monthly events' with 'Same DAY of a week'. Next event date is corrected to be the same day of a week as the day of week of a first event of the event series. --- .../calendar/CalendarEventPresenter.java | 144 +++++++++++------- 1 file changed, 88 insertions(+), 56 deletions(-) diff --git a/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java b/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java index bff055050..b915706c4 100644 --- a/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java +++ b/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java @@ -381,6 +381,9 @@ private void onSaveAction() { */ Boolean isAllDayEvent = view.getAllDayCheckbox().getValue(); + + Window.alert("isAllDayEvent=" + isAllDayEvent);//temp for checker + Boolean isDailyRepeatEvent = view.getDailyRepeatRB() != null ? view.getDailyRepeatRB().getValue() : Boolean.FALSE; Boolean isWeeklyRepeatEvent = view.getWeeklyRepeatRB().getValue(); Boolean isMonthlyRepeatEvent = view.getMonthlyRepeatRB().getValue(); @@ -390,7 +393,10 @@ private void onSaveAction() { Boolean isMonthlySameDate = view.getRadioMonthlySameDate().getValue(); Boolean isYearlySameDayOfWeek = view.getYearlySameDayOfWeekRB().getValue(); - Boolean isYearlySameDate = view.getYearlySameDateRB().getValue(); + Boolean isYearlySameDate = view.getYearlySameDateRB().getValue(); + + Window.alert("isYearlySameDayOfWeek=" +isYearlySameDayOfWeek);//temp for checker + Window.alert("isYearlySameDate=" +isYearlySameDate);//temp for checker long milisPerDay = 86400000; //24 * 60 * 60 * 1000) long milisPerWeek = 7* milisPerDay; //7 days * (24hour * 60minutes * 60seconds * 1000mili seconds) @@ -491,7 +497,8 @@ private void onSaveAction() { } } else if (isMonthlyRepeatEvent){ -Window.alert("MONTHLY : " + (isMonthlySameDayOfWeek?"Same Day of Week":"")+(isMonthlySameDate?"Sane DATE":"")); +Window.alert("MONTHLY : " + (isMonthlySameDayOfWeek?"Same DAY of a Week":"") + +(isMonthlySameDate?"Same DATE":""));//temp for checker int yearStart = beginEventIntervalDate.getYear(); int yearEnd = endEventIntervalDate.getYear(); @@ -505,28 +512,17 @@ private void onSaveAction() { }else{ monthInterval = monthEnd - monthStart + 1; } - - - //int dateStart = beginEventIntervalDate.getDate(); - // int dateEnd = endEventIntervalDate.getDate(); - - //int dayStart = beginEventIntervalDate.getDay();//day of week - // int dayEnd = endEventIntervalDate.getDay(); - if(monthInterval>1){ properties.put(Event.SUMMARY, (String)properties.get(Event.SUMMARY)+ " (Monthly event 1 of " + monthInterval + ")"); properties.put(Event.DESCRIPTION, (String)properties.get(Event.DESCRIPTION)+ " (Monthly event 1 of " + monthInterval + ")"); } - - - //long calBeginNextEventDateLong = beginEventIntervalDate.getTime(); + Date calBeginNextEventDate = beginEventIntervalDate; - // long calNextEventStartTime = startDate.getTime(); - // long calNextEventEndTime = endDate.getTime(); for (int i = 1; i < monthInterval; i++) { - calBeginNextEventDate = getMonthlySameDate(beginEventIntervalDate, calBeginNextEventDate, i); + //calBeginNextEventDate = getMonthlySameDate(beginEventIntervalDate, calBeginNextEventDate, i); + calBeginNextEventDate = getMonthlySameDayOfWeek2(beginEventIntervalDate, calBeginNextEventDate, i, isMonthlySameDayOfWeek); Map monthlyProperties = new HashMap(); monthlyProperties.put(Event.CALENDAR_ID, calendarWrapper); @@ -534,15 +530,6 @@ private void onSaveAction() { monthlyProperties.put(Event.DATE, calBeginNextEventDate); -// if (startDate != null) { -// startDate.setYear(calBeginNextEventDate.getYear()); -// startDate.setDate(10);// to prevent month slip past (f.e. 31 jan -> 3 march instead of 29 febr) -// startDate.setMonth(calBeginNextEventDate.getMonth()); -// startDate.setDate(calBeginNextEventDate.getDate()); -// monthlyProperties.put(Event.START_TIME, startDate.getTime()); -// } else { -// monthlyProperties.put(Event.START_TIME, null); -// } if (startDate != null) { calBeginNextEventDate.setHours(startDate.getHours()); calBeginNextEventDate.setMinutes(startDate.getMinutes()); @@ -559,22 +546,11 @@ private void onSaveAction() { }else{ monthlyProperties.put(Event.END_TIME, null); } - - -// if (endDate != null) { -// endDate.setYear(calBeginNextEventDate.getYear()); -// endDate.setDate(10);// to prevent month slip past (f.e. 31 jan -> 3 march instead of 29 febr) -// endDate.setMonth(calBeginNextEventDate.getMonth()); -// endDate.setDate(calBeginNextEventDate.getDate()); -// monthlyProperties.put(Event.END_TIME, endDate.getTime()); -// } else { -// monthlyProperties.put(Event.END_TIME, null); -// } String newSummary = eventSummary; String newDescription = eventDescription; newSummary += " (Monthly event " + (i + 1) + " of " + monthInterval + ")"; - newDescription += " (Monthly event " + (i + 1) + " of " + monthInterval + ")"; + newDescription += " (Monthly "+(isMonthlySameDayOfWeek?"same Day of a week ":"same Date ")+"event " + (i + 1) + " of " + monthInterval + ")"; monthlyProperties.put(Event.SUMMARY, newSummary); monthlyProperties.put(Event.DESCRIPTION, newDescription); @@ -745,28 +721,22 @@ private static boolean isFullDayEvent(final Event event) { } @SuppressWarnings({"deprecation"}) - private Date getMonthlySameDayOfWeek(Date dateObject, int numberMonths) { + +private Date getMonthlySameDayOfWeek(Date dateObject, int numberMonths) { Date firstDate = new Date(); firstDate.setYear(dateObject.getYear()); firstDate.setMonth(dateObject.getMonth()); firstDate.setDate(dateObject.getDate()); -// int n = dateObject.getDate(); dateObject.setDate(10);// to prevent month slip past (f.e. 31 jan -> 3 march instead of 29 febr) -// dateObject.setMonth(dateObject.getMonth() + numberMonths); dateObject.setMonth(dateObject.getMonth() + 1); - //dateObject.setDate(Math.min(n, getDaysInMonth(dateObject.getYear(), dateObject.getMonth()))); int daysInStartDate = getDaysInMonth(firstDate.getYear(), firstDate.getMonth()); - //&& daysInStartDate >= getDaysInMonth(dateObject.getYear(),dateObject.getMonth()) + if (firstDate.getDate() == daysInStartDate) {//if last day of the month dateObject.setDate(getDaysInMonth(dateObject.getYear(), dateObject.getMonth())); -// dateObject.setMonth(dateObject.getMonth() + 1); } else { -// dateObject.setMonth(dateObject.getMonth() + 1); - //dateObject.setDate(dateObject.getDate());//?? dateObject.setDate(firstDate.getDate());//?? - } //Calculate same day of week @@ -793,8 +763,9 @@ private Date getMonthlySameDayOfWeek(Date dateObject, int numberMonths) { newDate = new Date(curDate.getTime()); } - Window.alert("Date start: Month:" + firstDate.getMonth() + " | " + firstDate.getDay() + "| Date:" + getDaysInMonth(firstDate.getYear(), firstDate.getMonth()) + " ; " + firstDate.toLocaleString() + " : month " + numberMonths + ": Result " + " | " + dateObject.getDay() + " | " + dateObject.toLocaleString() - + " || " + newDate.getDay() + " || " + newDate.toLocaleString()); + Window.alert("Date start: Month:" + firstDate.getMonth() + + " | " + firstDate.getDay() + "| Date:" + getDaysInMonth(firstDate.getYear(), firstDate.getMonth()) + " ; " + firstDate.toLocaleString() + " : month " + numberMonths + ": Result " + " | " + dateObject.getDay() + " | " + dateObject.toLocaleString() + + " || " + newDate.getDay() + " || " + newDate.toLocaleString());//temp for checker return newDate; } @@ -824,21 +795,82 @@ public Date getMonthlySameDate(Date firstDate, Date dateObject, int numberMonths Window.alert("Date start: Month:" + firstDate.getMonth() + " | " + firstDate.getDay() + "| Date:" + getDaysInMonth(nextDate.getYear(), nextDate.getMonth()) + " ; " + firstDate.toLocaleString() + " : month " + numberMonths - + ": Result " + " | " + newDate.getDay() + " | " + newDate.toLocaleString()); + + ": Result " + " | " + newDate.getDay() + " | " + newDate.toLocaleString());//temp for checker return newDate; } - private int getDaysInMonth(int year, int month) { - int daysInMonth; + public Date getMonthlySameDayOfWeek2(Date firstDate, Date dateObject, int numberMonths, boolean isSameDayOfWeek) { + + Date nextDate = new Date(); + Date newDate = new Date(); + nextDate.setYear(dateObject.getYear()); + nextDate.setMonth(dateObject.getMonth() + 1); + nextDate.setDate(1);// to prevent month slip past (f.e. 31 jan -> 3 march instead of 29 febr) + newDate.setYear(dateObject.getYear()); - if (month == 3 || month == 5 || month == 8 || month == 10) { - return daysInMonth = 30; - } else if (month == 1) { + int daysInNextDate = getDaysInMonth(nextDate.getYear(), nextDate.getMonth()); + + if (firstDate.getDate() <= daysInNextDate) {//if last day of the month + newDate.setMonth(0); + newDate.setDate(firstDate.getDate()); + newDate.setMonth(dateObject.getMonth() + 1); - return daysInMonth = (isLeapYear(year)) ? 29 : 28; } else { - return daysInMonth = 31; + newDate.setDate(daysInNextDate); + newDate.setMonth(dateObject.getMonth() + 1); + + } + if (isSameDayOfWeek) { + //Calculate same day of week + int dayOfFirst = firstDate.getDay(); + + int dayOfCurrent = newDate.getDay(); + + Date curDate = newDate; + int mil = 86400000; + Date newDate2 = new Date(); + + if (dayOfFirst > dayOfCurrent) { + newDate2 = new Date(curDate.getTime() + (dayOfFirst - dayOfCurrent) * mil); + if (newDate2.getMonth() != curDate.getMonth()) { //> + newDate2 = new Date(curDate.getTime() - (7 - (dayOfFirst - dayOfCurrent)) * mil); + } + + } else if (dayOfFirst < dayOfCurrent) {//< + newDate2 = new Date(curDate.getTime() - (dayOfCurrent - dayOfFirst) * mil); + if (newDate2.getMonth() != curDate.getMonth()) { + newDate2 = new Date(curDate.getTime() + (7 - (dayOfFirst - dayOfCurrent)) * mil); + } + } else { + newDate2 = new Date(curDate.getTime()); + } + + //return newDate2; + newDate = newDate2; + } + Window.alert((isSameDayOfWeek ? "Same week DAY " : "Same DATE ") + "Date start: Month:" + firstDate.getMonth() + " | " + firstDate.getDay() + + "| " + getDaysInMonth(firstDate.getYear(), firstDate.getMonth()) + + " | " + firstDate.toLocaleString() + " | i= " + numberMonths + " | RESULT | Prev | " + + dateObject.getDay() + " | " + dateObject.toLocaleString() + + " || New | " + newDate.getDay() + " | " + newDate.toLocaleString());//temp for checker + + return newDate; + } + + private int getDaysInMonth(int year, int month) { + int daysInMonth; + + switch (month) { + case 3: + case 5: + case 8: + case 10: + return daysInMonth = 30; + case 1: + return daysInMonth = (isLeapYear(year)) ? 29 : 28; + default: + return daysInMonth = 31; } } From 8c59bb4707b8701a53eb32304cb4cf0b2cf6430a Mon Sep 17 00:00:00 2001 From: Seal98 Date: Thu, 22 Jun 2017 23:14:58 +0300 Subject: [PATCH 09/39] [WIP] Advanced calendar component (issue#852) Implemented functionality 'Add monthly events' 'Same Date of week'. Next event date corrected if day of week of next month not the same as a daye of week of first event (f.e. first event is on Monday the event on Next month will also on Monday) --- .../client/ui/presenter/calendar/CalendarEventPresenter.java | 3 +-- .../org/sigmah/client/ui/view/calendar/CalendarEventView.java | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java b/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java index b915706c4..1d889efe3 100644 --- a/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java +++ b/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java @@ -720,8 +720,7 @@ private static boolean isFullDayEvent(final Event event) { .getYear() != event.getDtend().getYear()); } - @SuppressWarnings({"deprecation"}) - +@SuppressWarnings({"deprecation"}) private Date getMonthlySameDayOfWeek(Date dateObject, int numberMonths) { Date firstDate = new Date(); firstDate.setYear(dateObject.getYear()); diff --git a/src/main/java/org/sigmah/client/ui/view/calendar/CalendarEventView.java b/src/main/java/org/sigmah/client/ui/view/calendar/CalendarEventView.java index c27cc53e9..98498a1b0 100644 --- a/src/main/java/org/sigmah/client/ui/view/calendar/CalendarEventView.java +++ b/src/main/java/org/sigmah/client/ui/view/calendar/CalendarEventView.java @@ -353,7 +353,7 @@ private void createMonthlyPanel() { panelMonthly.setVisible(false); //Radio radioMonthlySameDayOfWeek = new Radio(); - //Radio + radioMonthlySameDayOfWeek = Forms.radio("Same day of week"); //radioMonthlySameDayOfWeek.setBoxLabel("Same day of week"); radioMonthlySameDayOfWeek.setName("radioMonthlySameDayOfWeek"); From 90159b87a1e2f519631193cae908f3df57529726 Mon Sep 17 00:00:00 2001 From: Seal98 Date: Fri, 23 Jun 2017 11:15:06 +0300 Subject: [PATCH 10/39] [WIP] Advanced calendar component (issue#852) Implemented functionality 'Add monthly events' with: 1)'Same DAY of an YEAR' : Next event date is corrected to be the same day of a week as the day of week of a first event of the event series. 2)'Same DATE of an YEAR' Next event date is corrected to last month day (f.e. if first event created for 29 Feb 2020 next event will be 28 Feb 2021 etc) --- .../calendar/CalendarEventPresenter.java | 152 +++++++++++++++++- 1 file changed, 150 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java b/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java index 1d889efe3..7d7c0c2fd 100644 --- a/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java +++ b/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java @@ -558,6 +558,70 @@ private void onSaveAction() { } }////////////ELSE IF MONTHLY + else if (isYearlyRepeatEvent){ + +Window.alert("YEARLY : " + (isYearlySameDayOfWeek?"Same DAY of a Week":"") + +(isYearlySameDate?"Same DATE":""));//temp for checker + + int yearStart = beginEventIntervalDate.getYear(); + int yearEnd = endEventIntervalDate.getYear(); + int yearInterval = yearEnd - yearStart + 1; + + int monthStart = beginEventIntervalDate.getMonth();//0 Jan 11 Dec + int monthEnd = endEventIntervalDate.getMonth(); + int monthInterval = 0; + if (yearInterval > 0){ + monthInterval = (yearInterval-1)*12 + (12-monthStart) + (monthEnd + 1); + }else{ + monthInterval = monthEnd - monthStart + 1; + } + + if(yearInterval>1){ + properties.put(Event.SUMMARY, (String)properties.get(Event.SUMMARY)+ " (Yearly event 1 of " + yearInterval + ")"); + properties.put(Event.DESCRIPTION, (String)properties.get(Event.DESCRIPTION)+ " (Yearly event 1 of " + yearInterval + ")"); + } + + Date calBeginNextEventDate = beginEventIntervalDate; + + for (int i = 1; i < yearInterval; i++) { + //calBeginNextEventDate = getMonthlySameDate(beginEventIntervalDate, calBeginNextEventDate, i); + //calBeginNextEventDate = getMonthlySameDayOfWeek2(beginEventIntervalDate, calBeginNextEventDate, i, isMonthlySameDayOfWeek); + calBeginNextEventDate = getYearlySameDayOfWeek(beginEventIntervalDate, calBeginNextEventDate, i, isYearlySameDayOfWeek); + + Map yearlyProperties = new HashMap(); + yearlyProperties.put(Event.CALENDAR_ID, calendarWrapper); + yearlyProperties.put(Event.SUMMARY, view.getEventSummaryField().getValue()); + + yearlyProperties.put(Event.DATE, calBeginNextEventDate); + + if (startDate != null) { + calBeginNextEventDate.setHours(startDate.getHours()); + calBeginNextEventDate.setMinutes(startDate.getMinutes()); + yearlyProperties.put(Event.START_TIME, calBeginNextEventDate.getTime()); + }else{ + yearlyProperties.put(Event.START_TIME, null); + } + + + if (endDate != null) { + calBeginNextEventDate.setHours(endDate.getHours()); + calBeginNextEventDate.setMinutes(endDate.getMinutes()); + yearlyProperties.put(Event.END_TIME, calBeginNextEventDate.getTime()); + }else{ + yearlyProperties.put(Event.END_TIME, null); + } + + String newSummary = eventSummary; + String newDescription = eventDescription; + newSummary += " (Yearly event " + (i + 1) + " of " + monthInterval + ")"; + newDescription += " (Yearly "+(isYearlySameDayOfWeek?"same Day of a week ":"same Date ")+"event " + (i + 1) + " of " + yearInterval + ")"; + yearlyProperties.put(Event.SUMMARY, newSummary); + yearlyProperties.put(Event.DESCRIPTION, newDescription); + + addPersonalEvent(yearlyProperties); + } + + } //add first event addPersonalEvent(properties); @@ -839,7 +903,8 @@ public Date getMonthlySameDayOfWeek2(Date firstDate, Date dateObject, int number } else if (dayOfFirst < dayOfCurrent) {//< newDate2 = new Date(curDate.getTime() - (dayOfCurrent - dayOfFirst) * mil); if (newDate2.getMonth() != curDate.getMonth()) { - newDate2 = new Date(curDate.getTime() + (7 - (dayOfFirst - dayOfCurrent)) * mil); + //newDate2 = new Date(curDate.getTime() + (7 - (dayOfFirst - dayOfCurrent)) * mil); + newDate2 = new Date(curDate.getTime() + (7 - (dayOfCurrent - dayOfFirst)) * mil); } } else { newDate2 = new Date(curDate.getTime()); @@ -848,7 +913,7 @@ public Date getMonthlySameDayOfWeek2(Date firstDate, Date dateObject, int number //return newDate2; newDate = newDate2; } - Window.alert((isSameDayOfWeek ? "Same week DAY " : "Same DATE ") + "Date start: Month:" + firstDate.getMonth() + " | " + firstDate.getDay() + Window.alert("Monthly " + (isSameDayOfWeek ? "Same week DAY " : "Same DATE ") + "Date start: Month:" + firstDate.getMonth() + " | " + firstDate.getDay() + "| " + getDaysInMonth(firstDate.getYear(), firstDate.getMonth()) + " | " + firstDate.toLocaleString() + " | i= " + numberMonths + " | RESULT | Prev | " + dateObject.getDay() + " | " + dateObject.toLocaleString() @@ -857,6 +922,89 @@ public Date getMonthlySameDayOfWeek2(Date firstDate, Date dateObject, int number return newDate; } + @SuppressWarnings({"deprecation"}) + public Date getYearlySameDayOfWeek(Date firstDate, Date dateObject, int numberMonths, boolean isSameDayOfWeek) { +// Date firstDate = new Date(); +// firstDate.setYear(dateObject.getYear());; +// firstDate.setMonth(dateObject.getMonth()); +// firstDate.setDate(dateObject.getDate()); +// + + Date nextDate = new Date(); + nextDate.setYear(dateObject.getYear());; + nextDate.setMonth(dateObject.getMonth()); + nextDate.setDate(dateObject.getDate()); + + nextDate.setDate(1); +// nextDate.setMonth(dateObject.getMonth()); + nextDate.setYear(dateObject.getYear() + 1); + + +// Date nextDate = new Date(); +// Date newDate = new Date(); +// nextDate.setYear(dateObject.getYear()); +// nextDate.setMonth(dateObject.getMonth() + 1); +// nextDate.setDate(1);// to prevent month slip past (f.e. 31 jan -> 3 march instead of 29 febr) +// newDate.setYear(dateObject.getYear()); + + int daysInNextDate = getDaysInMonth(nextDate.getYear(), nextDate.getMonth()); + + if (firstDate.getDate() >= daysInNextDate) {//if last day of the month + //nextDate.setDate(firstDate.getDate());//?? + //nextDate.setDate(getDaysInMonth(dateObject.getYear(),dateObject.getMonth())); + nextDate.setDate(daysInNextDate); + + } else { + //nextDate.setDate(getDaysInMonth(dateObject.getYear(),dateObject.getMonth())); + //nextDate.setDate(firstDate.getDate());//?? + nextDate.setDate(firstDate.getDate()); + + } + + if (isSameDayOfWeek) { + + + //Calculate same day of week + int dayOfFirst = firstDate.getDay(); + + int dayOfCurrent = nextDate.getDay(); + + Date newDate = new Date(); + Date curDate = nextDate; + int mil = 86400000; + + if (dayOfFirst > dayOfCurrent) { + newDate = new Date(curDate.getTime() + (dayOfFirst - dayOfCurrent) + * mil); + if (newDate.getMonth() != curDate.getMonth()) { // > + newDate = new Date(curDate.getTime() + - (7 - (dayOfFirst - dayOfCurrent)) * mil); + } + + } else if (dayOfFirst < dayOfCurrent) {// < + newDate = new Date(curDate.getTime() - (dayOfCurrent - dayOfFirst) + * mil); + if (newDate.getMonth() != curDate.getMonth()) { + int dif = (dayOfFirst - dayOfCurrent) < 0 ? -(dayOfFirst - dayOfCurrent) : (dayOfFirst - dayOfCurrent); + newDate = new Date(curDate.getTime() + + (7 - dif) * mil); + } + } else { + newDate = new Date(curDate.getTime()); + } + + nextDate = newDate; + } + + Window.alert("Yearly " + (isSameDayOfWeek ? "Same week DAY " : "Same DATE ") + "Date start: Month:" + firstDate.getMonth() + " | " + firstDate.getDay() + + "| " + getDaysInMonth(firstDate.getYear(), firstDate.getMonth()) + + " | " + firstDate.toLocaleString() + " | i= " + numberMonths + " | RESULT | Prev | " + + dateObject.getDay() + " | " + dateObject.toLocaleString() + + " || New | " + nextDate.getDay() + " | " + nextDate.toLocaleString());//temp for checker + + return nextDate; + } + private int getDaysInMonth(int year, int month) { int daysInMonth; From 2678435904ea78ccc47b7427c3e5e7deb9757b2b Mon Sep 17 00:00:00 2001 From: Seal98 Date: Sun, 25 Jun 2017 20:37:47 +0300 Subject: [PATCH 11/39] [WIP] Advanced calendar component (issue#852) Refactoring of CalendarEventPresenter class --- .../calendar/CalendarEventPresenter.java | 891 +++++++++++------- 1 file changed, 542 insertions(+), 349 deletions(-) diff --git a/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java b/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java index 7d7c0c2fd..de5f71e35 100644 --- a/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java +++ b/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java @@ -83,52 +83,148 @@ public class CalendarEventPresenter extends AbstractPagePresenter getEventSummaryField(); + /** + * + * @return + */ DateField getEventDateStartField(); + /** + * + * @return + */ DateField getEventDateEndField(); + /** + * + * @return + */ TimeField getEventStartTimeField(); + /** + * + * @return + */ TimeField getEventEndTimeField(); + /** + * + * @return + */ TextArea getEventDescriptionField(); + /** + * + * @return + */ Button getSaveButton(); + /** + * + * @return + */ Button getCancelButton(); + /** + * + * @return + */ CheckBox getAllDayCheckbox(); + /** + * + * @return + */ FieldSet getPanelYearly(); + /** + * + * @return + */ FieldSet getPanelMonthly(); + /** + * + * @return + */ Radio getOnceRepeatRB(); + /** + * + * @return + */ Radio getDailyRepeatRB(); + /** + * + * @return + */ Radio getWeeklyRepeatRB(); + /** + * + * @return + */ Radio getMonthlyRepeatRB(); + /** + * + * @return + */ Radio getYearlyRepeatRB(); + /** + * + * @return + */ RadioGroup getYearlyVariantRG(); + /** + * + * @return + */ RadioGroup getMontlyVariantRG(); + /** + * + * @return + */ Radio getYearlySameDayOfWeekRB(); + /** + * + * @return + */ Radio getYearlySameDateRB(); + /** + * + * @return + */ RadioGroup getRepeatEventPeriodRG(); + /** + * + * @return + */ Radio getRadioMonthlySameDate(); + /** + * + * @return + */ Radio getRadioMonthlySameDayOfWeek(); @@ -343,9 +439,22 @@ private void onSaveAction() { final Date beginEventIntervalDate = view.getEventDateStartField().getValue(); properties.put(Event.DATE, beginEventIntervalDate); - final Date endEventIntervalDate = view.getEventDateEndField().getValue(); + //final + Date endEventIntervalDate = view.getEventDateEndField().getValue(); + if(endEventIntervalDate == null){ + endEventIntervalDate = beginEventIntervalDate; + } + + + Boolean isAllDayEvent = view.getAllDayCheckbox().getValue(); + + Window.alert("isAllDayEvent=" + isAllDayEvent);//temp for checker - final Date startDate = view.getEventStartTimeField().getDateValue(); + //final + Date startDate = null; //view.getEventStartTimeField().getDateValue(); + if (!isAllDayEvent) { + startDate = view.getEventStartTimeField().getDateValue(); + } if (startDate != null) { startDate.setYear(beginEventIntervalDate.getYear()); startDate.setMonth(beginEventIntervalDate.getMonth()); @@ -355,7 +464,12 @@ private void onSaveAction() { properties.put(Event.START_TIME, null); } - final Date endDate = view.getEventEndTimeField().getDateValue(); + //final + Date endDate = null;//view.getEventEndTimeField().getDateValue(); + if (isAllDayEvent) { + //endDate = null; + endDate = view.getEventEndTimeField().getDateValue(); + } if (endDate != null) { endDate.setYear(beginEventIntervalDate.getYear()); endDate.setMonth(beginEventIntervalDate.getMonth()); @@ -369,7 +483,8 @@ private void onSaveAction() { if (event == null) { Boolean isOnceRepeatEvent = view.getOnceRepeatRB().getValue(); - if(!isOnceRepeatEvent.booleanValue()){ + Window.alert("isOnceRepeatEvent=" + isOnceRepeatEvent);//temp for checker + //if(!isOnceRepeatEvent.booleanValue()){ //Here process properties and define repetable events dates /*take parameters from View Start Date, get End beginEventIntervalDate, period settings like Once, Daily, Monthly etc @@ -380,9 +495,9 @@ private void onSaveAction() { after that in cycle add new events */ - Boolean isAllDayEvent = view.getAllDayCheckbox().getValue(); - - Window.alert("isAllDayEvent=" + isAllDayEvent);//temp for checker +// Boolean isAllDayEvent = view.getAllDayCheckbox().getValue(); +// +// Window.alert("isAllDayEvent=" + isAllDayEvent);//temp for checker Boolean isDailyRepeatEvent = view.getDailyRepeatRB() != null ? view.getDailyRepeatRB().getValue() : Boolean.FALSE; Boolean isWeeklyRepeatEvent = view.getWeeklyRepeatRB().getValue(); @@ -393,239 +508,32 @@ private void onSaveAction() { Boolean isMonthlySameDate = view.getRadioMonthlySameDate().getValue(); Boolean isYearlySameDayOfWeek = view.getYearlySameDayOfWeekRB().getValue(); - Boolean isYearlySameDate = view.getYearlySameDateRB().getValue(); + Boolean isYearlySameDate = view.getYearlySameDateRB().getValue(); - Window.alert("isYearlySameDayOfWeek=" +isYearlySameDayOfWeek);//temp for checker - Window.alert("isYearlySameDate=" +isYearlySameDate);//temp for checker - - long milisPerDay = 86400000; //24 * 60 * 60 * 1000) - long milisPerWeek = 7* milisPerDay; //7 days * (24hour * 60minutes * 60seconds * 1000mili seconds) - long diffInMilis = endEventIntervalDate.getTime() - beginEventIntervalDate.getTime(); + Window.alert("isYearlySameDayOfWeek=" + isYearlySameDayOfWeek);//temp for checker + Window.alert("isYearlySameDate=" + isYearlySameDate);//temp for checker - - + long milisPerDay = 86400000; //24 * 60 * 60 * 1000) + long milisPerWeek = 7 * milisPerDay; //7 days * (24hour * 60minutes * 60seconds * 1000mili seconds) + long diffInMilis = endEventIntervalDate.getTime() - beginEventIntervalDate.getTime(); + if(isDailyRepeatEvent){ -// Map dailyProperties = new HashMap(); -// dailyProperties.put(Event.CALENDAR_ID, calendarWrapper); -// dailyProperties.put(Event.SUMMARY, view.getEventSummaryField().getValue()); -/// - /* - 1. find number of days between start and end - 2. in cycle create new event - */ - int daysInterval = 0; - -// long milisPerDay = 86400000; //24 * 60 * 60 * 1000) -// long diffInMilis = endEventIntervalDate.getTime() - beginEventIntervalDate.getTime(); - - long daysDiff = diffInMilis / milisPerDay + 1; - daysInterval = (int) daysDiff; -// java.util.Calendar is not supported by GWT !!! - - long calBeginNextEventDateLong = beginEventIntervalDate.getTime(); - Date calBeginNextEventDate = beginEventIntervalDate; - long calNextEventStartTime = startDate.getTime(); - long calNextEventEndTime = endDate.getTime(); - - if(daysInterval>1){ - properties.put(Event.SUMMARY, (String)properties.get(Event.SUMMARY)+ " (Daily event 1 of " + daysInterval + ")"); - properties.put(Event.DESCRIPTION, (String)properties.get(Event.DESCRIPTION)+ " (Daily event 1 of " + daysInterval + ")"); - } - - for (int i = 1; i < daysInterval; i++) { - - calBeginNextEventDateLong += milisPerDay; - calBeginNextEventDate = new Date(calBeginNextEventDateLong); - calNextEventStartTime += milisPerDay; - calNextEventEndTime += milisPerDay; - - Map dailyProperties = new HashMap(); - dailyProperties.put(Event.CALENDAR_ID, calendarWrapper); - dailyProperties.put(Event.SUMMARY, view.getEventSummaryField().getValue()); - - dailyProperties.put(Event.DATE, calBeginNextEventDate); - dailyProperties.put(Event.START_TIME, calNextEventStartTime); - dailyProperties.put(Event.END_TIME, calNextEventEndTime); - - String newSummary = eventSummary; - String newDescription = eventDescription; - newSummary += " (Daily event " + (i+1) + " of " + daysInterval + ")"; - newDescription += " (Daily event " + (i+1) + " of " + daysInterval + ")"; - dailyProperties.put(Event.SUMMARY, newSummary); - dailyProperties.put(Event.DESCRIPTION, newDescription); - - addPersonalEvent(dailyProperties); - } - }else if(isWeeklyRepeatEvent){ - // long diffInMilis = endEventIntervalDate.getTime() - beginEventIntervalDate.getTime(); - long weekDiff = diffInMilis / milisPerWeek + 1; - int weeksInterval = (int) weekDiff; - - long calBeginNextEventDateLong = beginEventIntervalDate.getTime(); - Date calBeginNextEventDate = beginEventIntervalDate; - long calNextEventStartTime = startDate.getTime(); - long calNextEventEndTime = endDate.getTime(); - - if(weeksInterval>1){ - properties.put(Event.SUMMARY, (String)properties.get(Event.SUMMARY)+ " (Weekly event 1 of " + weeksInterval + ")"); - properties.put(Event.DESCRIPTION, (String)properties.get(Event.DESCRIPTION)+ " (Weekly event 1 of " + weeksInterval + ")"); - } - - for (int i = 1; i < weeksInterval; i++) { - - calBeginNextEventDateLong += milisPerWeek; - calBeginNextEventDate = new Date(calBeginNextEventDateLong); - calNextEventStartTime += milisPerWeek; - calNextEventEndTime += milisPerWeek; - - Map weeklyProperties = new HashMap(); - weeklyProperties.put(Event.CALENDAR_ID, calendarWrapper); - weeklyProperties.put(Event.SUMMARY, view.getEventSummaryField().getValue()); - - weeklyProperties.put(Event.DATE, calBeginNextEventDate); - weeklyProperties.put(Event.START_TIME, calNextEventStartTime); - weeklyProperties.put(Event.END_TIME, calNextEventEndTime); - - String newSummary = eventSummary; - String newDescription = eventDescription; - newSummary += " (Weekly event " + (i+1) + " of " + weeksInterval + ")"; - newDescription += " (Weekly event " + (i+1) + " of " + weeksInterval + ")"; - weeklyProperties.put(Event.SUMMARY, newSummary); - weeklyProperties.put(Event.DESCRIPTION, newDescription); - - addPersonalEvent(weeklyProperties); - } + processDailyEvents(diffInMilis, milisPerDay, beginEventIntervalDate, startDate, endDate, properties, eventSummary, eventDescription); + } else if (isWeeklyRepeatEvent){ + processWeeklyEvents(diffInMilis, milisPerWeek, beginEventIntervalDate, startDate, endDate, properties, eventSummary, eventDescription); } else if (isMonthlyRepeatEvent){ - -Window.alert("MONTHLY : " + (isMonthlySameDayOfWeek?"Same DAY of a Week":"") - +(isMonthlySameDate?"Same DATE":""));//temp for checker - - int yearStart = beginEventIntervalDate.getYear(); - int yearEnd = endEventIntervalDate.getYear(); - int yearInterval = yearEnd - yearStart; - - int monthStart = beginEventIntervalDate.getMonth();//0 Jan 11 Dec - int monthEnd = endEventIntervalDate.getMonth(); - int monthInterval = 0; - if (yearInterval > 0){ - monthInterval = (yearInterval-1)*12 + (12-monthStart) + (monthEnd + 1); - }else{ - monthInterval = monthEnd - monthStart + 1; - } - - if(monthInterval>1){ - properties.put(Event.SUMMARY, (String)properties.get(Event.SUMMARY)+ " (Monthly event 1 of " + monthInterval + ")"); - properties.put(Event.DESCRIPTION, (String)properties.get(Event.DESCRIPTION)+ " (Monthly event 1 of " + monthInterval + ")"); - } - - Date calBeginNextEventDate = beginEventIntervalDate; - - for (int i = 1; i < monthInterval; i++) { - //calBeginNextEventDate = getMonthlySameDate(beginEventIntervalDate, calBeginNextEventDate, i); - calBeginNextEventDate = getMonthlySameDayOfWeek2(beginEventIntervalDate, calBeginNextEventDate, i, isMonthlySameDayOfWeek); - - Map monthlyProperties = new HashMap(); - monthlyProperties.put(Event.CALENDAR_ID, calendarWrapper); - monthlyProperties.put(Event.SUMMARY, view.getEventSummaryField().getValue()); - - monthlyProperties.put(Event.DATE, calBeginNextEventDate); - - if (startDate != null) { - calBeginNextEventDate.setHours(startDate.getHours()); - calBeginNextEventDate.setMinutes(startDate.getMinutes()); - monthlyProperties.put(Event.START_TIME, calBeginNextEventDate.getTime()); - }else{ - monthlyProperties.put(Event.START_TIME, null); - } - - - if (endDate != null) { - calBeginNextEventDate.setHours(endDate.getHours()); - calBeginNextEventDate.setMinutes(endDate.getMinutes()); - monthlyProperties.put(Event.END_TIME, calBeginNextEventDate.getTime()); - }else{ - monthlyProperties.put(Event.END_TIME, null); - } - - String newSummary = eventSummary; - String newDescription = eventDescription; - newSummary += " (Monthly event " + (i + 1) + " of " + monthInterval + ")"; - newDescription += " (Monthly "+(isMonthlySameDayOfWeek?"same Day of a week ":"same Date ")+"event " + (i + 1) + " of " + monthInterval + ")"; - monthlyProperties.put(Event.SUMMARY, newSummary); - monthlyProperties.put(Event.DESCRIPTION, newDescription); - - addPersonalEvent(monthlyProperties); - } - - }////////////ELSE IF MONTHLY - else if (isYearlyRepeatEvent){ - -Window.alert("YEARLY : " + (isYearlySameDayOfWeek?"Same DAY of a Week":"") - +(isYearlySameDate?"Same DATE":""));//temp for checker - - int yearStart = beginEventIntervalDate.getYear(); - int yearEnd = endEventIntervalDate.getYear(); - int yearInterval = yearEnd - yearStart + 1; - - int monthStart = beginEventIntervalDate.getMonth();//0 Jan 11 Dec - int monthEnd = endEventIntervalDate.getMonth(); - int monthInterval = 0; - if (yearInterval > 0){ - monthInterval = (yearInterval-1)*12 + (12-monthStart) + (monthEnd + 1); - }else{ - monthInterval = monthEnd - monthStart + 1; - } - - if(yearInterval>1){ - properties.put(Event.SUMMARY, (String)properties.get(Event.SUMMARY)+ " (Yearly event 1 of " + yearInterval + ")"); - properties.put(Event.DESCRIPTION, (String)properties.get(Event.DESCRIPTION)+ " (Yearly event 1 of " + yearInterval + ")"); - } - - Date calBeginNextEventDate = beginEventIntervalDate; - - for (int i = 1; i < yearInterval; i++) { - //calBeginNextEventDate = getMonthlySameDate(beginEventIntervalDate, calBeginNextEventDate, i); - //calBeginNextEventDate = getMonthlySameDayOfWeek2(beginEventIntervalDate, calBeginNextEventDate, i, isMonthlySameDayOfWeek); - calBeginNextEventDate = getYearlySameDayOfWeek(beginEventIntervalDate, calBeginNextEventDate, i, isYearlySameDayOfWeek); - - Map yearlyProperties = new HashMap(); - yearlyProperties.put(Event.CALENDAR_ID, calendarWrapper); - yearlyProperties.put(Event.SUMMARY, view.getEventSummaryField().getValue()); - - yearlyProperties.put(Event.DATE, calBeginNextEventDate); - - if (startDate != null) { - calBeginNextEventDate.setHours(startDate.getHours()); - calBeginNextEventDate.setMinutes(startDate.getMinutes()); - yearlyProperties.put(Event.START_TIME, calBeginNextEventDate.getTime()); - }else{ - yearlyProperties.put(Event.START_TIME, null); - } - - - if (endDate != null) { - calBeginNextEventDate.setHours(endDate.getHours()); - calBeginNextEventDate.setMinutes(endDate.getMinutes()); - yearlyProperties.put(Event.END_TIME, calBeginNextEventDate.getTime()); - }else{ - yearlyProperties.put(Event.END_TIME, null); - } - - String newSummary = eventSummary; - String newDescription = eventDescription; - newSummary += " (Yearly event " + (i + 1) + " of " + monthInterval + ")"; - newDescription += " (Yearly "+(isYearlySameDayOfWeek?"same Day of a week ":"same Date ")+"event " + (i + 1) + " of " + yearInterval + ")"; - yearlyProperties.put(Event.SUMMARY, newSummary); - yearlyProperties.put(Event.DESCRIPTION, newDescription); - - addPersonalEvent(yearlyProperties); + Window.alert("MONTHLY : " + (isMonthlySameDayOfWeek?"Same DAY of a Week":"") + +(isMonthlySameDate?"Same DATE":""));//temp for checker + processMonthlyEvents(beginEventIntervalDate, endEventIntervalDate, properties, isMonthlySameDayOfWeek, startDate, endDate, eventSummary, eventDescription); + } else if (isYearlyRepeatEvent) { + Window.alert("YEARLY : " + (isYearlySameDayOfWeek ? "Same DAY of a Week" : "") + + (isYearlySameDate ? "Same DATE" : ""));//temp for checker + processYearEvents(beginEventIntervalDate, endEventIntervalDate, properties, isYearlySameDayOfWeek, startDate, endDate, eventSummary, eventDescription); } - - } //add first event addPersonalEvent(properties); - } + //} //Here process properties and define repetable events dates } else { @@ -643,6 +551,258 @@ else if (isYearlyRepeatEvent){ // } } + /** + * + * @param diffInMilis the value of diffInMilis + * @param milisPerDay the value of milisPerDay + * @param beginEventIntervalDate the value of beginEventIntervalDate + * @param startDate the value of startDate + * @param endDate the value of endDate + * @param properties the value of properties + * @param eventSummary the value of eventSummary + * @param eventDescription the value of eventDescription + */ + private void processDailyEvents(long diffInMilis, long milisPerDay, final Date beginEventIntervalDate, final Date startDate, final Date endDate, final Map properties, String eventSummary, String eventDescription) { + /* + 1. find number of days between start and end + 2. in cycle create new event + */ + int daysInterval = 0; + +// long milisPerDay = 86400000; //24 * 60 * 60 * 1000) +// long diffInMilis = endEventIntervalDate.getTime() - beginEventIntervalDate.getTime(); + long daysDiff = diffInMilis / milisPerDay + 1; + daysInterval = (int) daysDiff; +// java.util.Calendar is not supported by GWT !!! + + long calBeginNextEventDateLong = beginEventIntervalDate.getTime(); + Date calBeginNextEventDate = beginEventIntervalDate; + // + long calNextEventStartTime ;//= startDate.getTime(); + // long calNextEventEndTime = endDate.getTime(); + + if (daysInterval > 1) { + properties.put(Event.SUMMARY, (String) properties.get(Event.SUMMARY) + " (Daily event 1 of " + daysInterval + ")"); + properties.put(Event.DESCRIPTION, (String) properties.get(Event.DESCRIPTION) + " (Daily event 1 of " + daysInterval + ")"); + } + + for (int i = 1; i < daysInterval; i++) { + + calBeginNextEventDateLong += milisPerDay; + calBeginNextEventDate = new Date(calBeginNextEventDateLong); + calNextEventStartTime = calBeginNextEventDateLong; + // calNextEventStartTime += milisPerDay; + // calNextEventEndTime += milisPerDay; + + Map dailyProperties = new HashMap(); + dailyProperties.put(Event.CALENDAR_ID, calendarWrapper); + dailyProperties.put(Event.SUMMARY, view.getEventSummaryField().getValue()); + + dailyProperties.put(Event.DATE, calBeginNextEventDate); + // setAllDayTime(startDate, endDate, calBeginNextEventDate, calNextEventEndTime, dailyProperties); + setAllDayTime(startDate, endDate, calBeginNextEventDate, dailyProperties); +// dailyProperties.put(Event.START_TIME, calNextEventStartTime); +// dailyProperties.put(Event.END_TIME, calNextEventEndTime); + + String newSummary = eventSummary; + String newDescription = eventDescription; + newSummary += " (Daily event " + (i + 1) + " of " + daysInterval + ")"; + newDescription += " (Daily event " + (i + 1) + " of " + daysInterval + ")"; + dailyProperties.put(Event.SUMMARY, newSummary); + dailyProperties.put(Event.DESCRIPTION, newDescription); + + addPersonalEvent(dailyProperties); + } + } + + /** + * + * @param diffInMilis the value of diffInMilis + * @param milisPerWeek the value of milisPerWeek + * @param beginEventIntervalDate the value of beginEventIntervalDate + * @param startDate the value of startDate + * @param endDate the value of endDate + * @param properties the value of properties + * @param eventSummary the value of eventSummary + * @param eventDescription the value of eventDescription + */ + private void processWeeklyEvents(long diffInMilis, long milisPerWeek, final Date beginEventIntervalDate, final Date startDate, final Date endDate, final Map properties, String eventSummary, String eventDescription) { + // long diffInMilis = endEventIntervalDate.getTime() - beginEventIntervalDate.getTime(); + long weekDiff = diffInMilis / milisPerWeek + 1; + int weeksInterval = (int) weekDiff; + + long calBeginNextEventDateLong = beginEventIntervalDate.getTime(); + Date calBeginNextEventDate = beginEventIntervalDate; + long calNextEventStartTime;// = startDate.getTime(); + //long calNextEventEndTime = endDate.getTime(); + + if (weeksInterval > 1) { + properties.put(Event.SUMMARY, (String) properties.get(Event.SUMMARY) + " (Weekly event 1 of " + weeksInterval + ")"); + properties.put(Event.DESCRIPTION, (String) properties.get(Event.DESCRIPTION) + " (Weekly event 1 of " + weeksInterval + ")"); + } + + for (int i = 1; i < weeksInterval; i++) { + + calBeginNextEventDateLong += milisPerWeek; + calBeginNextEventDate = new Date(calBeginNextEventDateLong); + + calNextEventStartTime = calBeginNextEventDateLong; + // calNextEventStartTime += milisPerWeek; + //calNextEventEndTime += milisPerWeek; + + Map weeklyProperties = new HashMap(); + weeklyProperties.put(Event.CALENDAR_ID, calendarWrapper); + weeklyProperties.put(Event.SUMMARY, view.getEventSummaryField().getValue()); + + weeklyProperties.put(Event.DATE, calBeginNextEventDate); + + // setAllDayTime(startDate, endDate, calBeginNextEventDate, calNextEventEndTime, weeklyProperties); + setAllDayTime(startDate, endDate, calBeginNextEventDate, weeklyProperties); +// weeklyProperties.put(Event.START_TIME, calNextEventStartTime); +// weeklyProperties.put(Event.END_TIME, calNextEventEndTime); + + String newSummary = eventSummary; + String newDescription = eventDescription; + newSummary += " (Weekly event " + (i + 1) + " of " + weeksInterval + ")"; + newDescription += " (Weekly event " + (i + 1) + " of " + weeksInterval + ")"; + weeklyProperties.put(Event.SUMMARY, newSummary); + weeklyProperties.put(Event.DESCRIPTION, newDescription); + + addPersonalEvent(weeklyProperties); + } + } + + /** + * + * @param startDate the value of startDate + * @param endDate the value of endDate + * @param calBeginNextEventDate the value of calBeginNextEventDate + * @param thePeriodProperties the value of thePeriodProperties + */ + private void setAllDayTime(final Date startDate, final Date endDate, Date calBeginNextEventDate, Map thePeriodProperties) { + if (startDate != null) { + calBeginNextEventDate.setHours(startDate.getHours()); + calBeginNextEventDate.setMinutes(startDate.getMinutes()); + thePeriodProperties.put(Event.START_TIME, calBeginNextEventDate.getTime()); + } else { + thePeriodProperties.put(Event.START_TIME, null); + } + + if (endDate != null) { +// if(calNextEventEndTime>0){ +// thePeriodProperties.put(Event.END_TIME, calNextEventEndTime); +// +// }else{ + Date endD = calBeginNextEventDate; + endD.setHours(endDate.getHours()); + endD.setMinutes(endDate.getMinutes()); + thePeriodProperties.put(Event.END_TIME, endD.getTime()); + // } + } else { + thePeriodProperties.put(Event.END_TIME, null); + } + } + + /** + * + * @param beginEventIntervalDate the value of beginEventIntervalDate + * @param endEventIntervalDate the value of endEventIntervalDate + * @param properties the value of properties + * @param isMonthlySameDayOfWeek the value of isMonthlySameDayOfWeek + * @param startDate the value of startDate + * @param endDate the value of endDate + * @param eventSummary the value of eventSummary + * @param eventDescription the value of eventDescription + */ + private void processMonthlyEvents(final Date beginEventIntervalDate, final Date endEventIntervalDate, final Map properties, Boolean isMonthlySameDayOfWeek, final Date startDate, final Date endDate, String eventSummary, String eventDescription) { + int yearStart = beginEventIntervalDate.getYear(); + int yearEnd = endEventIntervalDate.getYear(); + int yearInterval = yearEnd - yearStart; + + int monthStart = beginEventIntervalDate.getMonth();//0 Jan 11 Dec + int monthEnd = endEventIntervalDate.getMonth(); + int monthInterval = 0; + if (yearInterval > 0) { + monthInterval = (yearInterval - 1) * 12 + (12 - monthStart) + (monthEnd + 1); + } else { + monthInterval = monthEnd - monthStart + 1; + } + + if (monthInterval > 1) { + properties.put(Event.SUMMARY, (String) properties.get(Event.SUMMARY) + " (Monthly event 1 of " + monthInterval + ")"); + properties.put(Event.DESCRIPTION, (String) properties.get(Event.DESCRIPTION) + " (Monthly event 1 of " + monthInterval + ")"); + } + + Date calBeginNextEventDate = beginEventIntervalDate; + + for (int i = 1; i < monthInterval; i++) { + //calBeginNextEventDate = getMonthlySameDate(beginEventIntervalDate, calBeginNextEventDate, i); + calBeginNextEventDate = getMonthlySameDayOfWeek2(beginEventIntervalDate, calBeginNextEventDate, i, isMonthlySameDayOfWeek); + + Map monthlyProperties = new HashMap(); + monthlyProperties.put(Event.CALENDAR_ID, calendarWrapper); + monthlyProperties.put(Event.SUMMARY, view.getEventSummaryField().getValue()); + + monthlyProperties.put(Event.DATE, calBeginNextEventDate); + + setAllDayTime(startDate, endDate, calBeginNextEventDate, monthlyProperties); + + String newSummary = eventSummary; + String newDescription = eventDescription; + newSummary += " (Monthly event " + (i + 1) + " of " + monthInterval + ")"; + newDescription += " (Monthly " + (isMonthlySameDayOfWeek ? "same Day of a week " : "same Date ") + "event " + (i + 1) + " of " + monthInterval + ")"; + monthlyProperties.put(Event.SUMMARY, newSummary); + monthlyProperties.put(Event.DESCRIPTION, newDescription); + + addPersonalEvent(monthlyProperties); + } + } + + private void processYearEvents(final Date beginEventIntervalDate, final Date endEventIntervalDate, final Map properties, Boolean isYearlySameDayOfWeek, final Date startDate, final Date endDate, String eventSummary, String eventDescription) { + int yearStart = beginEventIntervalDate.getYear(); + int yearEnd = endEventIntervalDate.getYear(); + int yearInterval = yearEnd - yearStart + 1; + + int monthStart = beginEventIntervalDate.getMonth();//0 Jan 11 Dec + int monthEnd = endEventIntervalDate.getMonth(); + int monthInterval = 0; + if (yearInterval > 0) { + monthInterval = (yearInterval - 1) * 12 + (12 - monthStart) + (monthEnd + 1); + } else { + monthInterval = monthEnd - monthStart + 1; + } + + if (yearInterval > 1) { + properties.put(Event.SUMMARY, (String) properties.get(Event.SUMMARY) + " (Yearly event 1 of " + yearInterval + ")"); + properties.put(Event.DESCRIPTION, (String) properties.get(Event.DESCRIPTION) + " (Yearly event 1 of " + yearInterval + ")"); + } + + Date calBeginNextEventDate = beginEventIntervalDate; + + for (int i = 1; i < yearInterval; i++) { + //calBeginNextEventDate = getMonthlySameDate(beginEventIntervalDate, calBeginNextEventDate, i); + //calBeginNextEventDate = getMonthlySameDayOfWeek2(beginEventIntervalDate, calBeginNextEventDate, i, isMonthlySameDayOfWeek); + calBeginNextEventDate = getYearlySameDayOfWeek(beginEventIntervalDate, calBeginNextEventDate, i, isYearlySameDayOfWeek); + + Map yearlyProperties = new HashMap(); + yearlyProperties.put(Event.CALENDAR_ID, calendarWrapper); + yearlyProperties.put(Event.SUMMARY, view.getEventSummaryField().getValue()); + + yearlyProperties.put(Event.DATE, calBeginNextEventDate); + + setAllDayTime(startDate, endDate, calBeginNextEventDate, yearlyProperties); + + String newSummary = eventSummary; + String newDescription = eventDescription; + newSummary += " (Yearly event " + (i + 1) + " of " + monthInterval + ")"; + newDescription += " (Yearly " + (isYearlySameDayOfWeek ? "same Day of a week " : "same Date ") + "event " + (i + 1) + " of " + yearInterval + ")"; + yearlyProperties.put(Event.SUMMARY, newSummary); + yearlyProperties.put(Event.DESCRIPTION, newDescription); + + addPersonalEvent(yearlyProperties); + } + } + /** * Creates a new "Personal" calendar event. * @@ -784,8 +944,8 @@ private static boolean isFullDayEvent(final Event event) { .getYear() != event.getDtend().getYear()); } -@SuppressWarnings({"deprecation"}) -private Date getMonthlySameDayOfWeek(Date dateObject, int numberMonths) { + @SuppressWarnings({"deprecation"}) + private Date getMonthlySameDayOfWeek(Date dateObject, int numberMonths) { Date firstDate = new Date(); firstDate.setYear(dateObject.getYear()); firstDate.setMonth(dateObject.getMonth()); @@ -795,218 +955,246 @@ private Date getMonthlySameDayOfWeek(Date dateObject, int numberMonths) { dateObject.setMonth(dateObject.getMonth() + 1); int daysInStartDate = getDaysInMonth(firstDate.getYear(), firstDate.getMonth()); - + if (firstDate.getDate() == daysInStartDate) {//if last day of the month dateObject.setDate(getDaysInMonth(dateObject.getYear(), dateObject.getMonth())); } else { dateObject.setDate(firstDate.getDate());//?? } - //Calculate same day of week - int dayOfFirst = firstDate.getDay(); - - int dayOfCurrent = dateObject.getDay(); - - Date newDate = new Date(); - Date curDate = dateObject; - int mil = 86400000; - - if (dayOfFirst > dayOfCurrent) { - newDate = new Date(curDate.getTime() + (dayOfFirst - dayOfCurrent) * mil); - if (newDate.getMonth() != curDate.getMonth()) { //> - newDate = new Date(curDate.getTime() - (7 - (dayOfFirst - dayOfCurrent)) * mil); - } + Date newDate = getSameWeekDay(firstDate, dateObject); - } else if (dayOfFirst < dayOfCurrent) {//< - newDate = new Date(curDate.getTime() - (dayOfCurrent - dayOfFirst) * mil); - if (newDate.getMonth() != curDate.getMonth()) { - newDate = new Date(curDate.getTime() + (7 - (dayOfFirst - dayOfCurrent)) * mil); - } - } else { - newDate = new Date(curDate.getTime()); - } - - Window.alert("Date start: Month:" + firstDate.getMonth() + - " | " + firstDate.getDay() + "| Date:" + getDaysInMonth(firstDate.getYear(), firstDate.getMonth()) + " ; " + firstDate.toLocaleString() + " : month " + numberMonths + ": Result " + " | " + dateObject.getDay() + " | " + dateObject.toLocaleString() + Window.alert("Date start: Month:" + firstDate.getMonth() + + " | " + firstDate.getDay() + "| Date:" + getDaysInMonth(firstDate.getYear(), firstDate.getMonth()) + " ; " + firstDate.toLocaleString() + " : month " + numberMonths + ": Result " + " | " + dateObject.getDay() + " | " + dateObject.toLocaleString() + " || " + newDate.getDay() + " || " + newDate.toLocaleString());//temp for checker return newDate; } + /** + * + * @param firstDate + * @param nextDateOld + * @param numberMonths + * @return + */ @SuppressWarnings({"deprecation", "empty-statement"}) - public Date getMonthlySameDate(Date firstDate, Date dateObject, int numberMonths) { - Date nextDate = new Date(); + public Date getMonthlySameDate(Date firstDate, Date nextDateOld, int numberMonths) { + Date nextDateNew = new Date(); Date newDate = new Date(); - nextDate.setYear(dateObject.getYear()); - nextDate.setMonth(dateObject.getMonth() + 1); - nextDate.setDate(1);// to prevent month slip past (f.e. 31 jan -> 3 march instead of 29 febr) - newDate.setYear(dateObject.getYear()); + nextDateNew.setYear(nextDateOld.getYear()); + nextDateNew.setMonth(nextDateOld.getMonth() + 1); + nextDateNew.setDate(1);// to prevent month slip past (f.e. 31 jan -> 3 march instead of 29 febr) + newDate.setYear(nextDateOld.getYear()); - int daysInNextDate = getDaysInMonth(nextDate.getYear(), nextDate.getMonth()); + int daysInNextDate = getDaysInMonth(nextDateNew.getYear(), nextDateNew.getMonth()); if (firstDate.getDate() <= daysInNextDate) {//if last day of the month newDate.setMonth(0); newDate.setDate(firstDate.getDate()); - newDate.setMonth(dateObject.getMonth() + 1); + newDate.setMonth(nextDateOld.getMonth() + 1); } else { newDate.setDate(daysInNextDate); - newDate.setMonth(dateObject.getMonth() + 1); + newDate.setMonth(nextDateOld.getMonth() + 1); } Window.alert("Date start: Month:" + firstDate.getMonth() - + " | " + firstDate.getDay() + "| Date:" + getDaysInMonth(nextDate.getYear(), nextDate.getMonth()) + + " | " + firstDate.getDay() + "| Date:" + getDaysInMonth(nextDateNew.getYear(), nextDateNew.getMonth()) + " ; " + firstDate.toLocaleString() + " : month " + numberMonths + ": Result " + " | " + newDate.getDay() + " | " + newDate.toLocaleString());//temp for checker return newDate; } - public Date getMonthlySameDayOfWeek2(Date firstDate, Date dateObject, int numberMonths, boolean isSameDayOfWeek) { + /** + * + * @param firstDate + * @param nextDateOld + * @param numberMonths + * @param isSameDayOfWeek + * @return + */ + public Date getMonthlySameDayOfWeek2(Date firstDate, Date nextDateOld, int numberMonths, boolean isSameDayOfWeek) { - Date nextDate = new Date(); + Date nextDateNew = new Date(); Date newDate = new Date(); - nextDate.setYear(dateObject.getYear()); - nextDate.setMonth(dateObject.getMonth() + 1); - nextDate.setDate(1);// to prevent month slip past (f.e. 31 jan -> 3 march instead of 29 febr) - newDate.setYear(dateObject.getYear()); + nextDateNew.setYear(nextDateOld.getYear()); + nextDateNew.setMonth(nextDateOld.getMonth() + 1); + nextDateNew.setDate(1);// to prevent month slip past (f.e. 31 jan -> 3 march instead of 29 febr) + newDate.setYear(nextDateOld.getYear()); - int daysInNextDate = getDaysInMonth(nextDate.getYear(), nextDate.getMonth()); + int daysInNextDate = getDaysInMonth(nextDateNew.getYear(), nextDateNew.getMonth()); if (firstDate.getDate() <= daysInNextDate) {//if last day of the month newDate.setMonth(0); newDate.setDate(firstDate.getDate()); - newDate.setMonth(dateObject.getMonth() + 1); + newDate.setMonth(nextDateOld.getMonth() + 1); } else { newDate.setDate(daysInNextDate); - newDate.setMonth(dateObject.getMonth() + 1); + newDate.setMonth(nextDateOld.getMonth() + 1); } if (isSameDayOfWeek) { - //Calculate same day of week - int dayOfFirst = firstDate.getDay(); - - int dayOfCurrent = newDate.getDay(); - - Date curDate = newDate; - int mil = 86400000; - Date newDate2 = new Date(); - - if (dayOfFirst > dayOfCurrent) { - newDate2 = new Date(curDate.getTime() + (dayOfFirst - dayOfCurrent) * mil); - if (newDate2.getMonth() != curDate.getMonth()) { //> - newDate2 = new Date(curDate.getTime() - (7 - (dayOfFirst - dayOfCurrent)) * mil); - } + Date newDate2 = getSameWeekDay(firstDate, newDate); //getSameWeekDay22 - } else if (dayOfFirst < dayOfCurrent) {//< - newDate2 = new Date(curDate.getTime() - (dayOfCurrent - dayOfFirst) * mil); - if (newDate2.getMonth() != curDate.getMonth()) { - //newDate2 = new Date(curDate.getTime() + (7 - (dayOfFirst - dayOfCurrent)) * mil); - newDate2 = new Date(curDate.getTime() + (7 - (dayOfCurrent - dayOfFirst)) * mil); - } - } else { - newDate2 = new Date(curDate.getTime()); - } - - //return newDate2; + //return newDate; newDate = newDate2; } Window.alert("Monthly " + (isSameDayOfWeek ? "Same week DAY " : "Same DATE ") + "Date start: Month:" + firstDate.getMonth() + " | " + firstDate.getDay() + "| " + getDaysInMonth(firstDate.getYear(), firstDate.getMonth()) + " | " + firstDate.toLocaleString() + " | i= " + numberMonths + " | RESULT | Prev | " - + dateObject.getDay() + " | " + dateObject.toLocaleString() + + nextDateNew.getDay() + " | " + nextDateNew.toLocaleString() + " || New | " + newDate.getDay() + " | " + newDate.toLocaleString());//temp for checker return newDate; } + + + /** + * + * @param firstDate + * @param nextDateOld + * @param numberMonths + * @param isSameDayOfWeek + * @return + */ @SuppressWarnings({"deprecation"}) - public Date getYearlySameDayOfWeek(Date firstDate, Date dateObject, int numberMonths, boolean isSameDayOfWeek) { + public Date getYearlySameDayOfWeek(Date firstDate, Date nextDateOld, int numberMonths, boolean isSameDayOfWeek) { // Date firstDate = new Date(); -// firstDate.setYear(dateObject.getYear());; -// firstDate.setMonth(dateObject.getMonth()); -// firstDate.setDate(dateObject.getDate()); +// firstDate.setYear(nextDateOld.getYear());; +// firstDate.setMonth(nextDateOld.getMonth()); +// firstDate.setDate(nextDateOld.getDate()); // - Date nextDate = new Date(); - nextDate.setYear(dateObject.getYear());; - nextDate.setMonth(dateObject.getMonth()); - nextDate.setDate(dateObject.getDate()); + Date nextDateNew = new Date(); + nextDateNew.setYear(nextDateOld.getYear());; + nextDateNew.setMonth(nextDateOld.getMonth()); + nextDateNew.setDate(nextDateOld.getDate()); - nextDate.setDate(1); -// nextDate.setMonth(dateObject.getMonth()); - nextDate.setYear(dateObject.getYear() + 1); - - -// Date nextDate = new Date(); -// Date newDate = new Date(); -// nextDate.setYear(dateObject.getYear()); -// nextDate.setMonth(dateObject.getMonth() + 1); -// nextDate.setDate(1);// to prevent month slip past (f.e. 31 jan -> 3 march instead of 29 febr) -// newDate.setYear(dateObject.getYear()); + nextDateNew.setDate(1); +// nextDateNew.setMonth(nextDateOld.getMonth()); + nextDateNew.setYear(nextDateOld.getYear() + 1); - int daysInNextDate = getDaysInMonth(nextDate.getYear(), nextDate.getMonth()); +// Date nextDateNew = new Date(); +// Date newDate = new Date(); +// nextDateNew.setYear(nextDateOld.getYear()); +// nextDateNew.setMonth(nextDateOld.getMonth() + 1); +// nextDateNew.setDate(1);// to prevent month slip past (f.e. 31 jan -> 3 march instead of 29 febr) +// newDate.setYear(nextDateOld.getYear()); + int daysInNextDate = getDaysInMonth(nextDateNew.getYear(), nextDateNew.getMonth()); if (firstDate.getDate() >= daysInNextDate) {//if last day of the month //nextDate.setDate(firstDate.getDate());//?? - //nextDate.setDate(getDaysInMonth(dateObject.getYear(),dateObject.getMonth())); - nextDate.setDate(daysInNextDate); + //nextDate.setDate(getDaysInMonth(nextDateOld.getYear(),nextDateOld.getMonth())); + nextDateNew.setDate(daysInNextDate); } else { - //nextDate.setDate(getDaysInMonth(dateObject.getYear(),dateObject.getMonth())); + //nextDate.setDate(getDaysInMonth(nextDateOld.getYear(),nextDateOld.getMonth())); //nextDate.setDate(firstDate.getDate());//?? - nextDate.setDate(firstDate.getDate()); + nextDateNew.setDate(firstDate.getDate()); } if (isSameDayOfWeek) { + Date newDate = getSameWeekDay(firstDate, nextDateNew);//getSameWeekDay2 + nextDateNew = newDate; + } + + Window.alert("Yearly " + (isSameDayOfWeek ? "Same week DAY " : "Same DATE ") + "Date start: Month:" + firstDate.getMonth() + " | " + firstDate.getDay() + + "| " + getDaysInMonth(firstDate.getYear(), firstDate.getMonth()) + + " | " + firstDate.toLocaleString() + " | i= " + numberMonths + " | RESULT | Prev | " + + nextDateOld.getDay() + " | " + nextDateOld.toLocaleString() + + " || New | " + nextDateNew.getDay() + " | " + nextDateNew.toLocaleString());//temp for checker + + return nextDateNew; + } + + private Date getSameWeekDay(Date firstDate, Date nextDate) { //Calculate same day of week int dayOfFirst = firstDate.getDay(); - int dayOfCurrent = nextDate.getDay(); - Date newDate = new Date(); Date curDate = nextDate; - int mil = 86400000; + int milSecInDay = 86400000; //24 * 60 * 60 * 1000 + if (dayOfFirst > dayOfCurrent) { + newDate = new Date(curDate.getTime() + (dayOfFirst - dayOfCurrent) * milSecInDay); + if (newDate.getMonth() != curDate.getMonth()) { //> + newDate = new Date(curDate.getTime() - (7 - (dayOfFirst - dayOfCurrent)) * milSecInDay); + } + } else if (dayOfFirst < dayOfCurrent) {//< + newDate = new Date(curDate.getTime() - (dayOfCurrent - dayOfFirst) * milSecInDay); + if (newDate.getMonth() != curDate.getMonth()) { + // newDate = new Date(curDate.getTime() + (7 - (dayOfFirst - dayOfCurrent)) * milSecInDay); + newDate = new Date(curDate.getTime() + (7 - (dayOfCurrent - dayOfFirst)) * milSecInDay); + } + } else { + newDate = new Date(curDate.getTime()); + } + return newDate; + } + + private Date getSameWeekDay22(Date firstDate, Date nextDate) { + //Calculate same day of week + int dayOfFirst = firstDate.getDay(); + int dayOfCurrent = nextDate.getDay(); + Date curDate = nextDate; + int milSecInDay = 86400000;//24 * 60 * 60 * 1000 + Date newDate = new Date(); + if (dayOfFirst > dayOfCurrent) { + newDate = new Date(curDate.getTime() + (dayOfFirst - dayOfCurrent) * milSecInDay); + if (newDate.getMonth() != curDate.getMonth()) { //> + newDate = new Date(curDate.getTime() - (7 - (dayOfFirst - dayOfCurrent)) * milSecInDay); + } + + } else if (dayOfFirst < dayOfCurrent) {//< + newDate = new Date(curDate.getTime() - (dayOfCurrent - dayOfFirst) * milSecInDay); + if (newDate.getMonth() != curDate.getMonth()) { + //newDate2 = new Date(curDate.getTime() + (7 - (dayOfFirst - dayOfCurrent)) * milSecInDay); + newDate = new Date(curDate.getTime() + (7 - (dayOfCurrent - dayOfFirst)) * milSecInDay); + } + } else { + newDate = new Date(curDate.getTime()); + } + return newDate; + } + private Date getSameWeekDay2(Date firstDate, Date nextDate) { + //Calculate same day of week + int dayOfFirst = firstDate.getDay(); + int dayOfCurrent = nextDate.getDay(); + Date newDate = new Date(); + Date curDate = nextDate; + int milSecInDay = 86400000;//24 * 60 * 60 * 1000 if (dayOfFirst > dayOfCurrent) { newDate = new Date(curDate.getTime() + (dayOfFirst - dayOfCurrent) - * mil); + * milSecInDay); if (newDate.getMonth() != curDate.getMonth()) { // > newDate = new Date(curDate.getTime() - - (7 - (dayOfFirst - dayOfCurrent)) * mil); + - (7 - (dayOfFirst - dayOfCurrent)) * milSecInDay); } } else if (dayOfFirst < dayOfCurrent) {// < newDate = new Date(curDate.getTime() - (dayOfCurrent - dayOfFirst) - * mil); + * milSecInDay); if (newDate.getMonth() != curDate.getMonth()) { int dif = (dayOfFirst - dayOfCurrent) < 0 ? -(dayOfFirst - dayOfCurrent) : (dayOfFirst - dayOfCurrent); newDate = new Date(curDate.getTime() - + (7 - dif) * mil); + + (7 - dif) * milSecInDay); } } else { newDate = new Date(curDate.getTime()); } - - nextDate = newDate; - } - - Window.alert("Yearly " + (isSameDayOfWeek ? "Same week DAY " : "Same DATE ") + "Date start: Month:" + firstDate.getMonth() + " | " + firstDate.getDay() - + "| " + getDaysInMonth(firstDate.getYear(), firstDate.getMonth()) - + " | " + firstDate.toLocaleString() + " | i= " + numberMonths + " | RESULT | Prev | " - + dateObject.getDay() + " | " + dateObject.toLocaleString() - + " || New | " + nextDate.getDay() + " | " + nextDate.toLocaleString());//temp for checker - - return nextDate; + return newDate; } private int getDaysInMonth(int year, int month) { - int daysInMonth; + int daysInMonth = 31; switch (month) { case 3: @@ -1017,10 +1205,15 @@ private int getDaysInMonth(int year, int month) { case 1: return daysInMonth = (isLeapYear(year)) ? 29 : 28; default: - return daysInMonth = 31; + return daysInMonth;// = 31; } } + /** + * + * @param year the value of year + * @return the boolean + */ private boolean isLeapYear(int year) { return (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)); } From b4fd503ad746bb04b6d20104f6d9750f6b33eef4 Mon Sep 17 00:00:00 2001 From: Seal98 Date: Sun, 25 Jun 2017 21:35:26 +0300 Subject: [PATCH 12/39] [WIP] Advanced calendar component (issue#852) Refactoring#2 of CalendarEventPresenter class. Try to simplify method: ' onSaveAction() has an NPath complexity of 216' --- .../calendar/CalendarEventPresenter.java | 218 ++++++++++-------- 1 file changed, 127 insertions(+), 91 deletions(-) diff --git a/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java b/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java index de5f71e35..0587e6f8b 100644 --- a/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java +++ b/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java @@ -440,17 +440,114 @@ private void onSaveAction() { properties.put(Event.DATE, beginEventIntervalDate); //final - Date endEventIntervalDate = view.getEventDateEndField().getValue(); - if(endEventIntervalDate == null){ - endEventIntervalDate = beginEventIntervalDate; - } - - + Date endEventIntervalDate = view.getEventDateEndField().getValue(); + if(endEventIntervalDate == null){ + endEventIntervalDate = beginEventIntervalDate; + } + Boolean isAllDayEvent = view.getAllDayCheckbox().getValue(); Window.alert("isAllDayEvent=" + isAllDayEvent);//temp for checker - //final + Date startDate = createStartDateProperty(isAllDayEvent, beginEventIntervalDate, properties); + + Date endDate = createEndDateProperty(isAllDayEvent, beginEventIntervalDate, properties); + + properties.put(Event.DESCRIPTION, view.getEventDescriptionField().getValue()); + + if (event == null) { + + processAddEvent(endEventIntervalDate, beginEventIntervalDate, startDate, endDate, properties, eventSummary, eventDescription); + //add first event, to include in properties updated description and summary with event period type + //the first event is added last - after processing previous events + addPersonalEvent(properties); + //} + +//Here process properties and define repetable events dates + } else { + editPersonalEvent(event, properties); +// properties.remove(Event.START_TIME); +// properties.remove(Event.END_TIME); + //properties.remove(Event.DATE); + } + +// if (event == null) { +// addPersonalEvent(properties); +// +// } else { +// editPersonalEvent(event, properties); +// } +} + + /** + * + * @param endEventIntervalDate the value of endEventIntervalDate + * @param beginEventIntervalDate the value of beginEventIntervalDate + * @param startDate the value of startDate + * @param endDate the value of endDate + * @param properties the value of properties + * @param eventSummary the value of eventSummary + * @param eventDescription the value of eventDescription + */ + private void processAddEvent(Date endEventIntervalDate, final Date beginEventIntervalDate, Date startDate, Date endDate, final Map properties, String eventSummary, String eventDescription) { + Boolean isOnceRepeatEvent = view.getOnceRepeatRB().getValue(); + Window.alert("isOnceRepeatEvent=" + isOnceRepeatEvent);//temp for checker + //if(!isOnceRepeatEvent.booleanValue()){ + //Here process properties and define repetable events dates + /*take parameters from View + Start Date, get End beginEventIntervalDate, period settings like Once, Daily, Monthly etc + process values to prepare new properties for new event + if needed calculate same day of week for Monthly or Yearly + if needed compare if the Date exist in Month (like 29 30 31 Febr etc) + if needed define weekends + after that in cycle add new events + */ + +// Boolean isAllDayEvent = view.getAllDayCheckbox().getValue(); +// +// Window.alert("isAllDayEvent=" + isAllDayEvent);//temp for checker + +Boolean isDailyRepeatEvent = view.getDailyRepeatRB() != null ? view.getDailyRepeatRB().getValue() : Boolean.FALSE; +Boolean isWeeklyRepeatEvent = view.getWeeklyRepeatRB().getValue(); +Boolean isMonthlyRepeatEvent = view.getMonthlyRepeatRB().getValue(); +Boolean isYearlyRepeatEvent = view.getYearlyRepeatRB().getValue(); + +Boolean isMonthlySameDayOfWeek = view.getRadioMonthlySameDayOfWeek().getValue(); +Boolean isMonthlySameDate = view.getRadioMonthlySameDate().getValue(); + +Boolean isYearlySameDayOfWeek = view.getYearlySameDayOfWeekRB().getValue(); +Boolean isYearlySameDate = view.getYearlySameDateRB().getValue(); + +Window.alert("isYearlySameDayOfWeek=" + isYearlySameDayOfWeek);//temp for checker +Window.alert("isYearlySameDate=" + isYearlySameDate);//temp for checker + +long milisPerDay = 86400000; //24 * 60 * 60 * 1000) +long milisPerWeek = 7 * milisPerDay; //7 days * (24hour * 60minutes * 60seconds * 1000mili seconds) +long diffInMilis = endEventIntervalDate.getTime() - beginEventIntervalDate.getTime(); + +if(isDailyRepeatEvent){ + processDailyEvents(diffInMilis, milisPerDay, beginEventIntervalDate, startDate, endDate, properties, eventSummary, eventDescription); +} else if (isWeeklyRepeatEvent){ + processWeeklyEvents(diffInMilis, milisPerWeek, beginEventIntervalDate, startDate, endDate, properties, eventSummary, eventDescription); +} else if (isMonthlyRepeatEvent){ + Window.alert("MONTHLY : " + (isMonthlySameDayOfWeek?"Same DAY of a Week":"") + +(isMonthlySameDate?"Same DATE":""));//temp for checker + processMonthlyEvents(beginEventIntervalDate, endEventIntervalDate, properties, isMonthlySameDayOfWeek, startDate, endDate, eventSummary, eventDescription); +} else if (isYearlyRepeatEvent) { + Window.alert("YEARLY : " + (isYearlySameDayOfWeek ? "Same DAY of a Week" : "") + + (isYearlySameDate ? "Same DATE" : ""));//temp for checker + processYearEvents(beginEventIntervalDate, endEventIntervalDate, properties, isYearlySameDayOfWeek, startDate, endDate, eventSummary, eventDescription); +} + } + + /** + * + * @param isAllDayEvent the value of isAllDayEvent + * @param beginEventIntervalDate the value of beginEventIntervalDate + * @param properties the value of properties + */ + private Date createStartDateProperty(Boolean isAllDayEvent, final Date beginEventIntervalDate, final Map properties) { + //final Date startDate = null; //view.getEventStartTimeField().getDateValue(); if (!isAllDayEvent) { startDate = view.getEventStartTimeField().getDateValue(); @@ -463,9 +560,18 @@ private void onSaveAction() { } else { properties.put(Event.START_TIME, null); } + return startDate; + } - //final - Date endDate = null;//view.getEventEndTimeField().getDateValue(); + /** + * + * @param isAllDayEvent the value of isAllDayEvent + * @param beginEventIntervalDate the value of beginEventIntervalDate + * @param properties the value of properties + */ + private Date createEndDateProperty(Boolean isAllDayEvent, final Date beginEventIntervalDate, final Map properties) { + //final + Date endDate = null;//view.getEventEndTimeField().getDateValue(); if (isAllDayEvent) { //endDate = null; endDate = view.getEventEndTimeField().getDateValue(); @@ -478,78 +584,8 @@ private void onSaveAction() { } else { properties.put(Event.END_TIME, null); } - - properties.put(Event.DESCRIPTION, view.getEventDescriptionField().getValue()); - - if (event == null) { - Boolean isOnceRepeatEvent = view.getOnceRepeatRB().getValue(); - Window.alert("isOnceRepeatEvent=" + isOnceRepeatEvent);//temp for checker - //if(!isOnceRepeatEvent.booleanValue()){ - //Here process properties and define repetable events dates - /*take parameters from View - Start Date, get End beginEventIntervalDate, period settings like Once, Daily, Monthly etc - process values to prepare new properties for new event - if needed calculate same day of week for Monthly or Yearly - if needed compare if the Date exist in Month (like 29 30 31 Febr etc) - if needed define weekends - after that in cycle add new events - */ - -// Boolean isAllDayEvent = view.getAllDayCheckbox().getValue(); -// -// Window.alert("isAllDayEvent=" + isAllDayEvent);//temp for checker - - Boolean isDailyRepeatEvent = view.getDailyRepeatRB() != null ? view.getDailyRepeatRB().getValue() : Boolean.FALSE; - Boolean isWeeklyRepeatEvent = view.getWeeklyRepeatRB().getValue(); - Boolean isMonthlyRepeatEvent = view.getMonthlyRepeatRB().getValue(); - Boolean isYearlyRepeatEvent = view.getYearlyRepeatRB().getValue(); - - Boolean isMonthlySameDayOfWeek = view.getRadioMonthlySameDayOfWeek().getValue(); - Boolean isMonthlySameDate = view.getRadioMonthlySameDate().getValue(); - - Boolean isYearlySameDayOfWeek = view.getYearlySameDayOfWeekRB().getValue(); - Boolean isYearlySameDate = view.getYearlySameDateRB().getValue(); - - Window.alert("isYearlySameDayOfWeek=" + isYearlySameDayOfWeek);//temp for checker - Window.alert("isYearlySameDate=" + isYearlySameDate);//temp for checker - - long milisPerDay = 86400000; //24 * 60 * 60 * 1000) - long milisPerWeek = 7 * milisPerDay; //7 days * (24hour * 60minutes * 60seconds * 1000mili seconds) - long diffInMilis = endEventIntervalDate.getTime() - beginEventIntervalDate.getTime(); - - if(isDailyRepeatEvent){ - processDailyEvents(diffInMilis, milisPerDay, beginEventIntervalDate, startDate, endDate, properties, eventSummary, eventDescription); - } else if (isWeeklyRepeatEvent){ - processWeeklyEvents(diffInMilis, milisPerWeek, beginEventIntervalDate, startDate, endDate, properties, eventSummary, eventDescription); - } else if (isMonthlyRepeatEvent){ - Window.alert("MONTHLY : " + (isMonthlySameDayOfWeek?"Same DAY of a Week":"") - +(isMonthlySameDate?"Same DATE":""));//temp for checker - processMonthlyEvents(beginEventIntervalDate, endEventIntervalDate, properties, isMonthlySameDayOfWeek, startDate, endDate, eventSummary, eventDescription); - } else if (isYearlyRepeatEvent) { - Window.alert("YEARLY : " + (isYearlySameDayOfWeek ? "Same DAY of a Week" : "") - + (isYearlySameDate ? "Same DATE" : ""));//temp for checker - processYearEvents(beginEventIntervalDate, endEventIntervalDate, properties, isYearlySameDayOfWeek, startDate, endDate, eventSummary, eventDescription); - } - - //add first event - addPersonalEvent(properties); - //} - -//Here process properties and define repetable events dates - } else { - editPersonalEvent(event, properties); -// properties.remove(Event.START_TIME); -// properties.remove(Event.END_TIME); - //properties.remove(Event.DATE); - } - -// if (event == null) { -// addPersonalEvent(properties); -// -// } else { -// editPersonalEvent(event, properties); -// } -} + return endDate; + } /** * @@ -591,16 +627,16 @@ private void processDailyEvents(long diffInMilis, long milisPerDay, final Date b calBeginNextEventDateLong += milisPerDay; calBeginNextEventDate = new Date(calBeginNextEventDateLong); calNextEventStartTime = calBeginNextEventDateLong; - // calNextEventStartTime += milisPerDay; - // calNextEventEndTime += milisPerDay; + // calNextEventStartTime += milisPerDay; + // calNextEventEndTime += milisPerDay; Map dailyProperties = new HashMap(); dailyProperties.put(Event.CALENDAR_ID, calendarWrapper); dailyProperties.put(Event.SUMMARY, view.getEventSummaryField().getValue()); dailyProperties.put(Event.DATE, calBeginNextEventDate); - // setAllDayTime(startDate, endDate, calBeginNextEventDate, calNextEventEndTime, dailyProperties); - setAllDayTime(startDate, endDate, calBeginNextEventDate, dailyProperties); + // setAllDayTime(startDate, endDate, calBeginNextEventDate, calNextEventEndTime, dailyProperties); + setAllDayTime(startDate, endDate, calBeginNextEventDate, dailyProperties); // dailyProperties.put(Event.START_TIME, calNextEventStartTime); // dailyProperties.put(Event.END_TIME, calNextEventEndTime); @@ -645,9 +681,9 @@ private void processWeeklyEvents(long diffInMilis, long milisPerWeek, final Date calBeginNextEventDateLong += milisPerWeek; calBeginNextEventDate = new Date(calBeginNextEventDateLong); - + calNextEventStartTime = calBeginNextEventDateLong; - // calNextEventStartTime += milisPerWeek; + // calNextEventStartTime += milisPerWeek; //calNextEventEndTime += milisPerWeek; Map weeklyProperties = new HashMap(); @@ -655,9 +691,9 @@ private void processWeeklyEvents(long diffInMilis, long milisPerWeek, final Date weeklyProperties.put(Event.SUMMARY, view.getEventSummaryField().getValue()); weeklyProperties.put(Event.DATE, calBeginNextEventDate); - - // setAllDayTime(startDate, endDate, calBeginNextEventDate, calNextEventEndTime, weeklyProperties); - setAllDayTime(startDate, endDate, calBeginNextEventDate, weeklyProperties); + + // setAllDayTime(startDate, endDate, calBeginNextEventDate, calNextEventEndTime, weeklyProperties); + setAllDayTime(startDate, endDate, calBeginNextEventDate, weeklyProperties); // weeklyProperties.put(Event.START_TIME, calNextEventStartTime); // weeklyProperties.put(Event.END_TIME, calNextEventEndTime); @@ -1071,7 +1107,7 @@ public Date getYearlySameDayOfWeek(Date firstDate, Date nextDateOld, int numberM // Date nextDateNew = new Date(); - nextDateNew.setYear(nextDateOld.getYear());; + nextDateNew.setYear(nextDateOld.getYear()); nextDateNew.setMonth(nextDateOld.getMonth()); nextDateNew.setDate(nextDateOld.getDate()); From d5a88b7509a7acc5aa96cc32dca2c29e20b17821 Mon Sep 17 00:00:00 2001 From: Seal98 Date: Sun, 25 Jun 2017 21:54:39 +0300 Subject: [PATCH 13/39] [WIP] Advanced calendar component (issue#852) Refactoring#3 of CalendarEventPresenter class. 'Avoid really long methods. public void onPageRequest' 'Avoid unused local variables such as 'calNextEventStartTime' --- .../calendar/CalendarEventPresenter.java | 169 ++++++++++-------- 1 file changed, 92 insertions(+), 77 deletions(-) diff --git a/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java b/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java index 0587e6f8b..0ef8f4d95 100644 --- a/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java +++ b/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java @@ -322,93 +322,108 @@ public void onPageRequest(final PageRequest request) { // Loading event on view (if edition). // -- if (creation) { - // view.getForm().clearState(); - // view.initialize(); - //view.setShowAddEventView(true); - if (view.getRepeatEventPeriodRG() != null) { - view.getRepeatEventPeriodRG().enable(); - view.getRepeatEventPeriodRG().show(); - view.getOnceRepeatRB().setValue(true); - view.getPanelMonthly().hide(); - view.getPanelYearly().hide(); - //view.getMontlyVariantRG().show(); - //view.getYearlyVariantRG().show(); - } - view.getEventStartTimeField().show(); - view.getEventEndTimeField().show(); + prepareAddView(); + } else { + prepareEditView(); + } + } - view.getYearlyVariantRG().enable(); - view.getMontlyVariantRG().enable(); - view.getRepeatEventPeriodRG().enable(); - view.getMonthlyRepeatRB().enable(); - view.getYearlySameDateRB().enable(); - view.getYearlySameDayOfWeekRB().enable(); - view.getRadioMonthlySameDate().enable(); - view.getRadioMonthlySameDayOfWeek().enable(); - - view.getYearlyVariantRG().show(); - view.getMontlyVariantRG().show(); - view.getRepeatEventPeriodRG().show(); - view.getMonthlyRepeatRB().show(); - view.getYearlySameDateRB().show(); - view.getYearlySameDayOfWeekRB().show(); - view.getRadioMonthlySameDate().show(); - view.getRadioMonthlySameDayOfWeek().show(); - // view.getRepeatEventPeriodRG().show(); - // return; - //view.getRepeatEventPeriodRG().show(); - } else {// EDIST EXISTING EVENT - //view.setShowAddEventView(false); - //view.getRepeatEventPeriodRG().hide(); - //--->> } - - this.calendarWrapper = new CalendarWrapper(event.getParent()); - //view.setShowAddEventView(false); - view.getForm().clearState(); - view.getEventSummaryField().setValue(event.getSummary()); - view.getEventDateStartField().setValue(event.getKey()); - if (view.getRepeatEventPeriodRG() != null) { - view.getRepeatEventPeriodRG().clear(); - view.getRepeatEventPeriodRG().clearInvalid(); - view.getRepeatEventPeriodRG().clearState(); - view.getRepeatEventPeriodRG().setSelectionRequired(false); - view.getRepeatEventPeriodRG().hide(); - - view.getPanelMonthly().hide(); - view.getMontlyVariantRG().hide(); - - view.getPanelYearly().hide(); - view.getYearlyVariantRG().hide(); - - view.getYearlyVariantRG().hide(); - view.getMontlyVariantRG().hide(); - view.getRepeatEventPeriodRG().hide(); - view.getMonthlyRepeatRB().hide(); - view.getYearlySameDateRB().hide(); - view.getYearlySameDayOfWeekRB().hide(); - view.getRadioMonthlySameDate().hide(); - view.getRadioMonthlySameDayOfWeek().hide(); - } + /** + * + */ + private void prepareEditView() { + // EDIST EXISTING EVENT + //view.setShowAddEventView(false); + //view.getRepeatEventPeriodRG().hide(); + //--->> } + + this.calendarWrapper = new CalendarWrapper(event.getParent()); + //view.setShowAddEventView(false); + view.getForm().clearState(); + view.getEventSummaryField().setValue(event.getSummary()); + view.getEventDateStartField().setValue(event.getKey()); + if (view.getRepeatEventPeriodRG() != null) { + view.getRepeatEventPeriodRG().clear(); + view.getRepeatEventPeriodRG().clearInvalid(); + view.getRepeatEventPeriodRG().clearState(); + view.getRepeatEventPeriodRG().setSelectionRequired(false); + view.getRepeatEventPeriodRG().hide(); + + view.getPanelMonthly().hide(); + view.getMontlyVariantRG().hide(); + + view.getPanelYearly().hide(); + view.getYearlyVariantRG().hide(); + + view.getYearlyVariantRG().hide(); + view.getMontlyVariantRG().hide(); + view.getRepeatEventPeriodRG().hide(); + view.getMonthlyRepeatRB().hide(); + view.getYearlySameDateRB().hide(); + view.getYearlySameDayOfWeekRB().hide(); + view.getRadioMonthlySameDate().hide(); + view.getRadioMonthlySameDayOfWeek().hide(); + } // if(creation) { // view.getIsAllDayCheckbox().hide(); // } else {// CREATE NEW EVENT NEW BELOW // view.getRepeatEventPeriodRG().hide(); // } - view.getEventStartTimeField().show(); - view.getEventEndTimeField().show(); + view.getEventStartTimeField().show(); + view.getEventEndTimeField().show(); - if (!isFullDayEvent(event)) { + if (!isFullDayEvent(event)) { - final Time startTime = event.getDtstart() != null ? view.getEventStartTimeField().findModel(event.getDtstart()) : null; - view.getEventStartTimeField().setValue(startTime); + final Time startTime = event.getDtstart() != null ? view.getEventStartTimeField().findModel(event.getDtstart()) : null; + view.getEventStartTimeField().setValue(startTime); - final Time endTime = event.getDtend() != null ? view.getEventEndTimeField().findModel(event.getDtend()) : null; - view.getEventEndTimeField().setValue(endTime); + final Time endTime = event.getDtend() != null ? view.getEventEndTimeField().findModel(event.getDtend()) : null; + view.getEventEndTimeField().setValue(endTime); - } + } - view.getEventDescriptionField().setValue(event.getDescription()); + view.getEventDescriptionField().setValue(event.getDescription()); + } + + /** + * + */ + private void prepareAddView() { + // view.getForm().clearState(); + // view.initialize(); + //view.setShowAddEventView(true); + if (view.getRepeatEventPeriodRG() != null) { + view.getRepeatEventPeriodRG().enable(); + view.getRepeatEventPeriodRG().show(); + view.getOnceRepeatRB().setValue(true); + view.getPanelMonthly().hide(); + view.getPanelYearly().hide(); + //view.getMontlyVariantRG().show(); + //view.getYearlyVariantRG().show(); } + view.getEventStartTimeField().show(); + view.getEventEndTimeField().show(); + + view.getYearlyVariantRG().enable(); + view.getMontlyVariantRG().enable(); + view.getRepeatEventPeriodRG().enable(); + view.getMonthlyRepeatRB().enable(); + view.getYearlySameDateRB().enable(); + view.getYearlySameDayOfWeekRB().enable(); + view.getRadioMonthlySameDate().enable(); + view.getRadioMonthlySameDayOfWeek().enable(); + + view.getYearlyVariantRG().show(); + view.getMontlyVariantRG().show(); + view.getRepeatEventPeriodRG().show(); + view.getMonthlyRepeatRB().show(); + view.getYearlySameDateRB().show(); + view.getYearlySameDayOfWeekRB().show(); + view.getRadioMonthlySameDate().show(); + view.getRadioMonthlySameDayOfWeek().show(); + // view.getRepeatEventPeriodRG().show(); + // return; + //view.getRepeatEventPeriodRG().show(); } // --------------------------------------------------------------------------------------------------------------- @@ -614,7 +629,7 @@ private void processDailyEvents(long diffInMilis, long milisPerDay, final Date b long calBeginNextEventDateLong = beginEventIntervalDate.getTime(); Date calBeginNextEventDate = beginEventIntervalDate; // - long calNextEventStartTime ;//= startDate.getTime(); + // long calNextEventStartTime ;//= startDate.getTime(); // long calNextEventEndTime = endDate.getTime(); if (daysInterval > 1) { @@ -626,7 +641,7 @@ private void processDailyEvents(long diffInMilis, long milisPerDay, final Date b calBeginNextEventDateLong += milisPerDay; calBeginNextEventDate = new Date(calBeginNextEventDateLong); - calNextEventStartTime = calBeginNextEventDateLong; + long calNextEventStartTime = calBeginNextEventDateLong; // calNextEventStartTime += milisPerDay; // calNextEventEndTime += milisPerDay; From 6cafc6732bee600f286bc6cedd84958cc8426027 Mon Sep 17 00:00:00 2001 From: Seal98 Date: Sun, 25 Jun 2017 22:26:06 +0300 Subject: [PATCH 14/39] [WIP] Advanced calendar component (issue#852) Refactoring#4 of CalendarEventPresenter class. Commented out unused methods and variables --- .../calendar/CalendarEventPresenter.java | 90 ++++++++++--------- 1 file changed, 48 insertions(+), 42 deletions(-) diff --git a/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java b/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java index 0ef8f4d95..c946d52e0 100644 --- a/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java +++ b/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java @@ -505,8 +505,13 @@ private void onSaveAction() { * @param eventDescription the value of eventDescription */ private void processAddEvent(Date endEventIntervalDate, final Date beginEventIntervalDate, Date startDate, Date endDate, final Map properties, String eventSummary, String eventDescription) { + long milisPerDay = 86400000; //24 * 60 * 60 * 1000) + long milisPerWeek = 7 * milisPerDay; //7 days * (24hour * 60minutes * 60seconds * 1000mili seconds) + long diffInMilis = endEventIntervalDate.getTime() - beginEventIntervalDate.getTime(); + Boolean isOnceRepeatEvent = view.getOnceRepeatRB().getValue(); - Window.alert("isOnceRepeatEvent=" + isOnceRepeatEvent);//temp for checker + // Window.alert("isOnceRepeatEvent=" + isOnceRepeatEvent);//temp for checker + //if(!isOnceRepeatEvent.booleanValue()){ //Here process properties and define repetable events dates /*take parameters from View @@ -516,43 +521,36 @@ private void processAddEvent(Date endEventIntervalDate, final Date beginEventInt if needed compare if the Date exist in Month (like 29 30 31 Febr etc) if needed define weekends after that in cycle add new events - */ - + */ // Boolean isAllDayEvent = view.getAllDayCheckbox().getValue(); // // Window.alert("isAllDayEvent=" + isAllDayEvent);//temp for checker - -Boolean isDailyRepeatEvent = view.getDailyRepeatRB() != null ? view.getDailyRepeatRB().getValue() : Boolean.FALSE; -Boolean isWeeklyRepeatEvent = view.getWeeklyRepeatRB().getValue(); -Boolean isMonthlyRepeatEvent = view.getMonthlyRepeatRB().getValue(); -Boolean isYearlyRepeatEvent = view.getYearlyRepeatRB().getValue(); - -Boolean isMonthlySameDayOfWeek = view.getRadioMonthlySameDayOfWeek().getValue(); -Boolean isMonthlySameDate = view.getRadioMonthlySameDate().getValue(); - -Boolean isYearlySameDayOfWeek = view.getYearlySameDayOfWeekRB().getValue(); -Boolean isYearlySameDate = view.getYearlySameDateRB().getValue(); - -Window.alert("isYearlySameDayOfWeek=" + isYearlySameDayOfWeek);//temp for checker -Window.alert("isYearlySameDate=" + isYearlySameDate);//temp for checker - -long milisPerDay = 86400000; //24 * 60 * 60 * 1000) -long milisPerWeek = 7 * milisPerDay; //7 days * (24hour * 60minutes * 60seconds * 1000mili seconds) -long diffInMilis = endEventIntervalDate.getTime() - beginEventIntervalDate.getTime(); - -if(isDailyRepeatEvent){ - processDailyEvents(diffInMilis, milisPerDay, beginEventIntervalDate, startDate, endDate, properties, eventSummary, eventDescription); -} else if (isWeeklyRepeatEvent){ - processWeeklyEvents(diffInMilis, milisPerWeek, beginEventIntervalDate, startDate, endDate, properties, eventSummary, eventDescription); -} else if (isMonthlyRepeatEvent){ - Window.alert("MONTHLY : " + (isMonthlySameDayOfWeek?"Same DAY of a Week":"") - +(isMonthlySameDate?"Same DATE":""));//temp for checker - processMonthlyEvents(beginEventIntervalDate, endEventIntervalDate, properties, isMonthlySameDayOfWeek, startDate, endDate, eventSummary, eventDescription); -} else if (isYearlyRepeatEvent) { - Window.alert("YEARLY : " + (isYearlySameDayOfWeek ? "Same DAY of a Week" : "") - + (isYearlySameDate ? "Same DATE" : ""));//temp for checker - processYearEvents(beginEventIntervalDate, endEventIntervalDate, properties, isYearlySameDayOfWeek, startDate, endDate, eventSummary, eventDescription); -} + Boolean isDailyRepeatEvent = view.getDailyRepeatRB() != null ? view.getDailyRepeatRB().getValue() : Boolean.FALSE; + Boolean isWeeklyRepeatEvent = view.getWeeklyRepeatRB().getValue(); + Boolean isMonthlyRepeatEvent = view.getMonthlyRepeatRB().getValue(); + Boolean isYearlyRepeatEvent = view.getYearlyRepeatRB().getValue(); + + Boolean isMonthlySameDayOfWeek = view.getRadioMonthlySameDayOfWeek().getValue(); + Boolean isMonthlySameDate = view.getRadioMonthlySameDate().getValue(); + + Boolean isYearlySameDayOfWeek = view.getYearlySameDayOfWeekRB().getValue(); + Boolean isYearlySameDate = view.getYearlySameDateRB().getValue(); + +//Window.alert("isYearlySameDayOfWeek=" + isYearlySameDayOfWeek);//temp for checker +//Window.alert("isYearlySameDate=" + isYearlySameDate);//temp for checker + if (isDailyRepeatEvent) { + processDailyEvents(diffInMilis, milisPerDay, beginEventIntervalDate, startDate, endDate, properties, eventSummary, eventDescription); + } else if (isWeeklyRepeatEvent) { + processWeeklyEvents(diffInMilis, milisPerWeek, beginEventIntervalDate, startDate, endDate, properties, eventSummary, eventDescription); + } else if (isMonthlyRepeatEvent) { +// Window.alert("MONTHLY : " + (isMonthlySameDayOfWeek?"Same DAY of a Week":"") +// +(isMonthlySameDate?"Same DATE":""));//temp for checker + processMonthlyEvents(beginEventIntervalDate, endEventIntervalDate, properties, isMonthlySameDayOfWeek, startDate, endDate, eventSummary, eventDescription); + } else if (isYearlyRepeatEvent) { +// Window.alert("YEARLY : " + (isYearlySameDayOfWeek ? "Same DAY of a Week" : "") +// + (isYearlySameDate ? "Same DATE" : ""));//temp for checker + processYearEvents(beginEventIntervalDate, endEventIntervalDate, properties, isYearlySameDayOfWeek, startDate, endDate, eventSummary, eventDescription); + } } /** @@ -641,7 +639,7 @@ private void processDailyEvents(long diffInMilis, long milisPerDay, final Date b calBeginNextEventDateLong += milisPerDay; calBeginNextEventDate = new Date(calBeginNextEventDateLong); - long calNextEventStartTime = calBeginNextEventDateLong; + // long calNextEventStartTime = calBeginNextEventDateLong; // calNextEventStartTime += milisPerDay; // calNextEventEndTime += milisPerDay; @@ -684,7 +682,7 @@ private void processWeeklyEvents(long diffInMilis, long milisPerWeek, final Date long calBeginNextEventDateLong = beginEventIntervalDate.getTime(); Date calBeginNextEventDate = beginEventIntervalDate; - long calNextEventStartTime;// = startDate.getTime(); + //long calNextEventStartTime;// = startDate.getTime(); //long calNextEventEndTime = endDate.getTime(); if (weeksInterval > 1) { @@ -697,7 +695,7 @@ private void processWeeklyEvents(long diffInMilis, long milisPerWeek, final Date calBeginNextEventDateLong += milisPerWeek; calBeginNextEventDate = new Date(calBeginNextEventDateLong); - calNextEventStartTime = calBeginNextEventDateLong; + //calNextEventStartTime = calBeginNextEventDateLong; // calNextEventStartTime += milisPerWeek; //calNextEventEndTime += milisPerWeek; @@ -994,7 +992,7 @@ private static boolean isFullDayEvent(final Event event) { && (event.getDtstart().getDate() != event.getDtend().getDate() || event.getDtstart().getMonth() != event.getDtend().getMonth() || event.getDtstart() .getYear() != event.getDtend().getYear()); } - +/* @SuppressWarnings({"deprecation"}) private Date getMonthlySameDayOfWeek(Date dateObject, int numberMonths) { Date firstDate = new Date(); @@ -1021,7 +1019,7 @@ private Date getMonthlySameDayOfWeek(Date dateObject, int numberMonths) { return newDate; } - +*/ /** * * @param firstDate @@ -1190,7 +1188,7 @@ private Date getSameWeekDay(Date firstDate, Date nextDate) { } return newDate; } - +/* private Date getSameWeekDay22(Date firstDate, Date nextDate) { //Calculate same day of week int dayOfFirst = firstDate.getDay(); @@ -1243,7 +1241,15 @@ private Date getSameWeekDay2(Date firstDate, Date nextDate) { } return newDate; } - + */ + + /** + * + * @param year the value of year + * @param month the value of month + * @return the int + */ + private int getDaysInMonth(int year, int month) { int daysInMonth = 31; From e74e3723e1bf759416dbdfb57be4c6b515925f4b Mon Sep 17 00:00:00 2001 From: Seal98 Date: Mon, 26 Jun 2017 11:03:48 +0300 Subject: [PATCH 15/39] [WIP] Advanced calendar component (issue#852) Refactoring#5 of CalendarEventPresenter class. Commented out unused variables --- .../ui/presenter/calendar/CalendarEventPresenter.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java b/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java index c946d52e0..40ca361c9 100644 --- a/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java +++ b/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java @@ -509,7 +509,7 @@ private void processAddEvent(Date endEventIntervalDate, final Date beginEventInt long milisPerWeek = 7 * milisPerDay; //7 days * (24hour * 60minutes * 60seconds * 1000mili seconds) long diffInMilis = endEventIntervalDate.getTime() - beginEventIntervalDate.getTime(); - Boolean isOnceRepeatEvent = view.getOnceRepeatRB().getValue(); + //Boolean isOnceRepeatEvent = view.getOnceRepeatRB().getValue(); // Window.alert("isOnceRepeatEvent=" + isOnceRepeatEvent);//temp for checker //if(!isOnceRepeatEvent.booleanValue()){ @@ -531,10 +531,10 @@ private void processAddEvent(Date endEventIntervalDate, final Date beginEventInt Boolean isYearlyRepeatEvent = view.getYearlyRepeatRB().getValue(); Boolean isMonthlySameDayOfWeek = view.getRadioMonthlySameDayOfWeek().getValue(); - Boolean isMonthlySameDate = view.getRadioMonthlySameDate().getValue(); + //Boolean isMonthlySameDate = view.getRadioMonthlySameDate().getValue(); Boolean isYearlySameDayOfWeek = view.getYearlySameDayOfWeekRB().getValue(); - Boolean isYearlySameDate = view.getYearlySameDateRB().getValue(); + // Boolean isYearlySameDate = view.getYearlySameDateRB().getValue(); //Window.alert("isYearlySameDayOfWeek=" + isYearlySameDayOfWeek);//temp for checker //Window.alert("isYearlySameDate=" + isYearlySameDate);//temp for checker @@ -585,7 +585,7 @@ private Date createStartDateProperty(Boolean isAllDayEvent, final Date beginEven private Date createEndDateProperty(Boolean isAllDayEvent, final Date beginEventIntervalDate, final Map properties) { //final Date endDate = null;//view.getEventEndTimeField().getDateValue(); - if (isAllDayEvent) { + if (!isAllDayEvent) { //endDate = null; endDate = view.getEventEndTimeField().getDateValue(); } From 3222415ac9ff5f570b3cd62e94ec03b50d1c1732 Mon Sep 17 00:00:00 2001 From: Seal98 Date: Mon, 26 Jun 2017 21:42:14 +0300 Subject: [PATCH 16/39] [WIP] Advanced calendar component (issue#852) Refactoring#6 of CalendarEventPresenter and CalendarEventView classes. + fix to hide end event date filed on EditView --- .../calendar/CalendarEventPresenter.java | 6 +- .../ui/view/calendar/CalendarEventView.java | 234 ++++++++---------- 2 files changed, 103 insertions(+), 137 deletions(-) diff --git a/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java b/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java index 40ca361c9..a9ae6966e 100644 --- a/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java +++ b/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java @@ -363,6 +363,9 @@ private void prepareEditView() { view.getYearlySameDayOfWeekRB().hide(); view.getRadioMonthlySameDate().hide(); view.getRadioMonthlySameDayOfWeek().hide(); + + view.getEventDateEndField().clear(); + view.getEventDateEndField().hide(); } // if(creation) { // view.getIsAllDayCheckbox().hide(); @@ -424,6 +427,7 @@ private void prepareAddView() { // view.getRepeatEventPeriodRG().show(); // return; //view.getRepeatEventPeriodRG().show(); + view.getEventDateEndField().show(); } // --------------------------------------------------------------------------------------------------------------- @@ -455,7 +459,7 @@ private void onSaveAction() { properties.put(Event.DATE, beginEventIntervalDate); //final - Date endEventIntervalDate = view.getEventDateEndField().getValue(); + Date endEventIntervalDate = (view.getEventDateEndField()!=null?view.getEventDateEndField().getValue():null); if(endEventIntervalDate == null){ endEventIntervalDate = beginEventIntervalDate; } diff --git a/src/main/java/org/sigmah/client/ui/view/calendar/CalendarEventView.java b/src/main/java/org/sigmah/client/ui/view/calendar/CalendarEventView.java index 98498a1b0..0a0a315a1 100644 --- a/src/main/java/org/sigmah/client/ui/view/calendar/CalendarEventView.java +++ b/src/main/java/org/sigmah/client/ui/view/calendar/CalendarEventView.java @@ -85,19 +85,6 @@ public class CalendarEventView extends AbstractPopupView implements // private CheckBoxGroup allDayCheckboxGr; private RadioGroup RepeatEventPeriodRG; - //private boolean showAddEventView = true; - -// public boolean isShowAddEventView() { -// return showAddEventView; -// } - -// /** -// * {@inheritDoc} -// */ -// // @Override -// public void setShowAddEventView(boolean showAddEventView) { -// this.showAddEventView = showAddEventView; -// } /** * Builds the view. @@ -112,24 +99,11 @@ public CalendarEventView() { @Override public void initialize() { form = Forms.panel(); - //setShowAddEventView(Forms.panel().getTitle().equalsIgnoreCase(I18N.CONSTANTS.calendarAddEvent())); -// if (form.getTitle() != null) { -// // Window.alert( form.getTitle()+ " !!"); -// setShowAddEventView(Forms.panel().getTitle().equalsIgnoreCase(I18N.CONSTANTS.calendarAddEvent())); -// } else { -// Window.alert("setShowAddEventView(false)"); -// setShowAddEventView(false); -// } - // Window.alert("111"); - // if(isShowAddEventView()){ - // Window.alert(isShowAddEventView() + "isShowAddEventView 3"); + createYearlyPanel(); createMonthlyPanel(); createRepeatEventPeriodRadioGroup(); - // } -// CheckBoxGroup allDayCheckboxGr = -// createAllDayCheckboxGroup(); eventSummaryField = Forms.text(I18N.CONSTANTS.calendarEventObject(), true); eventSummaryField.setName(Event.SUMMARY); @@ -165,11 +139,9 @@ public void initialize() { //form.add(allDayCheckboxGr); form.add(eventStartTimeField); form.add(eventEndTimeField); -//if(isShowAddEventView()){ form.add(RepeatEventPeriodRG); form.add(panelYearly); form.add(panelMonthly); -//} form.add(eventDescriptionField); form.addButton(cancelButton); @@ -179,7 +151,7 @@ public void initialize() { } private CheckBox createAllDayCheckbox() { - // private CheckBoxGroup createAllDayCheckboxGroup() { + allDayCheckbox = Forms.checkbox(I18N.CONSTANTS.calendar_addEvent_isAllDayCB_boxLabel(), "All day name", false); allDayCheckbox.setFieldLabel(I18N.CONSTANTS.calendar_addEvent_allDayCbGr_label()); // allDayCheckbox.setBoxLabel(I18N.CONSTANTS.calendar_addEvent_isAllDayCB_boxLabel()); @@ -187,104 +159,67 @@ private CheckBox createAllDayCheckbox() { allDayCheckbox.addListener(Events.OnChange, new Listener() { @Override public void handleEvent(FieldEvent event) { -// eventStartTimeField.setVisible(((Boolean) event.getValue()).booleanValue()); -// eventEndTimeField.setVisible(((Boolean) event.getValue()).booleanValue()); -//checkbox.getValue() eventStartTimeField.setVisible(!allDayCheckbox.getValue()); eventEndTimeField.setVisible(!allDayCheckbox.getValue()); Window.alert(getAllDayCheckbox().getBoxLabel() + " is checked"); } }); -// CheckBoxGroup allDayCheckboxGr = Forms.checkBoxGroup(I18N.CONSTANTS.calendar_addEvent_allDayCbGr_label(), allDayCheckbox); -//// allDayCheckbox.addHandler(new ValueChangeHandler() { -//// @Override -//// public void onValueChange(ValueChangeEvent event) { -//// eventStartTimeField.setVisible(event.getValue()); -//// eventEndTimeField.setVisible(event.getValue()); -//// } -//// }, ValueChangeEvent.getType()); -// return allDayCheckboxGr; -// } + return allDayCheckbox; } private void createRepeatEventPeriodRadioGroup() { - //final Radio - onceRepeatRB = Forms.radio("once", "onceRepeatRBname", Boolean.FALSE); - onceRepeatRB.setOriginalValue(Boolean.TRUE); - onceRepeatRB.setToolTip(I18N.CONSTANTS.calendar_addEvent_repeatOnceRB_toolTip()); - //onceRepeatRB = new Radio(); -// onceRepeatRB.setBoxLabel("once"); -// onceRepeatRB.setName("once"); -// onceRepeatRB.setValue(true); -// onceRepeatRB.focus(); -//if(isShowAddEventView()){ - onceRepeatRB.addListener(Events.OnChange, new Listener() { - @Override - public void handleEvent(FieldEvent event) { + createOnceRb(); + createDailyRb(); + createWeeklyRb(); + createMonthlyRb(); + createYearlyRb(); - getPanelYearly().setVisible(!onceRepeatRB.getValue()); - getPanelMonthly().setVisible(!onceRepeatRB.getValue()); - eventStartTimeField.setVisible(!dailyRepeatRB.getValue()); - eventEndTimeField.setVisible(!dailyRepeatRB.getValue()); -// eventDateStartField.setAllowBlank(false); -// eventDateStartField.setAllowBlank(true); - ((TextArea) form.getItemByItemId(Event.DESCRIPTION)).setValue(" The Once event."); - Window.alert(getOnceRepeatRB().getBoxLabel() + " is checked Listener OnChange on ONCE radio"); - } - }); -//} + RepeatEventPeriodRG = Forms.radioGroup(I18N.CONSTANTS.calendar_addEvent_repeatPeriodRG_label(), + "Repeat event 999", + Style.Orientation.HORIZONTAL, + onceRepeatRB, + dailyRepeatRB, + weeklyRepeatRB, + monthlyRepeatRB, + yearlyRepeatRB); + RepeatEventPeriodRG.setSelectionRequired(Boolean.TRUE); + RepeatEventPeriodRG.enable(); + } -//final Radio -//dailyRepeatRB = new Radio(); - dailyRepeatRB = Forms.radio("daily", "daily", Boolean.FALSE); -// dailyRepeatRB.setBoxLabel("daily"); -// dailyRepeatRB.setName("daily"); -// dailyRepeatRB.setValue(false); -//if(isShowAddEventView()){ - dailyRepeatRB.addListener(Events.OnChange, new Listener() { - @Override - public void handleEvent(FieldEvent event) { - ((TextArea) form.getItemByItemId(Event.DESCRIPTION)).setValue(" The Daily event."); -// eventStartTimeField.setVisible(!dailyRepeatRB.getValue()); -// eventEndTimeField.setVisible(!dailyRepeatRB.getValue()); -// eventDateStartField.setAllowBlank(false); - getPanelYearly().setVisible(!dailyRepeatRB.getValue()); - getPanelMonthly().setVisible(!dailyRepeatRB.getValue()); - Window.alert(getDailyRepeatRB().getBoxLabel() + " is checked Listener OnChange on DAILY radio"); - } - }); -//} -//final Radio -// weeklyRepeatRB = new Radio(); - weeklyRepeatRB = Forms.radio("weekly", "weekly", Boolean.FALSE); - weeklyRepeatRB.setToolTip(I18N.CONSTANTS.calendar_addEvent_repeatWeeklyRB_toolTip()); -// weeklyRepeatRB.setBoxLabel("weekly"); -// weeklyRepeatRB.setName("weekly"); -// weeklyRepeatRB.setValue(false); -//if(isShowAddEventView()){ - weeklyRepeatRB.addListener(Events.OnChange, new Listener() { + private void createYearlyRb() { + //final Radio +// yearlyRepeatRB = Forms.radio("yearlyRepeatRB label", "yearlyRepeatRB name", Boolean.FALSE); +//yearlyRepeatRB = new Radio(); + yearlyRepeatRB = Forms.radio("yearly", "yearly", Boolean.FALSE); + yearlyRepeatRB.setToolTip(I18N.CONSTANTS.calendar_addEvent_repeatYearlyRB_toolTip()); +// yearlyRepeatRB.setBoxLabel("yearly"); +// yearlyRepeatRB.setName("yearly"); +// yearlyRepeatRB.setValue(false); + yearlyRepeatRB.addListener(Events.OnChange, new Listener() { @Override public void handleEvent(FieldEvent event) { //eventStartTimeField.setVisible(!yearlyRepeatRB.getValue()); // eventEndTimeField.setVisible(!yearlyRepeatRB.getValue()); - ((TextArea) form.getItemByItemId(Event.DESCRIPTION)).setValue(" The Weekly event."); - getPanelYearly().setVisible(!weeklyRepeatRB.getValue()); - getPanelMonthly().setVisible(!weeklyRepeatRB.getValue()); + ((TextArea) form.getItemByItemId(Event.DESCRIPTION)).setValue(" The Yearly event."); + getPanelYearly().setVisible(getYearlyRepeatRB().getValue()); + getPanelMonthly().setVisible(!yearlyRepeatRB.getValue()); + getYearlySameDateRB().show(); + getYearlySameDayOfWeekRB().show(); + getYearlySameDateRB().setValue(true); eventDateStartField.setAllowBlank(false); - Window.alert(getWeeklyRepeatRB().getBoxLabel() + " is checked Listener OnChange on weekly radio"); + Window.alert(getYearlyRepeatRB().getBoxLabel() + " is checked Listener OnChange on Yearly radio"); } }); -//} -//final Radio -// monthlyRepeatRB = new Radio(); + } + + private void createMonthlyRb() { monthlyRepeatRB = Forms.radio("monthly", "monthly", Boolean.FALSE); monthlyRepeatRB.setToolTip(I18N.CONSTANTS.calendar_addEvent_repeatMonthlyRB_toolTip()); // monthlyRepeatRB.setBoxLabel("monthly"); // monthlyRepeatRB.setName("monthly"); // monthlyRepeatRB.setValue(false); -//if(isShowAddEventView()){ monthlyRepeatRB.addListener(Events.OnChange, new Listener() { @Override public void handleEvent(FieldEvent event) { @@ -300,45 +235,72 @@ public void handleEvent(FieldEvent event) { Window.alert(getMonthlyRepeatRB().getBoxLabel() + " is checked Listener OnChange on monthly radio"); } }); -//} -//final Radio -// yearlyRepeatRB = Forms.radio("yearlyRepeatRB label", "yearlyRepeatRB name", Boolean.FALSE); -//yearlyRepeatRB = new Radio(); - yearlyRepeatRB = Forms.radio("yearly", "yearly", Boolean.FALSE); - yearlyRepeatRB.setToolTip(I18N.CONSTANTS.calendar_addEvent_repeatYearlyRB_toolTip()); -// yearlyRepeatRB.setBoxLabel("yearly"); -// yearlyRepeatRB.setName("yearly"); -// yearlyRepeatRB.setValue(false); -//if(isShowAddEventView()){ - yearlyRepeatRB.addListener(Events.OnChange, new Listener() { + } + + private void createWeeklyRb() { + weeklyRepeatRB = Forms.radio("weekly", "weekly", Boolean.FALSE); + weeklyRepeatRB.setToolTip(I18N.CONSTANTS.calendar_addEvent_repeatWeeklyRB_toolTip()); +// weeklyRepeatRB.setBoxLabel("weekly"); +// weeklyRepeatRB.setName("weekly"); +// weeklyRepeatRB.setValue(false); + weeklyRepeatRB.addListener(Events.OnChange, new Listener() { @Override public void handleEvent(FieldEvent event) { //eventStartTimeField.setVisible(!yearlyRepeatRB.getValue()); // eventEndTimeField.setVisible(!yearlyRepeatRB.getValue()); - ((TextArea) form.getItemByItemId(Event.DESCRIPTION)).setValue(" The Yearly event."); - getPanelYearly().setVisible(getYearlyRepeatRB().getValue()); - getPanelMonthly().setVisible(!yearlyRepeatRB.getValue()); - - getYearlySameDateRB().show(); - getYearlySameDayOfWeekRB().show(); - getYearlySameDateRB().setValue(true); + ((TextArea) form.getItemByItemId(Event.DESCRIPTION)).setValue(" The Weekly event."); + getPanelYearly().setVisible(!weeklyRepeatRB.getValue()); + getPanelMonthly().setVisible(!weeklyRepeatRB.getValue()); + eventDateStartField.setAllowBlank(false); - Window.alert(getYearlyRepeatRB().getBoxLabel() + " is checked Listener OnChange on Yearly radio"); + Window.alert(getWeeklyRepeatRB().getBoxLabel() + " is checked Listener OnChange on weekly radio"); + } + }); + } + + /** + * + */ + private void createDailyRb() { + //final Radio +//dailyRepeatRB = new Radio(); + dailyRepeatRB = Forms.radio("daily", "daily", Boolean.FALSE); +// dailyRepeatRB.setBoxLabel("daily"); +// dailyRepeatRB.setName("daily"); +// dailyRepeatRB.setValue(false); + dailyRepeatRB.addListener(Events.OnChange, new Listener() { + @Override + public void handleEvent(FieldEvent event) { + ((TextArea) form.getItemByItemId(Event.DESCRIPTION)).setValue(" The Daily event."); +// eventStartTimeField.setVisible(!dailyRepeatRB.getValue()); +// eventEndTimeField.setVisible(!dailyRepeatRB.getValue()); +// eventDateStartField.setAllowBlank(false); + getPanelYearly().setVisible(!dailyRepeatRB.getValue()); + getPanelMonthly().setVisible(!dailyRepeatRB.getValue()); + Window.alert(getDailyRepeatRB().getBoxLabel() + " is checked Listener OnChange on DAILY radio"); + } + }); + } + + private void createOnceRb() { + onceRepeatRB = Forms.radio("once", "onceRepeatRBname", Boolean.FALSE); + onceRepeatRB.setOriginalValue(Boolean.TRUE); + onceRepeatRB.setToolTip(I18N.CONSTANTS.calendar_addEvent_repeatOnceRB_toolTip()); + + onceRepeatRB.addListener(Events.OnChange, new Listener() { + @Override + public void handleEvent(FieldEvent event) { + + getPanelYearly().setVisible(!onceRepeatRB.getValue()); + getPanelMonthly().setVisible(!onceRepeatRB.getValue()); + eventStartTimeField.setVisible(!dailyRepeatRB.getValue()); + eventEndTimeField.setVisible(!dailyRepeatRB.getValue()); +// eventDateStartField.setAllowBlank(false); +// eventDateStartField.setAllowBlank(true); + ((TextArea) form.getItemByItemId(Event.DESCRIPTION)).setValue(" The Once event."); + Window.alert(getOnceRepeatRB().getBoxLabel() + " is checked Listener OnChange on ONCE radio"); } }); -//} -//YEARLY END -//final RadioGroup - RepeatEventPeriodRG = Forms.radioGroup(I18N.CONSTANTS.calendar_addEvent_repeatPeriodRG_label(), - "Repeat event 999", - Style.Orientation.HORIZONTAL, - onceRepeatRB, - dailyRepeatRB, - weeklyRepeatRB, - monthlyRepeatRB, - yearlyRepeatRB); - RepeatEventPeriodRG.setSelectionRequired(Boolean.TRUE); - RepeatEventPeriodRG.enable(); } private void createMonthlyPanel() { From 167a8b7729df977fe5553d6208abefc1b9430fd4 Mon Sep 17 00:00:00 2001 From: Seal98 Date: Mon, 10 Jul 2017 23:28:30 +0300 Subject: [PATCH 17/39] [Issue #852] : Calendar event chain functionality To provide event chain functionality: 1. added two new fields (referenceId and eventtype) into the database 2. changed java classes to provide the generation of the reference ids 3. added functionality to remove events chain by one click (Delete chain link in Calendar view) --- .../calendar/CalendarEventPresenter.java | 406 +++++++++++------- .../presenter/calendar/CalendarPresenter.java | 126 +++++- .../ui/view/calendar/CalendarEventView.java | 77 ++-- .../client/ui/widget/CalendarWidget.java | 15 +- .../sigmah/offline/js/PersonalEventJS.java | 23 +- .../server/domain/calendar/PersonalEvent.java | 31 ++ .../server/domain/util/EntityConstants.java | 5 +- .../calendar/PersonalCalendarHandler.java | 2 + .../server/service/PersonalEventService.java | 4 +- .../org/sigmah/shared/dto/calendar/Event.java | 30 +- .../sigmah/client/i18n/UIConstants.properties | 29 ++ 11 files changed, 532 insertions(+), 216 deletions(-) diff --git a/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java b/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java index a9ae6966e..e36c0b51d 100644 --- a/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java +++ b/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java @@ -1,5 +1,4 @@ package org.sigmah.client.ui.presenter.calendar; - /* * #%L * Sigmah @@ -50,7 +49,6 @@ import org.sigmah.shared.dto.calendar.CalendarWrapper; import org.sigmah.shared.dto.calendar.Event; import org.sigmah.shared.dto.calendar.PersonalEventDTO; - import com.allen_sauer.gwt.log.client.Log; import com.extjs.gxt.ui.client.event.ButtonEvent; import com.extjs.gxt.ui.client.event.SelectionListener; @@ -65,6 +63,8 @@ import com.extjs.gxt.ui.client.widget.form.TextField; import com.extjs.gxt.ui.client.widget.form.Time; import com.extjs.gxt.ui.client.widget.form.TimeField; +import static com.google.gwt.core.ext.TreeLogger.NULL; +import com.google.gwt.user.client.Timer; import com.google.inject.ImplementedBy; import com.google.inject.Inject; import com.google.inject.Singleton; @@ -329,16 +329,11 @@ public void onPageRequest(final PageRequest request) { } /** - * + * Create Edit Calendar Event View */ private void prepareEditView() { - // EDIST EXISTING EVENT - //view.setShowAddEventView(false); - //view.getRepeatEventPeriodRG().hide(); - //--->> } - this.calendarWrapper = new CalendarWrapper(event.getParent()); - //view.setShowAddEventView(false); + view.getForm().clearState(); view.getEventSummaryField().setValue(event.getSummary()); view.getEventDateStartField().setValue(event.getKey()); @@ -367,11 +362,7 @@ private void prepareEditView() { view.getEventDateEndField().clear(); view.getEventDateEndField().hide(); } -// if(creation) { -// view.getIsAllDayCheckbox().hide(); -// } else {// CREATE NEW EVENT NEW BELOW -// view.getRepeatEventPeriodRG().hide(); -// } + view.getEventStartTimeField().show(); view.getEventEndTimeField().show(); @@ -389,20 +380,15 @@ private void prepareEditView() { } /** - * + * Create Add Calendar Event View */ private void prepareAddView() { - // view.getForm().clearState(); - // view.initialize(); - //view.setShowAddEventView(true); if (view.getRepeatEventPeriodRG() != null) { view.getRepeatEventPeriodRG().enable(); view.getRepeatEventPeriodRG().show(); view.getOnceRepeatRB().setValue(true); view.getPanelMonthly().hide(); view.getPanelYearly().hide(); - //view.getMontlyVariantRG().show(); - //view.getYearlyVariantRG().show(); } view.getEventStartTimeField().show(); view.getEventEndTimeField().show(); @@ -424,9 +410,6 @@ private void prepareAddView() { view.getYearlySameDayOfWeekRB().show(); view.getRadioMonthlySameDate().show(); view.getRadioMonthlySameDayOfWeek().show(); - // view.getRepeatEventPeriodRG().show(); - // return; - //view.getRepeatEventPeriodRG().show(); view.getEventDateEndField().show(); } @@ -444,62 +427,46 @@ private void onSaveAction() { if (!view.getForm().isValid()) { return; } - // -- // Building properties map. // -- final Map properties = new HashMap(); properties.put(Event.CALENDAR_ID, calendarWrapper); properties.put(Event.SUMMARY, view.getEventSummaryField().getValue()); - + String eventSummary = view.getEventSummaryField().getValue(); String eventDescription = view.getEventDescriptionField().getValue(); final Date beginEventIntervalDate = view.getEventDateStartField().getValue(); properties.put(Event.DATE, beginEventIntervalDate); - - //final - Date endEventIntervalDate = (view.getEventDateEndField()!=null?view.getEventDateEndField().getValue():null); - if(endEventIntervalDate == null){ + + Date endEventIntervalDate = (view.getEventDateEndField() != null ? view.getEventDateEndField().getValue() : null); + if (endEventIntervalDate == null) { endEventIntervalDate = beginEventIntervalDate; } - - Boolean isAllDayEvent = view.getAllDayCheckbox().getValue(); - - Window.alert("isAllDayEvent=" + isAllDayEvent);//temp for checker - - Date startDate = createStartDateProperty(isAllDayEvent, beginEventIntervalDate, properties); - Date endDate = createEndDateProperty(isAllDayEvent, beginEventIntervalDate, properties); + Boolean isFullDayEvent = view.getAllDayCheckbox().getValue(); + + Window.alert("isAllDayEvent=" + isFullDayEvent);//temp for checker + + Date startDate = createStartDateProperty(isFullDayEvent, beginEventIntervalDate, properties); + Date endDate = createEndDateProperty(isFullDayEvent, beginEventIntervalDate, properties); properties.put(Event.DESCRIPTION, view.getEventDescriptionField().getValue()); if (event == null) { - + // process properties and define repetable events dates processAddEvent(endEventIntervalDate, beginEventIntervalDate, startDate, endDate, properties, eventSummary, eventDescription); //add first event, to include in properties updated description and summary with event period type //the first event is added last - after processing previous events - addPersonalEvent(properties); - //} - -//Here process properties and define repetable events dates + //addPersonalEvent(properties); } else { editPersonalEvent(event, properties); -// properties.remove(Event.START_TIME); -// properties.remove(Event.END_TIME); - //properties.remove(Event.DATE); } - -// if (event == null) { -// addPersonalEvent(properties); -// -// } else { -// editPersonalEvent(event, properties); -// } -} + } /** - * + * Add new calendar events processing. * @param endEventIntervalDate the value of endEventIntervalDate * @param beginEventIntervalDate the value of beginEventIntervalDate * @param startDate the value of startDate @@ -526,9 +493,9 @@ private void processAddEvent(Date endEventIntervalDate, final Date beginEventInt if needed define weekends after that in cycle add new events */ -// Boolean isAllDayEvent = view.getAllDayCheckbox().getValue(); +// Boolean isFullDayEvent = view.getAllDayCheckbox().getValue(); // -// Window.alert("isAllDayEvent=" + isAllDayEvent);//temp for checker +// Window.alert("isFullDayEvent=" + isFullDayEvent);//temp for checker Boolean isDailyRepeatEvent = view.getDailyRepeatRB() != null ? view.getDailyRepeatRB().getValue() : Boolean.FALSE; Boolean isWeeklyRepeatEvent = view.getWeeklyRepeatRB().getValue(); Boolean isMonthlyRepeatEvent = view.getMonthlyRepeatRB().getValue(); @@ -555,18 +522,21 @@ private void processAddEvent(Date endEventIntervalDate, final Date beginEventInt // + (isYearlySameDate ? "Same DATE" : ""));//temp for checker processYearEvents(beginEventIntervalDate, endEventIntervalDate, properties, isYearlySameDayOfWeek, startDate, endDate, eventSummary, eventDescription); } + else{ + processOnceEvent(startDate, endDate, properties, eventSummary, eventDescription); + } } /** - * - * @param isAllDayEvent the value of isAllDayEvent + * Create Start event date property + * @param isFulllDayEvent the value of isFullDayEvent * @param beginEventIntervalDate the value of beginEventIntervalDate * @param properties the value of properties */ - private Date createStartDateProperty(Boolean isAllDayEvent, final Date beginEventIntervalDate, final Map properties) { - //final - Date startDate = null; //view.getEventStartTimeField().getDateValue(); - if (!isAllDayEvent) { + private Date createStartDateProperty(Boolean isFulllDayEvent, final Date beginEventIntervalDate, final Map properties) { + + Date startDate = null; + if (!isFulllDayEvent) { startDate = view.getEventStartTimeField().getDateValue(); } if (startDate != null) { @@ -581,16 +551,15 @@ private Date createStartDateProperty(Boolean isAllDayEvent, final Date beginEven } /** - * - * @param isAllDayEvent the value of isAllDayEvent + * Create End event date property + * @param isFulllDayEvent the value of isFullDayEvent * @param beginEventIntervalDate the value of beginEventIntervalDate * @param properties the value of properties */ - private Date createEndDateProperty(Boolean isAllDayEvent, final Date beginEventIntervalDate, final Map properties) { - //final - Date endDate = null;//view.getEventEndTimeField().getDateValue(); - if (!isAllDayEvent) { - //endDate = null; + private Date createEndDateProperty(Boolean isFulllDayEvent, final Date beginEventIntervalDate, final Map properties) { + + Date endDate = null; + if (!isFulllDayEvent) { endDate = view.getEventEndTimeField().getDateValue(); } if (endDate != null) { @@ -604,8 +573,16 @@ private Date createEndDateProperty(Boolean isAllDayEvent, final Date beginEventI return endDate; } - /** - * + private void processOnceEvent(final Date startDate, final Date endDate, final Map properties, String eventSummary, String eventDescription){ + properties.put(Event.SUMMARY, (String) properties.get(Event.SUMMARY)); + properties.put(Event.DESCRIPTION, (String) properties.get(Event.DESCRIPTION)); + // properties.put(Event.EVENT_TYPE, "O"); + // properties.put(Event.REFERENCE_ID, 1); + addPersonalEvent(properties); + } + + /** + * Add new Daily calendar events processing. * @param diffInMilis the value of diffInMilis * @param milisPerDay the value of milisPerDay * @param beginEventIntervalDate the value of beginEventIntervalDate @@ -616,46 +593,63 @@ private Date createEndDateProperty(Boolean isAllDayEvent, final Date beginEventI * @param eventDescription the value of eventDescription */ private void processDailyEvents(long diffInMilis, long milisPerDay, final Date beginEventIntervalDate, final Date startDate, final Date endDate, final Map properties, String eventSummary, String eventDescription) { - /* - 1. find number of days between start and end - 2. in cycle create new event - */ int daysInterval = 0; - -// long milisPerDay = 86400000; //24 * 60 * 60 * 1000) -// long diffInMilis = endEventIntervalDate.getTime() - beginEventIntervalDate.getTime(); long daysDiff = diffInMilis / milisPerDay + 1; daysInterval = (int) daysDiff; -// java.util.Calendar is not supported by GWT !!! long calBeginNextEventDateLong = beginEventIntervalDate.getTime(); Date calBeginNextEventDate = beginEventIntervalDate; - // - // long calNextEventStartTime ;//= startDate.getTime(); - // long calNextEventEndTime = endDate.getTime(); if (daysInterval > 1) { - properties.put(Event.SUMMARY, (String) properties.get(Event.SUMMARY) + " (Daily event 1 of " + daysInterval + ")"); + properties.put(Event.SUMMARY, (String) properties.get(Event.SUMMARY) + " ( 1 of " + daysInterval + ")"); properties.put(Event.DESCRIPTION, (String) properties.get(Event.DESCRIPTION) + " (Daily event 1 of " + daysInterval + ")"); + properties.put(Event.EVENT_TYPE, "D"); } + addPersonalEventDaily(properties,daysInterval, calBeginNextEventDateLong, milisPerDay, startDate, endDate, eventSummary, eventDescription); + + } + private void addPersonalEventDaily(final Map properties, final int daysInterval, final long calBeginNextEventDateLong, final long milisPerDay, final Date startDate, final Date endDate, final String eventSummary, final String eventDescription) { + + final CreateEntity createEntity = new CreateEntity(PersonalEventDTO.ENTITY_NAME, properties); + + dispatch.execute(createEntity, new CommandResultHandler() { + + @Override + public void onCommandFailure(final Throwable caught) { + if (Log.isErrorEnabled()) { + Log.error(I18N.CONSTANTS.calendarAddEventError(), caught); + } + N10N.error(I18N.CONSTANTS.error(), I18N.CONSTANTS.calendarAddEventError()); + } + @Override + public void onCommandSuccess(final CreateResult result) { + + // Creating events. + final Event event = new Event(); + event.setIdentifier((Integer) result.getEntity().getId()); + properties.put(Event.REFERENCE_ID, (Integer) result.getEntity().getId()); + updateEvent(event, properties); + // properties.put(Event.REFERENCE_ID, (Integer) result.getEntity().getId()); + addDailySeriesEvent((String) result.getEntity().getId(), daysInterval, calBeginNextEventDateLong, milisPerDay, startDate, endDate, eventSummary, eventDescription); + } + }, view.getCancelButton(), view.getSaveButton()); + } + private void addDailySeriesEvent(String ids, int daysInterval, long calBeginNextEventDateLong, long milisPerDay, final Date startDate, final Date endDate, String eventSummary, String eventDescription) { + Date calBeginNextEventDate; + for (int i = 1; i < daysInterval; i++) { calBeginNextEventDateLong += milisPerDay; calBeginNextEventDate = new Date(calBeginNextEventDateLong); - // long calNextEventStartTime = calBeginNextEventDateLong; - // calNextEventStartTime += milisPerDay; - // calNextEventEndTime += milisPerDay; Map dailyProperties = new HashMap(); dailyProperties.put(Event.CALENDAR_ID, calendarWrapper); dailyProperties.put(Event.SUMMARY, view.getEventSummaryField().getValue()); dailyProperties.put(Event.DATE, calBeginNextEventDate); - // setAllDayTime(startDate, endDate, calBeginNextEventDate, calNextEventEndTime, dailyProperties); - setAllDayTime(startDate, endDate, calBeginNextEventDate, dailyProperties); -// dailyProperties.put(Event.START_TIME, calNextEventStartTime); -// dailyProperties.put(Event.END_TIME, calNextEventEndTime); + + setFullDayEvent(startDate, endDate, calBeginNextEventDate, dailyProperties); String newSummary = eventSummary; String newDescription = eventDescription; @@ -663,13 +657,13 @@ private void processDailyEvents(long diffInMilis, long milisPerDay, final Date b newDescription += " (Daily event " + (i + 1) + " of " + daysInterval + ")"; dailyProperties.put(Event.SUMMARY, newSummary); dailyProperties.put(Event.DESCRIPTION, newDescription); - + dailyProperties.put(Event.EVENT_TYPE, "D"); + dailyProperties.put(Event.REFERENCE_ID, ids); addPersonalEvent(dailyProperties); } } - /** - * + * Add new Weekly calendar events processing. * @param diffInMilis the value of diffInMilis * @param milisPerWeek the value of milisPerWeek * @param beginEventIntervalDate the value of beginEventIntervalDate @@ -680,39 +674,62 @@ private void processDailyEvents(long diffInMilis, long milisPerDay, final Date b * @param eventDescription the value of eventDescription */ private void processWeeklyEvents(long diffInMilis, long milisPerWeek, final Date beginEventIntervalDate, final Date startDate, final Date endDate, final Map properties, String eventSummary, String eventDescription) { - // long diffInMilis = endEventIntervalDate.getTime() - beginEventIntervalDate.getTime(); long weekDiff = diffInMilis / milisPerWeek + 1; int weeksInterval = (int) weekDiff; long calBeginNextEventDateLong = beginEventIntervalDate.getTime(); Date calBeginNextEventDate = beginEventIntervalDate; - //long calNextEventStartTime;// = startDate.getTime(); - //long calNextEventEndTime = endDate.getTime(); if (weeksInterval > 1) { properties.put(Event.SUMMARY, (String) properties.get(Event.SUMMARY) + " (Weekly event 1 of " + weeksInterval + ")"); properties.put(Event.DESCRIPTION, (String) properties.get(Event.DESCRIPTION) + " (Weekly event 1 of " + weeksInterval + ")"); + properties.put(Event.EVENT_TYPE, "W"); } + addPersonalEventWeekly(properties,weeksInterval, calBeginNextEventDateLong, milisPerWeek, startDate, endDate, eventSummary, eventDescription); + + } + private void addPersonalEventWeekly(final Map properties, final int daysInterval, final long calBeginNextEventDateLong, final long milisPerDay, final Date startDate, final Date endDate, final String eventSummary, final String eventDescription) { + + final CreateEntity createEntity = new CreateEntity(PersonalEventDTO.ENTITY_NAME, properties); + + dispatch.execute(createEntity, new CommandResultHandler() { + + @Override + public void onCommandFailure(final Throwable caught) { + if (Log.isErrorEnabled()) { + Log.error(I18N.CONSTANTS.calendarAddEventError(), caught); + } + N10N.error(I18N.CONSTANTS.error(), I18N.CONSTANTS.calendarAddEventError()); + } + @Override + public void onCommandSuccess(final CreateResult result) { + + // Creating events. + final Event event = new Event(); + event.setIdentifier((Integer) result.getEntity().getId()); + properties.put(Event.REFERENCE_ID, (Integer) result.getEntity().getId()); + updateEvent(event, properties); + // properties.put(Event.REFERENCE_ID, (Integer) result.getEntity().getId()); + addWeeklySeriesEvent((String) result.getEntity().getId(), daysInterval, calBeginNextEventDateLong, milisPerDay, startDate, endDate, eventSummary, eventDescription); + } + }, view.getCancelButton(), view.getSaveButton()); + } + private void addWeeklySeriesEvent(String ids, int weeksInterval, long calBeginNextEventDateLong, long milisPerWeek, final Date startDate, final Date endDate, String eventSummary, String eventDescription) { + Date calBeginNextEventDate; + for (int i = 1; i < weeksInterval; i++) { calBeginNextEventDateLong += milisPerWeek; calBeginNextEventDate = new Date(calBeginNextEventDateLong); - //calNextEventStartTime = calBeginNextEventDateLong; - // calNextEventStartTime += milisPerWeek; - //calNextEventEndTime += milisPerWeek; - Map weeklyProperties = new HashMap(); weeklyProperties.put(Event.CALENDAR_ID, calendarWrapper); weeklyProperties.put(Event.SUMMARY, view.getEventSummaryField().getValue()); weeklyProperties.put(Event.DATE, calBeginNextEventDate); - // setAllDayTime(startDate, endDate, calBeginNextEventDate, calNextEventEndTime, weeklyProperties); - setAllDayTime(startDate, endDate, calBeginNextEventDate, weeklyProperties); -// weeklyProperties.put(Event.START_TIME, calNextEventStartTime); -// weeklyProperties.put(Event.END_TIME, calNextEventEndTime); + setFullDayEvent(startDate, endDate, calBeginNextEventDate, weeklyProperties); String newSummary = eventSummary; String newDescription = eventDescription; @@ -720,19 +737,19 @@ private void processWeeklyEvents(long diffInMilis, long milisPerWeek, final Date newDescription += " (Weekly event " + (i + 1) + " of " + weeksInterval + ")"; weeklyProperties.put(Event.SUMMARY, newSummary); weeklyProperties.put(Event.DESCRIPTION, newDescription); - + weeklyProperties.put(Event.EVENT_TYPE, "W"); + weeklyProperties.put(Event.REFERENCE_ID, ids); addPersonalEvent(weeklyProperties); } } - /** - * + * Set date and time values for Full day events. * @param startDate the value of startDate * @param endDate the value of endDate * @param calBeginNextEventDate the value of calBeginNextEventDate * @param thePeriodProperties the value of thePeriodProperties */ - private void setAllDayTime(final Date startDate, final Date endDate, Date calBeginNextEventDate, Map thePeriodProperties) { + private void setFullDayEvent(final Date startDate, final Date endDate, Date calBeginNextEventDate, Map thePeriodProperties) { if (startDate != null) { calBeginNextEventDate.setHours(startDate.getHours()); calBeginNextEventDate.setMinutes(startDate.getMinutes()); @@ -742,22 +759,17 @@ private void setAllDayTime(final Date startDate, final Date endDate, Date calBeg } if (endDate != null) { -// if(calNextEventEndTime>0){ -// thePeriodProperties.put(Event.END_TIME, calNextEventEndTime); -// -// }else{ Date endD = calBeginNextEventDate; endD.setHours(endDate.getHours()); endD.setMinutes(endDate.getMinutes()); thePeriodProperties.put(Event.END_TIME, endD.getTime()); - // } } else { thePeriodProperties.put(Event.END_TIME, null); } } /** - * + * Add new Monthly calendar events processing. * @param beginEventIntervalDate the value of beginEventIntervalDate * @param endEventIntervalDate the value of endEventIntervalDate * @param properties the value of properties @@ -784,10 +796,40 @@ private void processMonthlyEvents(final Date beginEventIntervalDate, final Date if (monthInterval > 1) { properties.put(Event.SUMMARY, (String) properties.get(Event.SUMMARY) + " (Monthly event 1 of " + monthInterval + ")"); properties.put(Event.DESCRIPTION, (String) properties.get(Event.DESCRIPTION) + " (Monthly event 1 of " + monthInterval + ")"); + if(isMonthlySameDayOfWeek) properties.put(Event.EVENT_TYPE, "M1"); + else properties.put(Event.EVENT_TYPE, "M2"); } + addPersonalEventMonthly(properties, monthInterval, beginEventIntervalDate, endEventIntervalDate, startDate, endDate, eventSummary, eventDescription, isMonthlySameDayOfWeek); + } + private void addPersonalEventMonthly(final Map properties, final int monthInterval, final Date beginEventIntervalDate, final Date endEventIntervalDate, final Date startDate, final Date endDate, final String eventSummary, final String eventDescription, final boolean isMonthlySameDayOfWeek) { - Date calBeginNextEventDate = beginEventIntervalDate; + final CreateEntity createEntity = new CreateEntity(PersonalEventDTO.ENTITY_NAME, properties); + + dispatch.execute(createEntity, new CommandResultHandler() { + + @Override + public void onCommandFailure(final Throwable caught) { + if (Log.isErrorEnabled()) { + Log.error(I18N.CONSTANTS.calendarAddEventError(), caught); + } + N10N.error(I18N.CONSTANTS.error(), I18N.CONSTANTS.calendarAddEventError()); + } + @Override + public void onCommandSuccess(final CreateResult result) { + + // Creating events. + final Event event = new Event(); + event.setIdentifier((Integer) result.getEntity().getId()); + properties.put(Event.REFERENCE_ID, (Integer) result.getEntity().getId()); + updateEvent(event, properties); + // properties.put(Event.REFERENCE_ID, (Integer) result.getEntity().getId()); + addMonthlySeriesEvent((String) result.getEntity().getId(), monthInterval, beginEventIntervalDate, endEventIntervalDate, startDate, endDate, eventSummary, eventDescription,isMonthlySameDayOfWeek); + } + }, view.getCancelButton(), view.getSaveButton()); + } + private void addMonthlySeriesEvent(String ids, int monthInterval, Date beginEventIntervalDate, Date endEventIntervalDate, final Date startDate, final Date endDate, String eventSummary, String eventDescription, final boolean isMonthlySameDayOfWeek) { + Date calBeginNextEventDate = beginEventIntervalDate; for (int i = 1; i < monthInterval; i++) { //calBeginNextEventDate = getMonthlySameDate(beginEventIntervalDate, calBeginNextEventDate, i); calBeginNextEventDate = getMonthlySameDayOfWeek2(beginEventIntervalDate, calBeginNextEventDate, i, isMonthlySameDayOfWeek); @@ -798,7 +840,7 @@ private void processMonthlyEvents(final Date beginEventIntervalDate, final Date monthlyProperties.put(Event.DATE, calBeginNextEventDate); - setAllDayTime(startDate, endDate, calBeginNextEventDate, monthlyProperties); + setFullDayEvent(startDate, endDate, calBeginNextEventDate, monthlyProperties); String newSummary = eventSummary; String newDescription = eventDescription; @@ -806,35 +848,67 @@ private void processMonthlyEvents(final Date beginEventIntervalDate, final Date newDescription += " (Monthly " + (isMonthlySameDayOfWeek ? "same Day of a week " : "same Date ") + "event " + (i + 1) + " of " + monthInterval + ")"; monthlyProperties.put(Event.SUMMARY, newSummary); monthlyProperties.put(Event.DESCRIPTION, newDescription); - + if(isMonthlySameDayOfWeek) monthlyProperties.put(Event.EVENT_TYPE, "M1"); + else monthlyProperties.put(Event.EVENT_TYPE, "M2"); + monthlyProperties.put(Event.REFERENCE_ID, ids); addPersonalEvent(monthlyProperties); } } - + /** + * Add new Yearly calendar events processing. + * @param beginEventIntervalDate the value of beginEventIntervalDate + * @param endEventIntervalDate the value of endEventIntervalDate + * @param properties the value of properties + * @param isYearlySameDayOfWeek the value of isYearlySameDayOfWeek + * @param startDate the value of startDate + * @param endDate the value of endDate + * @param eventSummary the value of eventSummary + * @param eventDescription the value of eventDescription + */ private void processYearEvents(final Date beginEventIntervalDate, final Date endEventIntervalDate, final Map properties, Boolean isYearlySameDayOfWeek, final Date startDate, final Date endDate, String eventSummary, String eventDescription) { int yearStart = beginEventIntervalDate.getYear(); int yearEnd = endEventIntervalDate.getYear(); int yearInterval = yearEnd - yearStart + 1; - int monthStart = beginEventIntervalDate.getMonth();//0 Jan 11 Dec - int monthEnd = endEventIntervalDate.getMonth(); - int monthInterval = 0; - if (yearInterval > 0) { - monthInterval = (yearInterval - 1) * 12 + (12 - monthStart) + (monthEnd + 1); - } else { - monthInterval = monthEnd - monthStart + 1; - } - if (yearInterval > 1) { properties.put(Event.SUMMARY, (String) properties.get(Event.SUMMARY) + " (Yearly event 1 of " + yearInterval + ")"); - properties.put(Event.DESCRIPTION, (String) properties.get(Event.DESCRIPTION) + " (Yearly event 1 of " + yearInterval + ")"); + properties.put(Event.DESCRIPTION, (String) properties.get(Event.DESCRIPTION) + " (Yearly " + (isYearlySameDayOfWeek ? "same Day of a week " : "same Date ") + "event 1 of " + yearInterval + ")"); + if(isYearlySameDayOfWeek) properties.put(Event.EVENT_TYPE, "Y1"); + else properties.put(Event.EVENT_TYPE, "Y2"); } + addPersonalEventYearly(properties, yearInterval, beginEventIntervalDate, endEventIntervalDate, startDate, endDate, eventSummary, eventDescription, isYearlySameDayOfWeek); - Date calBeginNextEventDate = beginEventIntervalDate; + } + private void addPersonalEventYearly(final Map properties, final int yearInterval, final Date beginEventIntervalDate, final Date endEventIntervalDate, final Date startDate, final Date endDate, final String eventSummary, final String eventDescription, final boolean isYearlySameDayOfWeek) { + final CreateEntity createEntity = new CreateEntity(PersonalEventDTO.ENTITY_NAME, properties); + + dispatch.execute(createEntity, new CommandResultHandler() { + + @Override + public void onCommandFailure(final Throwable caught) { + if (Log.isErrorEnabled()) { + Log.error(I18N.CONSTANTS.calendarAddEventError(), caught); + } + N10N.error(I18N.CONSTANTS.error(), I18N.CONSTANTS.calendarAddEventError()); + } + + @Override + public void onCommandSuccess(final CreateResult result) { + + // Creating events. + final Event event = new Event(); + event.setIdentifier((Integer) result.getEntity().getId()); + properties.put(Event.REFERENCE_ID, (Integer) result.getEntity().getId()); + updateEvent(event, properties); + // properties.put(Event.REFERENCE_ID, (Integer) result.getEntity().getId()); + addYearlySeriesEvent((String) result.getEntity().getId(), yearInterval, beginEventIntervalDate, endEventIntervalDate, startDate, endDate, eventSummary, eventDescription,isYearlySameDayOfWeek); + } + }, view.getCancelButton(), view.getSaveButton()); + } + private void addYearlySeriesEvent(String ids, int yearInterval, Date beginEventIntervalDate, Date endEventIntervalDate, final Date startDate, final Date endDate, String eventSummary, String eventDescription, final boolean isYearlySameDayOfWeek) { + Date calBeginNextEventDate = beginEventIntervalDate; for (int i = 1; i < yearInterval; i++) { - //calBeginNextEventDate = getMonthlySameDate(beginEventIntervalDate, calBeginNextEventDate, i); - //calBeginNextEventDate = getMonthlySameDayOfWeek2(beginEventIntervalDate, calBeginNextEventDate, i, isMonthlySameDayOfWeek); calBeginNextEventDate = getYearlySameDayOfWeek(beginEventIntervalDate, calBeginNextEventDate, i, isYearlySameDayOfWeek); Map yearlyProperties = new HashMap(); @@ -843,19 +917,20 @@ private void processYearEvents(final Date beginEventIntervalDate, final Date end yearlyProperties.put(Event.DATE, calBeginNextEventDate); - setAllDayTime(startDate, endDate, calBeginNextEventDate, yearlyProperties); + setFullDayEvent(startDate, endDate, calBeginNextEventDate, yearlyProperties); String newSummary = eventSummary; String newDescription = eventDescription; - newSummary += " (Yearly event " + (i + 1) + " of " + monthInterval + ")"; + newSummary += " (Yearly event " + (i + 1) + " of " + yearInterval + ")"; newDescription += " (Yearly " + (isYearlySameDayOfWeek ? "same Day of a week " : "same Date ") + "event " + (i + 1) + " of " + yearInterval + ")"; yearlyProperties.put(Event.SUMMARY, newSummary); yearlyProperties.put(Event.DESCRIPTION, newDescription); - - addPersonalEvent(yearlyProperties); + if(isYearlySameDayOfWeek) yearlyProperties.put(Event.EVENT_TYPE, "Y1"); + else yearlyProperties.put(Event.EVENT_TYPE, "Y2"); + yearlyProperties.put(Event.REFERENCE_ID, ids); + addPersonalEvent(yearlyProperties); } } - /** * Creates a new "Personal" calendar event. * @@ -881,7 +956,9 @@ public void onCommandSuccess(final CreateResult result) { // Creating events. final Event event = new Event(); event.setIdentifier((Integer) result.getEntity().getId()); - + // properties.put(Event.REFERENCE_ID, result.getEntity().getId()); + // Window.alert("ID1 = " + result.getEntity().getId()); + // Window.alert("ID2 = " + properties.get(Event.REFERENCE_ID)); updateEvent(event, properties); } }, view.getCancelButton(), view.getSaveButton()); @@ -934,7 +1011,10 @@ private void updateEvent(final Event event, final Map properties) { // -- event.setSummary((String) properties.get(Event.SUMMARY)); event.setDescription((String) properties.get(Event.DESCRIPTION)); - + event.setEventType((String) properties.get(Event.EVENT_TYPE)); + + event.setReferenceId((Integer) properties.get(Event.REFERENCE_ID)); + final Date day = (Date) properties.get(Event.DATE); final Object startHourSerialized = properties.get(Event.START_TIME); final Object endHourSerialized = properties.get(Event.END_TIME); @@ -1025,11 +1105,11 @@ private Date getMonthlySameDayOfWeek(Date dateObject, int numberMonths) { } */ /** - * + * * @param firstDate * @param nextDateOld * @param numberMonths - * @return + * @return the java.util.Date */ @SuppressWarnings({"deprecation", "empty-statement"}) public Date getMonthlySameDate(Date firstDate, Date nextDateOld, int numberMonths) { @@ -1062,20 +1142,22 @@ public Date getMonthlySameDate(Date firstDate, Date nextDateOld, int numberMonth } /** - * + * Calculates same date or same day of week in next month. * @param firstDate * @param nextDateOld * @param numberMonths - * @param isSameDayOfWeek - * @return + * @param isSameDayOfWeek if the value is true then will be calculated Date of the nearest same day of week + * @return next month date */ public Date getMonthlySameDayOfWeek2(Date firstDate, Date nextDateOld, int numberMonths, boolean isSameDayOfWeek) { Date nextDateNew = new Date(); Date newDate = new Date(); + nextDateNew.setDate(1);// to prevent month slip past (f.e. 31 jan -> 3 march instead of 29 febr) + newDate.setDate(1); nextDateNew.setYear(nextDateOld.getYear()); nextDateNew.setMonth(nextDateOld.getMonth() + 1); - nextDateNew.setDate(1);// to prevent month slip past (f.e. 31 jan -> 3 march instead of 29 febr) + //nextDateNew.setDate(1);// to prevent month slip past (f.e. 31 jan -> 3 march instead of 29 febr) newDate.setYear(nextDateOld.getYear()); int daysInNextDate = getDaysInMonth(nextDateNew.getYear(), nextDateNew.getMonth()); @@ -1105,49 +1187,34 @@ public Date getMonthlySameDayOfWeek2(Date firstDate, Date nextDateOld, int numbe return newDate; } - - /** - * + * Calculates same date or same day of week in next year. * @param firstDate * @param nextDateOld * @param numberMonths - * @param isSameDayOfWeek + * @param isSameDayOfWeek if the value is true then will be calculated Date of the nearest same day of week * @return */ @SuppressWarnings({"deprecation"}) public Date getYearlySameDayOfWeek(Date firstDate, Date nextDateOld, int numberMonths, boolean isSameDayOfWeek) { -// Date firstDate = new Date(); -// firstDate.setYear(nextDateOld.getYear());; -// firstDate.setMonth(nextDateOld.getMonth()); -// firstDate.setDate(nextDateOld.getDate()); -// Date nextDateNew = new Date(); + nextDateNew.setDate(1); nextDateNew.setYear(nextDateOld.getYear()); nextDateNew.setMonth(nextDateOld.getMonth()); - nextDateNew.setDate(nextDateOld.getDate()); + // nextDateNew.setDate(nextDateOld.getDate()); - nextDateNew.setDate(1); -// nextDateNew.setMonth(nextDateOld.getMonth()); + // nextDateNew.setDate(1); nextDateNew.setYear(nextDateOld.getYear() + 1); -// Date nextDateNew = new Date(); -// Date newDate = new Date(); -// nextDateNew.setYear(nextDateOld.getYear()); -// nextDateNew.setMonth(nextDateOld.getMonth() + 1); -// nextDateNew.setDate(1);// to prevent month slip past (f.e. 31 jan -> 3 march instead of 29 febr) -// newDate.setYear(nextDateOld.getYear()); int daysInNextDate = getDaysInMonth(nextDateNew.getYear(), nextDateNew.getMonth()); if (firstDate.getDate() >= daysInNextDate) {//if last day of the month - //nextDate.setDate(firstDate.getDate());//?? - //nextDate.setDate(getDaysInMonth(nextDateOld.getYear(),nextDateOld.getMonth())); + nextDateNew.setDate(daysInNextDate); } else { - //nextDate.setDate(getDaysInMonth(nextDateOld.getYear(),nextDateOld.getMonth())); - //nextDate.setDate(firstDate.getDate());//?? + nextDateNew.setDate(firstDate.getDate()); } @@ -1168,6 +1235,11 @@ public Date getYearlySameDayOfWeek(Date firstDate, Date nextDateOld, int numberM return nextDateNew; } + /** + * Calculates same week day date(as in firstDate) for nextDate + * @param firstDate the value of firstDate + * @param nextDate the value of nextDate + */ private Date getSameWeekDay(Date firstDate, Date nextDate) { //Calculate same day of week int dayOfFirst = firstDate.getDay(); @@ -1248,7 +1320,7 @@ private Date getSameWeekDay2(Date firstDate, Date nextDate) { */ /** - * + * Returns numver od days in the month of the year * @param year the value of year * @param month the value of month * @return the int @@ -1271,7 +1343,7 @@ private int getDaysInMonth(int year, int month) { } /** - * + * Validate if the year is leap year. * @param year the value of year * @return the boolean */ diff --git a/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarPresenter.java b/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarPresenter.java index 93d828d98..2123d608d 100644 --- a/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarPresenter.java +++ b/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarPresenter.java @@ -60,12 +60,17 @@ import com.extjs.gxt.ui.client.event.SelectionListener; import com.extjs.gxt.ui.client.store.ListStore; import com.extjs.gxt.ui.client.widget.selection.AbstractStoreSelectionModel; +import com.google.gwt.user.client.Window; import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.inject.ImplementedBy; import com.google.inject.Inject; +import java.util.Date; +import java.util.Iterator; import org.sigmah.client.ui.presenter.reminder.ReminderType; import org.sigmah.client.util.profiler.Profiler; import org.sigmah.client.util.profiler.Scenario; +import org.sigmah.server.dao.PersonalEventDAO; +import org.sigmah.server.domain.calendar.PersonalEvent; import org.sigmah.shared.dto.calendar.CalendarIdentifier; import org.sigmah.shared.dto.calendar.PersonalCalendarIdentifier; import org.sigmah.shared.util.ProjectUtils; @@ -115,7 +120,8 @@ public static interface View extends ViewInterface { private CalendarWidget calendar; private Integer projectId; - + // @Inject + // private PersonalEventDAO personalEventDAO; /** * Presenters's initialization. * @@ -163,7 +169,11 @@ public void delete(final Event event, final CalendarWidget calendarWidget) { final CalendarIdentifier calendarIdentifier = event.getParent().getIdentifier(); final Integer parentId = calendarIdentifier instanceof PersonalCalendarIdentifier ? ((PersonalCalendarIdentifier)calendarIdentifier).getId() : null; - + // Window.alert("refId = "+event.getReferenceId());//temp for checker + // Window.alert("Type = "+event.getEventType());//temp for checker + // Window.alert("Description = "+event.getDescription());//temp for checker + // Window.alert("Summary = "+event.getSummary());//temp for checker + // event.setReferenceId(null); dispatch.execute(new Delete(PersonalEventDTO.ENTITY_NAME, event.getIdentifier(), parentId), new CommandResultHandler() { @Override @@ -175,12 +185,122 @@ public void onCommandFailure(final Throwable caught) { public void onCommandSuccess(final VoidResult result) { final List oldEventList = - event.getParent().getEvents().get(event.getKey()); + event.getParent().getEvents().get(event.getKey()); oldEventList.remove(event); calendar.refresh(); } }); } + + @Override + public void deleteChain(final Event event, final CalendarWidget calendarWidget) { + final CalendarIdentifier calendarIdentifier = event.getParent().getIdentifier(); + final Integer parentId = calendarIdentifier instanceof PersonalCalendarIdentifier ? + ((PersonalCalendarIdentifier)calendarIdentifier).getId() : null; + + final Map> eventMap = event.getParent().getEvents(); + int refId; + int mainId = event.getIdentifier(); + if(event.getReferenceId() != null) refId = event.getReferenceId().intValue(); + else refId = 0; + String typeStr = (String)event.getEventType(); + Window.alert("refId = "+event.getReferenceId());//temp for checker + Window.alert("Type = "+event.getEventType());//temp for checker + for (final Date key : eventMap.keySet()) { + for (final Event next : eventMap.get(key)) { + calendar.refresh(); + if (typeStr != null) { + //удаляем цепочку кроме главного - для тестирования надо выбирать не первый ивент серии на каледнаре + if (refId != 0) { + + if (next.getReferenceId() != null && (next.getReferenceId().intValue() == refId)) { + // Window.alert(next.getReferenceId()+" | "+refId);//temp for checker + dispatch.execute(new Delete(PersonalEventDTO.ENTITY_NAME, next.getIdentifier(), parentId), new CommandResultHandler() { + + @Override + public void onCommandFailure(final Throwable caught) { + N10N.error(I18N.CONSTANTS.error(), I18N.CONSTANTS.calendarDeleteEventError()); + } + + @Override + public void onCommandSuccess(final VoidResult result) { + eventMap.remove(next); + calendar.refresh(); + } + }); + + } + } else { + if (next.getReferenceId() != null && (next.getReferenceId().intValue() == mainId)) { + // Window.alert(next.getReferenceId()+" | "+refId);//temp for checker + dispatch.execute(new Delete(PersonalEventDTO.ENTITY_NAME, next.getIdentifier(), parentId), new CommandResultHandler() { + + @Override + public void onCommandFailure(final Throwable caught) { + N10N.error(I18N.CONSTANTS.error(), I18N.CONSTANTS.calendarDeleteEventError()); + } + + @Override + public void onCommandSuccess(final VoidResult result) { + eventMap.remove(next); + calendar.refresh(); + } + }); + } + } + } else { + dispatch.execute(new Delete(PersonalEventDTO.ENTITY_NAME, event.getIdentifier(), parentId), new CommandResultHandler() { + + @Override + public void onCommandFailure(final Throwable caught) { + N10N.error(I18N.CONSTANTS.error(), I18N.CONSTANTS.calendarDeleteEventError()); + } + + @Override + public void onCommandSuccess(final VoidResult result) { + eventMap.remove(next); + calendar.refresh(); + } + }); + } + } + } + if (typeStr != null) { + if (refId != 0) { + dispatch.execute(new Delete(PersonalEventDTO.ENTITY_NAME, refId, parentId), new CommandResultHandler() { + + @Override + public void onCommandFailure(final Throwable caught) { + N10N.error(I18N.CONSTANTS.error(), I18N.CONSTANTS.calendarDeleteEventError()); + } + + @Override + public void onCommandSuccess(final VoidResult result) { + final List oldEventList + = event.getParent().getEvents().get(event.getKey()); + oldEventList.remove(event); + calendar.refresh(); + } + }); + } else { + dispatch.execute(new Delete(PersonalEventDTO.ENTITY_NAME, mainId, parentId), new CommandResultHandler() { + + @Override + public void onCommandFailure(final Throwable caught) { + N10N.error(I18N.CONSTANTS.error(), I18N.CONSTANTS.calendarDeleteEventError()); + } + + @Override + public void onCommandSuccess(final VoidResult result) { + final List oldEventList + = event.getParent().getEvents().get(event.getKey()); + oldEventList.remove(event); + calendar.refresh(); + } + }); + } + } + } }); // -- diff --git a/src/main/java/org/sigmah/client/ui/view/calendar/CalendarEventView.java b/src/main/java/org/sigmah/client/ui/view/calendar/CalendarEventView.java index 0a0a315a1..0a874876f 100644 --- a/src/main/java/org/sigmah/client/ui/view/calendar/CalendarEventView.java +++ b/src/main/java/org/sigmah/client/ui/view/calendar/CalendarEventView.java @@ -107,7 +107,7 @@ public void initialize() { eventSummaryField = Forms.text(I18N.CONSTANTS.calendarEventObject(), true); eventSummaryField.setName(Event.SUMMARY); - eventDateStartField = Forms.date(I18N.CONSTANTS.calendarEventDate()+ " start", true); + eventDateStartField = Forms.date(I18N.CONSTANTS.calendar_addEvent_dateStart_label(), true); eventDateStartField.setName(Event.DATE); //eventDateStartField.setAllowBlank(true); @@ -119,7 +119,7 @@ public void initialize() { eventEndTimeField.setName(Event.END_TIME); eventEndTimeField.setTriggerAction(TriggerAction.ALL); - eventDateEndField = Forms.date(I18N.CONSTANTS.calendarEventDate() + " end", false); + eventDateEndField = Forms.date(I18N.CONSTANTS.calendar_addEvent_dateEnd_label(), false); eventDateEndField.setName(Event.DATE + "888end"); eventDescriptionField = Forms.textarea(I18N.CONSTANTS.calendarEventDescription(), false); @@ -152,7 +152,7 @@ public void initialize() { private CheckBox createAllDayCheckbox() { - allDayCheckbox = Forms.checkbox(I18N.CONSTANTS.calendar_addEvent_isAllDayCB_boxLabel(), "All day name", false); + allDayCheckbox = Forms.checkbox(I18N.CONSTANTS.calendar_addEvent_isAllDayCB_boxLabel(), I18N.CONSTANTS.calendar_addEvent_isAllDayCB_allDayName(), false); allDayCheckbox.setFieldLabel(I18N.CONSTANTS.calendar_addEvent_allDayCbGr_label()); // allDayCheckbox.setBoxLabel(I18N.CONSTANTS.calendar_addEvent_isAllDayCB_boxLabel()); allDayCheckbox.validate(false); @@ -161,7 +161,7 @@ private CheckBox createAllDayCheckbox() { public void handleEvent(FieldEvent event) { eventStartTimeField.setVisible(!allDayCheckbox.getValue()); eventEndTimeField.setVisible(!allDayCheckbox.getValue()); - Window.alert(getAllDayCheckbox().getBoxLabel() + " is checked"); + // Window.alert(getAllDayCheckbox().getBoxLabel() + " is checked = " + getAllDayCheckbox().getValue()); } }); @@ -176,7 +176,7 @@ private void createRepeatEventPeriodRadioGroup() { createYearlyRb(); RepeatEventPeriodRG = Forms.radioGroup(I18N.CONSTANTS.calendar_addEvent_repeatPeriodRG_label(), - "Repeat event 999", + I18N.CONSTANTS.calendar_addEvent_repeatPeriodRG_name(), Style.Orientation.HORIZONTAL, onceRepeatRB, dailyRepeatRB, @@ -191,7 +191,7 @@ private void createYearlyRb() { //final Radio // yearlyRepeatRB = Forms.radio("yearlyRepeatRB label", "yearlyRepeatRB name", Boolean.FALSE); //yearlyRepeatRB = new Radio(); - yearlyRepeatRB = Forms.radio("yearly", "yearly", Boolean.FALSE); + yearlyRepeatRB = Forms.radio(I18N.CONSTANTS.calendar_addEvent_repeatYearlyRB_label(), I18N.CONSTANTS.calendar_addEvent_repeatYearlyRB_label(), Boolean.FALSE); yearlyRepeatRB.setToolTip(I18N.CONSTANTS.calendar_addEvent_repeatYearlyRB_toolTip()); // yearlyRepeatRB.setBoxLabel("yearly"); // yearlyRepeatRB.setName("yearly"); @@ -201,7 +201,7 @@ private void createYearlyRb() { public void handleEvent(FieldEvent event) { //eventStartTimeField.setVisible(!yearlyRepeatRB.getValue()); // eventEndTimeField.setVisible(!yearlyRepeatRB.getValue()); - ((TextArea) form.getItemByItemId(Event.DESCRIPTION)).setValue(" The Yearly event."); + ((TextArea) form.getItemByItemId(Event.DESCRIPTION)).setValue(I18N.CONSTANTS.calendar_addEvent_description_textArea_yearly()); getPanelYearly().setVisible(getYearlyRepeatRB().getValue()); getPanelMonthly().setVisible(!yearlyRepeatRB.getValue()); @@ -209,13 +209,13 @@ public void handleEvent(FieldEvent event) { getYearlySameDayOfWeekRB().show(); getYearlySameDateRB().setValue(true); eventDateStartField.setAllowBlank(false); - Window.alert(getYearlyRepeatRB().getBoxLabel() + " is checked Listener OnChange on Yearly radio"); + // Window.alert(getYearlyRepeatRB().getBoxLabel() + " is checked Listener OnChange on Yearly radio"); } }); } private void createMonthlyRb() { - monthlyRepeatRB = Forms.radio("monthly", "monthly", Boolean.FALSE); + monthlyRepeatRB = Forms.radio(I18N.CONSTANTS.calendar_addEvent_repeatMonthlyRB_label(), I18N.CONSTANTS.calendar_addEvent_repeatMonthlyRB_label(), Boolean.FALSE); monthlyRepeatRB.setToolTip(I18N.CONSTANTS.calendar_addEvent_repeatMonthlyRB_toolTip()); // monthlyRepeatRB.setBoxLabel("monthly"); // monthlyRepeatRB.setName("monthly"); @@ -225,20 +225,20 @@ private void createMonthlyRb() { public void handleEvent(FieldEvent event) { //eventStartTimeField.setVisible(!yearlyRepeatRB.getValue()); // eventEndTimeField.setVisible(!yearlyRepeatRB.getValue()); - ((TextArea) form.getItemByItemId(Event.DESCRIPTION)).setValue(" The Monthly event."); + ((TextArea) form.getItemByItemId(Event.DESCRIPTION)).setValue(I18N.CONSTANTS.calendar_addEvent_description_textArea_monthly()); getPanelYearly().setVisible(!monthlyRepeatRB.getValue()); getPanelMonthly().setVisible(getMonthlyRepeatRB().getValue()); eventDateStartField.setAllowBlank(false); getRadioMonthlySameDate().show(); getRadioMonthlySameDayOfWeek().show(); getRadioMonthlySameDayOfWeek().setValue(true); - Window.alert(getMonthlyRepeatRB().getBoxLabel() + " is checked Listener OnChange on monthly radio"); + // Window.alert(getMonthlyRepeatRB().getBoxLabel() + " is checked Listener OnChange on monthly radio"); } }); } private void createWeeklyRb() { - weeklyRepeatRB = Forms.radio("weekly", "weekly", Boolean.FALSE); + weeklyRepeatRB = Forms.radio(I18N.CONSTANTS.calendar_addEvent_repeatWeeklyRB_label(), I18N.CONSTANTS.calendar_addEvent_repeatWeeklyRB_label(), Boolean.FALSE); weeklyRepeatRB.setToolTip(I18N.CONSTANTS.calendar_addEvent_repeatWeeklyRB_toolTip()); // weeklyRepeatRB.setBoxLabel("weekly"); // weeklyRepeatRB.setName("weekly"); @@ -248,12 +248,12 @@ private void createWeeklyRb() { public void handleEvent(FieldEvent event) { //eventStartTimeField.setVisible(!yearlyRepeatRB.getValue()); // eventEndTimeField.setVisible(!yearlyRepeatRB.getValue()); - ((TextArea) form.getItemByItemId(Event.DESCRIPTION)).setValue(" The Weekly event."); + ((TextArea) form.getItemByItemId(Event.DESCRIPTION)).setValue(I18N.CONSTANTS.calendar_addEvent_description_textArea_weekly()); getPanelYearly().setVisible(!weeklyRepeatRB.getValue()); getPanelMonthly().setVisible(!weeklyRepeatRB.getValue()); eventDateStartField.setAllowBlank(false); - Window.alert(getWeeklyRepeatRB().getBoxLabel() + " is checked Listener OnChange on weekly radio"); + // Window.alert(getWeeklyRepeatRB().getBoxLabel() + " is checked Listener OnChange on weekly radio"); } }); } @@ -264,26 +264,26 @@ public void handleEvent(FieldEvent event) { private void createDailyRb() { //final Radio //dailyRepeatRB = new Radio(); - dailyRepeatRB = Forms.radio("daily", "daily", Boolean.FALSE); + dailyRepeatRB = Forms.radio(I18N.CONSTANTS.calendar_addEvent_repeatDailyRB_label(), I18N.CONSTANTS.calendar_addEvent_repeatDailyRB_label(), Boolean.FALSE); // dailyRepeatRB.setBoxLabel("daily"); // dailyRepeatRB.setName("daily"); // dailyRepeatRB.setValue(false); dailyRepeatRB.addListener(Events.OnChange, new Listener() { @Override public void handleEvent(FieldEvent event) { - ((TextArea) form.getItemByItemId(Event.DESCRIPTION)).setValue(" The Daily event."); + ((TextArea) form.getItemByItemId(Event.DESCRIPTION)).setValue(I18N.CONSTANTS.calendar_addEvent_description_textArea_daily()); // eventStartTimeField.setVisible(!dailyRepeatRB.getValue()); // eventEndTimeField.setVisible(!dailyRepeatRB.getValue()); // eventDateStartField.setAllowBlank(false); getPanelYearly().setVisible(!dailyRepeatRB.getValue()); getPanelMonthly().setVisible(!dailyRepeatRB.getValue()); - Window.alert(getDailyRepeatRB().getBoxLabel() + " is checked Listener OnChange on DAILY radio"); + // Window.alert(getDailyRepeatRB().getBoxLabel() + " is checked Listener OnChange on DAILY radio"); } }); } private void createOnceRb() { - onceRepeatRB = Forms.radio("once", "onceRepeatRBname", Boolean.FALSE); + onceRepeatRB = Forms.radio(I18N.CONSTANTS.calendar_addEvent_repeatOnceRB_label(), I18N.CONSTANTS.calendar_addEvent_repeatOnceRB_name(), Boolean.FALSE); onceRepeatRB.setOriginalValue(Boolean.TRUE); onceRepeatRB.setToolTip(I18N.CONSTANTS.calendar_addEvent_repeatOnceRB_toolTip()); @@ -293,12 +293,12 @@ public void handleEvent(FieldEvent event) { getPanelYearly().setVisible(!onceRepeatRB.getValue()); getPanelMonthly().setVisible(!onceRepeatRB.getValue()); - eventStartTimeField.setVisible(!dailyRepeatRB.getValue()); - eventEndTimeField.setVisible(!dailyRepeatRB.getValue()); + // eventStartTimeField.setVisible(!dailyRepeatRB.getValue()); + // eventEndTimeField.setVisible(!dailyRepeatRB.getValue()); // eventDateStartField.setAllowBlank(false); // eventDateStartField.setAllowBlank(true); - ((TextArea) form.getItemByItemId(Event.DESCRIPTION)).setValue(" The Once event."); - Window.alert(getOnceRepeatRB().getBoxLabel() + " is checked Listener OnChange on ONCE radio"); + ((TextArea) form.getItemByItemId(Event.DESCRIPTION)).setValue(I18N.CONSTANTS.calendar_addEvent_description_textArea_once()); + // Window.alert(getOnceRepeatRB().getBoxLabel() + " is checked Listener OnChange on ONCE radio"); } }); } @@ -308,7 +308,7 @@ private void createMonthlyPanel() { panelMonthly.setExpanded(true); //panelMonthly.setTitle("Montly panel title"); panelMonthly.setBorders(true); - panelMonthly.setHeadingHtml("Montly repeats settings"); + panelMonthly.setHeadingHtml(I18N.CONSTANTS.calendar_addEvent_repeatsSettings_headingHtml_monthly()); // panelMonthly.setCollapsible(true); panelMonthly.setAutoHeight(true); //panelMonthly.setToolTip("Set Monthly event repeats options."); @@ -316,22 +316,22 @@ private void createMonthlyPanel() { //Radio radioMonthlySameDayOfWeek = new Radio(); - radioMonthlySameDayOfWeek = Forms.radio("Same day of week"); + radioMonthlySameDayOfWeek = Forms.radio(I18N.CONSTANTS.calendar_addEvent_repeatsSettings_SameDayOfWeekRB_label()); //radioMonthlySameDayOfWeek.setBoxLabel("Same day of week"); - radioMonthlySameDayOfWeek.setName("radioMonthlySameDayOfWeek"); + radioMonthlySameDayOfWeek.setName(I18N.CONSTANTS.calendar_addEvent_repeatsSettings_SameDayOfWeekRB_monthly_name()); radioMonthlySameDayOfWeek.setValue(Boolean.FALSE); radioMonthlySameDayOfWeek.setOriginalValue(Boolean.FALSE); - radioMonthlySameDayOfWeek.setToolTip("Every next month at the same day of week. (with autochange to ...h)"); + radioMonthlySameDayOfWeek.setToolTip(I18N.CONSTANTS.calendar_addEvent_repeatsSettings_SameDayOfWeekRB_monthly_toolTip()); //Radio radioMonthlySameDate = new Radio(); - radioMonthlySameDate = Forms.radio("Same date"); - radioMonthlySameDate.setBoxLabel("Same date"); - radioMonthlySameDate.setName("radioMonthlySameDate"); + radioMonthlySameDate = Forms.radio(I18N.CONSTANTS.calendar_addEvent_repeatsSettings_SameDateRB_label()); + radioMonthlySameDate.setBoxLabel(I18N.CONSTANTS.calendar_addEvent_repeatsSettings_SameDateRB_label()); + radioMonthlySameDate.setName(I18N.CONSTANTS.calendar_addEvent_repeatsSettings_SameDateRB_monthly_name()); radioMonthlySameDate.setValue(Boolean.FALSE); - radioMonthlySameDate.setToolTip("Every next month at the same date. (with autochange to last day of month)"); + radioMonthlySameDate.setToolTip(I18N.CONSTANTS.calendar_addEvent_repeatsSettings_SameDateRB_monthly_toolTip()); //montlyVariantRG= new RadioGroup(); - montlyVariantRG = Forms.radioGroup("Montly settings 999"); + montlyVariantRG = Forms.radioGroup(I18N.CONSTANTS.calendar_addEvent_repeatsSettings_radioGroup_monthly_settings()); //montlyVariantRG.setSelectionRequired(Boolean.TRUE); montlyVariantRG.setSelectionRequired(Boolean.FALSE); montlyVariantRG.setOrientation(Style.Orientation.HORIZONTAL); @@ -347,26 +347,27 @@ private void createYearlyPanel() { panelYearly.setExpanded(true); //panelYearly.setTitle("Yearly panel title"); panelYearly.setBorders(true); - panelYearly.setHeadingHtml("Yearly repeats settings"); + panelYearly.setHeadingHtml(I18N.CONSTANTS.calendar_addEvent_repeatsSettings_headingHtml_yearly()); // panelYearly.setCollapsible(true); panelYearly.setAutoHeight(true); // panelYearly.setToolTip("Set Yearly event repeats options"); panelYearly.setVisible(false); - yearlySameDayOfWeekRB = Forms.radio("Same day of week", Boolean.FALSE); - yearlySameDayOfWeekRB.setToolTip("Repeat Calendar event at the same DAY of week annually"); + yearlySameDayOfWeekRB = Forms.radio(I18N.CONSTANTS.calendar_addEvent_repeatsSettings_SameDayOfWeekRB_label(), Boolean.FALSE); + yearlySameDayOfWeekRB.setToolTip(I18N.CONSTANTS.calendar_addEvent_repeatsSettings_SameDayOfWeekRB_yearly_toolTip()); yearlySameDayOfWeekRB.setOriginalValue(Boolean.TRUE); //yearlySameDayOfWeekRB.setBoxLabel("Same day of week"); - yearlySameDayOfWeekRB.setName("radioYearlySameDayOfWeek"); + yearlySameDayOfWeekRB.setName(I18N.CONSTANTS.calendar_addEvent_repeatsSettings_SameDayOfWeekRB_yearly_name()); yearlySameDayOfWeekRB.setValue(Boolean.TRUE); //yearlySameDateRB = new Radio(); - yearlySameDateRB = Forms.radio("Same date", Boolean.FALSE); + yearlySameDateRB = Forms.radio(I18N.CONSTANTS.calendar_addEvent_repeatsSettings_SameDateRB_label(), Boolean.FALSE); //yearlySameDateRB.setBoxLabel("Same date"); - yearlySameDateRB.setName("radioYearlySameDate"); + yearlySameDateRB.setName(I18N.CONSTANTS.calendar_addEvent_repeatsSettings_SameDateRB_yearly_name()); //yearlySameDateRB.setValue(false); - yearlyVariantRG = Forms.radioGroup("Yearly settings 888", "Yearly settings name", + yearlyVariantRG = Forms.radioGroup(I18N.CONSTANTS.calendar_addEvent_repeatsSettings_radioGroup_yearly_settings(), + I18N.CONSTANTS.calendar_addEvent_repeatsSettings_radioGroup_yearly_settings_name(), Style.Orientation.HORIZONTAL, yearlySameDayOfWeekRB, yearlySameDateRB); diff --git a/src/main/java/org/sigmah/client/ui/widget/CalendarWidget.java b/src/main/java/org/sigmah/client/ui/widget/CalendarWidget.java index b223a6031..bb9c0f1b8 100644 --- a/src/main/java/org/sigmah/client/ui/widget/CalendarWidget.java +++ b/src/main/java/org/sigmah/client/ui/widget/CalendarWidget.java @@ -77,6 +77,8 @@ public interface Delegate { void edit(Event event, CalendarWidget calendarWidget); void delete(Event event, CalendarWidget calendarWidget); + + void deleteChain(Event event, CalendarWidget calendarWidget); } @@ -727,7 +729,7 @@ else if (o1Start > o2Start) final DecoratedPopupPanel detailPopup = new DecoratedPopupPanel(true); - final Grid popupContent = new Grid(event.getParent().isEditable() ? 5 : 3, 1); + final Grid popupContent = new Grid(event.getParent().isEditable() ? 6 : 3, 1); popupContent.setText(0, 0, event.getSummary()); popupContent.getCellFormatter().addStyleName(0, 0, "calendar-popup-header"); @@ -766,8 +768,19 @@ public void onClick(ClickEvent clickEvent) { } }); + final Anchor deleteChainAnchor = new Anchor("Delete chain"); + deleteChainAnchor.addClickHandler(new ClickHandler() { + + @Override + public void onClick(ClickEvent clickEvent) { + delegate.deleteChain(event, CalendarWidget.this); + detailPopup.hide(); + } + }); + popupContent.setWidget(3, 0, editAnchor); popupContent.setWidget(4, 0, deleteAnchor); + popupContent.setWidget(5, 0, deleteChainAnchor); } detailPopup.setWidget(popupContent); diff --git a/src/main/java/org/sigmah/offline/js/PersonalEventJS.java b/src/main/java/org/sigmah/offline/js/PersonalEventJS.java index a86d01e11..cae716d5f 100644 --- a/src/main/java/org/sigmah/offline/js/PersonalEventJS.java +++ b/src/main/java/org/sigmah/offline/js/PersonalEventJS.java @@ -43,7 +43,9 @@ public static PersonalEventJS toJavaScript(Event event) { personalEventJS.setDescription(event.getDescription()); personalEventJS.setDtstart(Values.toJsDate(event.getDtstart())); personalEventJS.setDtend(Values.toJsDate(event.getDtend())); - + personalEventJS.setEventType(event.getEventType()); + personalEventJS.setReferenceId(event.getReferenceId()); + return personalEventJS; } @@ -55,7 +57,8 @@ public Event toEvent() { event.setDescription(getDescription()); event.setDtstart(Values.toDate(getDtstart())); event.setDtend(Values.toDate(getDtend())); - + event.setEventType(getEventType()); + event.setReferenceId(getReferenceId()); return event; } @@ -98,4 +101,20 @@ public native JsDate getDtend() /*-{ public native void setDtend(JsDate dtend) /*-{ this.dtend = dtend; }-*/; + + public native void setEventType(String eventtype) /*-{ + this.eventtype = eventtype; + }-*/; + + public native String getEventType() /*-{ + return this.eventtype; + }-*/; + + public native void setReferenceId(Integer referenceid) /*-{ + this.referenceid = referenceid; + }-*/; + + public native Integer getReferenceId() /*-{ + return this.referenceid; + }-*/; } diff --git a/src/main/java/org/sigmah/server/domain/calendar/PersonalEvent.java b/src/main/java/org/sigmah/server/domain/calendar/PersonalEvent.java index aa593c631..bd42d8d96 100644 --- a/src/main/java/org/sigmah/server/domain/calendar/PersonalEvent.java +++ b/src/main/java/org/sigmah/server/domain/calendar/PersonalEvent.java @@ -80,6 +80,18 @@ public class PersonalEvent extends AbstractEntityId implements Deleteab private Integer calendarId; /** + * Type of the event. + */ + @Column(name = EntityConstants.PERSONAL_EVENT_COLUMN_TYPE) + @Size(max = EntityConstants.PERSONAL_EVENT_TYPE_MAX_LENGTH) + private String eventtype; + /** + * Reference ID of the event. + */ + @Column(name = EntityConstants.PERSONAL_EVENT_COLUMN_REFERENCE_ID) + private Integer referenceid; + + /** * Title of the event (a short description). */ @Column(name = EntityConstants.PERSONAL_EVENT_COLUMN_SUMMARY) @@ -144,12 +156,15 @@ public boolean isDeleted() { */ @Override protected void appendToString(ToStringBuilder builder) { + builder.append("eventtype", eventtype); + builder.append("referenceid", referenceid); builder.append("summary", summary); builder.append("description", description); builder.append("startDate", startDate); builder.append("endDate", endDate); builder.append("dateCreated", dateCreated); builder.append("dateDeleted", dateDeleted); + } // -------------------------------------------------------------------------------- @@ -223,4 +238,20 @@ public Date getDateDeleted() { public void setDateDeleted(Date dateDeleted) { this.dateDeleted = dateDeleted; } + + public String getEventType() { + return eventtype; + } + + public void setEventType(String eventtype) { + this.eventtype = eventtype; + } + + public Integer getReferenceId() { + return referenceid; + } + + public void setReferenceId(Integer referenceid) { + this.referenceid = referenceid; + } } diff --git a/src/main/java/org/sigmah/server/domain/util/EntityConstants.java b/src/main/java/org/sigmah/server/domain/util/EntityConstants.java index 66ade06cd..77ce487f8 100644 --- a/src/main/java/org/sigmah/server/domain/util/EntityConstants.java +++ b/src/main/java/org/sigmah/server/domain/util/EntityConstants.java @@ -1021,10 +1021,13 @@ private EntityConstants() { public static final String PERSONAL_EVENT_COLUMN_END_DATE = "enddate"; public static final String PERSONAL_EVENT_COLUMN_START_DATE = "startdate"; public static final String PERSONAL_EVENT_COLUMN_SUMMARY = "summary"; + public static final String PERSONAL_EVENT_COLUMN_TYPE = "eventtype"; + public static final String PERSONAL_EVENT_COLUMN_REFERENCE_ID = "referenceid"; + public static final int PERSONAL_EVENT_TYPE_MAX_LENGTH = 2; public static final int PERSONAL_EVENT_DESCRIPTION_MAX_LENGTH = 255; public static final int PERSONAL_EVENT_SUMMARY_MAX_LENGTH = 255; - + // -------------------------------------------------------------------------------- // // PHASE ENTITY. diff --git a/src/main/java/org/sigmah/server/handler/calendar/PersonalCalendarHandler.java b/src/main/java/org/sigmah/server/handler/calendar/PersonalCalendarHandler.java index 3bb77578e..5ad9c0267 100644 --- a/src/main/java/org/sigmah/server/handler/calendar/PersonalCalendarHandler.java +++ b/src/main/java/org/sigmah/server/handler/calendar/PersonalCalendarHandler.java @@ -100,6 +100,8 @@ public Calendar getCalendar(CalendarIdentifier identifier, EntityManager em) { calendarEvent.setSummary(event.getSummary()); calendarEvent.setDescription(event.getDescription()); calendarEvent.setDtstart(new Date(event.getStartDate().getTime())); + calendarEvent.setReferenceId(event.getReferenceId()); + calendarEvent.setEventType(event.getEventType()); if (event.getEndDate() != null) calendarEvent.setDtend(new Date(event.getEndDate().getTime())); diff --git a/src/main/java/org/sigmah/server/service/PersonalEventService.java b/src/main/java/org/sigmah/server/service/PersonalEventService.java index 1859e9727..d57c22100 100644 --- a/src/main/java/org/sigmah/server/service/PersonalEventService.java +++ b/src/main/java/org/sigmah/server/service/PersonalEventService.java @@ -91,7 +91,9 @@ private static void fillEvent(PersonalEvent event, PropertyMap properties) { event.setSummary((String) properties.get(Event.SUMMARY)); event.setDescription((String) properties.get(Event.DESCRIPTION)); - + event.setEventType((String) properties.get(Event.EVENT_TYPE)); + event.setReferenceId((Integer) properties.get(Event.REFERENCE_ID)); + final Date day = (Date) properties.get(Event.DATE); final Serializable startHourSerialized = properties.get(Event.START_TIME); final Serializable endHourSerialized = properties.get(Event.END_TIME); diff --git a/src/main/java/org/sigmah/shared/dto/calendar/Event.java b/src/main/java/org/sigmah/shared/dto/calendar/Event.java index a2e2d9424..10a9199ec 100644 --- a/src/main/java/org/sigmah/shared/dto/calendar/Event.java +++ b/src/main/java/org/sigmah/shared/dto/calendar/Event.java @@ -47,24 +47,30 @@ public class Event implements Serializable { public static final String START_TIME = "startDate"; public static final String END_TIME = "endDate"; public static final String DESCRIPTION = "description"; - + public static final String REFERENCE_ID = "referenceid"; + public static final String EVENT_TYPE = "eventtype"; + + private String eventtype; private Integer identifier; private String summary; private String description; private Date dtstart; private Date dtend; private Calendar parent; + private Integer referenceid; public Event() { // Serialization. } - public Event(String summary, String description, Date dtstart, Date dtend, Calendar parent) { + public Event(String summary, String description, Date dtstart, Date dtend, Calendar parent, String eventtype, Integer referenceid) { this.summary = summary; this.description = description; this.dtstart = dtstart; this.dtend = dtend; this.parent = parent; + this.eventtype = eventtype; + this.referenceid = referenceid; } /** @@ -102,7 +108,9 @@ public void fillValues(Map values) { setSummary((String) values.get(Event.SUMMARY)); setDescription((String) values.get(Event.DESCRIPTION)); - + setEventType((String) values.get(Event.EVENT_TYPE)); + setReferenceId((Integer) values.get(Event.REFERENCE_ID)); + final Date day = (Date) values.get(Event.DATE); final Object startHourSerialized = values.get(Event.START_TIME); final Object endHourSerialized = values.get(Event.END_TIME); @@ -164,6 +172,22 @@ public void setSummary(String summary) { this.summary = summary; } + public String getEventType() { + return eventtype; + } + + public void setEventType(String eventtype) { + this.eventtype = eventtype; + } + + public Integer getReferenceId() { + return referenceid; + } + + public void setReferenceId(Integer referenceid) { + this.referenceid = referenceid; + } + public Calendar getParent() { return parent; } diff --git a/src/main/resources/org/sigmah/client/i18n/UIConstants.properties b/src/main/resources/org/sigmah/client/i18n/UIConstants.properties index 401da775d..98dd7fa00 100644 --- a/src/main/resources/org/sigmah/client/i18n/UIConstants.properties +++ b/src/main/resources/org/sigmah/client/i18n/UIConstants.properties @@ -1991,3 +1991,32 @@ contactFullName=Contact Name iterationName=Iteration Name seeIterationDetails=See details +calendar.addEvent.dateStart.label=Date start +calendar.addEvent.dateEnd.label=Date end +calendar.addEvent.isAllDayCB.allDayName=All day name +calendar.addEvent.repeatPeriodRG.name=Repeat event 999 +calendar.addEvent.repeatYearlyRB.label=yearly +calendar.addEvent.description.textArea.yearly=\ The Yearly event. +calendar.addEvent.repeatMonthlyRB.label=monthly +calendar.addEvent.description.textArea.monthly=\ The Monthly event. +calendar.addEvent.repeatWeeklyRB.label=weekly +calendar.addEvent.description.textArea.weekly=\ The Weekly event. +calendar.addEvent.repeatDailyRB.label=daily +calendar.addEvent.description.textArea.daily=\ The Daily event. +calendar.addEvent.repeatOnceRB.label=once +calendar.addEvent.repeatOnceRB.name=onceRepeatRBname +calendar.addEvent.description.textArea.once=\ The Once event. +calendar.addEvent.repeatsSettings.headingHtml.monthly=Monthly repeats settings +calendar.addEvent.repeatsSettings.SameDayOfWeekRB.label=Same day of week +calendar.addEvent.repeatsSettings.SameDayOfWeekRB.monthly.name=radioMonthlySameDayOfWeek +calendar.addEvent.repeatsSettings.SameDayOfWeekRB.monthly.toolTip=Every next month at the same day of week. (with autochange to ...h) +calendar.addEvent.repeatsSettings.SameDateRB.label=Same date +calendar.addEvent.repeatsSettings.SameDateRB.monthly.name=radioMonthlySameDate +calendar.addEvent.repeatsSettings.SameDateRB.monthly.toolTip=Every next month at the same date. (with autochange to last day of month) +calendar.addEvent.repeatsSettings.radioGroup.monthly.settings=Montly settings 999 +calendar.addEvent.repeatsSettings.headingHtml.yearly=Yearly repeats settings +calendar.addEvent.repeatsSettings.SameDayOfWeekRB.yearly.toolTip=Repeat Calendar event at the same DAY of week annually +calendar.addEvent.repeatsSettings.SameDayOfWeekRB.yearly.name=radioYearlySameDayOfWeek +calendar.addEvent.repeatsSettings.SameDateRB.yearly.name=radioYearlySameDate +calendar.addEvent.repeatsSettings.radioGroup.yearly.settings=Yearly settings 888 +calendar.addEvent.repeatsSettings.radioGroup.yearly.settings.name=Yearly settings name From 278c5741c684c8e2026e22421025fd1721b48f20 Mon Sep 17 00:00:00 2001 From: Seal98 Date: Tue, 11 Jul 2017 10:02:12 +0300 Subject: [PATCH 18/39] (issue#852) Delete chain performance improved. Implemented changes to improve performance of delete chain functionality. Fixed issue with refreshing calendar view after chain deletion. --- .../presenter/calendar/CalendarPresenter.java | 817 +++++++++--------- 1 file changed, 403 insertions(+), 414 deletions(-) diff --git a/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarPresenter.java b/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarPresenter.java index 2123d608d..bcd70ad5b 100644 --- a/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarPresenter.java +++ b/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarPresenter.java @@ -21,8 +21,6 @@ * . * #L% */ - - import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -82,192 +80,140 @@ */ public class CalendarPresenter extends AbstractPresenter { - /** - * Description of the view managed by this presenter. - */ - @ImplementedBy(CalendarView.class) - public static interface View extends ViewInterface { + /** + * Description of the view managed by this presenter. + */ + @ImplementedBy(CalendarView.class) + public static interface View extends ViewInterface { - void initializeCalendarWidget(final CalendarWidget calendarWidget); + void initializeCalendarWidget(final CalendarWidget calendarWidget); - void setAddEventButtonEnabled(final boolean addEventButtonEnabled); + void setAddEventButtonEnabled(final boolean addEventButtonEnabled); - AbstractStoreSelectionModel getCalendarsSelectionModel(); + AbstractStoreSelectionModel getCalendarsSelectionModel(); - ListStore getCalendarsStore(); + ListStore getCalendarsStore(); - Button getAddEventButton(); + Button getAddEventButton(); - Button getTodayButton(); + Button getTodayButton(); - Button getWeekButton(); + Button getWeekButton(); - Button getMonthButton(); + Button getMonthButton(); - Button getPreviousButton(); + Button getPreviousButton(); - Button getNextButton(); + Button getNextButton(); Button getReminderAddButton(); - Button getMonitoredPointsAddButton(); + Button getMonitoredPointsAddButton(); - } + } - /** - * The calendar widget. - */ - private CalendarWidget calendar; + /** + * The calendar widget. + */ + private CalendarWidget calendar; private Integer projectId; - // @Inject - // private PersonalEventDAO personalEventDAO; - /** - * Presenters's initialization. - * - * @param view - * Presenter's view interface. - * @param injector - * Injected client injector. - */ - @Inject - protected CalendarPresenter(final View view, final Injector injector) { - super(view, injector); - } - - /** - * {@inheritDoc} - */ - @Override - public void onBind() { - - // -- - // Initialize calendar widget. - // -- - - calendar = new CalendarWidget(CalendarWidget.COLUMN_HEADERS, true, auth()); - calendar.today(); // Reset the current date. - calendar.setDisplayMode(CalendarWidget.DisplayMode.MONTH); - - view.initializeCalendarWidget(calendar); - - view.setAddEventButtonEnabled(false); - - // -- - // Configuring calendar delegate. - // -- - - calendar.setDelegate(new CalendarWidget.Delegate() { - - @Override - public void edit(final Event event, final CalendarWidget calendarWidget) { - eventBus.navigateRequest(Page.CALENDAR_EVENT.request().addData(RequestParameter.DTO, event).addData(RequestParameter.CONTENT, getCalendars())); - } - - @Override - public void delete(final Event event, final CalendarWidget calendarWidget) { - final CalendarIdentifier calendarIdentifier = event.getParent().getIdentifier(); - final Integer parentId = calendarIdentifier instanceof PersonalCalendarIdentifier ? - ((PersonalCalendarIdentifier)calendarIdentifier).getId() : null; - // Window.alert("refId = "+event.getReferenceId());//temp for checker - // Window.alert("Type = "+event.getEventType());//temp for checker - // Window.alert("Description = "+event.getDescription());//temp for checker - // Window.alert("Summary = "+event.getSummary());//temp for checker - // event.setReferenceId(null); - dispatch.execute(new Delete(PersonalEventDTO.ENTITY_NAME, event.getIdentifier(), parentId), new CommandResultHandler() { - - @Override - public void onCommandFailure(final Throwable caught) { - N10N.error(I18N.CONSTANTS.error(), I18N.CONSTANTS.calendarDeleteEventError()); - } - - @Override - public void onCommandSuccess(final VoidResult result) { - - final List oldEventList = - event.getParent().getEvents().get(event.getKey()); - oldEventList.remove(event); - calendar.refresh(); - } - }); - } - - @Override - public void deleteChain(final Event event, final CalendarWidget calendarWidget) { - final CalendarIdentifier calendarIdentifier = event.getParent().getIdentifier(); - final Integer parentId = calendarIdentifier instanceof PersonalCalendarIdentifier ? - ((PersonalCalendarIdentifier)calendarIdentifier).getId() : null; - - final Map> eventMap = event.getParent().getEvents(); - int refId; - int mainId = event.getIdentifier(); - if(event.getReferenceId() != null) refId = event.getReferenceId().intValue(); - else refId = 0; - String typeStr = (String)event.getEventType(); - Window.alert("refId = "+event.getReferenceId());//temp for checker - Window.alert("Type = "+event.getEventType());//temp for checker - for (final Date key : eventMap.keySet()) { - for (final Event next : eventMap.get(key)) { - calendar.refresh(); - if (typeStr != null) { - //удаляем цепочку кроме главного - для тестирования надо выбирать не первый ивент серии на каледнаре - if (refId != 0) { - - if (next.getReferenceId() != null && (next.getReferenceId().intValue() == refId)) { - // Window.alert(next.getReferenceId()+" | "+refId);//temp for checker - dispatch.execute(new Delete(PersonalEventDTO.ENTITY_NAME, next.getIdentifier(), parentId), new CommandResultHandler() { - - @Override - public void onCommandFailure(final Throwable caught) { - N10N.error(I18N.CONSTANTS.error(), I18N.CONSTANTS.calendarDeleteEventError()); - } - - @Override - public void onCommandSuccess(final VoidResult result) { - eventMap.remove(next); - calendar.refresh(); - } - }); - - } - } else { - if (next.getReferenceId() != null && (next.getReferenceId().intValue() == mainId)) { - // Window.alert(next.getReferenceId()+" | "+refId);//temp for checker - dispatch.execute(new Delete(PersonalEventDTO.ENTITY_NAME, next.getIdentifier(), parentId), new CommandResultHandler() { - - @Override - public void onCommandFailure(final Throwable caught) { - N10N.error(I18N.CONSTANTS.error(), I18N.CONSTANTS.calendarDeleteEventError()); - } - - @Override - public void onCommandSuccess(final VoidResult result) { - eventMap.remove(next); - calendar.refresh(); - } - }); - } - } - } else { - dispatch.execute(new Delete(PersonalEventDTO.ENTITY_NAME, event.getIdentifier(), parentId), new CommandResultHandler() { - - @Override - public void onCommandFailure(final Throwable caught) { - N10N.error(I18N.CONSTANTS.error(), I18N.CONSTANTS.calendarDeleteEventError()); - } - - @Override - public void onCommandSuccess(final VoidResult result) { - eventMap.remove(next); - calendar.refresh(); - } - }); - } - } - } - if (typeStr != null) { - if (refId != 0) { - dispatch.execute(new Delete(PersonalEventDTO.ENTITY_NAME, refId, parentId), new CommandResultHandler() { + // @Inject + // private PersonalEventDAO personalEventDAO; + + /** + * Presenters's initialization. + * + * @param view Presenter's view interface. + * @param injector Injected client injector. + */ + @Inject + protected CalendarPresenter(final View view, final Injector injector) { + super(view, injector); + } + + /** + * {@inheritDoc} + */ + @Override + public void onBind() { + + // -- + // Initialize calendar widget. + // -- + calendar = new CalendarWidget(CalendarWidget.COLUMN_HEADERS, true, auth()); + calendar.today(); // Reset the current date. + calendar.setDisplayMode(CalendarWidget.DisplayMode.MONTH); + + view.initializeCalendarWidget(calendar); + + view.setAddEventButtonEnabled(false); + + // -- + // Configuring calendar delegate. + // -- + calendar.setDelegate(new CalendarWidget.Delegate() { + + @Override + public void edit(final Event event, final CalendarWidget calendarWidget) { + eventBus.navigateRequest(Page.CALENDAR_EVENT.request().addData(RequestParameter.DTO, event).addData(RequestParameter.CONTENT, getCalendars())); + } + + @Override + public void delete(final Event event, final CalendarWidget calendarWidget) { + final CalendarIdentifier calendarIdentifier = event.getParent().getIdentifier(); + final Integer parentId = calendarIdentifier instanceof PersonalCalendarIdentifier + ? ((PersonalCalendarIdentifier) calendarIdentifier).getId() : null; + // Window.alert("refId = "+event.getReferenceId());//temp for checker + // Window.alert("Type = "+event.getEventType());//temp for checker + // Window.alert("Description = "+event.getDescription());//temp for checker + // Window.alert("Summary = "+event.getSummary());//temp for checker + // event.setReferenceId(null); + dispatch.execute(new Delete(PersonalEventDTO.ENTITY_NAME, event.getIdentifier(), parentId), new CommandResultHandler() { + + @Override + public void onCommandFailure(final Throwable caught) { + N10N.error(I18N.CONSTANTS.error(), I18N.CONSTANTS.calendarDeleteEventError()); + } + + @Override + public void onCommandSuccess(final VoidResult result) { + + final List oldEventList + = event.getParent().getEvents().get(event.getKey()); + oldEventList.remove(event); + calendar.refresh(); + } + }); + } + + @Override + public void deleteChain(final Event event, final CalendarWidget calendarWidget) { + final CalendarIdentifier calendarIdentifier = event.getParent().getIdentifier(); + final Integer parentId = calendarIdentifier instanceof PersonalCalendarIdentifier + ? ((PersonalCalendarIdentifier) calendarIdentifier).getId() : null; + + final Map> eventMap = event.getParent().getEvents(); + + int mainId = event.getIdentifier(); + int refId = 0; + if (event.getReferenceId() != null) { + refId = event.getReferenceId().intValue(); + } + String typeStr = (String) event.getEventType(); + Window.alert("refId = " + event.getReferenceId());//temp for checker + Window.alert("Type = " + event.getEventType());//temp for checker + if (typeStr != null) { + for (final Date key : eventMap.keySet()) { + for (final Event next : eventMap.get(key)) { + //calendar.refresh(); + // if (typeStr != null) { + //удаляем цепочку кроме главного - для тестирования надо выбирать не первый ивент серии на каледнаре + if (refId != 0) { + + if (next.getReferenceId() != null && (next.getReferenceId().intValue() == refId)) { + // Window.alert(next.getReferenceId()+" | "+refId);//temp for checker + dispatch.execute(new Delete(PersonalEventDTO.ENTITY_NAME, next.getIdentifier(), parentId), new CommandResultHandler() { @Override public void onCommandFailure(final Throwable caught) { @@ -276,14 +222,17 @@ public void onCommandFailure(final Throwable caught) { @Override public void onCommandSuccess(final VoidResult result) { - final List oldEventList - = event.getParent().getEvents().get(event.getKey()); - oldEventList.remove(event); + //List remove = event.getParent().getEvents().remove(next); + eventMap.get(key).remove(next); calendar.refresh(); } }); - } else { - dispatch.execute(new Delete(PersonalEventDTO.ENTITY_NAME, mainId, parentId), new CommandResultHandler() { + break; + } + } else { + if (next.getReferenceId() != null && (next.getReferenceId().intValue() == mainId)) { + // Window.alert(next.getReferenceId()+" | "+refId);//temp for checker + dispatch.execute(new Delete(PersonalEventDTO.ENTITY_NAME, next.getIdentifier(), parentId), new CommandResultHandler() { @Override public void onCommandFailure(final Throwable caught) { @@ -292,288 +241,328 @@ public void onCommandFailure(final Throwable caught) { @Override public void onCommandSuccess(final VoidResult result) { - final List oldEventList - = event.getParent().getEvents().get(event.getKey()); - oldEventList.remove(event); + eventMap.get(key).remove(next); calendar.refresh(); } }); } - } + } +// } else { +// dispatch.execute(new Delete(PersonalEventDTO.ENTITY_NAME, event.getIdentifier(), parentId), new CommandResultHandler() { +// +// @Override +// public void onCommandFailure(final Throwable caught) { +// N10N.error(I18N.CONSTANTS.error(), I18N.CONSTANTS.calendarDeleteEventError()); +// } +// +// @Override +// public void onCommandSuccess(final VoidResult result) { +// eventMap.remove(next); +// calendar.refresh(); +// } +// }); +// } } - }); + } +// if (typeStr != null) { +// if (refId != 0) { +// dispatch.execute(new Delete(PersonalEventDTO.ENTITY_NAME, refId, parentId), new CommandResultHandler() { +// +// @Override +// public void onCommandFailure(final Throwable caught) { +// N10N.error(I18N.CONSTANTS.error(), I18N.CONSTANTS.calendarDeleteEventError()); +// } +// +// @Override +// public void onCommandSuccess(final VoidResult result) { +// final List oldEventList +// = event.getParent().getEvents().get(event.getKey()); +// oldEventList.remove(event); +// calendar.refresh(); +// } +// }); + } else { + dispatch.execute(new Delete(PersonalEventDTO.ENTITY_NAME, mainId, parentId), new CommandResultHandler() { - // -- - // Calendars selection change event. - // -- + @Override + public void onCommandFailure(final Throwable caught) { + N10N.error(I18N.CONSTANTS.error(), I18N.CONSTANTS.calendarDeleteEventError()); + } - view.getCalendarsSelectionModel().addSelectionChangedListener(new SelectionChangedListener() { - - @Override - public void selectionChanged(SelectionChangedEvent se) { - final List wrappers = se.getSelection(); - final ArrayList calendars = new ArrayList(); - for (final CalendarWrapper wrapper : wrappers) { - calendars.add(wrapper.getCalendar()); - } - calendar.setCalendars(calendars); - } - }); + @Override + public void onCommandSuccess(final VoidResult result) { + final List oldEventList + = event.getParent().getEvents().get(event.getKey()); + oldEventList.remove(event); + calendar.refresh(); + } + }); + } + } +// } + }); + + // -- + // Calendars selection change event. + // -- + view.getCalendarsSelectionModel().addSelectionChangedListener(new SelectionChangedListener() { + + @Override + public void selectionChanged(SelectionChangedEvent se) { + final List wrappers = se.getSelection(); + final ArrayList calendars = new ArrayList(); + for (final CalendarWrapper wrapper : wrappers) { + calendars.add(wrapper.getCalendar()); + } + calendar.setCalendars(calendars); + } + }); + + // -- + // Add event button. + // -- + view.getAddEventButton().addSelectionListener(new SelectionListener() { - // -- - // Add event button. - // -- + @Override + public void componentSelected(final ButtonEvent ce) { - view.getAddEventButton().addSelectionListener(new SelectionListener() { + if (view.getCalendarsStore().getCount() == 0) { + N10N.warn(I18N.CONSTANTS.calendar_addEvent_noCalendar_ko()); + return; + } + + eventBus.navigateRequest(Page.CALENDAR_EVENT.request().addData(RequestParameter.CONTENT, getCalendars())); + } + }); - @Override - public void componentSelected(final ButtonEvent ce) { - - if (view.getCalendarsStore().getCount() == 0) { - N10N.warn(I18N.CONSTANTS.calendar_addEvent_noCalendar_ko()); - return; - } - - eventBus.navigateRequest(Page.CALENDAR_EVENT.request().addData(RequestParameter.CONTENT, getCalendars())); - } - }); - - // -- - // Today button. - // -- - - view.getTodayButton().addSelectionListener(new SelectionListener() { - - @Override - public void componentSelected(final ButtonEvent ce) { - calendar.today(); - } - }); - - // -- - // Week button. - // -- - - view.getWeekButton().addSelectionListener(new SelectionListener() { - - @Override - public void componentSelected(final ButtonEvent ce) { - calendar.setDisplayMode(CalendarWidget.DisplayMode.WEEK); - } - }); - - // -- - // Month button. - // -- - - view.getMonthButton().addSelectionListener(new SelectionListener() { - - @Override - public void componentSelected(final ButtonEvent ce) { - calendar.setDisplayMode(CalendarWidget.DisplayMode.MONTH); - } - }); - - // -- - // Previous button. - // -- - - view.getPreviousButton().addSelectionListener(new SelectionListener() { - - @Override - public void componentSelected(final ButtonEvent ce) { - calendar.previous(); - } - }); - - // -- - // Next button. - // -- - - view.getNextButton().addSelectionListener(new SelectionListener() { - - @Override - public void componentSelected(final ButtonEvent ce) { - calendar.next(); - } - }); - - // -- - // Reminders / Monitored Points add buttons handlers. - // -- - - view.getReminderAddButton().addSelectionListener(new SelectionListener() { - - @Override - public void componentSelected(final ButtonEvent event) { - eventBus.navigateRequest(Page.REMINDER_EDIT.requestWith(RequestParameter.TYPE, ReminderType.REMINDER).addParameter(RequestParameter.ID, - projectId)); - } - }); - - view.getMonitoredPointsAddButton().addSelectionListener(new SelectionListener() { - - @Override - public void componentSelected(final ButtonEvent event) { - eventBus.navigateRequest(Page.REMINDER_EDIT.requestWith(RequestParameter.TYPE, ReminderType.MONITORED_POINT).addParameter(RequestParameter.ID, - projectId)); - } - }); + // -- + // Today button. + // -- + view.getTodayButton().addSelectionListener(new SelectionListener() { - // -- - // Update event handler. - // -- + @Override + public void componentSelected(final ButtonEvent ce) { + calendar.today(); + } + }); - registerHandler(eventBus.addHandler(UpdateEvent.getType(), new UpdateHandler() { + // -- + // Week button. + // -- + view.getWeekButton().addSelectionListener(new SelectionListener() { + + @Override + public void componentSelected(final ButtonEvent ce) { + calendar.setDisplayMode(CalendarWidget.DisplayMode.WEEK); + } + }); + + // -- + // Month button. + // -- + view.getMonthButton().addSelectionListener(new SelectionListener() { + + @Override + public void componentSelected(final ButtonEvent ce) { + calendar.setDisplayMode(CalendarWidget.DisplayMode.MONTH); + } + }); + + // -- + // Previous button. + // -- + view.getPreviousButton().addSelectionListener(new SelectionListener() { + + @Override + public void componentSelected(final ButtonEvent ce) { + calendar.previous(); + } + }); + + // -- + // Next button. + // -- + view.getNextButton().addSelectionListener(new SelectionListener() { + + @Override + public void componentSelected(final ButtonEvent ce) { + calendar.next(); + } + }); + + // -- + // Reminders / Monitored Points add buttons handlers. + // -- + view.getReminderAddButton().addSelectionListener(new SelectionListener() { + + @Override + public void componentSelected(final ButtonEvent event) { + eventBus.navigateRequest(Page.REMINDER_EDIT.requestWith(RequestParameter.TYPE, ReminderType.REMINDER).addParameter(RequestParameter.ID, + projectId)); + } + }); + + view.getMonitoredPointsAddButton().addSelectionListener(new SelectionListener() { + + @Override + public void componentSelected(final ButtonEvent event) { + eventBus.navigateRequest(Page.REMINDER_EDIT.requestWith(RequestParameter.TYPE, ReminderType.MONITORED_POINT).addParameter(RequestParameter.ID, + projectId)); + } + }); + + // -- + // Update event handler. + // -- + registerHandler(eventBus.addHandler(UpdateEvent.getType(), new UpdateHandler() { + + @Override + public void onUpdate(final UpdateEvent event) { + if (event.concern(UpdateEvent.CALENDAR_EVENT_UPDATE)) { + calendar.refresh(); + } - @Override - public void onUpdate(final UpdateEvent event) { - if (event.concern(UpdateEvent.CALENDAR_EVENT_UPDATE)) { - calendar.refresh(); - } - if (event.concern(UpdateEvent.REMINDER_UPDATED)) { // TODO appel reloadEventsOfReminderType((ReminderType) event.getParam(0)); calendar.refresh(); } - } - })); - } - - /** - * Reloads the calendars data (if necessary). - * - * @param calendars - * The calendar types with their corresponding identifier. - */ - public void reload(final Map calendars, boolean editable) { - Profiler.INSTANCE.markCheckpoint(Scenario.AGENDA, "Before refresh."); - - calendar.refresh(); - Profiler.INSTANCE.markCheckpoint(Scenario.AGENDA, "calendar.refresh ended."); + } + })); + } + + /** + * Reloads the calendars data (if necessary). + * + * @param calendars The calendar types with their corresponding identifier. + */ + public void reload(final Map calendars, boolean editable) { + Profiler.INSTANCE.markCheckpoint(Scenario.AGENDA, "Before refresh."); + + calendar.refresh(); + Profiler.INSTANCE.markCheckpoint(Scenario.AGENDA, "calendar.refresh ended."); this.projectId = calendars.get(CalendarType.Activity); - view.setAddEventButtonEnabled(editable); - Profiler.INSTANCE.markCheckpoint(Scenario.AGENDA, "Before refresh."); - reloadEvents(calendars); - } - - /** - * {@inheritDoc}
- * Updates the calendar view. - */ - @Override - public void onViewRevealed() { - calendar.refresh(); - } - - /** - * Returns the {@link CalendarWrapper} list from the view store. - * - * @return The collection. - */ - private List getCalendars() { - - final List calendars = new ArrayList(); - final ListStore store = view.getCalendarsStore(); - - for (int i = 0; i < store.getCount(); i++) { - calendars.add(store.getAt(i)); - } - - return calendars; - } - - /** - * Reloads the calendar events using a {@link GetCalendar} command. - * - * @param calendars - * The calendar types with their corresponding identifier. - */ - private void reloadEvents(final Map calendars) { - - view.getCalendarsStore().removeAll(); - - if (ClientUtils.isEmpty(calendars)) { - calendar.refresh(); - Profiler.INSTANCE.endScenario(Scenario.AGENDA); - return; - } - - final DispatchQueue queue = new DispatchQueue(dispatch, true) { - - @Override - protected void onComplete() { - calendar.refresh(); - Profiler.INSTANCE.endScenario(Scenario.AGENDA); - } - }; - - for (final Entry calendarEntry : calendars.entrySet()) { - - if (calendarEntry == null) { - continue; - } - - final CalendarType calendarType = calendarEntry.getKey(); - final Integer calendarId = calendarEntry.getValue(); - - queue.add(new GetCalendar(calendarType, CalendarType.getIdentifier(calendarType, calendarId)), new CommandResultHandler() { - - @Override - public void onCommandSuccess(final Calendar result) { - Profiler.INSTANCE.markCheckpoint(Scenario.AGENDA, calendarType + " ended."); - if(result != null) { - // Defines the color index of the calendar. - result.setStyle(calendarType.getColorCode()); + view.setAddEventButtonEnabled(editable); + Profiler.INSTANCE.markCheckpoint(Scenario.AGENDA, "Before refresh."); + reloadEvents(calendars); + } + + /** + * {@inheritDoc}
+ * Updates the calendar view. + */ + @Override + public void onViewRevealed() { + calendar.refresh(); + } + + /** + * Returns the {@link CalendarWrapper} list from the view store. + * + * @return The collection. + */ + private List getCalendars() { + + final List calendars = new ArrayList(); + final ListStore store = view.getCalendarsStore(); + + for (int i = 0; i < store.getCount(); i++) { + calendars.add(store.getAt(i)); + } + + return calendars; + } + + /** + * Reloads the calendar events using a {@link GetCalendar} command. + * + * @param calendars The calendar types with their corresponding identifier. + */ + private void reloadEvents(final Map calendars) { + + view.getCalendarsStore().removeAll(); + + if (ClientUtils.isEmpty(calendars)) { + calendar.refresh(); + Profiler.INSTANCE.endScenario(Scenario.AGENDA); + return; + } + + final DispatchQueue queue = new DispatchQueue(dispatch, true) { + + @Override + protected void onComplete() { + calendar.refresh(); + Profiler.INSTANCE.endScenario(Scenario.AGENDA); + } + }; + + for (final Entry calendarEntry : calendars.entrySet()) { + + if (calendarEntry == null) { + continue; + } + + final CalendarType calendarType = calendarEntry.getKey(); + final Integer calendarId = calendarEntry.getValue(); + + queue.add(new GetCalendar(calendarType, CalendarType.getIdentifier(calendarType, calendarId)), new CommandResultHandler() { + + @Override + public void onCommandSuccess(final Calendar result) { + Profiler.INSTANCE.markCheckpoint(Scenario.AGENDA, calendarType + " ended."); + if (result != null) { + // Defines the color index of the calendar. + result.setStyle(calendarType.getColorCode()); result.setType(calendarType); - view.getCalendarsStore().add(new CalendarWrapper(result)); - view.getCalendarsSelectionModel().select(view.getCalendarsStore().getCount() - 1, true); - } - } - - @Override - protected void onCommandFailure(Throwable caught) { - Profiler.INSTANCE.markCheckpoint(Scenario.AGENDA, calendarType + " ended with error."); - super.onCommandFailure(caught); - } - - }); - } - Profiler.INSTANCE.markCheckpoint(Scenario.AGENDA, "Before queue started."); - queue.start(); - } + view.getCalendarsStore().add(new CalendarWrapper(result)); + view.getCalendarsSelectionModel().select(view.getCalendarsStore().getCount() - 1, true); + } + } + + @Override + protected void onCommandFailure(Throwable caught) { + Profiler.INSTANCE.markCheckpoint(Scenario.AGENDA, calendarType + " ended with error."); + super.onCommandFailure(caught); + } + + }); + } + Profiler.INSTANCE.markCheckpoint(Scenario.AGENDA, "Before queue started."); + queue.start(); + } + /** * Reload a given type of reminder into the calendar. - * + * * @param reminderType Type of reminder to refresh. */ private void reloadEventsOfReminderType(final ReminderType reminderType) { final CalendarType calendarType = reminderType == ReminderType.REMINDER ? CalendarType.Reminder : CalendarType.MonitoredPoint; - + final List calendars = calendar.getCalendars(); for (int index = 0; index < calendars.size(); index++) { final Calendar currentCalendar = calendars.get(index); - + if (currentCalendar.getType() == calendarType) { final GetCalendar getCalendar = new GetCalendar(calendarType, currentCalendar.getIdentifier()); final int location = index; - + dispatch.execute(getCalendar, new CommandResultHandler() { - + @Override protected void onCommandSuccess(Calendar result) { - if(result != null) { + if (result != null) { result.setStyle(calendarType.getColorCode()); result.setType(calendarType); calendars.set(location, result); calendar.refresh(); } } - + }); return; } From 253b3f4fab695d12ae249055e9d0cf08c11c737f Mon Sep 17 00:00:00 2001 From: Seal98 Date: Tue, 11 Jul 2017 17:34:04 +0300 Subject: [PATCH 19/39] [Issue #852] : Delete chain fixes Fixes: adding the information into database fields after the event editing --- .../calendar/CalendarEventPresenter.java | 7 +- .../presenter/calendar/CalendarPresenter.java | 76 ++++++++----------- 2 files changed, 33 insertions(+), 50 deletions(-) diff --git a/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java b/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java index e36c0b51d..338466104 100644 --- a/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java +++ b/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java @@ -453,14 +453,13 @@ private void onSaveAction() { Date endDate = createEndDateProperty(isFullDayEvent, beginEventIntervalDate, properties); properties.put(Event.DESCRIPTION, view.getEventDescriptionField().getValue()); + if (event == null) { - // process properties and define repetable events dates processAddEvent(endEventIntervalDate, beginEventIntervalDate, startDate, endDate, properties, eventSummary, eventDescription); - //add first event, to include in properties updated description and summary with event period type - //the first event is added last - after processing previous events - //addPersonalEvent(properties); } else { + properties.put(Event.EVENT_TYPE, event.getEventType()); + properties.put(Event.REFERENCE_ID, event.getReferenceId()); editPersonalEvent(event, properties); } } diff --git a/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarPresenter.java b/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarPresenter.java index bcd70ad5b..e521cd432 100644 --- a/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarPresenter.java +++ b/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarPresenter.java @@ -164,11 +164,6 @@ public void delete(final Event event, final CalendarWidget calendarWidget) { final CalendarIdentifier calendarIdentifier = event.getParent().getIdentifier(); final Integer parentId = calendarIdentifier instanceof PersonalCalendarIdentifier ? ((PersonalCalendarIdentifier) calendarIdentifier).getId() : null; - // Window.alert("refId = "+event.getReferenceId());//temp for checker - // Window.alert("Type = "+event.getEventType());//temp for checker - // Window.alert("Description = "+event.getDescription());//temp for checker - // Window.alert("Summary = "+event.getSummary());//temp for checker - // event.setReferenceId(null); dispatch.execute(new Delete(PersonalEventDTO.ENTITY_NAME, event.getIdentifier(), parentId), new CommandResultHandler() { @Override @@ -201,18 +196,11 @@ public void deleteChain(final Event event, final CalendarWidget calendarWidget) refId = event.getReferenceId().intValue(); } String typeStr = (String) event.getEventType(); - Window.alert("refId = " + event.getReferenceId());//temp for checker - Window.alert("Type = " + event.getEventType());//temp for checker if (typeStr != null) { for (final Date key : eventMap.keySet()) { for (final Event next : eventMap.get(key)) { - //calendar.refresh(); - // if (typeStr != null) { - //удаляем цепочку кроме главного - для тестирования надо выбирать не первый ивент серии на каледнаре if (refId != 0) { - if (next.getReferenceId() != null && (next.getReferenceId().intValue() == refId)) { - // Window.alert(next.getReferenceId()+" | "+refId);//temp for checker dispatch.execute(new Delete(PersonalEventDTO.ENTITY_NAME, next.getIdentifier(), parentId), new CommandResultHandler() { @Override @@ -222,16 +210,29 @@ public void onCommandFailure(final Throwable caught) { @Override public void onCommandSuccess(final VoidResult result) { - //List remove = event.getParent().getEvents().remove(next); eventMap.get(key).remove(next); calendar.refresh(); } }); break; } + else if((next.getReferenceId() == null) && (next.getIdentifier().intValue() == refId)){ + dispatch.execute(new Delete(PersonalEventDTO.ENTITY_NAME, next.getIdentifier(), parentId), new CommandResultHandler() { + + @Override + public void onCommandFailure(final Throwable caught) { + N10N.error(I18N.CONSTANTS.error(), I18N.CONSTANTS.calendarDeleteEventError()); + } + + @Override + public void onCommandSuccess(final VoidResult result) { + eventMap.get(key).remove(next); + calendar.refresh(); + } + }); + } } else { if (next.getReferenceId() != null && (next.getReferenceId().intValue() == mainId)) { - // Window.alert(next.getReferenceId()+" | "+refId);//temp for checker dispatch.execute(new Delete(PersonalEventDTO.ENTITY_NAME, next.getIdentifier(), parentId), new CommandResultHandler() { @Override @@ -246,41 +247,24 @@ public void onCommandSuccess(final VoidResult result) { } }); } + else if(next.getReferenceId() == null && next.getIdentifier().intValue() == mainId){ + dispatch.execute(new Delete(PersonalEventDTO.ENTITY_NAME, mainId, parentId), new CommandResultHandler() { + + @Override + public void onCommandFailure(final Throwable caught) { + N10N.error(I18N.CONSTANTS.error(), I18N.CONSTANTS.calendarDeleteEventError()); + } + + @Override + public void onCommandSuccess(final VoidResult result) { + eventMap.get(key).remove(next); + calendar.refresh(); + } + }); + } } -// } else { -// dispatch.execute(new Delete(PersonalEventDTO.ENTITY_NAME, event.getIdentifier(), parentId), new CommandResultHandler() { -// -// @Override -// public void onCommandFailure(final Throwable caught) { -// N10N.error(I18N.CONSTANTS.error(), I18N.CONSTANTS.calendarDeleteEventError()); -// } -// -// @Override -// public void onCommandSuccess(final VoidResult result) { -// eventMap.remove(next); -// calendar.refresh(); -// } -// }); -// } } } -// if (typeStr != null) { -// if (refId != 0) { -// dispatch.execute(new Delete(PersonalEventDTO.ENTITY_NAME, refId, parentId), new CommandResultHandler() { -// -// @Override -// public void onCommandFailure(final Throwable caught) { -// N10N.error(I18N.CONSTANTS.error(), I18N.CONSTANTS.calendarDeleteEventError()); -// } -// -// @Override -// public void onCommandSuccess(final VoidResult result) { -// final List oldEventList -// = event.getParent().getEvents().get(event.getKey()); -// oldEventList.remove(event); -// calendar.refresh(); -// } -// }); } else { dispatch.execute(new Delete(PersonalEventDTO.ENTITY_NAME, mainId, parentId), new CommandResultHandler() { From 019d8913e64a3a1c15e802d2216b568ecad6befc Mon Sep 17 00:00:00 2001 From: Seal98 Date: Tue, 11 Jul 2017 18:40:22 +0300 Subject: [PATCH 20/39] (Issue#852) Refactoring Refactoring and cleaning up java code --- .../calendar/CalendarEventPresenter.java | 273 ++++++------------ .../presenter/calendar/CalendarPresenter.java | 98 +++---- .../ui/view/calendar/CalendarEventView.java | 59 ---- 3 files changed, 131 insertions(+), 299 deletions(-) diff --git a/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java b/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java index 338466104..798df8e60 100644 --- a/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java +++ b/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java @@ -1,4 +1,5 @@ package org.sigmah.client.ui.presenter.calendar; + /* * #%L * Sigmah @@ -52,7 +53,6 @@ import com.allen_sauer.gwt.log.client.Log; import com.extjs.gxt.ui.client.event.ButtonEvent; import com.extjs.gxt.ui.client.event.SelectionListener; -//import com.extjs.gxt.ui.client.widget.Window; import com.google.gwt.user.client.Window; import com.extjs.gxt.ui.client.widget.form.CheckBox; import com.extjs.gxt.ui.client.widget.form.DateField; @@ -63,8 +63,6 @@ import com.extjs.gxt.ui.client.widget.form.TextField; import com.extjs.gxt.ui.client.widget.form.Time; import com.extjs.gxt.ui.client.widget.form.TimeField; -import static com.google.gwt.core.ext.TreeLogger.NULL; -import com.google.gwt.user.client.Timer; import com.google.inject.ImplementedBy; import com.google.inject.Inject; import com.google.inject.Singleton; @@ -227,8 +225,7 @@ public static interface View extends ViewInterface { */ Radio getRadioMonthlySameDayOfWeek(); - - // void setShowAddEventView(boolean showAddEventView); + // void setShowAddEventView(boolean showAddEventView); } /** @@ -329,7 +326,7 @@ public void onPageRequest(final PageRequest request) { } /** - * Create Edit Calendar Event View + * Create Edit Calendar Event View */ private void prepareEditView() { this.calendarWrapper = new CalendarWrapper(event.getParent()); @@ -358,7 +355,7 @@ private void prepareEditView() { view.getYearlySameDayOfWeekRB().hide(); view.getRadioMonthlySameDate().hide(); view.getRadioMonthlySameDayOfWeek().hide(); - + view.getEventDateEndField().clear(); view.getEventDateEndField().hide(); } @@ -380,7 +377,7 @@ private void prepareEditView() { } /** - * Create Add Calendar Event View + * Create Add Calendar Event View */ private void prepareAddView() { if (view.getRepeatEventPeriodRG() != null) { @@ -453,19 +450,19 @@ private void onSaveAction() { Date endDate = createEndDateProperty(isFullDayEvent, beginEventIntervalDate, properties); properties.put(Event.DESCRIPTION, view.getEventDescriptionField().getValue()); - if (event == null) { processAddEvent(endEventIntervalDate, beginEventIntervalDate, startDate, endDate, properties, eventSummary, eventDescription); } else { - properties.put(Event.EVENT_TYPE, event.getEventType()); - properties.put(Event.REFERENCE_ID, event.getReferenceId()); + properties.put(Event.EVENT_TYPE, event.getEventType()); + properties.put(Event.REFERENCE_ID, event.getReferenceId()); editPersonalEvent(event, properties); } } /** * Add new calendar events processing. + * * @param endEventIntervalDate the value of endEventIntervalDate * @param beginEventIntervalDate the value of beginEventIntervalDate * @param startDate the value of startDate @@ -478,56 +475,31 @@ private void processAddEvent(Date endEventIntervalDate, final Date beginEventInt long milisPerDay = 86400000; //24 * 60 * 60 * 1000) long milisPerWeek = 7 * milisPerDay; //7 days * (24hour * 60minutes * 60seconds * 1000mili seconds) long diffInMilis = endEventIntervalDate.getTime() - beginEventIntervalDate.getTime(); - - //Boolean isOnceRepeatEvent = view.getOnceRepeatRB().getValue(); - // Window.alert("isOnceRepeatEvent=" + isOnceRepeatEvent);//temp for checker - - //if(!isOnceRepeatEvent.booleanValue()){ - //Here process properties and define repetable events dates - /*take parameters from View - Start Date, get End beginEventIntervalDate, period settings like Once, Daily, Monthly etc - process values to prepare new properties for new event - if needed calculate same day of week for Monthly or Yearly - if needed compare if the Date exist in Month (like 29 30 31 Febr etc) - if needed define weekends - after that in cycle add new events - */ -// Boolean isFullDayEvent = view.getAllDayCheckbox().getValue(); -// -// Window.alert("isFullDayEvent=" + isFullDayEvent);//temp for checker Boolean isDailyRepeatEvent = view.getDailyRepeatRB() != null ? view.getDailyRepeatRB().getValue() : Boolean.FALSE; Boolean isWeeklyRepeatEvent = view.getWeeklyRepeatRB().getValue(); Boolean isMonthlyRepeatEvent = view.getMonthlyRepeatRB().getValue(); Boolean isYearlyRepeatEvent = view.getYearlyRepeatRB().getValue(); Boolean isMonthlySameDayOfWeek = view.getRadioMonthlySameDayOfWeek().getValue(); - //Boolean isMonthlySameDate = view.getRadioMonthlySameDate().getValue(); Boolean isYearlySameDayOfWeek = view.getYearlySameDayOfWeekRB().getValue(); - // Boolean isYearlySameDate = view.getYearlySameDateRB().getValue(); -//Window.alert("isYearlySameDayOfWeek=" + isYearlySameDayOfWeek);//temp for checker -//Window.alert("isYearlySameDate=" + isYearlySameDate);//temp for checker if (isDailyRepeatEvent) { processDailyEvents(diffInMilis, milisPerDay, beginEventIntervalDate, startDate, endDate, properties, eventSummary, eventDescription); } else if (isWeeklyRepeatEvent) { processWeeklyEvents(diffInMilis, milisPerWeek, beginEventIntervalDate, startDate, endDate, properties, eventSummary, eventDescription); } else if (isMonthlyRepeatEvent) { -// Window.alert("MONTHLY : " + (isMonthlySameDayOfWeek?"Same DAY of a Week":"") -// +(isMonthlySameDate?"Same DATE":""));//temp for checker processMonthlyEvents(beginEventIntervalDate, endEventIntervalDate, properties, isMonthlySameDayOfWeek, startDate, endDate, eventSummary, eventDescription); } else if (isYearlyRepeatEvent) { -// Window.alert("YEARLY : " + (isYearlySameDayOfWeek ? "Same DAY of a Week" : "") -// + (isYearlySameDate ? "Same DATE" : ""));//temp for checker processYearEvents(beginEventIntervalDate, endEventIntervalDate, properties, isYearlySameDayOfWeek, startDate, endDate, eventSummary, eventDescription); - } - else{ + } else { processOnceEvent(startDate, endDate, properties, eventSummary, eventDescription); } } /** * Create Start event date property + * * @param isFulllDayEvent the value of isFullDayEvent * @param beginEventIntervalDate the value of beginEventIntervalDate * @param properties the value of properties @@ -551,6 +523,7 @@ private Date createStartDateProperty(Boolean isFulllDayEvent, final Date beginEv /** * Create End event date property + * * @param isFulllDayEvent the value of isFullDayEvent * @param beginEventIntervalDate the value of beginEventIntervalDate * @param properties the value of properties @@ -572,16 +545,15 @@ private Date createEndDateProperty(Boolean isFulllDayEvent, final Date beginEven return endDate; } - private void processOnceEvent(final Date startDate, final Date endDate, final Map properties, String eventSummary, String eventDescription){ - properties.put(Event.SUMMARY, (String) properties.get(Event.SUMMARY)); - properties.put(Event.DESCRIPTION, (String) properties.get(Event.DESCRIPTION)); - // properties.put(Event.EVENT_TYPE, "O"); - // properties.put(Event.REFERENCE_ID, 1); - addPersonalEvent(properties); - } - - /** + private void processOnceEvent(final Date startDate, final Date endDate, final Map properties, String eventSummary, String eventDescription) { + properties.put(Event.SUMMARY, (String) properties.get(Event.SUMMARY)); + properties.put(Event.DESCRIPTION, (String) properties.get(Event.DESCRIPTION)); + addPersonalEvent(properties); + } + + /** * Add new Daily calendar events processing. + * * @param diffInMilis the value of diffInMilis * @param milisPerDay the value of milisPerDay * @param beginEventIntervalDate the value of beginEventIntervalDate @@ -604,10 +576,11 @@ private void processDailyEvents(long diffInMilis, long milisPerDay, final Date b properties.put(Event.DESCRIPTION, (String) properties.get(Event.DESCRIPTION) + " (Daily event 1 of " + daysInterval + ")"); properties.put(Event.EVENT_TYPE, "D"); } - addPersonalEventDaily(properties,daysInterval, calBeginNextEventDateLong, milisPerDay, startDate, endDate, eventSummary, eventDescription); - + addPersonalEventDaily(properties, daysInterval, calBeginNextEventDateLong, milisPerDay, startDate, endDate, eventSummary, eventDescription); + } - private void addPersonalEventDaily(final Map properties, final int daysInterval, final long calBeginNextEventDateLong, final long milisPerDay, final Date startDate, final Date endDate, final String eventSummary, final String eventDescription) { + + private void addPersonalEventDaily(final Map properties, final int daysInterval, final long calBeginNextEventDateLong, final long milisPerDay, final Date startDate, final Date endDate, final String eventSummary, final String eventDescription) { final CreateEntity createEntity = new CreateEntity(PersonalEventDTO.ENTITY_NAME, properties); @@ -629,14 +602,14 @@ public void onCommandSuccess(final CreateResult result) { event.setIdentifier((Integer) result.getEntity().getId()); properties.put(Event.REFERENCE_ID, (Integer) result.getEntity().getId()); updateEvent(event, properties); - // properties.put(Event.REFERENCE_ID, (Integer) result.getEntity().getId()); addDailySeriesEvent((String) result.getEntity().getId(), daysInterval, calBeginNextEventDateLong, milisPerDay, startDate, endDate, eventSummary, eventDescription); } }, view.getCancelButton(), view.getSaveButton()); } - private void addDailySeriesEvent(String ids, int daysInterval, long calBeginNextEventDateLong, long milisPerDay, final Date startDate, final Date endDate, String eventSummary, String eventDescription) { + + private void addDailySeriesEvent(String ids, int daysInterval, long calBeginNextEventDateLong, long milisPerDay, final Date startDate, final Date endDate, String eventSummary, String eventDescription) { Date calBeginNextEventDate; - + for (int i = 1; i < daysInterval; i++) { calBeginNextEventDateLong += milisPerDay; @@ -647,7 +620,7 @@ private void addDailySeriesEvent(String ids, int daysInterval, long calBeginNext dailyProperties.put(Event.SUMMARY, view.getEventSummaryField().getValue()); dailyProperties.put(Event.DATE, calBeginNextEventDate); - + setFullDayEvent(startDate, endDate, calBeginNextEventDate, dailyProperties); String newSummary = eventSummary; @@ -661,8 +634,10 @@ private void addDailySeriesEvent(String ids, int daysInterval, long calBeginNext addPersonalEvent(dailyProperties); } } + /** * Add new Weekly calendar events processing. + * * @param diffInMilis the value of diffInMilis * @param milisPerWeek the value of milisPerWeek * @param beginEventIntervalDate the value of beginEventIntervalDate @@ -684,10 +659,11 @@ private void processWeeklyEvents(long diffInMilis, long milisPerWeek, final Date properties.put(Event.DESCRIPTION, (String) properties.get(Event.DESCRIPTION) + " (Weekly event 1 of " + weeksInterval + ")"); properties.put(Event.EVENT_TYPE, "W"); } - addPersonalEventWeekly(properties,weeksInterval, calBeginNextEventDateLong, milisPerWeek, startDate, endDate, eventSummary, eventDescription); + addPersonalEventWeekly(properties, weeksInterval, calBeginNextEventDateLong, milisPerWeek, startDate, endDate, eventSummary, eventDescription); } - private void addPersonalEventWeekly(final Map properties, final int daysInterval, final long calBeginNextEventDateLong, final long milisPerDay, final Date startDate, final Date endDate, final String eventSummary, final String eventDescription) { + + private void addPersonalEventWeekly(final Map properties, final int daysInterval, final long calBeginNextEventDateLong, final long milisPerDay, final Date startDate, final Date endDate, final String eventSummary, final String eventDescription) { final CreateEntity createEntity = new CreateEntity(PersonalEventDTO.ENTITY_NAME, properties); @@ -707,16 +683,16 @@ public void onCommandSuccess(final CreateResult result) { // Creating events. final Event event = new Event(); event.setIdentifier((Integer) result.getEntity().getId()); - properties.put(Event.REFERENCE_ID, (Integer) result.getEntity().getId()); + properties.put(Event.REFERENCE_ID, (Integer) result.getEntity().getId()); updateEvent(event, properties); - // properties.put(Event.REFERENCE_ID, (Integer) result.getEntity().getId()); addWeeklySeriesEvent((String) result.getEntity().getId(), daysInterval, calBeginNextEventDateLong, milisPerDay, startDate, endDate, eventSummary, eventDescription); } }, view.getCancelButton(), view.getSaveButton()); } - private void addWeeklySeriesEvent(String ids, int weeksInterval, long calBeginNextEventDateLong, long milisPerWeek, final Date startDate, final Date endDate, String eventSummary, String eventDescription) { + + private void addWeeklySeriesEvent(String ids, int weeksInterval, long calBeginNextEventDateLong, long milisPerWeek, final Date startDate, final Date endDate, String eventSummary, String eventDescription) { Date calBeginNextEventDate; - + for (int i = 1; i < weeksInterval; i++) { calBeginNextEventDateLong += milisPerWeek; @@ -741,8 +717,10 @@ private void addWeeklySeriesEvent(String ids, int weeksInterval, long calBeginNe addPersonalEvent(weeklyProperties); } } + /** * Set date and time values for Full day events. + * * @param startDate the value of startDate * @param endDate the value of endDate * @param calBeginNextEventDate the value of calBeginNextEventDate @@ -769,6 +747,7 @@ private void setFullDayEvent(final Date startDate, final Date endDate, Date calB /** * Add new Monthly calendar events processing. + * * @param beginEventIntervalDate the value of beginEventIntervalDate * @param endEventIntervalDate the value of endEventIntervalDate * @param properties the value of properties @@ -795,12 +774,16 @@ private void processMonthlyEvents(final Date beginEventIntervalDate, final Date if (monthInterval > 1) { properties.put(Event.SUMMARY, (String) properties.get(Event.SUMMARY) + " (Monthly event 1 of " + monthInterval + ")"); properties.put(Event.DESCRIPTION, (String) properties.get(Event.DESCRIPTION) + " (Monthly event 1 of " + monthInterval + ")"); - if(isMonthlySameDayOfWeek) properties.put(Event.EVENT_TYPE, "M1"); - else properties.put(Event.EVENT_TYPE, "M2"); + if (isMonthlySameDayOfWeek) { + properties.put(Event.EVENT_TYPE, "M1"); + } else { + properties.put(Event.EVENT_TYPE, "M2"); + } } addPersonalEventMonthly(properties, monthInterval, beginEventIntervalDate, endEventIntervalDate, startDate, endDate, eventSummary, eventDescription, isMonthlySameDayOfWeek); } - private void addPersonalEventMonthly(final Map properties, final int monthInterval, final Date beginEventIntervalDate, final Date endEventIntervalDate, final Date startDate, final Date endDate, final String eventSummary, final String eventDescription, final boolean isMonthlySameDayOfWeek) { + + private void addPersonalEventMonthly(final Map properties, final int monthInterval, final Date beginEventIntervalDate, final Date endEventIntervalDate, final Date startDate, final Date endDate, final String eventSummary, final String eventDescription, final boolean isMonthlySameDayOfWeek) { final CreateEntity createEntity = new CreateEntity(PersonalEventDTO.ENTITY_NAME, properties); @@ -820,15 +803,16 @@ public void onCommandSuccess(final CreateResult result) { // Creating events. final Event event = new Event(); event.setIdentifier((Integer) result.getEntity().getId()); - properties.put(Event.REFERENCE_ID, (Integer) result.getEntity().getId()); + properties.put(Event.REFERENCE_ID, (Integer) result.getEntity().getId()); updateEvent(event, properties); - // properties.put(Event.REFERENCE_ID, (Integer) result.getEntity().getId()); - addMonthlySeriesEvent((String) result.getEntity().getId(), monthInterval, beginEventIntervalDate, endEventIntervalDate, startDate, endDate, eventSummary, eventDescription,isMonthlySameDayOfWeek); + // properties.put(Event.REFERENCE_ID, (Integer) result.getEntity().getId()); + addMonthlySeriesEvent((String) result.getEntity().getId(), monthInterval, beginEventIntervalDate, endEventIntervalDate, startDate, endDate, eventSummary, eventDescription, isMonthlySameDayOfWeek); } }, view.getCancelButton(), view.getSaveButton()); } - private void addMonthlySeriesEvent(String ids, int monthInterval, Date beginEventIntervalDate, Date endEventIntervalDate, final Date startDate, final Date endDate, String eventSummary, String eventDescription, final boolean isMonthlySameDayOfWeek) { - Date calBeginNextEventDate = beginEventIntervalDate; + + private void addMonthlySeriesEvent(String ids, int monthInterval, Date beginEventIntervalDate, Date endEventIntervalDate, final Date startDate, final Date endDate, String eventSummary, String eventDescription, final boolean isMonthlySameDayOfWeek) { + Date calBeginNextEventDate = beginEventIntervalDate; for (int i = 1; i < monthInterval; i++) { //calBeginNextEventDate = getMonthlySameDate(beginEventIntervalDate, calBeginNextEventDate, i); calBeginNextEventDate = getMonthlySameDayOfWeek2(beginEventIntervalDate, calBeginNextEventDate, i, isMonthlySameDayOfWeek); @@ -847,14 +831,19 @@ private void addMonthlySeriesEvent(String ids, int monthInterval, Date beginEven newDescription += " (Monthly " + (isMonthlySameDayOfWeek ? "same Day of a week " : "same Date ") + "event " + (i + 1) + " of " + monthInterval + ")"; monthlyProperties.put(Event.SUMMARY, newSummary); monthlyProperties.put(Event.DESCRIPTION, newDescription); - if(isMonthlySameDayOfWeek) monthlyProperties.put(Event.EVENT_TYPE, "M1"); - else monthlyProperties.put(Event.EVENT_TYPE, "M2"); + if (isMonthlySameDayOfWeek) { + monthlyProperties.put(Event.EVENT_TYPE, "M1"); + } else { + monthlyProperties.put(Event.EVENT_TYPE, "M2"); + } monthlyProperties.put(Event.REFERENCE_ID, ids); addPersonalEvent(monthlyProperties); } } + /** * Add new Yearly calendar events processing. + * * @param beginEventIntervalDate the value of beginEventIntervalDate * @param endEventIntervalDate the value of endEventIntervalDate * @param properties the value of properties @@ -872,13 +861,17 @@ private void processYearEvents(final Date beginEventIntervalDate, final Date end if (yearInterval > 1) { properties.put(Event.SUMMARY, (String) properties.get(Event.SUMMARY) + " (Yearly event 1 of " + yearInterval + ")"); properties.put(Event.DESCRIPTION, (String) properties.get(Event.DESCRIPTION) + " (Yearly " + (isYearlySameDayOfWeek ? "same Day of a week " : "same Date ") + "event 1 of " + yearInterval + ")"); - if(isYearlySameDayOfWeek) properties.put(Event.EVENT_TYPE, "Y1"); - else properties.put(Event.EVENT_TYPE, "Y2"); + if (isYearlySameDayOfWeek) { + properties.put(Event.EVENT_TYPE, "Y1"); + } else { + properties.put(Event.EVENT_TYPE, "Y2"); + } } addPersonalEventYearly(properties, yearInterval, beginEventIntervalDate, endEventIntervalDate, startDate, endDate, eventSummary, eventDescription, isYearlySameDayOfWeek); } - private void addPersonalEventYearly(final Map properties, final int yearInterval, final Date beginEventIntervalDate, final Date endEventIntervalDate, final Date startDate, final Date endDate, final String eventSummary, final String eventDescription, final boolean isYearlySameDayOfWeek) { + + private void addPersonalEventYearly(final Map properties, final int yearInterval, final Date beginEventIntervalDate, final Date endEventIntervalDate, final Date startDate, final Date endDate, final String eventSummary, final String eventDescription, final boolean isYearlySameDayOfWeek) { final CreateEntity createEntity = new CreateEntity(PersonalEventDTO.ENTITY_NAME, properties); @@ -898,15 +891,15 @@ public void onCommandSuccess(final CreateResult result) { // Creating events. final Event event = new Event(); event.setIdentifier((Integer) result.getEntity().getId()); - properties.put(Event.REFERENCE_ID, (Integer) result.getEntity().getId()); + properties.put(Event.REFERENCE_ID, (Integer) result.getEntity().getId()); updateEvent(event, properties); - // properties.put(Event.REFERENCE_ID, (Integer) result.getEntity().getId()); - addYearlySeriesEvent((String) result.getEntity().getId(), yearInterval, beginEventIntervalDate, endEventIntervalDate, startDate, endDate, eventSummary, eventDescription,isYearlySameDayOfWeek); + addYearlySeriesEvent((String) result.getEntity().getId(), yearInterval, beginEventIntervalDate, endEventIntervalDate, startDate, endDate, eventSummary, eventDescription, isYearlySameDayOfWeek); } }, view.getCancelButton(), view.getSaveButton()); } - private void addYearlySeriesEvent(String ids, int yearInterval, Date beginEventIntervalDate, Date endEventIntervalDate, final Date startDate, final Date endDate, String eventSummary, String eventDescription, final boolean isYearlySameDayOfWeek) { - Date calBeginNextEventDate = beginEventIntervalDate; + + private void addYearlySeriesEvent(String ids, int yearInterval, Date beginEventIntervalDate, Date endEventIntervalDate, final Date startDate, final Date endDate, String eventSummary, String eventDescription, final boolean isYearlySameDayOfWeek) { + Date calBeginNextEventDate = beginEventIntervalDate; for (int i = 1; i < yearInterval; i++) { calBeginNextEventDate = getYearlySameDayOfWeek(beginEventIntervalDate, calBeginNextEventDate, i, isYearlySameDayOfWeek); @@ -924,12 +917,16 @@ private void addYearlySeriesEvent(String ids, int yearInterval, Date beginEventI newDescription += " (Yearly " + (isYearlySameDayOfWeek ? "same Day of a week " : "same Date ") + "event " + (i + 1) + " of " + yearInterval + ")"; yearlyProperties.put(Event.SUMMARY, newSummary); yearlyProperties.put(Event.DESCRIPTION, newDescription); - if(isYearlySameDayOfWeek) yearlyProperties.put(Event.EVENT_TYPE, "Y1"); - else yearlyProperties.put(Event.EVENT_TYPE, "Y2"); + if (isYearlySameDayOfWeek) { + yearlyProperties.put(Event.EVENT_TYPE, "Y1"); + } else { + yearlyProperties.put(Event.EVENT_TYPE, "Y2"); + } yearlyProperties.put(Event.REFERENCE_ID, ids); - addPersonalEvent(yearlyProperties); + addPersonalEvent(yearlyProperties); } } + /** * Creates a new "Personal" calendar event. * @@ -955,9 +952,6 @@ public void onCommandSuccess(final CreateResult result) { // Creating events. final Event event = new Event(); event.setIdentifier((Integer) result.getEntity().getId()); - // properties.put(Event.REFERENCE_ID, result.getEntity().getId()); - // Window.alert("ID1 = " + result.getEntity().getId()); - // Window.alert("ID2 = " + properties.get(Event.REFERENCE_ID)); updateEvent(event, properties); } }, view.getCancelButton(), view.getSaveButton()); @@ -1011,9 +1005,9 @@ private void updateEvent(final Event event, final Map properties) { event.setSummary((String) properties.get(Event.SUMMARY)); event.setDescription((String) properties.get(Event.DESCRIPTION)); event.setEventType((String) properties.get(Event.EVENT_TYPE)); - + event.setReferenceId((Integer) properties.get(Event.REFERENCE_ID)); - + final Date day = (Date) properties.get(Event.DATE); final Object startHourSerialized = properties.get(Event.START_TIME); final Object endHourSerialized = properties.get(Event.END_TIME); @@ -1075,36 +1069,9 @@ private static boolean isFullDayEvent(final Event event) { && (event.getDtstart().getDate() != event.getDtend().getDate() || event.getDtstart().getMonth() != event.getDtend().getMonth() || event.getDtstart() .getYear() != event.getDtend().getYear()); } -/* - @SuppressWarnings({"deprecation"}) - private Date getMonthlySameDayOfWeek(Date dateObject, int numberMonths) { - Date firstDate = new Date(); - firstDate.setYear(dateObject.getYear()); - firstDate.setMonth(dateObject.getMonth()); - firstDate.setDate(dateObject.getDate()); - - dateObject.setDate(10);// to prevent month slip past (f.e. 31 jan -> 3 march instead of 29 febr) - dateObject.setMonth(dateObject.getMonth() + 1); - int daysInStartDate = getDaysInMonth(firstDate.getYear(), firstDate.getMonth()); - - if (firstDate.getDate() == daysInStartDate) {//if last day of the month - dateObject.setDate(getDaysInMonth(dateObject.getYear(), dateObject.getMonth())); - } else { - dateObject.setDate(firstDate.getDate());//?? - } - - Date newDate = getSameWeekDay(firstDate, dateObject); - - Window.alert("Date start: Month:" + firstDate.getMonth() - + " | " + firstDate.getDay() + "| Date:" + getDaysInMonth(firstDate.getYear(), firstDate.getMonth()) + " ; " + firstDate.toLocaleString() + " : month " + numberMonths + ": Result " + " | " + dateObject.getDay() + " | " + dateObject.toLocaleString() - + " || " + newDate.getDay() + " || " + newDate.toLocaleString());//temp for checker - - return newDate; - } -*/ /** - * + * * @param firstDate * @param nextDateOld * @param numberMonths @@ -1139,13 +1106,15 @@ public Date getMonthlySameDate(Date firstDate, Date nextDateOld, int numberMonth return newDate; } - + /** * Calculates same date or same day of week in next month. + * * @param firstDate * @param nextDateOld * @param numberMonths - * @param isSameDayOfWeek if the value is true then will be calculated Date of the nearest same day of week + * @param isSameDayOfWeek if the value is true then will be calculated Date + * of the nearest same day of week * @return next month date */ public Date getMonthlySameDayOfWeek2(Date firstDate, Date nextDateOld, int numberMonths, boolean isSameDayOfWeek) { @@ -1156,7 +1125,6 @@ public Date getMonthlySameDayOfWeek2(Date firstDate, Date nextDateOld, int numbe newDate.setDate(1); nextDateNew.setYear(nextDateOld.getYear()); nextDateNew.setMonth(nextDateOld.getMonth() + 1); - //nextDateNew.setDate(1);// to prevent month slip past (f.e. 31 jan -> 3 march instead of 29 febr) newDate.setYear(nextDateOld.getYear()); int daysInNextDate = getDaysInMonth(nextDateNew.getYear(), nextDateNew.getMonth()); @@ -1188,10 +1156,12 @@ public Date getMonthlySameDayOfWeek2(Date firstDate, Date nextDateOld, int numbe /** * Calculates same date or same day of week in next year. + * * @param firstDate * @param nextDateOld * @param numberMonths - * @param isSameDayOfWeek if the value is true then will be calculated Date of the nearest same day of week + * @param isSameDayOfWeek if the value is true then will be calculated Date + * of the nearest same day of week * @return */ @SuppressWarnings({"deprecation"}) @@ -1201,9 +1171,9 @@ public Date getYearlySameDayOfWeek(Date firstDate, Date nextDateOld, int numberM nextDateNew.setDate(1); nextDateNew.setYear(nextDateOld.getYear()); nextDateNew.setMonth(nextDateOld.getMonth()); - // nextDateNew.setDate(nextDateOld.getDate()); + // nextDateNew.setDate(nextDateOld.getDate()); - // nextDateNew.setDate(1); + // nextDateNew.setDate(1); nextDateNew.setYear(nextDateOld.getYear() + 1); int daysInNextDate = getDaysInMonth(nextDateNew.getYear(), nextDateNew.getMonth()); @@ -1236,6 +1206,7 @@ public Date getYearlySameDayOfWeek(Date firstDate, Date nextDateOld, int numberM /** * Calculates same week day date(as in firstDate) for nextDate + * * @param firstDate the value of firstDate * @param nextDate the value of nextDate */ @@ -1255,32 +1226,6 @@ private Date getSameWeekDay(Date firstDate, Date nextDate) { } else if (dayOfFirst < dayOfCurrent) {//< newDate = new Date(curDate.getTime() - (dayOfCurrent - dayOfFirst) * milSecInDay); if (newDate.getMonth() != curDate.getMonth()) { - // newDate = new Date(curDate.getTime() + (7 - (dayOfFirst - dayOfCurrent)) * milSecInDay); - newDate = new Date(curDate.getTime() + (7 - (dayOfCurrent - dayOfFirst)) * milSecInDay); - } - } else { - newDate = new Date(curDate.getTime()); - } - return newDate; - } -/* - private Date getSameWeekDay22(Date firstDate, Date nextDate) { - //Calculate same day of week - int dayOfFirst = firstDate.getDay(); - int dayOfCurrent = nextDate.getDay(); - Date curDate = nextDate; - int milSecInDay = 86400000;//24 * 60 * 60 * 1000 - Date newDate = new Date(); - if (dayOfFirst > dayOfCurrent) { - newDate = new Date(curDate.getTime() + (dayOfFirst - dayOfCurrent) * milSecInDay); - if (newDate.getMonth() != curDate.getMonth()) { //> - newDate = new Date(curDate.getTime() - (7 - (dayOfFirst - dayOfCurrent)) * milSecInDay); - } - - } else if (dayOfFirst < dayOfCurrent) {//< - newDate = new Date(curDate.getTime() - (dayOfCurrent - dayOfFirst) * milSecInDay); - if (newDate.getMonth() != curDate.getMonth()) { - //newDate2 = new Date(curDate.getTime() + (7 - (dayOfFirst - dayOfCurrent)) * milSecInDay); newDate = new Date(curDate.getTime() + (7 - (dayOfCurrent - dayOfFirst)) * milSecInDay); } } else { @@ -1288,43 +1233,14 @@ private Date getSameWeekDay22(Date firstDate, Date nextDate) { } return newDate; } - private Date getSameWeekDay2(Date firstDate, Date nextDate) { - //Calculate same day of week - int dayOfFirst = firstDate.getDay(); - int dayOfCurrent = nextDate.getDay(); - Date newDate = new Date(); - Date curDate = nextDate; - int milSecInDay = 86400000;//24 * 60 * 60 * 1000 - if (dayOfFirst > dayOfCurrent) { - newDate = new Date(curDate.getTime() + (dayOfFirst - dayOfCurrent) - * milSecInDay); - if (newDate.getMonth() != curDate.getMonth()) { // > - newDate = new Date(curDate.getTime() - - (7 - (dayOfFirst - dayOfCurrent)) * milSecInDay); - } - - } else if (dayOfFirst < dayOfCurrent) {// < - newDate = new Date(curDate.getTime() - (dayOfCurrent - dayOfFirst) - * milSecInDay); - if (newDate.getMonth() != curDate.getMonth()) { - int dif = (dayOfFirst - dayOfCurrent) < 0 ? -(dayOfFirst - dayOfCurrent) : (dayOfFirst - dayOfCurrent); - newDate = new Date(curDate.getTime() - + (7 - dif) * milSecInDay); - } - } else { - newDate = new Date(curDate.getTime()); - } - return newDate; - } - */ /** * Returns numver od days in the month of the year + * * @param year the value of year * @param month the value of month * @return the int */ - private int getDaysInMonth(int year, int month) { int daysInMonth = 31; @@ -1340,13 +1256,14 @@ private int getDaysInMonth(int year, int month) { return daysInMonth;// = 31; } } - + /** * Validate if the year is leap year. + * * @param year the value of year * @return the boolean */ private boolean isLeapYear(int year) { return (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)); } -} \ No newline at end of file +} diff --git a/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarPresenter.java b/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarPresenter.java index e521cd432..904812105 100644 --- a/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarPresenter.java +++ b/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarPresenter.java @@ -49,29 +49,20 @@ import org.sigmah.shared.dto.calendar.CalendarWrapper; import org.sigmah.shared.dto.calendar.Event; import org.sigmah.shared.dto.calendar.PersonalEventDTO; -import org.sigmah.shared.dto.referential.GlobalPermissionEnum; -import org.sigmah.shared.util.ProfileUtils; - import com.extjs.gxt.ui.client.event.ButtonEvent; import com.extjs.gxt.ui.client.event.SelectionChangedEvent; import com.extjs.gxt.ui.client.event.SelectionChangedListener; import com.extjs.gxt.ui.client.event.SelectionListener; import com.extjs.gxt.ui.client.store.ListStore; import com.extjs.gxt.ui.client.widget.selection.AbstractStoreSelectionModel; -import com.google.gwt.user.client.Window; -import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.inject.ImplementedBy; import com.google.inject.Inject; import java.util.Date; -import java.util.Iterator; import org.sigmah.client.ui.presenter.reminder.ReminderType; import org.sigmah.client.util.profiler.Profiler; import org.sigmah.client.util.profiler.Scenario; -import org.sigmah.server.dao.PersonalEventDAO; -import org.sigmah.server.domain.calendar.PersonalEvent; import org.sigmah.shared.dto.calendar.CalendarIdentifier; import org.sigmah.shared.dto.calendar.PersonalCalendarIdentifier; -import org.sigmah.shared.util.ProjectUtils; /** * Calendar widget presenter. @@ -181,7 +172,39 @@ public void onCommandSuccess(final VoidResult result) { } }); } + + public void deleteEventFunction1(final Event next, Integer parentId, final Map> eventMap, final Date key) { + dispatch.execute(new Delete(PersonalEventDTO.ENTITY_NAME, next.getIdentifier(), parentId), new CommandResultHandler() { + + @Override + public void onCommandFailure(final Throwable caught) { + N10N.error(I18N.CONSTANTS.error(), I18N.CONSTANTS.calendarDeleteEventError()); + } + + @Override + public void onCommandSuccess(final VoidResult result) { + eventMap.get(key).remove(next); + calendar.refresh(); + } + }); + } + + public void deleteEventFunction2(final Event next, Integer parentId, final Map> eventMap, final Date key, int mainId) { + dispatch.execute(new Delete(PersonalEventDTO.ENTITY_NAME, mainId, parentId), new CommandResultHandler() { + + @Override + public void onCommandFailure(final Throwable caught) { + N10N.error(I18N.CONSTANTS.error(), I18N.CONSTANTS.calendarDeleteEventError()); + } + @Override + public void onCommandSuccess(final VoidResult result) { + eventMap.get(key).remove(next); + calendar.refresh(); + } + }); + } + @Override public void deleteChain(final Event event, final CalendarWidget calendarWidget) { final CalendarIdentifier calendarIdentifier = event.getParent().getIdentifier(); @@ -201,66 +224,17 @@ public void deleteChain(final Event event, final CalendarWidget calendarWidget) for (final Event next : eventMap.get(key)) { if (refId != 0) { if (next.getReferenceId() != null && (next.getReferenceId().intValue() == refId)) { - dispatch.execute(new Delete(PersonalEventDTO.ENTITY_NAME, next.getIdentifier(), parentId), new CommandResultHandler() { - - @Override - public void onCommandFailure(final Throwable caught) { - N10N.error(I18N.CONSTANTS.error(), I18N.CONSTANTS.calendarDeleteEventError()); - } - - @Override - public void onCommandSuccess(final VoidResult result) { - eventMap.get(key).remove(next); - calendar.refresh(); - } - }); - break; + deleteEventFunction1(next, parentId, eventMap, key); } else if((next.getReferenceId() == null) && (next.getIdentifier().intValue() == refId)){ - dispatch.execute(new Delete(PersonalEventDTO.ENTITY_NAME, next.getIdentifier(), parentId), new CommandResultHandler() { - - @Override - public void onCommandFailure(final Throwable caught) { - N10N.error(I18N.CONSTANTS.error(), I18N.CONSTANTS.calendarDeleteEventError()); - } - - @Override - public void onCommandSuccess(final VoidResult result) { - eventMap.get(key).remove(next); - calendar.refresh(); - } - }); + deleteEventFunction1(next, parentId, eventMap, key); } } else { if (next.getReferenceId() != null && (next.getReferenceId().intValue() == mainId)) { - dispatch.execute(new Delete(PersonalEventDTO.ENTITY_NAME, next.getIdentifier(), parentId), new CommandResultHandler() { - - @Override - public void onCommandFailure(final Throwable caught) { - N10N.error(I18N.CONSTANTS.error(), I18N.CONSTANTS.calendarDeleteEventError()); - } - - @Override - public void onCommandSuccess(final VoidResult result) { - eventMap.get(key).remove(next); - calendar.refresh(); - } - }); + deleteEventFunction1(next, parentId, eventMap, key); } else if(next.getReferenceId() == null && next.getIdentifier().intValue() == mainId){ - dispatch.execute(new Delete(PersonalEventDTO.ENTITY_NAME, mainId, parentId), new CommandResultHandler() { - - @Override - public void onCommandFailure(final Throwable caught) { - N10N.error(I18N.CONSTANTS.error(), I18N.CONSTANTS.calendarDeleteEventError()); - } - - @Override - public void onCommandSuccess(final VoidResult result) { - eventMap.get(key).remove(next); - calendar.refresh(); - } - }); + deleteEventFunction2(next, parentId, eventMap, key, mainId); } } } diff --git a/src/main/java/org/sigmah/client/ui/view/calendar/CalendarEventView.java b/src/main/java/org/sigmah/client/ui/view/calendar/CalendarEventView.java index 0a874876f..b8eaf2714 100644 --- a/src/main/java/org/sigmah/client/ui/view/calendar/CalendarEventView.java +++ b/src/main/java/org/sigmah/client/ui/view/calendar/CalendarEventView.java @@ -45,7 +45,6 @@ import com.extjs.gxt.ui.client.widget.form.CheckBox; import com.extjs.gxt.ui.client.widget.form.FieldSet; import com.google.inject.Singleton; -import com.google.gwt.user.client.Window; /** * Calendar event edit frame view used to create/edit a calendar event. @@ -109,7 +108,6 @@ public void initialize() { eventDateStartField = Forms.date(I18N.CONSTANTS.calendar_addEvent_dateStart_label(), true); eventDateStartField.setName(Event.DATE); - //eventDateStartField.setAllowBlank(true); eventStartTimeField = Forms.time(I18N.CONSTANTS.calendarEventStartHour(), false); eventStartTimeField.setName(Event.START_TIME); @@ -133,10 +131,8 @@ public void initialize() { form.add(eventSummaryField); form.add(eventDateStartField); form.add(eventDateEndField); - //form.add(allDayCheckbox); form.add(createAllDayCheckbox()); - //form.add(allDayCheckboxGr); form.add(eventStartTimeField); form.add(eventEndTimeField); form.add(RepeatEventPeriodRG); @@ -154,14 +150,12 @@ private CheckBox createAllDayCheckbox() { allDayCheckbox = Forms.checkbox(I18N.CONSTANTS.calendar_addEvent_isAllDayCB_boxLabel(), I18N.CONSTANTS.calendar_addEvent_isAllDayCB_allDayName(), false); allDayCheckbox.setFieldLabel(I18N.CONSTANTS.calendar_addEvent_allDayCbGr_label()); - // allDayCheckbox.setBoxLabel(I18N.CONSTANTS.calendar_addEvent_isAllDayCB_boxLabel()); allDayCheckbox.validate(false); allDayCheckbox.addListener(Events.OnChange, new Listener() { @Override public void handleEvent(FieldEvent event) { eventStartTimeField.setVisible(!allDayCheckbox.getValue()); eventEndTimeField.setVisible(!allDayCheckbox.getValue()); - // Window.alert(getAllDayCheckbox().getBoxLabel() + " is checked = " + getAllDayCheckbox().getValue()); } }); @@ -188,19 +182,11 @@ private void createRepeatEventPeriodRadioGroup() { } private void createYearlyRb() { - //final Radio -// yearlyRepeatRB = Forms.radio("yearlyRepeatRB label", "yearlyRepeatRB name", Boolean.FALSE); -//yearlyRepeatRB = new Radio(); yearlyRepeatRB = Forms.radio(I18N.CONSTANTS.calendar_addEvent_repeatYearlyRB_label(), I18N.CONSTANTS.calendar_addEvent_repeatYearlyRB_label(), Boolean.FALSE); yearlyRepeatRB.setToolTip(I18N.CONSTANTS.calendar_addEvent_repeatYearlyRB_toolTip()); -// yearlyRepeatRB.setBoxLabel("yearly"); -// yearlyRepeatRB.setName("yearly"); -// yearlyRepeatRB.setValue(false); yearlyRepeatRB.addListener(Events.OnChange, new Listener() { @Override public void handleEvent(FieldEvent event) { - //eventStartTimeField.setVisible(!yearlyRepeatRB.getValue()); - // eventEndTimeField.setVisible(!yearlyRepeatRB.getValue()); ((TextArea) form.getItemByItemId(Event.DESCRIPTION)).setValue(I18N.CONSTANTS.calendar_addEvent_description_textArea_yearly()); getPanelYearly().setVisible(getYearlyRepeatRB().getValue()); getPanelMonthly().setVisible(!yearlyRepeatRB.getValue()); @@ -209,7 +195,6 @@ public void handleEvent(FieldEvent event) { getYearlySameDayOfWeekRB().show(); getYearlySameDateRB().setValue(true); eventDateStartField.setAllowBlank(false); - // Window.alert(getYearlyRepeatRB().getBoxLabel() + " is checked Listener OnChange on Yearly radio"); } }); } @@ -217,14 +202,9 @@ public void handleEvent(FieldEvent event) { private void createMonthlyRb() { monthlyRepeatRB = Forms.radio(I18N.CONSTANTS.calendar_addEvent_repeatMonthlyRB_label(), I18N.CONSTANTS.calendar_addEvent_repeatMonthlyRB_label(), Boolean.FALSE); monthlyRepeatRB.setToolTip(I18N.CONSTANTS.calendar_addEvent_repeatMonthlyRB_toolTip()); -// monthlyRepeatRB.setBoxLabel("monthly"); -// monthlyRepeatRB.setName("monthly"); -// monthlyRepeatRB.setValue(false); monthlyRepeatRB.addListener(Events.OnChange, new Listener() { @Override public void handleEvent(FieldEvent event) { - //eventStartTimeField.setVisible(!yearlyRepeatRB.getValue()); - // eventEndTimeField.setVisible(!yearlyRepeatRB.getValue()); ((TextArea) form.getItemByItemId(Event.DESCRIPTION)).setValue(I18N.CONSTANTS.calendar_addEvent_description_textArea_monthly()); getPanelYearly().setVisible(!monthlyRepeatRB.getValue()); getPanelMonthly().setVisible(getMonthlyRepeatRB().getValue()); @@ -232,7 +212,6 @@ public void handleEvent(FieldEvent event) { getRadioMonthlySameDate().show(); getRadioMonthlySameDayOfWeek().show(); getRadioMonthlySameDayOfWeek().setValue(true); - // Window.alert(getMonthlyRepeatRB().getBoxLabel() + " is checked Listener OnChange on monthly radio"); } }); } @@ -240,20 +219,14 @@ public void handleEvent(FieldEvent event) { private void createWeeklyRb() { weeklyRepeatRB = Forms.radio(I18N.CONSTANTS.calendar_addEvent_repeatWeeklyRB_label(), I18N.CONSTANTS.calendar_addEvent_repeatWeeklyRB_label(), Boolean.FALSE); weeklyRepeatRB.setToolTip(I18N.CONSTANTS.calendar_addEvent_repeatWeeklyRB_toolTip()); -// weeklyRepeatRB.setBoxLabel("weekly"); -// weeklyRepeatRB.setName("weekly"); -// weeklyRepeatRB.setValue(false); weeklyRepeatRB.addListener(Events.OnChange, new Listener() { @Override public void handleEvent(FieldEvent event) { - //eventStartTimeField.setVisible(!yearlyRepeatRB.getValue()); - // eventEndTimeField.setVisible(!yearlyRepeatRB.getValue()); ((TextArea) form.getItemByItemId(Event.DESCRIPTION)).setValue(I18N.CONSTANTS.calendar_addEvent_description_textArea_weekly()); getPanelYearly().setVisible(!weeklyRepeatRB.getValue()); getPanelMonthly().setVisible(!weeklyRepeatRB.getValue()); eventDateStartField.setAllowBlank(false); - // Window.alert(getWeeklyRepeatRB().getBoxLabel() + " is checked Listener OnChange on weekly radio"); } }); } @@ -262,22 +235,13 @@ public void handleEvent(FieldEvent event) { * */ private void createDailyRb() { - //final Radio -//dailyRepeatRB = new Radio(); dailyRepeatRB = Forms.radio(I18N.CONSTANTS.calendar_addEvent_repeatDailyRB_label(), I18N.CONSTANTS.calendar_addEvent_repeatDailyRB_label(), Boolean.FALSE); -// dailyRepeatRB.setBoxLabel("daily"); -// dailyRepeatRB.setName("daily"); -// dailyRepeatRB.setValue(false); dailyRepeatRB.addListener(Events.OnChange, new Listener() { @Override public void handleEvent(FieldEvent event) { ((TextArea) form.getItemByItemId(Event.DESCRIPTION)).setValue(I18N.CONSTANTS.calendar_addEvent_description_textArea_daily()); -// eventStartTimeField.setVisible(!dailyRepeatRB.getValue()); -// eventEndTimeField.setVisible(!dailyRepeatRB.getValue()); -// eventDateStartField.setAllowBlank(false); getPanelYearly().setVisible(!dailyRepeatRB.getValue()); getPanelMonthly().setVisible(!dailyRepeatRB.getValue()); - // Window.alert(getDailyRepeatRB().getBoxLabel() + " is checked Listener OnChange on DAILY radio"); } }); } @@ -293,12 +257,7 @@ public void handleEvent(FieldEvent event) { getPanelYearly().setVisible(!onceRepeatRB.getValue()); getPanelMonthly().setVisible(!onceRepeatRB.getValue()); - // eventStartTimeField.setVisible(!dailyRepeatRB.getValue()); - // eventEndTimeField.setVisible(!dailyRepeatRB.getValue()); -// eventDateStartField.setAllowBlank(false); -// eventDateStartField.setAllowBlank(true); ((TextArea) form.getItemByItemId(Event.DESCRIPTION)).setValue(I18N.CONSTANTS.calendar_addEvent_description_textArea_once()); - // Window.alert(getOnceRepeatRB().getBoxLabel() + " is checked Listener OnChange on ONCE radio"); } }); } @@ -306,36 +265,26 @@ public void handleEvent(FieldEvent event) { private void createMonthlyPanel() { panelMonthly = new FieldSet(); panelMonthly.setExpanded(true); - //panelMonthly.setTitle("Montly panel title"); panelMonthly.setBorders(true); panelMonthly.setHeadingHtml(I18N.CONSTANTS.calendar_addEvent_repeatsSettings_headingHtml_monthly()); - // panelMonthly.setCollapsible(true); panelMonthly.setAutoHeight(true); - //panelMonthly.setToolTip("Set Monthly event repeats options."); panelMonthly.setVisible(false); - //Radio radioMonthlySameDayOfWeek = new Radio(); - radioMonthlySameDayOfWeek = Forms.radio(I18N.CONSTANTS.calendar_addEvent_repeatsSettings_SameDayOfWeekRB_label()); - //radioMonthlySameDayOfWeek.setBoxLabel("Same day of week"); radioMonthlySameDayOfWeek.setName(I18N.CONSTANTS.calendar_addEvent_repeatsSettings_SameDayOfWeekRB_monthly_name()); radioMonthlySameDayOfWeek.setValue(Boolean.FALSE); radioMonthlySameDayOfWeek.setOriginalValue(Boolean.FALSE); radioMonthlySameDayOfWeek.setToolTip(I18N.CONSTANTS.calendar_addEvent_repeatsSettings_SameDayOfWeekRB_monthly_toolTip()); - //Radio radioMonthlySameDate = new Radio(); radioMonthlySameDate = Forms.radio(I18N.CONSTANTS.calendar_addEvent_repeatsSettings_SameDateRB_label()); radioMonthlySameDate.setBoxLabel(I18N.CONSTANTS.calendar_addEvent_repeatsSettings_SameDateRB_label()); radioMonthlySameDate.setName(I18N.CONSTANTS.calendar_addEvent_repeatsSettings_SameDateRB_monthly_name()); radioMonthlySameDate.setValue(Boolean.FALSE); radioMonthlySameDate.setToolTip(I18N.CONSTANTS.calendar_addEvent_repeatsSettings_SameDateRB_monthly_toolTip()); - //montlyVariantRG= new RadioGroup(); montlyVariantRG = Forms.radioGroup(I18N.CONSTANTS.calendar_addEvent_repeatsSettings_radioGroup_monthly_settings()); - //montlyVariantRG.setSelectionRequired(Boolean.TRUE); montlyVariantRG.setSelectionRequired(Boolean.FALSE); montlyVariantRG.setOrientation(Style.Orientation.HORIZONTAL); - //montlyVariantRG.setFieldLabel("Montly settings 999"); montlyVariantRG.add(radioMonthlySameDayOfWeek); montlyVariantRG.add(radioMonthlySameDate); @@ -345,27 +294,19 @@ private void createMonthlyPanel() { private void createYearlyPanel() { panelYearly = new FieldSet(); panelYearly.setExpanded(true); - //panelYearly.setTitle("Yearly panel title"); panelYearly.setBorders(true); panelYearly.setHeadingHtml(I18N.CONSTANTS.calendar_addEvent_repeatsSettings_headingHtml_yearly()); - // panelYearly.setCollapsible(true); panelYearly.setAutoHeight(true); - // panelYearly.setToolTip("Set Yearly event repeats options"); panelYearly.setVisible(false); yearlySameDayOfWeekRB = Forms.radio(I18N.CONSTANTS.calendar_addEvent_repeatsSettings_SameDayOfWeekRB_label(), Boolean.FALSE); yearlySameDayOfWeekRB.setToolTip(I18N.CONSTANTS.calendar_addEvent_repeatsSettings_SameDayOfWeekRB_yearly_toolTip()); yearlySameDayOfWeekRB.setOriginalValue(Boolean.TRUE); - //yearlySameDayOfWeekRB.setBoxLabel("Same day of week"); yearlySameDayOfWeekRB.setName(I18N.CONSTANTS.calendar_addEvent_repeatsSettings_SameDayOfWeekRB_yearly_name()); yearlySameDayOfWeekRB.setValue(Boolean.TRUE); - //yearlySameDateRB = new Radio(); yearlySameDateRB = Forms.radio(I18N.CONSTANTS.calendar_addEvent_repeatsSettings_SameDateRB_label(), Boolean.FALSE); - //yearlySameDateRB.setBoxLabel("Same date"); yearlySameDateRB.setName(I18N.CONSTANTS.calendar_addEvent_repeatsSettings_SameDateRB_yearly_name()); - //yearlySameDateRB.setValue(false); - yearlyVariantRG = Forms.radioGroup(I18N.CONSTANTS.calendar_addEvent_repeatsSettings_radioGroup_yearly_settings(), I18N.CONSTANTS.calendar_addEvent_repeatsSettings_radioGroup_yearly_settings_name(), Style.Orientation.HORIZONTAL, From 50b1a5dda88df8dbdad38a213b3b49703bd23b3e Mon Sep 17 00:00:00 2001 From: Seal98 Date: Wed, 12 Jul 2017 11:15:11 +0300 Subject: [PATCH 21/39] (issue#852) Code refactoring #2. Applied refactoring to: -avoid unused method parameters -avoid duplicated code blocks -avoid debug alert messages --- .../calendar/CalendarEventPresenter.java | 95 +++++++++---------- 1 file changed, 45 insertions(+), 50 deletions(-) diff --git a/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java b/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java index 798df8e60..e711c22a2 100644 --- a/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java +++ b/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java @@ -74,7 +74,8 @@ */ @Singleton public class CalendarEventPresenter extends AbstractPagePresenter { - + private Event event; + private CalendarWrapper calendarWrapper; /** * Description of the view managed by this presenter. */ @@ -231,9 +232,7 @@ public static interface View extends ViewInterface { /** * The edited calendar event, or {@code null} if creation. */ - private Event event; - private CalendarWrapper calendarWrapper; /** * Presenters's initialization. @@ -444,7 +443,7 @@ private void onSaveAction() { Boolean isFullDayEvent = view.getAllDayCheckbox().getValue(); - Window.alert("isAllDayEvent=" + isFullDayEvent);//temp for checker + // Window.alert("isAllDayEvent=" + isFullDayEvent);//temp for checker Date startDate = createStartDateProperty(isFullDayEvent, beginEventIntervalDate, properties); Date endDate = createEndDateProperty(isFullDayEvent, beginEventIntervalDate, properties); @@ -569,7 +568,7 @@ private void processDailyEvents(long diffInMilis, long milisPerDay, final Date b daysInterval = (int) daysDiff; long calBeginNextEventDateLong = beginEventIntervalDate.getTime(); - Date calBeginNextEventDate = beginEventIntervalDate; + //Date calBeginNextEventDate = beginEventIntervalDate; if (daysInterval > 1) { properties.put(Event.SUMMARY, (String) properties.get(Event.SUMMARY) + " ( 1 of " + daysInterval + ")"); @@ -588,10 +587,7 @@ private void addPersonalEventDaily(final Map properties, f @Override public void onCommandFailure(final Throwable caught) { - if (Log.isErrorEnabled()) { - Log.error(I18N.CONSTANTS.calendarAddEventError(), caught); - } - N10N.error(I18N.CONSTANTS.error(), I18N.CONSTANTS.calendarAddEventError()); + processAddEventError(caught); } @Override @@ -607,21 +603,28 @@ public void onCommandSuccess(final CreateResult result) { }, view.getCancelButton(), view.getSaveButton()); } + private void processAddEventError(final Throwable caught) { + if (Log.isErrorEnabled()) { + Log.error(I18N.CONSTANTS.calendarAddEventError(), caught); + } + N10N.error(I18N.CONSTANTS.error(), I18N.CONSTANTS.calendarAddEventError()); + } + private void addDailySeriesEvent(String ids, int daysInterval, long calBeginNextEventDateLong, long milisPerDay, final Date startDate, final Date endDate, String eventSummary, String eventDescription) { - Date calBeginNextEventDate; + //Date calBeginNextEventDate; for (int i = 1; i < daysInterval; i++) { calBeginNextEventDateLong += milisPerDay; - calBeginNextEventDate = new Date(calBeginNextEventDateLong); + //calBeginNextEventDate = new Date(calBeginNextEventDateLong); Map dailyProperties = new HashMap(); dailyProperties.put(Event.CALENDAR_ID, calendarWrapper); dailyProperties.put(Event.SUMMARY, view.getEventSummaryField().getValue()); - dailyProperties.put(Event.DATE, calBeginNextEventDate); + dailyProperties.put(Event.DATE, new Date(calBeginNextEventDateLong)); - setFullDayEvent(startDate, endDate, calBeginNextEventDate, dailyProperties); + setFullDayEvent(startDate, endDate, new Date(calBeginNextEventDateLong), dailyProperties); String newSummary = eventSummary; String newDescription = eventDescription; @@ -652,7 +655,7 @@ private void processWeeklyEvents(long diffInMilis, long milisPerWeek, final Date int weeksInterval = (int) weekDiff; long calBeginNextEventDateLong = beginEventIntervalDate.getTime(); - Date calBeginNextEventDate = beginEventIntervalDate; + //Date calBeginNextEventDate = beginEventIntervalDate; if (weeksInterval > 1) { properties.put(Event.SUMMARY, (String) properties.get(Event.SUMMARY) + " (Weekly event 1 of " + weeksInterval + ")"); @@ -671,10 +674,7 @@ private void addPersonalEventWeekly(final Map properties, @Override public void onCommandFailure(final Throwable caught) { - if (Log.isErrorEnabled()) { - Log.error(I18N.CONSTANTS.calendarAddEventError(), caught); - } - N10N.error(I18N.CONSTANTS.error(), I18N.CONSTANTS.calendarAddEventError()); + processAddEventError(caught); } @Override @@ -691,20 +691,20 @@ public void onCommandSuccess(final CreateResult result) { } private void addWeeklySeriesEvent(String ids, int weeksInterval, long calBeginNextEventDateLong, long milisPerWeek, final Date startDate, final Date endDate, String eventSummary, String eventDescription) { - Date calBeginNextEventDate; + //Date calBeginNextEventDate; for (int i = 1; i < weeksInterval; i++) { calBeginNextEventDateLong += milisPerWeek; - calBeginNextEventDate = new Date(calBeginNextEventDateLong); + // calBeginNextEventDate = new Date(calBeginNextEventDateLong); Map weeklyProperties = new HashMap(); weeklyProperties.put(Event.CALENDAR_ID, calendarWrapper); weeklyProperties.put(Event.SUMMARY, view.getEventSummaryField().getValue()); - weeklyProperties.put(Event.DATE, calBeginNextEventDate); + weeklyProperties.put(Event.DATE, new Date(calBeginNextEventDateLong)); - setFullDayEvent(startDate, endDate, calBeginNextEventDate, weeklyProperties); + setFullDayEvent(startDate, endDate, new Date(calBeginNextEventDateLong), weeklyProperties); String newSummary = eventSummary; String newDescription = eventDescription; @@ -780,21 +780,19 @@ private void processMonthlyEvents(final Date beginEventIntervalDate, final Date properties.put(Event.EVENT_TYPE, "M2"); } } - addPersonalEventMonthly(properties, monthInterval, beginEventIntervalDate, endEventIntervalDate, startDate, endDate, eventSummary, eventDescription, isMonthlySameDayOfWeek); + //addPersonalEventMonthly(properties, monthInterval, beginEventIntervalDate, endEventIntervalDate, startDate, endDate, eventSummary, eventDescription, isMonthlySameDayOfWeek); + addPersonalEventMonthly(properties, monthInterval, beginEventIntervalDate, startDate, endDate, eventSummary, eventDescription, isMonthlySameDayOfWeek); } - private void addPersonalEventMonthly(final Map properties, final int monthInterval, final Date beginEventIntervalDate, final Date endEventIntervalDate, final Date startDate, final Date endDate, final String eventSummary, final String eventDescription, final boolean isMonthlySameDayOfWeek) { - + //private void addPersonalEventMonthly(final Map properties, final int monthInterval, final Date beginEventIntervalDate, final Date endEventIntervalDate, final Date startDate, final Date endDate, final String eventSummary, final String eventDescription, final boolean isMonthlySameDayOfWeek) { + private void addPersonalEventMonthly(final Map properties, final int monthInterval, final Date beginEventIntervalDate, final Date startDate, final Date endDate, final String eventSummary, final String eventDescription, final boolean isMonthlySameDayOfWeek) { final CreateEntity createEntity = new CreateEntity(PersonalEventDTO.ENTITY_NAME, properties); dispatch.execute(createEntity, new CommandResultHandler() { @Override public void onCommandFailure(final Throwable caught) { - if (Log.isErrorEnabled()) { - Log.error(I18N.CONSTANTS.calendarAddEventError(), caught); - } - N10N.error(I18N.CONSTANTS.error(), I18N.CONSTANTS.calendarAddEventError()); + processAddEventError(caught); } @Override @@ -806,12 +804,14 @@ public void onCommandSuccess(final CreateResult result) { properties.put(Event.REFERENCE_ID, (Integer) result.getEntity().getId()); updateEvent(event, properties); // properties.put(Event.REFERENCE_ID, (Integer) result.getEntity().getId()); - addMonthlySeriesEvent((String) result.getEntity().getId(), monthInterval, beginEventIntervalDate, endEventIntervalDate, startDate, endDate, eventSummary, eventDescription, isMonthlySameDayOfWeek); + //addMonthlySeriesEvent((String) result.getEntity().getId(), monthInterval, beginEventIntervalDate, endEventIntervalDate, startDate, endDate, eventSummary, eventDescription, isMonthlySameDayOfWeek); + addMonthlySeriesEvent((String) result.getEntity().getId(), monthInterval, beginEventIntervalDate, startDate, endDate, eventSummary, eventDescription, isMonthlySameDayOfWeek); } }, view.getCancelButton(), view.getSaveButton()); } - private void addMonthlySeriesEvent(String ids, int monthInterval, Date beginEventIntervalDate, Date endEventIntervalDate, final Date startDate, final Date endDate, String eventSummary, String eventDescription, final boolean isMonthlySameDayOfWeek) { + //private void addMonthlySeriesEvent(String ids, int monthInterval, Date beginEventIntervalDate, Date endEventIntervalDate, final Date startDate, final Date endDate, String eventSummary, String eventDescription, final boolean isMonthlySameDayOfWeek) { + private void addMonthlySeriesEvent(String ids, int monthInterval, Date beginEventIntervalDate, final Date startDate, final Date endDate, String eventSummary, String eventDescription, final boolean isMonthlySameDayOfWeek) { Date calBeginNextEventDate = beginEventIntervalDate; for (int i = 1; i < monthInterval; i++) { //calBeginNextEventDate = getMonthlySameDate(beginEventIntervalDate, calBeginNextEventDate, i); @@ -879,21 +879,22 @@ private void addPersonalEventYearly(final Map properties, @Override public void onCommandFailure(final Throwable caught) { - if (Log.isErrorEnabled()) { - Log.error(I18N.CONSTANTS.calendarAddEventError(), caught); - } - N10N.error(I18N.CONSTANTS.error(), I18N.CONSTANTS.calendarAddEventError()); + processAddEventError(caught); } @Override public void onCommandSuccess(final CreateResult result) { + createNewEvent(result); + addYearlySeriesEvent((String) result.getEntity().getId(), yearInterval, beginEventIntervalDate, endEventIntervalDate, startDate, endDate, eventSummary, eventDescription, isYearlySameDayOfWeek); + } + + private void createNewEvent(final CreateResult result) { // Creating events. final Event event = new Event(); event.setIdentifier((Integer) result.getEntity().getId()); properties.put(Event.REFERENCE_ID, (Integer) result.getEntity().getId()); updateEvent(event, properties); - addYearlySeriesEvent((String) result.getEntity().getId(), yearInterval, beginEventIntervalDate, endEventIntervalDate, startDate, endDate, eventSummary, eventDescription, isYearlySameDayOfWeek); } }, view.getCancelButton(), view.getSaveButton()); } @@ -940,10 +941,7 @@ private void addPersonalEvent(final Map properties) { @Override public void onCommandFailure(final Throwable caught) { - if (Log.isErrorEnabled()) { - Log.error(I18N.CONSTANTS.calendarAddEventError(), caught); - } - N10N.error(I18N.CONSTANTS.error(), I18N.CONSTANTS.calendarAddEventError()); + processAddEventError(caught); } @Override @@ -971,10 +969,7 @@ private void editPersonalEvent(final Event event, final Map propertie @Override public void onCommandFailure(final Throwable caught) { - if (Log.isErrorEnabled()) { - Log.error(I18N.CONSTANTS.calendarAddEventError(), caught); - } - N10N.error(I18N.CONSTANTS.error(), I18N.CONSTANTS.calendarAddEventError()); + processAddEventError(caught); } @Override @@ -1099,11 +1094,11 @@ public Date getMonthlySameDate(Date firstDate, Date nextDateOld, int numberMonth } - Window.alert("Date start: Month:" + firstDate.getMonth() + /* Window.alert("Date start: Month:" + firstDate.getMonth() + " | " + firstDate.getDay() + "| Date:" + getDaysInMonth(nextDateNew.getYear(), nextDateNew.getMonth()) + " ; " + firstDate.toLocaleString() + " : month " + numberMonths + ": Result " + " | " + newDate.getDay() + " | " + newDate.toLocaleString());//temp for checker - +*/ return newDate; } @@ -1145,12 +1140,12 @@ public Date getMonthlySameDayOfWeek2(Date firstDate, Date nextDateOld, int numbe //return newDate; newDate = newDate2; } - Window.alert("Monthly " + (isSameDayOfWeek ? "Same week DAY " : "Same DATE ") + "Date start: Month:" + firstDate.getMonth() + " | " + firstDate.getDay() + /* Window.alert("Monthly " + (isSameDayOfWeek ? "Same week DAY " : "Same DATE ") + "Date start: Month:" + firstDate.getMonth() + " | " + firstDate.getDay() + "| " + getDaysInMonth(firstDate.getYear(), firstDate.getMonth()) + " | " + firstDate.toLocaleString() + " | i= " + numberMonths + " | RESULT | Prev | " + nextDateNew.getDay() + " | " + nextDateNew.toLocaleString() + " || New | " + newDate.getDay() + " | " + newDate.toLocaleString());//temp for checker - +*/ return newDate; } @@ -1195,12 +1190,12 @@ public Date getYearlySameDayOfWeek(Date firstDate, Date nextDateOld, int numberM nextDateNew = newDate; } - Window.alert("Yearly " + (isSameDayOfWeek ? "Same week DAY " : "Same DATE ") + "Date start: Month:" + firstDate.getMonth() + " | " + firstDate.getDay() + /* Window.alert("Yearly " + (isSameDayOfWeek ? "Same week DAY " : "Same DATE ") + "Date start: Month:" + firstDate.getMonth() + " | " + firstDate.getDay() + "| " + getDaysInMonth(firstDate.getYear(), firstDate.getMonth()) + " | " + firstDate.toLocaleString() + " | i= " + numberMonths + " | RESULT | Prev | " + nextDateOld.getDay() + " | " + nextDateOld.toLocaleString() + " || New | " + nextDateNew.getDay() + " | " + nextDateNew.toLocaleString());//temp for checker - +*/ return nextDateNew; } From c1c8339ad7a5fd39bb71b44e2158ba6e03bfacbe Mon Sep 17 00:00:00 2001 From: Seal98 Date: Fri, 14 Jul 2017 15:33:41 +0300 Subject: [PATCH 22/39] (Issue#852) Create weekly series multi-days events Implemented preliminary functionality to create weekly series multi-days events. --- .../calendar/CalendarEventPresenter.java | 131 ++++++++++++++---- 1 file changed, 104 insertions(+), 27 deletions(-) diff --git a/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java b/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java index e711c22a2..2f7037e4d 100644 --- a/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java +++ b/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java @@ -358,10 +358,16 @@ private void prepareEditView() { view.getEventDateEndField().clear(); view.getEventDateEndField().hide(); } - + if(event.getDtend().getDate() - event.getDtstart().getDate() == 1){ + view.getAllDayCheckbox().setValue(true); + view.getEventStartTimeField().hide(); + view.getEventEndTimeField().hide(); + } + else{ + view.getAllDayCheckbox().setValue(false); view.getEventStartTimeField().show(); - view.getEventEndTimeField().show(); - + view.getEventEndTimeField().show(); + } if (!isFullDayEvent(event)) { final Time startTime = event.getDtstart() != null ? view.getEventStartTimeField().findModel(event.getDtstart()) : null; @@ -407,6 +413,9 @@ private void prepareAddView() { view.getRadioMonthlySameDate().show(); view.getRadioMonthlySameDayOfWeek().show(); view.getEventDateEndField().show(); + view.getAllDayCheckbox().setValue(true); + view.getEventStartTimeField().hide(); + view.getEventEndTimeField().hide(); } // --------------------------------------------------------------------------------------------------------------- @@ -578,6 +587,22 @@ private void processDailyEvents(long diffInMilis, long milisPerDay, final Date b addPersonalEventDaily(properties, daysInterval, calBeginNextEventDateLong, milisPerDay, startDate, endDate, eventSummary, eventDescription); } + + private void processDailyEventsNew(int daysInterval, long milisPerDay, final Date beginEventIntervalDate, final Date startDate, final Date endDate, final Map properties, String eventSummary, String eventDescription) { + + long calBeginNextEventDateLong = beginEventIntervalDate.getTime(); + //Date calBeginNextEventDate = beginEventIntervalDate; + +// if (daysInterval > 1) { +// properties.put(Event.SUMMARY, (String) properties.get(Event.SUMMARY) + " ( 1 of " + daysInterval + ")"); +// properties.put(Event.DESCRIPTION, (String) properties.get(Event.DESCRIPTION) + " (Daily event 1 of " + daysInterval + ")"); +// properties.put(Event.EVENT_TYPE, "D"); +// } + addPersonalEventDaily(properties, daysInterval, calBeginNextEventDateLong, milisPerDay, startDate, endDate, eventSummary, eventDescription); + + } + + private void addPersonalEventDaily(final Map properties, final int daysInterval, final long calBeginNextEventDateLong, final long milisPerDay, final Date startDate, final Date endDate, final String eventSummary, final String eventDescription) { @@ -598,7 +623,7 @@ public void onCommandSuccess(final CreateResult result) { event.setIdentifier((Integer) result.getEntity().getId()); properties.put(Event.REFERENCE_ID, (Integer) result.getEntity().getId()); updateEvent(event, properties); - addDailySeriesEvent((String) result.getEntity().getId(), daysInterval, calBeginNextEventDateLong, milisPerDay, startDate, endDate, eventSummary, eventDescription); + addDailySeriesEvent((Integer) result.getEntity().getId(), daysInterval, calBeginNextEventDateLong, milisPerDay, startDate, endDate, eventSummary, eventDescription); } }, view.getCancelButton(), view.getSaveButton()); } @@ -610,9 +635,9 @@ private void processAddEventError(final Throwable caught) { N10N.error(I18N.CONSTANTS.error(), I18N.CONSTANTS.calendarAddEventError()); } - private void addDailySeriesEvent(String ids, int daysInterval, long calBeginNextEventDateLong, long milisPerDay, final Date startDate, final Date endDate, String eventSummary, String eventDescription) { + private void addDailySeriesEvent(Integer ids, int daysInterval, long calBeginNextEventDateLong, long milisPerDay, final Date startDate, final Date endDate, String eventSummary, String eventDescription) { //Date calBeginNextEventDate; - + for (int i = 1; i < daysInterval; i++) { calBeginNextEventDateLong += milisPerDay; @@ -634,6 +659,7 @@ private void addDailySeriesEvent(String ids, int daysInterval, long calBeginNext dailyProperties.put(Event.DESCRIPTION, newDescription); dailyProperties.put(Event.EVENT_TYPE, "D"); dailyProperties.put(Event.REFERENCE_ID, ids); + addPersonalEvent(dailyProperties); } } @@ -657,16 +683,18 @@ private void processWeeklyEvents(long diffInMilis, long milisPerWeek, final Date long calBeginNextEventDateLong = beginEventIntervalDate.getTime(); //Date calBeginNextEventDate = beginEventIntervalDate; - if (weeksInterval > 1) { + // if (weeksInterval > 1) { properties.put(Event.SUMMARY, (String) properties.get(Event.SUMMARY) + " (Weekly event 1 of " + weeksInterval + ")"); properties.put(Event.DESCRIPTION, (String) properties.get(Event.DESCRIPTION) + " (Weekly event 1 of " + weeksInterval + ")"); properties.put(Event.EVENT_TYPE, "W"); - } + //} addPersonalEventWeekly(properties, weeksInterval, calBeginNextEventDateLong, milisPerWeek, startDate, endDate, eventSummary, eventDescription); } - private void addPersonalEventWeekly(final Map properties, final int daysInterval, final long calBeginNextEventDateLong, final long milisPerDay, final Date startDate, final Date endDate, final String eventSummary, final String eventDescription) { +int evLen=3; +int []count = new int[100]; + private void addPersonalEventWeekly(final Map properties, final int weeksInterval, final long calBeginNextEventDateLong, final long milisPerDay, final Date startDate, final Date endDate, final String eventSummary, final String eventDescription) { final CreateEntity createEntity = new CreateEntity(PersonalEventDTO.ENTITY_NAME, properties); @@ -681,43 +709,92 @@ public void onCommandFailure(final Throwable caught) { public void onCommandSuccess(final CreateResult result) { // Creating events. + final Event event = new Event(); event.setIdentifier((Integer) result.getEntity().getId()); - properties.put(Event.REFERENCE_ID, (Integer) result.getEntity().getId()); updateEvent(event, properties); - addWeeklySeriesEvent((String) result.getEntity().getId(), daysInterval, calBeginNextEventDateLong, milisPerDay, startDate, endDate, eventSummary, eventDescription); + properties.put(Event.REFERENCE_ID, (Integer) result.getEntity().getId()); + int daysInterval = 4; + + addDailySeriesEventNew2((Integer)properties.get(Event.REFERENCE_ID), weeksInterval, calBeginNextEventDateLong, milisPerDay, startDate, endDate, eventSummary, eventDescription); + + addWeeklySeriesEvent(properties, (String) result.getEntity().getId(), daysInterval, weeksInterval, calBeginNextEventDateLong, milisPerDay, startDate, endDate, eventSummary, eventDescription); } }, view.getCancelButton(), view.getSaveButton()); } - private void addWeeklySeriesEvent(String ids, int weeksInterval, long calBeginNextEventDateLong, long milisPerWeek, final Date startDate, final Date endDate, String eventSummary, String eventDescription) { - //Date calBeginNextEventDate; - - for (int i = 1; i < weeksInterval; i++) { - - calBeginNextEventDateLong += milisPerWeek; - // calBeginNextEventDate = new Date(calBeginNextEventDateLong); + private void addWeeklySeriesEvent(final Map properties, String ids, int daysInterval, int weeksInterval, long calBeginNextEventDateLong, long milisPerWeek, final Date startDate, final Date endDate, String eventSummary, String eventDescription) { + for (int i = 0; i < weeksInterval; i++) { + long milisPerDay = 86400000; Map weeklyProperties = new HashMap(); weeklyProperties.put(Event.CALENDAR_ID, calendarWrapper); weeklyProperties.put(Event.SUMMARY, view.getEventSummaryField().getValue()); + weeklyProperties.put(Event.EVENT_TYPE, "W"); + weeklyProperties.put(Event.REFERENCE_ID, ids); + //int daysInterval = 4; + // addPersonalEvent(weeklyProperties); + + addDailySeriesEventNew((Integer)properties.get(Event.REFERENCE_ID), daysInterval, calBeginNextEventDateLong, milisPerDay, startDate, endDate, eventSummary, eventDescription, i, weeksInterval); + calBeginNextEventDateLong += milisPerWeek; + } + } + private void addDailySeriesEventNew2(Integer ids, int daysInterval, long calBeginNextEventDateLong, long milisPerDay, final Date startDate, final Date endDate, String eventSummary, String eventDescription) { + //Date calBeginNextEventDate; + + for (int i = 1; i < daysInterval; i++) { + + calBeginNextEventDateLong += milisPerDay; + //calBeginNextEventDate = new Date(calBeginNextEventDateLong); + + Map dailyProperties = new HashMap(); + dailyProperties.put(Event.CALENDAR_ID, calendarWrapper); + dailyProperties.put(Event.SUMMARY, view.getEventSummaryField().getValue()); - weeklyProperties.put(Event.DATE, new Date(calBeginNextEventDateLong)); + dailyProperties.put(Event.DATE, new Date(calBeginNextEventDateLong)); - setFullDayEvent(startDate, endDate, new Date(calBeginNextEventDateLong), weeklyProperties); + setFullDayEvent(startDate, endDate, new Date(calBeginNextEventDateLong), dailyProperties); String newSummary = eventSummary; String newDescription = eventDescription; - newSummary += " (Weekly event " + (i + 1) + " of " + weeksInterval + ")"; - newDescription += " (Weekly event " + (i + 1) + " of " + weeksInterval + ")"; - weeklyProperties.put(Event.SUMMARY, newSummary); - weeklyProperties.put(Event.DESCRIPTION, newDescription); - weeklyProperties.put(Event.EVENT_TYPE, "W"); - weeklyProperties.put(Event.REFERENCE_ID, ids); - addPersonalEvent(weeklyProperties); + newSummary += " (Weekly event " + (i + 1) + " of " + daysInterval + ")"; + newDescription += " (Weekly event " + (i + 1) + " of " + daysInterval + ")"; + dailyProperties.put(Event.SUMMARY, newSummary); + dailyProperties.put(Event.DESCRIPTION, newDescription); + dailyProperties.put(Event.EVENT_TYPE, "W"); + dailyProperties.put(Event.REFERENCE_ID, ids); + + addPersonalEvent(dailyProperties); } } + private void addDailySeriesEventNew(Integer ids, int daysInterval, long calBeginNextEventDateLong, long milisPerDay, final Date startDate, final Date endDate, String eventSummary, String eventDescription, final int j, final int weeksInterval) { + //Date calBeginNextEventDate; + + for (int i = 1; i < daysInterval; i++) { + + calBeginNextEventDateLong += milisPerDay; + //calBeginNextEventDate = new Date(calBeginNextEventDateLong); + Map dailyProperties = new HashMap(); + dailyProperties.put(Event.CALENDAR_ID, calendarWrapper); + dailyProperties.put(Event.SUMMARY, view.getEventSummaryField().getValue()); + + dailyProperties.put(Event.DATE, new Date(calBeginNextEventDateLong)); + + setFullDayEvent(startDate, endDate, new Date(calBeginNextEventDateLong), dailyProperties); + + String newSummary = eventSummary; + String newDescription = eventDescription; + newSummary += " (Weekly event " + (j + 1) + " of " + weeksInterval + ")"; + newDescription += " (Weekly event " + (j + 1) + " of " + weeksInterval + ")"; + dailyProperties.put(Event.SUMMARY, newSummary); + dailyProperties.put(Event.DESCRIPTION, newDescription); + dailyProperties.put(Event.EVENT_TYPE, "W"); + dailyProperties.put(Event.REFERENCE_ID, ids); + + addPersonalEvent(dailyProperties); + } + } /** * Set date and time values for Full day events. * From d81279a01eb1bebda5098c85b51462d8104954a4 Mon Sep 17 00:00:00 2001 From: Seal98 Date: Fri, 14 Jul 2017 20:58:04 +0300 Subject: [PATCH 23/39] (Issue#852) Creating weekly series multi-days events Implemented the creating of weekly multi-day event (with the listBox) --- .../calendar/CalendarEventPresenter.java | 20 ++++++- .../ui/view/calendar/CalendarEventView.java | 56 +++++++++++++++++-- 2 files changed, 67 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java b/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java index 2f7037e4d..24388d873 100644 --- a/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java +++ b/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java @@ -63,6 +63,7 @@ import com.extjs.gxt.ui.client.widget.form.TextField; import com.extjs.gxt.ui.client.widget.form.Time; import com.extjs.gxt.ui.client.widget.form.TimeField; +import com.google.gwt.user.client.ui.ListBox; import com.google.inject.ImplementedBy; import com.google.inject.Inject; import com.google.inject.Singleton; @@ -154,6 +155,12 @@ public static interface View extends ViewInterface { */ FieldSet getPanelMonthly(); + /** + * + * @return + */ + FieldSet getPanelWeekly(); + /** * * @return @@ -225,7 +232,12 @@ public static interface View extends ViewInterface { * @return */ Radio getRadioMonthlySameDayOfWeek(); - + + /** + * + * @return + */ + ListBox getListBoxWeekly(); // void setShowAddEventView(boolean showAddEventView); } @@ -391,6 +403,7 @@ private void prepareAddView() { view.getOnceRepeatRB().setValue(true); view.getPanelMonthly().hide(); view.getPanelYearly().hide(); + view.getPanelWeekly().hide(); } view.getEventStartTimeField().show(); view.getEventEndTimeField().show(); @@ -714,8 +727,9 @@ public void onCommandSuccess(final CreateResult result) { event.setIdentifier((Integer) result.getEntity().getId()); updateEvent(event, properties); properties.put(Event.REFERENCE_ID, (Integer) result.getEntity().getId()); - int daysInterval = 4; - + int daysInterval=0; + daysInterval = Integer.parseInt(view.getListBoxWeekly().getItemText(view.getListBoxWeekly().getSelectedIndex())); + // Window.alert("DaysInterval = "+daysInterval); addDailySeriesEventNew2((Integer)properties.get(Event.REFERENCE_ID), weeksInterval, calBeginNextEventDateLong, milisPerDay, startDate, endDate, eventSummary, eventDescription); addWeeklySeriesEvent(properties, (String) result.getEntity().getId(), daysInterval, weeksInterval, calBeginNextEventDateLong, milisPerDay, startDate, endDate, eventSummary, eventDescription); diff --git a/src/main/java/org/sigmah/client/ui/view/calendar/CalendarEventView.java b/src/main/java/org/sigmah/client/ui/view/calendar/CalendarEventView.java index b8eaf2714..fac93d0ab 100644 --- a/src/main/java/org/sigmah/client/ui/view/calendar/CalendarEventView.java +++ b/src/main/java/org/sigmah/client/ui/view/calendar/CalendarEventView.java @@ -43,7 +43,9 @@ import com.extjs.gxt.ui.client.widget.form.TextField; import com.extjs.gxt.ui.client.widget.form.TimeField; import com.extjs.gxt.ui.client.widget.form.CheckBox; +import com.extjs.gxt.ui.client.widget.form.ComboBox; import com.extjs.gxt.ui.client.widget.form.FieldSet; +import com.google.gwt.user.client.ui.ListBox; import com.google.inject.Singleton; /** @@ -70,7 +72,8 @@ public class CalendarEventView extends AbstractPopupView implements private RadioGroup montlyVariantRG; private FieldSet panelYearly; private FieldSet panelMonthly; - + private FieldSet panelWeekly; + private Radio yearlySameDayOfWeekRB; private Radio yearlySameDateRB; @@ -81,6 +84,9 @@ public class CalendarEventView extends AbstractPopupView implements private Radio yearlyRepeatRB; private Radio radioMonthlySameDate; private Radio radioMonthlySameDayOfWeek; + + private ListBox listBoxWeekly; + // private CheckBoxGroup allDayCheckboxGr; private RadioGroup RepeatEventPeriodRG; @@ -101,8 +107,11 @@ public void initialize() { createYearlyPanel(); createMonthlyPanel(); + createWeeklyPanel(); createRepeatEventPeriodRadioGroup(); - + + listBoxWeekly.setName("listBoxWeekly"); + eventSummaryField = Forms.text(I18N.CONSTANTS.calendarEventObject(), true); eventSummaryField.setName(Event.SUMMARY); @@ -138,6 +147,7 @@ public void initialize() { form.add(RepeatEventPeriodRG); form.add(panelYearly); form.add(panelMonthly); + form.add(panelWeekly); form.add(eventDescriptionField); form.addButton(cancelButton); @@ -189,6 +199,7 @@ private void createYearlyRb() { public void handleEvent(FieldEvent event) { ((TextArea) form.getItemByItemId(Event.DESCRIPTION)).setValue(I18N.CONSTANTS.calendar_addEvent_description_textArea_yearly()); getPanelYearly().setVisible(getYearlyRepeatRB().getValue()); + getPanelWeekly().setVisible(!yearlyRepeatRB.getValue()); getPanelMonthly().setVisible(!yearlyRepeatRB.getValue()); getYearlySameDateRB().show(); @@ -206,6 +217,7 @@ private void createMonthlyRb() { @Override public void handleEvent(FieldEvent event) { ((TextArea) form.getItemByItemId(Event.DESCRIPTION)).setValue(I18N.CONSTANTS.calendar_addEvent_description_textArea_monthly()); + getPanelWeekly().setVisible(!monthlyRepeatRB.getValue()); getPanelYearly().setVisible(!monthlyRepeatRB.getValue()); getPanelMonthly().setVisible(getMonthlyRepeatRB().getValue()); eventDateStartField.setAllowBlank(false); @@ -225,7 +237,8 @@ public void handleEvent(FieldEvent event) { ((TextArea) form.getItemByItemId(Event.DESCRIPTION)).setValue(I18N.CONSTANTS.calendar_addEvent_description_textArea_weekly()); getPanelYearly().setVisible(!weeklyRepeatRB.getValue()); getPanelMonthly().setVisible(!weeklyRepeatRB.getValue()); - + getPanelWeekly().setVisible(getWeeklyRepeatRB().getValue()); + eventDateStartField.setAllowBlank(false); } }); @@ -242,6 +255,7 @@ public void handleEvent(FieldEvent event) { ((TextArea) form.getItemByItemId(Event.DESCRIPTION)).setValue(I18N.CONSTANTS.calendar_addEvent_description_textArea_daily()); getPanelYearly().setVisible(!dailyRepeatRB.getValue()); getPanelMonthly().setVisible(!dailyRepeatRB.getValue()); + getPanelWeekly().setVisible(!dailyRepeatRB.getValue()); } }); } @@ -257,11 +271,26 @@ public void handleEvent(FieldEvent event) { getPanelYearly().setVisible(!onceRepeatRB.getValue()); getPanelMonthly().setVisible(!onceRepeatRB.getValue()); + getPanelWeekly().setVisible(!onceRepeatRB.getValue()); ((TextArea) form.getItemByItemId(Event.DESCRIPTION)).setValue(I18N.CONSTANTS.calendar_addEvent_description_textArea_once()); } }); } - + + private void createWeeklyPanel() { + panelWeekly = new FieldSet(); + panelWeekly.setExpanded(true); + panelWeekly.setBorders(true); + panelWeekly.setHeadingHtml("Weekly repeats settings"); + panelWeekly.setAutoHeight(true); + panelWeekly.setVisible(false); + + listBoxWeekly = new ListBox(); + for(int i=1;i<=7;i++) listBoxWeekly.addItem(""+i); + + panelWeekly.add(listBoxWeekly); + } + private void createMonthlyPanel() { panelMonthly = new FieldSet(); panelMonthly.setExpanded(true); @@ -288,7 +317,12 @@ private void createMonthlyPanel() { montlyVariantRG.add(radioMonthlySameDayOfWeek); montlyVariantRG.add(radioMonthlySameDate); + // ListBox lb = new ListBox(); + // lb.addItem("day(s)"); + // lb.addItem("week(s)"); + panelMonthly.add(montlyVariantRG); + // panelMonthly.add(lb); } private void createYearlyPanel() { @@ -404,6 +438,11 @@ public FieldSet getPanelMonthly() { return panelMonthly; } + @Override + public FieldSet getPanelWeekly() { + return panelWeekly; + } + /** * * @return @@ -443,6 +482,11 @@ public RadioGroup getMontlyVariantRG() { return montlyVariantRG; } + @Override + public ListBox getListBoxWeekly() { + return listBoxWeekly; + } + @Override public Radio getYearlySameDayOfWeekRB() { return yearlySameDayOfWeekRB; @@ -457,11 +501,11 @@ public Radio getYearlySameDateRB() { public RadioGroup getRepeatEventPeriodRG() { return RepeatEventPeriodRG; } - + @Override public Radio getRadioMonthlySameDate() { return radioMonthlySameDate; } - + @Override public Radio getRadioMonthlySameDayOfWeek() { return radioMonthlySameDayOfWeek; } From 4a27f7e833b22d66d44bbff61c244306b314a9b1 Mon Sep 17 00:00:00 2001 From: Seal98 Date: Sat, 15 Jul 2017 16:26:36 +0300 Subject: [PATCH 24/39] (Issue#852) Creating Monthly and Yearly series multi-days events Implemented the creating of Monthly and Yearly multi-day event (with the listBox) --- .../calendar/CalendarEventPresenter.java | 174 ++++++++++++++++-- .../ui/view/calendar/CalendarEventView.java | 65 ++++++- 2 files changed, 219 insertions(+), 20 deletions(-) diff --git a/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java b/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java index 24388d873..a6dc5f98c 100644 --- a/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java +++ b/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java @@ -238,6 +238,30 @@ public static interface View extends ViewInterface { * @return */ ListBox getListBoxWeekly(); + + /** + * + * @return + */ + ListBox getListBoxMonthly1(); + + /** + * + * @return + */ + ListBox getListBoxMonthly2(); + + /** + * + * @return + */ + ListBox getListBoxYearly1(); + + /** + * + * @return + */ + ListBox getListBoxYearly2(); // void setShowAddEventView(boolean showAddEventView); } @@ -729,7 +753,6 @@ public void onCommandSuccess(final CreateResult result) { properties.put(Event.REFERENCE_ID, (Integer) result.getEntity().getId()); int daysInterval=0; daysInterval = Integer.parseInt(view.getListBoxWeekly().getItemText(view.getListBoxWeekly().getSelectedIndex())); - // Window.alert("DaysInterval = "+daysInterval); addDailySeriesEventNew2((Integer)properties.get(Event.REFERENCE_ID), weeksInterval, calBeginNextEventDateLong, milisPerDay, startDate, endDate, eventSummary, eventDescription); addWeeklySeriesEvent(properties, (String) result.getEntity().getId(), daysInterval, weeksInterval, calBeginNextEventDateLong, milisPerDay, startDate, endDate, eventSummary, eventDescription); @@ -862,7 +885,6 @@ private void processMonthlyEvents(final Date beginEventIntervalDate, final Date monthInterval = monthEnd - monthStart + 1; } - if (monthInterval > 1) { properties.put(Event.SUMMARY, (String) properties.get(Event.SUMMARY) + " (Monthly event 1 of " + monthInterval + ")"); properties.put(Event.DESCRIPTION, (String) properties.get(Event.DESCRIPTION) + " (Monthly event 1 of " + monthInterval + ")"); if (isMonthlySameDayOfWeek) { @@ -870,9 +892,9 @@ private void processMonthlyEvents(final Date beginEventIntervalDate, final Date } else { properties.put(Event.EVENT_TYPE, "M2"); } - } //addPersonalEventMonthly(properties, monthInterval, beginEventIntervalDate, endEventIntervalDate, startDate, endDate, eventSummary, eventDescription, isMonthlySameDayOfWeek); addPersonalEventMonthly(properties, monthInterval, beginEventIntervalDate, startDate, endDate, eventSummary, eventDescription, isMonthlySameDayOfWeek); + } //private void addPersonalEventMonthly(final Map properties, final int monthInterval, final Date beginEventIntervalDate, final Date endEventIntervalDate, final Date startDate, final Date endDate, final String eventSummary, final String eventDescription, final boolean isMonthlySameDayOfWeek) { @@ -892,15 +914,81 @@ public void onCommandSuccess(final CreateResult result) { // Creating events. final Event event = new Event(); event.setIdentifier((Integer) result.getEntity().getId()); - properties.put(Event.REFERENCE_ID, (Integer) result.getEntity().getId()); updateEvent(event, properties); - // properties.put(Event.REFERENCE_ID, (Integer) result.getEntity().getId()); - //addMonthlySeriesEvent((String) result.getEntity().getId(), monthInterval, beginEventIntervalDate, endEventIntervalDate, startDate, endDate, eventSummary, eventDescription, isMonthlySameDayOfWeek); - addMonthlySeriesEvent((String) result.getEntity().getId(), monthInterval, beginEventIntervalDate, startDate, endDate, eventSummary, eventDescription, isMonthlySameDayOfWeek); + properties.put(Event.REFERENCE_ID, (Integer) result.getEntity().getId()); + int daysInterval=0; + + daysInterval = Integer.parseInt(view.getListBoxMonthly2().getItemText(view.getListBoxMonthly2().getSelectedIndex())); + // addDailySeriesEventNew4((Integer)properties.get(Event.REFERENCE_ID), milisPerDay*7, beginEventIntervalDate, milisPerDay, startDate, endDate, eventSummary, eventDescription); + addMonthlySeriesEvent((String) result.getEntity().getId(), monthInterval, beginEventIntervalDate, startDate, endDate, eventSummary, eventDescription, isMonthlySameDayOfWeek); + addMonthlySeriesEventNew((String) result.getEntity().getId(), monthInterval,daysInterval, beginEventIntervalDate, startDate, endDate, eventSummary, eventDescription, isMonthlySameDayOfWeek); + } }, view.getCancelButton(), view.getSaveButton()); } + private void addMonthlySeriesEventNew(String ids, int monthInterval, final long daysInterval, Date beginEventIntervalDate, final Date startDate, final Date endDate, String eventSummary, String eventDescription, final boolean isMonthlySameDayOfWeek) { + Date calBeginNextEventDate = beginEventIntervalDate; + long milisPerDay = 86400000; + for (int i = 0; i < monthInterval; i++) { + //calBeginNextEventDate = getMonthlySameDate(beginEventIntervalDate, calBeginNextEventDate, i); + + + Map monthlyProperties = new HashMap(); + monthlyProperties.put(Event.CALENDAR_ID, calendarWrapper); + monthlyProperties.put(Event.SUMMARY, view.getEventSummaryField().getValue()); + + monthlyProperties.put(Event.DATE, calBeginNextEventDate); + + setFullDayEvent(startDate, endDate, calBeginNextEventDate, monthlyProperties); + + String newSummary = eventSummary; + String newDescription = eventDescription; + newSummary += " (Monthly event " + (i + 1) + " of " + monthInterval + ")"; + newDescription += " (Monthly " + (isMonthlySameDayOfWeek ? "same Day of a week " : "same Date ") + "event " + (i + 1) + " of " + monthInterval + ")"; + monthlyProperties.put(Event.SUMMARY, newSummary); + monthlyProperties.put(Event.DESCRIPTION, newDescription); + if (isMonthlySameDayOfWeek) { + monthlyProperties.put(Event.EVENT_TYPE, "M1"); + } else { + monthlyProperties.put(Event.EVENT_TYPE, "M2"); + } + monthlyProperties.put(Event.REFERENCE_ID, ids); + addMonthlySeriesEventNew2((Integer)monthlyProperties.get(Event.REFERENCE_ID), daysInterval, calBeginNextEventDate.getTime(), milisPerDay, startDate, endDate, eventSummary, eventDescription, i, isMonthlySameDayOfWeek, monthInterval); + calBeginNextEventDate = getMonthlySameDayOfWeek2(beginEventIntervalDate, calBeginNextEventDate, i, isMonthlySameDayOfWeek); + } + } + + private void addMonthlySeriesEventNew2(Integer ids, long daysInterval, long calBeginNextEventDateLong1, long milisPerDay, final Date startDate, final Date endDate, String eventSummary, String eventDescription, int j, final boolean isMonthlySameDayOfWeek, final int monthInterval) { + //Date calBeginNextEventDate; + long calBeginNextEventDateLong = calBeginNextEventDateLong1; + for (int i = 1; i < daysInterval; i++) { + calBeginNextEventDateLong += milisPerDay; + //calBeginNextEventDate = getMonthlySameDate(beginEventIntervalDate, calBeginNextEventDate, i); + + Map monthlyProperties = new HashMap(); + monthlyProperties.put(Event.CALENDAR_ID, calendarWrapper); + monthlyProperties.put(Event.SUMMARY, view.getEventSummaryField().getValue()); + monthlyProperties.put(Event.DATE, new Date(calBeginNextEventDateLong)); + + setFullDayEvent(startDate, endDate, new Date(calBeginNextEventDateLong), monthlyProperties); + + String newSummary = eventSummary; + String newDescription = eventDescription; + newSummary += " (Monthly event " + (j + 1) + " of " + monthInterval + ")"; + newDescription += " (Monthly " + (isMonthlySameDayOfWeek ? "same Day of a week " : "same Date ") + "event " + (j + 1) + " of " + monthInterval + ")"; + monthlyProperties.put(Event.SUMMARY, newSummary); + monthlyProperties.put(Event.DESCRIPTION, newDescription); + if (isMonthlySameDayOfWeek) { + monthlyProperties.put(Event.EVENT_TYPE, "M1"); + } else { + monthlyProperties.put(Event.EVENT_TYPE, "M2"); + } + monthlyProperties.put(Event.REFERENCE_ID, ids); + addPersonalEvent(monthlyProperties); + } + } + //private void addMonthlySeriesEvent(String ids, int monthInterval, Date beginEventIntervalDate, Date endEventIntervalDate, final Date startDate, final Date endDate, String eventSummary, String eventDescription, final boolean isMonthlySameDayOfWeek) { private void addMonthlySeriesEvent(String ids, int monthInterval, Date beginEventIntervalDate, final Date startDate, final Date endDate, String eventSummary, String eventDescription, final boolean isMonthlySameDayOfWeek) { Date calBeginNextEventDate = beginEventIntervalDate; @@ -976,20 +1064,80 @@ public void onCommandFailure(final Throwable caught) { @Override public void onCommandSuccess(final CreateResult result) { - createNewEvent(result); - addYearlySeriesEvent((String) result.getEntity().getId(), yearInterval, beginEventIntervalDate, endEventIntervalDate, startDate, endDate, eventSummary, eventDescription, isYearlySameDayOfWeek); - } - - private void createNewEvent(final CreateResult result) { - // Creating events. final Event event = new Event(); event.setIdentifier((Integer) result.getEntity().getId()); properties.put(Event.REFERENCE_ID, (Integer) result.getEntity().getId()); updateEvent(event, properties); + int daysInterval=0; + daysInterval = Integer.parseInt(view.getListBoxYearly2().getItemText(view.getListBoxYearly2().getSelectedIndex())); + + addYearlySeriesEvent((String) result.getEntity().getId(), yearInterval, beginEventIntervalDate, endEventIntervalDate, startDate, endDate, eventSummary, eventDescription, isYearlySameDayOfWeek); + addYearlySeriesEventNew((String) result.getEntity().getId(), yearInterval,daysInterval, beginEventIntervalDate, startDate, endDate, eventSummary, eventDescription, isYearlySameDayOfWeek); } }, view.getCancelButton(), view.getSaveButton()); } + private void addYearlySeriesEventNew(String ids, int yearInterval, final long daysInterval, Date beginEventIntervalDate, final Date startDate, final Date endDate, String eventSummary, String eventDescription, final boolean isYearlySameDayOfWeek) { + Date calBeginNextEventDate = beginEventIntervalDate; + long milisPerDay = 86400000; + for (int i = 0; i < yearInterval; i++) { + //calBeginNextEventDate = getMonthlySameDate(beginEventIntervalDate, calBeginNextEventDate, i); + + + Map monthlyProperties = new HashMap(); + monthlyProperties.put(Event.CALENDAR_ID, calendarWrapper); + monthlyProperties.put(Event.SUMMARY, view.getEventSummaryField().getValue()); + monthlyProperties.put(Event.DATE, calBeginNextEventDate); + + setFullDayEvent(startDate, endDate, calBeginNextEventDate, monthlyProperties); + + String newSummary = eventSummary; + String newDescription = eventDescription; + newSummary += " (Yearly event " + (i + 1) + " of " + yearInterval + ")"; + newDescription += " (Yearly " + (isYearlySameDayOfWeek ? "same Day of a week " : "same Date ") + "event " + (i + 1) + " of " + yearInterval + ")"; + monthlyProperties.put(Event.SUMMARY, newSummary); + monthlyProperties.put(Event.DESCRIPTION, newDescription); + if (isYearlySameDayOfWeek) { + monthlyProperties.put(Event.EVENT_TYPE, "Y1"); + } else { + monthlyProperties.put(Event.EVENT_TYPE, "Y2"); + } + monthlyProperties.put(Event.REFERENCE_ID, ids); + addYearlySeriesEventNew2((Integer)monthlyProperties.get(Event.REFERENCE_ID), daysInterval, calBeginNextEventDate.getTime(), milisPerDay, startDate, endDate, eventSummary, eventDescription, i, isYearlySameDayOfWeek, yearInterval); + calBeginNextEventDate = getYearlySameDayOfWeek(beginEventIntervalDate, calBeginNextEventDate, i, isYearlySameDayOfWeek); + } + } + + private void addYearlySeriesEventNew2(Integer ids, long daysInterval, long calBeginNextEventDateLong1, long milisPerDay, final Date startDate, final Date endDate, String eventSummary, String eventDescription, int j, final boolean isYearlySameDayOfWeek, final int yearInterval) { + //Date calBeginNextEventDate; + long calBeginNextEventDateLong = calBeginNextEventDateLong1; + for (int i = 1; i < daysInterval; i++) { + calBeginNextEventDateLong += milisPerDay; + //calBeginNextEventDate = getMonthlySameDate(beginEventIntervalDate, calBeginNextEventDate, i); + + Map monthlyProperties = new HashMap(); + monthlyProperties.put(Event.CALENDAR_ID, calendarWrapper); + monthlyProperties.put(Event.SUMMARY, view.getEventSummaryField().getValue()); + + monthlyProperties.put(Event.DATE, new Date(calBeginNextEventDateLong)); + + setFullDayEvent(startDate, endDate, new Date(calBeginNextEventDateLong), monthlyProperties); + + String newSummary = eventSummary; + String newDescription = eventDescription; + newSummary += " (Yearly event " + (j + 1) + " of " + yearInterval + ")"; + newDescription += " (Yearly " + (isYearlySameDayOfWeek ? "same Day of a week " : "same Date ") + "event " + (j + 1) + " of " + yearInterval + ")"; + monthlyProperties.put(Event.SUMMARY, newSummary); + monthlyProperties.put(Event.DESCRIPTION, newDescription); + if (isYearlySameDayOfWeek) { + monthlyProperties.put(Event.EVENT_TYPE, "Y1"); + } else { + monthlyProperties.put(Event.EVENT_TYPE, "Y2"); + } + monthlyProperties.put(Event.REFERENCE_ID, ids); + addPersonalEvent(monthlyProperties); + } + } private void addYearlySeriesEvent(String ids, int yearInterval, Date beginEventIntervalDate, Date endEventIntervalDate, final Date startDate, final Date endDate, String eventSummary, String eventDescription, final boolean isYearlySameDayOfWeek) { Date calBeginNextEventDate = beginEventIntervalDate; for (int i = 1; i < yearInterval; i++) { diff --git a/src/main/java/org/sigmah/client/ui/view/calendar/CalendarEventView.java b/src/main/java/org/sigmah/client/ui/view/calendar/CalendarEventView.java index fac93d0ab..753533068 100644 --- a/src/main/java/org/sigmah/client/ui/view/calendar/CalendarEventView.java +++ b/src/main/java/org/sigmah/client/ui/view/calendar/CalendarEventView.java @@ -22,6 +22,7 @@ * #L% */ import com.extjs.gxt.ui.client.Style; +import com.extjs.gxt.ui.client.data.ChangeListener; import com.extjs.gxt.ui.client.event.Events; import com.extjs.gxt.ui.client.event.FieldEvent; import com.extjs.gxt.ui.client.event.Listener; @@ -45,6 +46,8 @@ import com.extjs.gxt.ui.client.widget.form.CheckBox; import com.extjs.gxt.ui.client.widget.form.ComboBox; import com.extjs.gxt.ui.client.widget.form.FieldSet; +import com.google.gwt.event.dom.client.ChangeEvent; +import com.google.gwt.user.client.Window; import com.google.gwt.user.client.ui.ListBox; import com.google.inject.Singleton; @@ -86,7 +89,10 @@ public class CalendarEventView extends AbstractPopupView implements private Radio radioMonthlySameDayOfWeek; private ListBox listBoxWeekly; - + private ListBox listBoxMonthly1; + private ListBox listBoxMonthly2; + private ListBox listBoxYearly1; + private ListBox listBoxYearly2; // private CheckBoxGroup allDayCheckboxGr; private RadioGroup RepeatEventPeriodRG; @@ -111,6 +117,10 @@ public void initialize() { createRepeatEventPeriodRadioGroup(); listBoxWeekly.setName("listBoxWeekly"); + listBoxMonthly1.setName("listBoxMonthly1"); + listBoxMonthly2.setName("listBoxMonthly2"); + listBoxYearly1.setName("listBoxYearly1"); + listBoxYearly2.setName("listBoxYearly2"); eventSummaryField = Forms.text(I18N.CONSTANTS.calendarEventObject(), true); eventSummaryField.setName(Event.SUMMARY); @@ -238,7 +248,7 @@ public void handleEvent(FieldEvent event) { getPanelYearly().setVisible(!weeklyRepeatRB.getValue()); getPanelMonthly().setVisible(!weeklyRepeatRB.getValue()); getPanelWeekly().setVisible(getWeeklyRepeatRB().getValue()); - + Window.alert("Test"); eventDateStartField.setAllowBlank(false); } }); @@ -276,6 +286,7 @@ public void handleEvent(FieldEvent event) { } }); } + private void createWeeklyPanel() { panelWeekly = new FieldSet(); @@ -316,13 +327,20 @@ private void createMonthlyPanel() { montlyVariantRG.setOrientation(Style.Orientation.HORIZONTAL); montlyVariantRG.add(radioMonthlySameDayOfWeek); montlyVariantRG.add(radioMonthlySameDate); + panelMonthly.add(montlyVariantRG); + + listBoxMonthly1 = new ListBox(); + listBoxMonthly1.addItem("day(s)"); + listBoxMonthly1.addItem("week(s)"); + panelMonthly.add(listBoxMonthly1); + + + + listBoxMonthly2 = new ListBox(); + for(int i=1;i<=30;i++) listBoxMonthly2.addItem(""+i); + panelMonthly.add(listBoxMonthly2); - // ListBox lb = new ListBox(); - // lb.addItem("day(s)"); - // lb.addItem("week(s)"); - panelMonthly.add(montlyVariantRG); - // panelMonthly.add(lb); } private void createYearlyPanel() { @@ -349,6 +367,18 @@ private void createYearlyPanel() { yearlyVariantRG.setSelectionRequired(Boolean.FALSE); panelYearly.add(yearlyVariantRG); + + listBoxYearly1 = new ListBox(); + listBoxYearly1.addItem("day(s)"); + listBoxYearly1.addItem("week(s)"); + listBoxYearly1.addItem("month(s)"); + panelYearly.add(listBoxYearly1); + + + + listBoxYearly2 = new ListBox(); + for(int i=1;i<=30;i++) listBoxYearly2.addItem(""+i); + panelYearly.add(listBoxYearly2); } /** @@ -482,11 +512,32 @@ public RadioGroup getMontlyVariantRG() { return montlyVariantRG; } + + @Override public ListBox getListBoxWeekly() { return listBoxWeekly; } + @Override + public ListBox getListBoxMonthly1() { + return listBoxMonthly1; + } + + @Override + public ListBox getListBoxMonthly2() { + return listBoxMonthly2; + } + @Override + public ListBox getListBoxYearly1() { + return listBoxYearly1; + } + @Override + public ListBox getListBoxYearly2() { + return listBoxYearly2; + } + + @Override public Radio getYearlySameDayOfWeekRB() { return yearlySameDayOfWeekRB; From b1978519a28774dfce4ea418569bf94453284065 Mon Sep 17 00:00:00 2001 From: Seal98 Date: Tue, 25 Jul 2017 13:52:02 +0300 Subject: [PATCH 25/39] (issue#852) creating several-days events New fields were added for each type of the event --- .../calendar/CalendarEventPresenter.java | 433 ++++++++++++--- .../ui/view/calendar/CalendarEventView.java | 504 +++++++++++++++--- 2 files changed, 795 insertions(+), 142 deletions(-) diff --git a/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java b/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java index a6dc5f98c..7fee6af45 100644 --- a/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java +++ b/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java @@ -67,6 +67,7 @@ import com.google.inject.ImplementedBy; import com.google.inject.Inject; import com.google.inject.Singleton; +import static java.lang.Integer.parseInt; /** * Calendar event presenter which manages the {@link CalendarEventView}. @@ -161,6 +162,24 @@ public static interface View extends ViewInterface { */ FieldSet getPanelWeekly(); + /** + * + * @return + */ + FieldSet getPanelDaily(); + + /** + * + * @return + */ + FieldSet getMonthlyRepSettings(); + + /** + * + * @return + */ + FieldSet getYearlyRepSettings(); + /** * * @return @@ -221,6 +240,12 @@ public static interface View extends ViewInterface { */ RadioGroup getRepeatEventPeriodRG(); + /** + * + * @return + */ + RadioGroup getRepeatMultiEventPeriodRG(); + /** * * @return @@ -237,31 +262,98 @@ public static interface View extends ViewInterface { * * @return */ - ListBox getListBoxWeekly(); - + Radio getRadioRepetitionEndDate(); + + /** + * + * @return + */ + Radio getRadioNumberOfRepetitions(); + + /** + * + * @return + */ + Radio getDailyRadioRepetitionEndDate(); + + /** + * + * @return + */ + Radio getDailyRadioNumberOfRepetitions(); + + /** + * + * @return + */ + Radio getWeeklyRadioRepetitionEndDate(); + + /** + * + * @return + */ + Radio getWeeklyRadioNumberOfRepetitions(); + + /** + * + * @return + */ + Radio getYearlyRadioRepetitionEndDate(); + /** * * @return */ - ListBox getListBoxMonthly1(); + Radio getYearlyRadioNumberOfRepetitions(); /** * * @return */ - ListBox getListBoxMonthly2(); + TextArea getNumberOfRepetitions(); /** * * @return */ - ListBox getListBoxYearly1(); + DateField getRepetitionEndDate(); /** * * @return */ - ListBox getListBoxYearly2(); + TextArea getWeeklyNumberOfRepetitions(); + + /** + * + * @return + */ + DateField getWeeklyRepetitionEndDate(); + + /** + * + * @return + */ + TextArea getYearlyNumberOfRepetitions(); + + /** + * + * @return + */ + DateField getYearlyRepetitionEndDate(); + + /** + * + * @return + */ + TextArea getDailyNumberOfRepetitions(); + + /** + * + * @return + */ + DateField getDailyRepetitionEndDate(); + // void setShowAddEventView(boolean showAddEventView); } @@ -381,7 +473,11 @@ private void prepareEditView() { view.getPanelYearly().hide(); view.getYearlyVariantRG().hide(); - + + view.getPanelWeekly().hide(); + + view.getPanelDaily().hide(); + view.getYearlyVariantRG().hide(); view.getMontlyVariantRG().hide(); view.getRepeatEventPeriodRG().hide(); @@ -393,6 +489,30 @@ private void prepareEditView() { view.getEventDateEndField().clear(); view.getEventDateEndField().hide(); + + view.getRadioNumberOfRepetitions().setValue(true); + view.getNumberOfRepetitions().enable(); + view.getRepetitionEndDate().disable(); + view.getNumberOfRepetitions().setValue("1"); + view.getRepetitionEndDate().setValue(new Date()); + + view.getYearlyRadioNumberOfRepetitions().setValue(true); + view.getYearlyNumberOfRepetitions().enable(); + view.getYearlyRepetitionEndDate().disable(); + view.getYearlyNumberOfRepetitions().setValue("1"); + view.getYearlyRepetitionEndDate().setValue(new Date()); + + view.getWeeklyRadioNumberOfRepetitions().setValue(true); + view.getWeeklyNumberOfRepetitions().enable(); + view.getWeeklyRepetitionEndDate().disable(); + view.getWeeklyNumberOfRepetitions().setValue("1"); + view.getWeeklyRepetitionEndDate().setValue(new Date()); + + view.getDailyRadioNumberOfRepetitions().setValue(true); + view.getDailyNumberOfRepetitions().enable(); + view.getDailyRepetitionEndDate().disable(); + view.getDailyNumberOfRepetitions().setValue("1"); + view.getDailyRepetitionEndDate().setValue(new Date()); } if(event.getDtend().getDate() - event.getDtstart().getDate() == 1){ view.getAllDayCheckbox().setValue(true); @@ -428,6 +548,9 @@ private void prepareAddView() { view.getPanelMonthly().hide(); view.getPanelYearly().hide(); view.getPanelWeekly().hide(); + view.getPanelDaily().hide(); + // view.getMonthlyRepSettings().hide(); + // view.getYearlyRepSettings().hide(); } view.getEventStartTimeField().show(); view.getEventEndTimeField().show(); @@ -440,7 +563,19 @@ private void prepareAddView() { view.getYearlySameDayOfWeekRB().enable(); view.getRadioMonthlySameDate().enable(); view.getRadioMonthlySameDayOfWeek().enable(); - + + view.getRepeatMultiEventPeriodRG().enable(); + view.getRadioNumberOfRepetitions().enable(); + view.getRadioRepetitionEndDate().enable(); + view.getNumberOfRepetitions().enable(); + view.getRepetitionEndDate().enable(); + + view.getRepeatMultiEventPeriodRG().show(); + view.getRadioNumberOfRepetitions().show(); + view.getRadioRepetitionEndDate().show(); + view.getNumberOfRepetitions().show(); + view.getRepetitionEndDate().show(); + view.getYearlyVariantRG().show(); view.getMontlyVariantRG().show(); view.getRepeatEventPeriodRG().show(); @@ -453,6 +588,30 @@ private void prepareAddView() { view.getAllDayCheckbox().setValue(true); view.getEventStartTimeField().hide(); view.getEventEndTimeField().hide(); + + view.getRadioNumberOfRepetitions().setValue(true); + view.getNumberOfRepetitions().enable(); + view.getRepetitionEndDate().disable(); + view.getNumberOfRepetitions().setValue("1"); + view.getRepetitionEndDate().setValue(new Date()); + + view.getYearlyRadioNumberOfRepetitions().setValue(true); + view.getYearlyNumberOfRepetitions().enable(); + view.getYearlyRepetitionEndDate().disable(); + view.getYearlyNumberOfRepetitions().setValue("1"); + view.getYearlyRepetitionEndDate().setValue(new Date()); + + view.getWeeklyRadioNumberOfRepetitions().setValue(true); + view.getWeeklyNumberOfRepetitions().enable(); + view.getWeeklyRepetitionEndDate().disable(); + view.getWeeklyNumberOfRepetitions().setValue("1"); + view.getWeeklyRepetitionEndDate().setValue(new Date()); + + view.getDailyRadioNumberOfRepetitions().setValue(true); + view.getDailyNumberOfRepetitions().enable(); + view.getDailyRepetitionEndDate().disable(); + view.getDailyNumberOfRepetitions().setValue("1"); + view.getDailyRepetitionEndDate().setValue(new Date()); } // --------------------------------------------------------------------------------------------------------------- @@ -486,7 +645,9 @@ private void onSaveAction() { if (endEventIntervalDate == null) { endEventIntervalDate = beginEventIntervalDate; } - +//Window.alert("Date start: " +beginEventIntervalDate.getYear()+"." +beginEventIntervalDate.getMonth() + // + "." + beginEventIntervalDate.getDate() + " | Date end: " +endEventIntervalDate.getYear()+"." +endEventIntervalDate.getMonth() + // + "." + endEventIntervalDate.getDate());//temp for checker Boolean isFullDayEvent = view.getAllDayCheckbox().getValue(); // Window.alert("isAllDayEvent=" + isFullDayEvent);//temp for checker @@ -528,17 +689,51 @@ private void processAddEvent(Date endEventIntervalDate, final Date beginEventInt Boolean isMonthlySameDayOfWeek = view.getRadioMonthlySameDayOfWeek().getValue(); Boolean isYearlySameDayOfWeek = view.getYearlySameDayOfWeekRB().getValue(); - + // Date endEventIntervalDate = (view.getEventDateEndField() != null ? view.getEventDateEndField().getValue() : null); + Date endEventIntervalDateRadio=view.getEventDateStartField().getValue(); + if (isDailyRepeatEvent) { - processDailyEvents(diffInMilis, milisPerDay, beginEventIntervalDate, startDate, endDate, properties, eventSummary, eventDescription); + long count=0; + long lengthDailyEvent=((endEventIntervalDate.getTime()-beginEventIntervalDate.getTime())/milisPerDay)+1; + if(view.getDailyRadioNumberOfRepetitions().getValue() == true){ + count = parseInt(view.getDailyNumberOfRepetitions().getValue()); + Window.alert("Count1 = "+count); + } + else{ + endEventIntervalDateRadio = view.getDailyRepetitionEndDate().getValue(); + count = (((endEventIntervalDateRadio.getTime() - beginEventIntervalDate.getTime())/milisPerDay)+1)/lengthDailyEvent; + } + diffInMilis = endEventIntervalDateRadio.getTime() - beginEventIntervalDate.getTime(); + if(count==0) count=1; + Window.alert("Count2 = "+count); + processDailyEvents(count,lengthDailyEvent, milisPerDay, beginEventIntervalDate, endEventIntervalDateRadio, endEventIntervalDate, startDate, endDate, properties, eventSummary, eventDescription); } else if (isWeeklyRepeatEvent) { - processWeeklyEvents(diffInMilis, milisPerWeek, beginEventIntervalDate, startDate, endDate, properties, eventSummary, eventDescription); + if(view.getWeeklyRadioNumberOfRepetitions().getValue() == true){ + endEventIntervalDateRadio.setDate(beginEventIntervalDate.getDate() + parseInt(view.getWeeklyNumberOfRepetitions().getValue())*7); + } + else{ + endEventIntervalDateRadio = view.getWeeklyRepetitionEndDate().getValue(); + } + diffInMilis = endEventIntervalDateRadio.getTime() - beginEventIntervalDate.getTime(); + processWeeklyEvents(beginEventIntervalDate,endEventIntervalDate, endEventIntervalDateRadio, startDate, endDate, properties, eventSummary, eventDescription); } else if (isMonthlyRepeatEvent) { - processMonthlyEvents(beginEventIntervalDate, endEventIntervalDate, properties, isMonthlySameDayOfWeek, startDate, endDate, eventSummary, eventDescription); + if(view.getRadioNumberOfRepetitions().getValue() == true){ + endEventIntervalDateRadio.setMonth(beginEventIntervalDate.getMonth() + parseInt(view.getNumberOfRepetitions().getValue())); + } + else{ + endEventIntervalDateRadio = view.getRepetitionEndDate().getValue(); + } + processMonthlyEvents(beginEventIntervalDate, endEventIntervalDate, endEventIntervalDateRadio, properties, isMonthlySameDayOfWeek, startDate, endDate, eventSummary, eventDescription); } else if (isYearlyRepeatEvent) { - processYearEvents(beginEventIntervalDate, endEventIntervalDate, properties, isYearlySameDayOfWeek, startDate, endDate, eventSummary, eventDescription); + if(view.getYearlyRadioNumberOfRepetitions().getValue() == true){ + endEventIntervalDateRadio.setYear(beginEventIntervalDate.getYear() + parseInt(view.getYearlyNumberOfRepetitions().getValue())); + } + else{ + endEventIntervalDateRadio = view.getYearlyRepetitionEndDate().getValue(); + } + processYearEvents(beginEventIntervalDate, endEventIntervalDate, endEventIntervalDateRadio, properties, isYearlySameDayOfWeek, startDate, endDate, eventSummary, eventDescription); } else { - processOnceEvent(startDate, endDate, properties, eventSummary, eventDescription); + processOnceEvent(beginEventIntervalDate, diffInMilis, milisPerDay, startDate, endDate, properties, eventSummary, eventDescription); } } @@ -590,12 +785,74 @@ private Date createEndDateProperty(Boolean isFulllDayEvent, final Date beginEven return endDate; } - private void processOnceEvent(final Date startDate, final Date endDate, final Map properties, String eventSummary, String eventDescription) { + private void processOnceEvent(final Date beginEventIntervalDate1, long diffInMilis, long milisPerDay, final Date startDate, final Date endDate, final Map properties, String eventSummary, String eventDescription) { + long daysDiff = diffInMilis / milisPerDay + 1; + long beginEventIntervalDate = beginEventIntervalDate1.getTime(); properties.put(Event.SUMMARY, (String) properties.get(Event.SUMMARY)); properties.put(Event.DESCRIPTION, (String) properties.get(Event.DESCRIPTION)); - addPersonalEvent(properties); + // Window.alert("DaysDiff = "+daysDiff); + if(daysDiff == 1) addPersonalEvent(properties); + else{ + properties.put(Event.SUMMARY, (String) properties.get(Event.SUMMARY) + " (Once event 1 of " + daysDiff + ")"); + properties.put(Event.DESCRIPTION, (String) properties.get(Event.DESCRIPTION) + " (Once event 1 of " + daysDiff + ")"); + properties.put(Event.EVENT_TYPE, "O"); + addPersonalEventOnce(properties, daysDiff, beginEventIntervalDate, milisPerDay, startDate, endDate, eventSummary, eventDescription); + + + } + } + private void addPersonalEventOnce(final Map properties, final long daysInterval, final long calBeginNextEventDateLong, final long milisPerDay, final Date startDate, final Date endDate, final String eventSummary, final String eventDescription) { + + final CreateEntity createEntity = new CreateEntity(PersonalEventDTO.ENTITY_NAME, properties); + + dispatch.execute(createEntity, new CommandResultHandler() { + + @Override + public void onCommandFailure(final Throwable caught) { + processAddEventError(caught); + } + + @Override + public void onCommandSuccess(final CreateResult result) { + + // Creating events. + final Event event = new Event(); + event.setIdentifier((Integer) result.getEntity().getId()); + properties.put(Event.REFERENCE_ID, (Integer) result.getEntity().getId()); + updateEvent(event, properties); + addOnceSeriesEvent((Integer) result.getEntity().getId(), daysInterval, calBeginNextEventDateLong, milisPerDay, startDate, endDate, eventSummary, eventDescription); + } + }, view.getCancelButton(), view.getSaveButton()); } + + private void addOnceSeriesEvent(Integer ids, long daysInterval, long calBeginNextEventDateLong, long milisPerDay, final Date startDate, final Date endDate, String eventSummary, String eventDescription) { + //Date calBeginNextEventDate; + + for (int i = 1; i < daysInterval; i++) { + + calBeginNextEventDateLong += milisPerDay; + //calBeginNextEventDate = new Date(calBeginNextEventDateLong); + + Map dailyProperties = new HashMap(); + dailyProperties.put(Event.CALENDAR_ID, calendarWrapper); + dailyProperties.put(Event.SUMMARY, view.getEventSummaryField().getValue()); + dailyProperties.put(Event.DATE, new Date(calBeginNextEventDateLong)); + + setFullDayEvent(startDate, endDate, new Date(calBeginNextEventDateLong), dailyProperties); + + String newSummary = eventSummary; + String newDescription = eventDescription; + newSummary += " (Once event " + (i + 1) + " of " + daysInterval + ")"; + newDescription += " (Once event " + (i + 1) + " of " + daysInterval + ")"; + dailyProperties.put(Event.SUMMARY, newSummary); + dailyProperties.put(Event.DESCRIPTION, newDescription); + dailyProperties.put(Event.EVENT_TYPE, "O"); + dailyProperties.put(Event.REFERENCE_ID, ids); + + addPersonalEvent(dailyProperties); + } + } /** * Add new Daily calendar events processing. * @@ -608,40 +865,21 @@ private void processOnceEvent(final Date startDate, final Date endDate, final Ma * @param eventSummary the value of eventSummary * @param eventDescription the value of eventDescription */ - private void processDailyEvents(long diffInMilis, long milisPerDay, final Date beginEventIntervalDate, final Date startDate, final Date endDate, final Map properties, String eventSummary, String eventDescription) { - int daysInterval = 0; - long daysDiff = diffInMilis / milisPerDay + 1; - daysInterval = (int) daysDiff; - + private void processDailyEvents(long count, long lengthDailyEvent, long milisPerDay, final Date beginEventIntervalDate, final Date endEventIntervalDateRadio, final Date endEventIntervalDate, final Date startDate, final Date endDate, final Map properties, String eventSummary, String eventDescription) { long calBeginNextEventDateLong = beginEventIntervalDate.getTime(); //Date calBeginNextEventDate = beginEventIntervalDate; - if (daysInterval > 1) { - properties.put(Event.SUMMARY, (String) properties.get(Event.SUMMARY) + " ( 1 of " + daysInterval + ")"); - properties.put(Event.DESCRIPTION, (String) properties.get(Event.DESCRIPTION) + " (Daily event 1 of " + daysInterval + ")"); - properties.put(Event.EVENT_TYPE, "D"); - } - addPersonalEventDaily(properties, daysInterval, calBeginNextEventDateLong, milisPerDay, startDate, endDate, eventSummary, eventDescription); - - } - - private void processDailyEventsNew(int daysInterval, long milisPerDay, final Date beginEventIntervalDate, final Date startDate, final Date endDate, final Map properties, String eventSummary, String eventDescription) { - long calBeginNextEventDateLong = beginEventIntervalDate.getTime(); - //Date calBeginNextEventDate = beginEventIntervalDate; + properties.put(Event.SUMMARY, (String) properties.get(Event.SUMMARY) + " (Daily event 1 of " + count + ")"); + properties.put(Event.DESCRIPTION, (String) properties.get(Event.DESCRIPTION) + " (Daily event 1 of " + count + ")"); + properties.put(Event.EVENT_TYPE, "D"); -// if (daysInterval > 1) { -// properties.put(Event.SUMMARY, (String) properties.get(Event.SUMMARY) + " ( 1 of " + daysInterval + ")"); -// properties.put(Event.DESCRIPTION, (String) properties.get(Event.DESCRIPTION) + " (Daily event 1 of " + daysInterval + ")"); -// properties.put(Event.EVENT_TYPE, "D"); -// } - addPersonalEventDaily(properties, daysInterval, calBeginNextEventDateLong, milisPerDay, startDate, endDate, eventSummary, eventDescription); + addPersonalEventDaily(properties, count, lengthDailyEvent, calBeginNextEventDateLong, milisPerDay, startDate, endDate, eventSummary, eventDescription); } - - + - private void addPersonalEventDaily(final Map properties, final int daysInterval, final long calBeginNextEventDateLong, final long milisPerDay, final Date startDate, final Date endDate, final String eventSummary, final String eventDescription) { + private void addPersonalEventDaily(final Map properties, final long daysInterval,final long lengthDailyEvent, final long calBeginNextEventDateLong, final long milisPerDay, final Date startDate, final Date endDate, final String eventSummary, final String eventDescription) { final CreateEntity createEntity = new CreateEntity(PersonalEventDTO.ENTITY_NAME, properties); @@ -660,11 +898,42 @@ public void onCommandSuccess(final CreateResult result) { event.setIdentifier((Integer) result.getEntity().getId()); properties.put(Event.REFERENCE_ID, (Integer) result.getEntity().getId()); updateEvent(event, properties); - addDailySeriesEvent((Integer) result.getEntity().getId(), daysInterval, calBeginNextEventDateLong, milisPerDay, startDate, endDate, eventSummary, eventDescription); + addDailySeriesEvent((Integer) result.getEntity().getId(), daysInterval, lengthDailyEvent, calBeginNextEventDateLong, milisPerDay, startDate, endDate, eventSummary, eventDescription); + addDailySeriesEventNew((Integer) result.getEntity().getId(), daysInterval, lengthDailyEvent, calBeginNextEventDateLong, milisPerDay, startDate, endDate, eventSummary, eventDescription); } }, view.getCancelButton(), view.getSaveButton()); } + private void addDailySeriesEventNew(Integer ids, long daysInterval, long lengthDailyEvent, long calBeginNextEventDateLong1, long milisPerDay, final Date startDate, final Date endDate, String eventSummary, String eventDescription) { + //Date calBeginNextEventDate; + long calBeginNextEventDateLong = calBeginNextEventDateLong1; + for (int i = 0; i < daysInterval; i++) { + + for(int j=1;j dailyProperties = new HashMap(); + dailyProperties.put(Event.CALENDAR_ID, calendarWrapper); + dailyProperties.put(Event.SUMMARY, view.getEventSummaryField().getValue()); + + dailyProperties.put(Event.DATE, new Date(calBeginNextEventDateLong)); + + setFullDayEvent(startDate, endDate, new Date(calBeginNextEventDateLong), dailyProperties); + String newSummary = eventSummary; + String newDescription = eventDescription; + newSummary += " (Daily event " + (i + 1) + " of " + daysInterval + ")"; + newDescription += " (Daily event " + (i + 1) + " of " + daysInterval + ")"; + dailyProperties.put(Event.SUMMARY, newSummary); + dailyProperties.put(Event.DESCRIPTION, newDescription); + dailyProperties.put(Event.EVENT_TYPE, "D"); + dailyProperties.put(Event.REFERENCE_ID, ids); + + addPersonalEvent(dailyProperties); + } + calBeginNextEventDateLong += milisPerDay; + } + } private void processAddEventError(final Throwable caught) { if (Log.isErrorEnabled()) { Log.error(I18N.CONSTANTS.calendarAddEventError(), caught); @@ -672,12 +941,12 @@ private void processAddEventError(final Throwable caught) { N10N.error(I18N.CONSTANTS.error(), I18N.CONSTANTS.calendarAddEventError()); } - private void addDailySeriesEvent(Integer ids, int daysInterval, long calBeginNextEventDateLong, long milisPerDay, final Date startDate, final Date endDate, String eventSummary, String eventDescription) { + private void addDailySeriesEvent(Integer ids, long daysInterval, long lengthDailyEvent, long calBeginNextEventDateLong1, long milisPerDay, final Date startDate, final Date endDate, String eventSummary, String eventDescription) { //Date calBeginNextEventDate; - + long calBeginNextEventDateLong = calBeginNextEventDateLong1; for (int i = 1; i < daysInterval; i++) { - calBeginNextEventDateLong += milisPerDay; + calBeginNextEventDateLong += (milisPerDay*lengthDailyEvent); //calBeginNextEventDate = new Date(calBeginNextEventDateLong); Map dailyProperties = new HashMap(); @@ -713,11 +982,15 @@ private void addDailySeriesEvent(Integer ids, int daysInterval, long calBeginNex * @param eventSummary the value of eventSummary * @param eventDescription the value of eventDescription */ - private void processWeeklyEvents(long diffInMilis, long milisPerWeek, final Date beginEventIntervalDate, final Date startDate, final Date endDate, final Map properties, String eventSummary, String eventDescription) { - long weekDiff = diffInMilis / milisPerWeek + 1; + private void processWeeklyEvents(final Date beginEventIntervalDate, final Date endEventIntervalDate, final Date endEventIntervalDateRadio, final Date startDate, final Date endDate, final Map properties, String eventSummary, String eventDescription) { + long milisPerDay = 86400000; + long weekDiff = ((endEventIntervalDateRadio.getTime() - beginEventIntervalDate.getTime()+milisPerDay) / (milisPerDay*7)); int weeksInterval = (int) weekDiff; - + if(weeksInterval == 0) weeksInterval = 1; + // if(view.getWeeklyRadioNumberOfRepetitions().getValue() == true) weeksInterval--; long calBeginNextEventDateLong = beginEventIntervalDate.getTime(); + long daysInterval = ((endEventIntervalDate.getTime() - beginEventIntervalDate.getTime())/milisPerDay)+1; + Window.alert("WeeksInterva = "+weekDiff+" | daysInterval = "+daysInterval); //Date calBeginNextEventDate = beginEventIntervalDate; // if (weeksInterval > 1) { @@ -725,13 +998,11 @@ private void processWeeklyEvents(long diffInMilis, long milisPerWeek, final Date properties.put(Event.DESCRIPTION, (String) properties.get(Event.DESCRIPTION) + " (Weekly event 1 of " + weeksInterval + ")"); properties.put(Event.EVENT_TYPE, "W"); //} - addPersonalEventWeekly(properties, weeksInterval, calBeginNextEventDateLong, milisPerWeek, startDate, endDate, eventSummary, eventDescription); + addPersonalEventWeekly(properties, weeksInterval, calBeginNextEventDateLong,daysInterval, startDate, endDate, eventSummary, eventDescription); } -int evLen=3; -int []count = new int[100]; - private void addPersonalEventWeekly(final Map properties, final int weeksInterval, final long calBeginNextEventDateLong, final long milisPerDay, final Date startDate, final Date endDate, final String eventSummary, final String eventDescription) { + private void addPersonalEventWeekly(final Map properties, final int weeksInterval, final long calBeginNextEventDateLong, final long daysInterval, final Date startDate, final Date endDate, final String eventSummary, final String eventDescription) { final CreateEntity createEntity = new CreateEntity(PersonalEventDTO.ENTITY_NAME, properties); @@ -751,18 +1022,16 @@ public void onCommandSuccess(final CreateResult result) { event.setIdentifier((Integer) result.getEntity().getId()); updateEvent(event, properties); properties.put(Event.REFERENCE_ID, (Integer) result.getEntity().getId()); - int daysInterval=0; - daysInterval = Integer.parseInt(view.getListBoxWeekly().getItemText(view.getListBoxWeekly().getSelectedIndex())); - addDailySeriesEventNew2((Integer)properties.get(Event.REFERENCE_ID), weeksInterval, calBeginNextEventDateLong, milisPerDay, startDate, endDate, eventSummary, eventDescription); + long milisPerDay = 86400000; + addDailySeriesEventNew2((Integer)properties.get(Event.REFERENCE_ID), weeksInterval, calBeginNextEventDateLong, milisPerDay*7, startDate, endDate, eventSummary, eventDescription); addWeeklySeriesEvent(properties, (String) result.getEntity().getId(), daysInterval, weeksInterval, calBeginNextEventDateLong, milisPerDay, startDate, endDate, eventSummary, eventDescription); } }, view.getCancelButton(), view.getSaveButton()); } - private void addWeeklySeriesEvent(final Map properties, String ids, int daysInterval, int weeksInterval, long calBeginNextEventDateLong, long milisPerWeek, final Date startDate, final Date endDate, String eventSummary, String eventDescription) { + private void addWeeklySeriesEvent(final Map properties, String ids, long daysInterval, int weeksInterval, long calBeginNextEventDateLong, long milisPerDay, final Date startDate, final Date endDate, String eventSummary, String eventDescription) { for (int i = 0; i < weeksInterval; i++) { - long milisPerDay = 86400000; Map weeklyProperties = new HashMap(); weeklyProperties.put(Event.CALENDAR_ID, calendarWrapper); @@ -773,15 +1042,15 @@ private void addWeeklySeriesEvent(final Map properties, St // addPersonalEvent(weeklyProperties); addDailySeriesEventNew((Integer)properties.get(Event.REFERENCE_ID), daysInterval, calBeginNextEventDateLong, milisPerDay, startDate, endDate, eventSummary, eventDescription, i, weeksInterval); - calBeginNextEventDateLong += milisPerWeek; + calBeginNextEventDateLong += (milisPerDay*7); } } - private void addDailySeriesEventNew2(Integer ids, int daysInterval, long calBeginNextEventDateLong, long milisPerDay, final Date startDate, final Date endDate, String eventSummary, String eventDescription) { + private void addDailySeriesEventNew2(Integer ids, int daysInterval, long calBeginNextEventDateLong, long milisPerWeek, final Date startDate, final Date endDate, String eventSummary, String eventDescription) { //Date calBeginNextEventDate; for (int i = 1; i < daysInterval; i++) { - calBeginNextEventDateLong += milisPerDay; + calBeginNextEventDateLong += milisPerWeek; //calBeginNextEventDate = new Date(calBeginNextEventDateLong); Map dailyProperties = new HashMap(); @@ -804,7 +1073,7 @@ private void addDailySeriesEventNew2(Integer ids, int daysInterval, long calBegi addPersonalEvent(dailyProperties); } } - private void addDailySeriesEventNew(Integer ids, int daysInterval, long calBeginNextEventDateLong, long milisPerDay, final Date startDate, final Date endDate, String eventSummary, String eventDescription, final int j, final int weeksInterval) { + private void addDailySeriesEventNew(Integer ids, long daysInterval, long calBeginNextEventDateLong, long milisPerDay, final Date startDate, final Date endDate, String eventSummary, String eventDescription, final int j, final int weeksInterval) { //Date calBeginNextEventDate; for (int i = 1; i < daysInterval; i++) { @@ -871,7 +1140,10 @@ private void setFullDayEvent(final Date startDate, final Date endDate, Date calB * @param eventSummary the value of eventSummary * @param eventDescription the value of eventDescription */ - private void processMonthlyEvents(final Date beginEventIntervalDate, final Date endEventIntervalDate, final Map properties, Boolean isMonthlySameDayOfWeek, final Date startDate, final Date endDate, String eventSummary, String eventDescription) { + private void processMonthlyEvents(final Date beginEventIntervalDate, Date endEventIntervalDate, final Date endEventIntervalDateRadio, final Map properties, Boolean isMonthlySameDayOfWeek, final Date startDate, final Date endDate, String eventSummary, String eventDescription) { + long milisDiff =endEventIntervalDate.getTime() - beginEventIntervalDate.getTime(); + endEventIntervalDate = endEventIntervalDateRadio; + // Window.alert(beginEventIntervalDate1.getDate() + "."+beginEventIntervalDate1.getMonth()+"."+beginEventIntervalDate1.getYear()+" | "+ endEventIntervalDate1.getDate()+"."+endEventIntervalDate1.getMonth()+"."+endEventIntervalDate1.getYear()); int yearStart = beginEventIntervalDate.getYear(); int yearEnd = endEventIntervalDate.getYear(); int yearInterval = yearEnd - yearStart; @@ -884,7 +1156,7 @@ private void processMonthlyEvents(final Date beginEventIntervalDate, final Date } else { monthInterval = monthEnd - monthStart + 1; } - + if(view.getRadioNumberOfRepetitions().getValue() == true) monthInterval--; properties.put(Event.SUMMARY, (String) properties.get(Event.SUMMARY) + " (Monthly event 1 of " + monthInterval + ")"); properties.put(Event.DESCRIPTION, (String) properties.get(Event.DESCRIPTION) + " (Monthly event 1 of " + monthInterval + ")"); if (isMonthlySameDayOfWeek) { @@ -892,13 +1164,17 @@ private void processMonthlyEvents(final Date beginEventIntervalDate, final Date } else { properties.put(Event.EVENT_TYPE, "M2"); } + //addPersonalEventMonthly(properties, monthInterval, beginEventIntervalDate, endEventIntervalDate, startDate, endDate, eventSummary, eventDescription, isMonthlySameDayOfWeek); - addPersonalEventMonthly(properties, monthInterval, beginEventIntervalDate, startDate, endDate, eventSummary, eventDescription, isMonthlySameDayOfWeek); + //Window.alert("MultiEvent = "+beginEventIntervalDate1.getDate() + "."+beginEventIntervalDate1.getMonth()+"."+beginEventIntervalDate1.getYear()+" | "+ endEventIntervalDate1.getDate()+"."+endEventIntervalDate1.getMonth()+"."+endEventIntervalDate1.getYear()); + //Window.alert("EndDateRadio = "+endEventIntervalDateRadio.getDate() + "."+endEventIntervalDateRadio.getMonth()+"."+endEventIntervalDateRadio.getYear()); + + addPersonalEventMonthly(properties, monthInterval, beginEventIntervalDate, milisDiff, startDate, endDate, eventSummary, eventDescription, isMonthlySameDayOfWeek); } //private void addPersonalEventMonthly(final Map properties, final int monthInterval, final Date beginEventIntervalDate, final Date endEventIntervalDate, final Date startDate, final Date endDate, final String eventSummary, final String eventDescription, final boolean isMonthlySameDayOfWeek) { - private void addPersonalEventMonthly(final Map properties, final int monthInterval, final Date beginEventIntervalDate, final Date startDate, final Date endDate, final String eventSummary, final String eventDescription, final boolean isMonthlySameDayOfWeek) { + private void addPersonalEventMonthly(final Map properties, final int monthInterval, final Date beginEventIntervalDate, final long milisDiff, final Date startDate, final Date endDate, final String eventSummary, final String eventDescription, final boolean isMonthlySameDayOfWeek) { final CreateEntity createEntity = new CreateEntity(PersonalEventDTO.ENTITY_NAME, properties); dispatch.execute(createEntity, new CommandResultHandler() { @@ -916,9 +1192,9 @@ public void onCommandSuccess(final CreateResult result) { event.setIdentifier((Integer) result.getEntity().getId()); updateEvent(event, properties); properties.put(Event.REFERENCE_ID, (Integer) result.getEntity().getId()); - int daysInterval=0; - - daysInterval = Integer.parseInt(view.getListBoxMonthly2().getItemText(view.getListBoxMonthly2().getSelectedIndex())); + long milisPerDay = 86400000; + long daysInterval = milisDiff/milisPerDay+1; + Window.alert("DaysInterval = "+daysInterval); // addDailySeriesEventNew4((Integer)properties.get(Event.REFERENCE_ID), milisPerDay*7, beginEventIntervalDate, milisPerDay, startDate, endDate, eventSummary, eventDescription); addMonthlySeriesEvent((String) result.getEntity().getId(), monthInterval, beginEventIntervalDate, startDate, endDate, eventSummary, eventDescription, isMonthlySameDayOfWeek); addMonthlySeriesEventNew((String) result.getEntity().getId(), monthInterval,daysInterval, beginEventIntervalDate, startDate, endDate, eventSummary, eventDescription, isMonthlySameDayOfWeek); @@ -1032,12 +1308,14 @@ private void addMonthlySeriesEvent(String ids, int monthInterval, Date beginEven * @param eventSummary the value of eventSummary * @param eventDescription the value of eventDescription */ - private void processYearEvents(final Date beginEventIntervalDate, final Date endEventIntervalDate, final Map properties, Boolean isYearlySameDayOfWeek, final Date startDate, final Date endDate, String eventSummary, String eventDescription) { + private void processYearEvents(final Date beginEventIntervalDate, Date endEventIntervalDate, final Date endEventIntervalDateRadio, final Map properties, Boolean isYearlySameDayOfWeek, final Date startDate, final Date endDate, String eventSummary, String eventDescription) { + long milisDiff =endEventIntervalDate.getTime() - beginEventIntervalDate.getTime(); + endEventIntervalDate = endEventIntervalDateRadio; int yearStart = beginEventIntervalDate.getYear(); int yearEnd = endEventIntervalDate.getYear(); int yearInterval = yearEnd - yearStart + 1; + if(view.getYearlyRadioNumberOfRepetitions().getValue() == true) yearInterval--; - if (yearInterval > 1) { properties.put(Event.SUMMARY, (String) properties.get(Event.SUMMARY) + " (Yearly event 1 of " + yearInterval + ")"); properties.put(Event.DESCRIPTION, (String) properties.get(Event.DESCRIPTION) + " (Yearly " + (isYearlySameDayOfWeek ? "same Day of a week " : "same Date ") + "event 1 of " + yearInterval + ")"); if (isYearlySameDayOfWeek) { @@ -1045,12 +1323,13 @@ private void processYearEvents(final Date beginEventIntervalDate, final Date end } else { properties.put(Event.EVENT_TYPE, "Y2"); } - } - addPersonalEventYearly(properties, yearInterval, beginEventIntervalDate, endEventIntervalDate, startDate, endDate, eventSummary, eventDescription, isYearlySameDayOfWeek); + + + addPersonalEventYearly(milisDiff, properties, yearInterval, beginEventIntervalDate, endEventIntervalDate, startDate, endDate, eventSummary, eventDescription, isYearlySameDayOfWeek); } - private void addPersonalEventYearly(final Map properties, final int yearInterval, final Date beginEventIntervalDate, final Date endEventIntervalDate, final Date startDate, final Date endDate, final String eventSummary, final String eventDescription, final boolean isYearlySameDayOfWeek) { + private void addPersonalEventYearly(final long milisDiff, final Map properties, final int yearInterval, final Date beginEventIntervalDate, final Date endEventIntervalDate, final Date startDate, final Date endDate, final String eventSummary, final String eventDescription, final boolean isYearlySameDayOfWeek) { final CreateEntity createEntity = new CreateEntity(PersonalEventDTO.ENTITY_NAME, properties); @@ -1068,8 +1347,8 @@ public void onCommandSuccess(final CreateResult result) { event.setIdentifier((Integer) result.getEntity().getId()); properties.put(Event.REFERENCE_ID, (Integer) result.getEntity().getId()); updateEvent(event, properties); - int daysInterval=0; - daysInterval = Integer.parseInt(view.getListBoxYearly2().getItemText(view.getListBoxYearly2().getSelectedIndex())); + long milisPerDay = 86400000; + long daysInterval = milisDiff/milisPerDay+1; addYearlySeriesEvent((String) result.getEntity().getId(), yearInterval, beginEventIntervalDate, endEventIntervalDate, startDate, endDate, eventSummary, eventDescription, isYearlySameDayOfWeek); addYearlySeriesEventNew((String) result.getEntity().getId(), yearInterval,daysInterval, beginEventIntervalDate, startDate, endDate, eventSummary, eventDescription, isYearlySameDayOfWeek); diff --git a/src/main/java/org/sigmah/client/ui/view/calendar/CalendarEventView.java b/src/main/java/org/sigmah/client/ui/view/calendar/CalendarEventView.java index 753533068..4cacd7524 100644 --- a/src/main/java/org/sigmah/client/ui/view/calendar/CalendarEventView.java +++ b/src/main/java/org/sigmah/client/ui/view/calendar/CalendarEventView.java @@ -26,6 +26,7 @@ import com.extjs.gxt.ui.client.event.Events; import com.extjs.gxt.ui.client.event.FieldEvent; import com.extjs.gxt.ui.client.event.Listener; +import com.extjs.gxt.ui.client.store.Store; import org.sigmah.client.i18n.I18N; import org.sigmah.client.ui.presenter.calendar.CalendarEventPresenter; import org.sigmah.client.ui.res.icon.IconImageBundle; @@ -50,7 +51,37 @@ import com.google.gwt.user.client.Window; import com.google.gwt.user.client.ui.ListBox; import com.google.inject.Singleton; - +import com.google.gwt.core.client.EntryPoint; +import com.google.gwt.event.dom.client.ChangeHandler; +import com.google.gwt.user.client.ui.RootPanel; +import java.util.HashMap; +import java.util.Map; +import com.extjs.gxt.ui.client.data.BaseModelData; +import java.util.ArrayList; +import java.util.List; + +import com.extjs.gxt.ui.client.data.BaseModelData; +import com.extjs.gxt.ui.client.store.ListStore; +import com.extjs.gxt.ui.client.widget.HorizontalPanel; +import com.extjs.gxt.ui.client.widget.LayoutContainer; +import com.extjs.gxt.ui.client.widget.VerticalPanel; +import com.extjs.gxt.ui.client.widget.form.ComboBox; +import com.extjs.gxt.ui.client.widget.form.ComboBox.TriggerAction; +import com.google.gwt.core.client.EntryPoint; +import com.google.gwt.user.client.Element; +import com.google.gwt.user.client.Random; +import com.google.gwt.user.client.ui.HTML; +import com.google.gwt.user.client.ui.RootPanel; +import java.util.Date; +/* +import com.gwtext.client.data.Record; +import com.gwtext.client.data.SimpleStore; +import com.gwtext.client.data.Store; +import com.gwtext.client.widgets.Panel; +import com.gwtext.client.widgets.form.ComboBox; +import com.gwtext.client.widgets.form.FormPanel; +import com.gwtext.client.widgets.form.event.ComboBoxListenerAdapter; +*/ /** * Calendar event edit frame view used to create/edit a calendar event. * @@ -76,6 +107,9 @@ public class CalendarEventView extends AbstractPopupView implements private FieldSet panelYearly; private FieldSet panelMonthly; private FieldSet panelWeekly; + private FieldSet panelDaily; + private FieldSet monthlyRepSettings; + private FieldSet yearlyRepSettings; private Radio yearlySameDayOfWeekRB; private Radio yearlySameDateRB; @@ -87,16 +121,31 @@ public class CalendarEventView extends AbstractPopupView implements private Radio yearlyRepeatRB; private Radio radioMonthlySameDate; private Radio radioMonthlySameDayOfWeek; + private Radio radioNumberOfRepetitions; + private Radio radioRepetitionEndDate; + + private Radio radioWeeklyNumberOfRepetitions; + private Radio radioWeeklyRepetitionEndDate; + private Radio radioYearlyNumberOfRepetitions; + private Radio radioYearlyRepetitionEndDate; + private Radio radioDailyNumberOfRepetitions; + private Radio radioDailyRepetitionEndDate; - private ListBox listBoxWeekly; - private ListBox listBoxMonthly1; - private ListBox listBoxMonthly2; - private ListBox listBoxYearly1; - private ListBox listBoxYearly2; + private DateField repetitionEndDate; + private TextArea numberOfRepetitions; + private DateField dailyRepetitionEndDate; + private TextArea dailyNumberOfRepetitions; + private DateField weeklyRepetitionEndDate; + private TextArea weeklyNumberOfRepetitions; + private DateField yearlyRepetitionEndDate; + private TextArea yearlyNumberOfRepetitions; // private CheckBoxGroup allDayCheckboxGr; private RadioGroup RepeatEventPeriodRG; - + private RadioGroup RepeatMultiEventPeriodRG; + private RadioGroup RepeatYearlyMultiEventPeriodRG; + private RadioGroup RepeatWeeklyMultiEventPeriodRG; + private RadioGroup RepeatDailyMultiEventPeriodRG; /** * Builds the view. */ @@ -114,13 +163,9 @@ public void initialize() { createYearlyPanel(); createMonthlyPanel(); createWeeklyPanel(); + createDailyPanel(); createRepeatEventPeriodRadioGroup(); - - listBoxWeekly.setName("listBoxWeekly"); - listBoxMonthly1.setName("listBoxMonthly1"); - listBoxMonthly2.setName("listBoxMonthly2"); - listBoxYearly1.setName("listBoxYearly1"); - listBoxYearly2.setName("listBoxYearly2"); + eventSummaryField = Forms.text(I18N.CONSTANTS.calendarEventObject(), true); eventSummaryField.setName(Event.SUMMARY); @@ -158,6 +203,7 @@ public void initialize() { form.add(panelYearly); form.add(panelMonthly); form.add(panelWeekly); + form.add(panelDaily); form.add(eventDescriptionField); form.addButton(cancelButton); @@ -211,7 +257,8 @@ public void handleEvent(FieldEvent event) { getPanelYearly().setVisible(getYearlyRepeatRB().getValue()); getPanelWeekly().setVisible(!yearlyRepeatRB.getValue()); getPanelMonthly().setVisible(!yearlyRepeatRB.getValue()); - + getPanelDaily().setVisible(!yearlyRepeatRB.getValue()); + getYearlySameDateRB().show(); getYearlySameDayOfWeekRB().show(); getYearlySameDateRB().setValue(true); @@ -229,6 +276,7 @@ public void handleEvent(FieldEvent event) { ((TextArea) form.getItemByItemId(Event.DESCRIPTION)).setValue(I18N.CONSTANTS.calendar_addEvent_description_textArea_monthly()); getPanelWeekly().setVisible(!monthlyRepeatRB.getValue()); getPanelYearly().setVisible(!monthlyRepeatRB.getValue()); + getPanelDaily().setVisible(!monthlyRepeatRB.getValue()); getPanelMonthly().setVisible(getMonthlyRepeatRB().getValue()); eventDateStartField.setAllowBlank(false); getRadioMonthlySameDate().show(); @@ -247,8 +295,9 @@ public void handleEvent(FieldEvent event) { ((TextArea) form.getItemByItemId(Event.DESCRIPTION)).setValue(I18N.CONSTANTS.calendar_addEvent_description_textArea_weekly()); getPanelYearly().setVisible(!weeklyRepeatRB.getValue()); getPanelMonthly().setVisible(!weeklyRepeatRB.getValue()); + getPanelDaily().setVisible(!weeklyRepeatRB.getValue()); getPanelWeekly().setVisible(getWeeklyRepeatRB().getValue()); - Window.alert("Test"); + // Window.alert("Test"); eventDateStartField.setAllowBlank(false); } }); @@ -266,6 +315,7 @@ public void handleEvent(FieldEvent event) { getPanelYearly().setVisible(!dailyRepeatRB.getValue()); getPanelMonthly().setVisible(!dailyRepeatRB.getValue()); getPanelWeekly().setVisible(!dailyRepeatRB.getValue()); + getPanelDaily().setVisible(getDailyRepeatRB().getValue()); } }); } @@ -282,24 +332,148 @@ public void handleEvent(FieldEvent event) { getPanelYearly().setVisible(!onceRepeatRB.getValue()); getPanelMonthly().setVisible(!onceRepeatRB.getValue()); getPanelWeekly().setVisible(!onceRepeatRB.getValue()); + getPanelDaily().setVisible(!onceRepeatRB.getValue()); ((TextArea) form.getItemByItemId(Event.DESCRIPTION)).setValue(I18N.CONSTANTS.calendar_addEvent_description_textArea_once()); } }); } + + + private void createDailyPanel() { + panelDaily = new FieldSet(); + panelDaily.setExpanded(true); + panelDaily.setBorders(true); + panelDaily.setHeadingHtml("End of daily repetition event"); + panelDaily.setAutoHeight(true); + panelDaily.setVisible(false); + + radioDailyNumberOfRepetitions = Forms.radio("Number of repetitions"); + radioDailyNumberOfRepetitions.setName("Number of repetitonsYearly"); + radioDailyNumberOfRepetitions.setValue(Boolean.FALSE); + radioDailyNumberOfRepetitions.setOriginalValue(Boolean.FALSE); + radioDailyNumberOfRepetitions.setToolTip("Set a number of repetitons (Yearly)"); + + dailyNumberOfRepetitions = Forms.textarea("", false); + dailyNumberOfRepetitions.setName("numberOfRepetitionsyearly"); + dailyNumberOfRepetitions.setId("numberOfRepetitionsyearly"); + dailyNumberOfRepetitions.setMaxLength(255); + dailyNumberOfRepetitions.setHeight(19); + + radioDailyRepetitionEndDate = Forms.radio("Repetition end date"); + radioDailyRepetitionEndDate.setBoxLabel("Repetition end date"); + radioDailyRepetitionEndDate.setName("Repetition end dateyearly"); + radioDailyRepetitionEndDate.setValue(Boolean.FALSE); + radioDailyRepetitionEndDate.setToolTip("Set a repetition end date"); + + dailyRepetitionEndDate = Forms.date("", true); + dailyRepetitionEndDate.setName("RepetitionEndDateFieldyearly"); + dailyNumberOfRepetitions.disable(); + dailyRepetitionEndDate.disable(); + + radioDailyNumberOfRepetitions.addListener(Events.OnChange, new Listener() { + @Override + public void handleEvent(FieldEvent event) { + dailyNumberOfRepetitions.enable(); + dailyRepetitionEndDate.disable(); + } + }); + + + radioDailyRepetitionEndDate.addListener(Events.OnChange, new Listener() { + @Override + public void handleEvent(FieldEvent event) { + + dailyRepetitionEndDate.enable(); + dailyNumberOfRepetitions.disable(); + } + }); + + RepeatDailyMultiEventPeriodRG = Forms.radioGroup("Multi-event periodRGyearly", + "Multi-event periodRGyearly", + Style.Orientation.VERTICAL, + radioDailyNumberOfRepetitions, + radioDailyRepetitionEndDate); + RepeatDailyMultiEventPeriodRG.setSelectionRequired(Boolean.TRUE); + RepeatDailyMultiEventPeriodRG.enable(); + + //panelMonthly.add(RepeatMultiEventPeriodRG); + VerticalPanel verticalPanel = new VerticalPanel(); + verticalPanel.add(dailyNumberOfRepetitions); + verticalPanel.add(dailyRepetitionEndDate); + HorizontalPanel horizontalPanel = new HorizontalPanel(); + horizontalPanel.add(RepeatDailyMultiEventPeriodRG); + horizontalPanel.add(verticalPanel); + + panelDaily.add(horizontalPanel); + } private void createWeeklyPanel() { panelWeekly = new FieldSet(); panelWeekly.setExpanded(true); panelWeekly.setBorders(true); - panelWeekly.setHeadingHtml("Weekly repeats settings"); + panelWeekly.setHeadingHtml("End of weekly repetition event"); panelWeekly.setAutoHeight(true); panelWeekly.setVisible(false); + + radioWeeklyNumberOfRepetitions = Forms.radio("Number of repetitions"); + radioWeeklyNumberOfRepetitions.setName("Number of repetitonsYearly"); + radioWeeklyNumberOfRepetitions.setValue(Boolean.FALSE); + radioWeeklyNumberOfRepetitions.setOriginalValue(Boolean.FALSE); + radioWeeklyNumberOfRepetitions.setToolTip("Set a number of repetitons"); + + weeklyNumberOfRepetitions = Forms.textarea("", false); + weeklyNumberOfRepetitions.setName("numberOfRepetitionsyearly"); + weeklyNumberOfRepetitions.setId("numberOfRepetitionsyearly"); + weeklyNumberOfRepetitions.setMaxLength(255); + weeklyNumberOfRepetitions.setHeight(19); + + radioWeeklyRepetitionEndDate = Forms.radio("Repetition end date"); + radioWeeklyRepetitionEndDate.setBoxLabel("Repetition end date"); + radioWeeklyRepetitionEndDate.setName("Repetition end dateyearly"); + radioWeeklyRepetitionEndDate.setValue(Boolean.FALSE); + radioWeeklyRepetitionEndDate.setToolTip("Set a repetition end date"); + + weeklyRepetitionEndDate = Forms.date("", true); + weeklyRepetitionEndDate.setName("RepetitionEndDateFieldyearly"); + weeklyNumberOfRepetitions.disable(); + weeklyRepetitionEndDate.disable(); + + radioWeeklyNumberOfRepetitions.addListener(Events.OnChange, new Listener() { + @Override + public void handleEvent(FieldEvent event) { + weeklyNumberOfRepetitions.enable(); + weeklyRepetitionEndDate.disable(); + } + }); + + + radioWeeklyRepetitionEndDate.addListener(Events.OnChange, new Listener() { + @Override + public void handleEvent(FieldEvent event) { - listBoxWeekly = new ListBox(); - for(int i=1;i<=7;i++) listBoxWeekly.addItem(""+i); - - panelWeekly.add(listBoxWeekly); + weeklyRepetitionEndDate.enable(); + weeklyNumberOfRepetitions.disable(); + } + }); + + RepeatWeeklyMultiEventPeriodRG = Forms.radioGroup("Multi-event periodRGyearly", + "Multi-event periodRGyearly", + Style.Orientation.VERTICAL, + radioWeeklyNumberOfRepetitions, + radioWeeklyRepetitionEndDate); + RepeatWeeklyMultiEventPeriodRG.setSelectionRequired(Boolean.TRUE); + RepeatWeeklyMultiEventPeriodRG.enable(); + + //panelMonthly.add(RepeatMultiEventPeriodRG); + VerticalPanel verticalPanel = new VerticalPanel(); + verticalPanel.add(weeklyNumberOfRepetitions); + verticalPanel.add(weeklyRepetitionEndDate); + HorizontalPanel horizontalPanel = new HorizontalPanel(); + horizontalPanel.add(RepeatWeeklyMultiEventPeriodRG); + horizontalPanel.add(verticalPanel); + + panelWeekly.add(horizontalPanel); } private void createMonthlyPanel() { @@ -329,18 +503,84 @@ private void createMonthlyPanel() { montlyVariantRG.add(radioMonthlySameDate); panelMonthly.add(montlyVariantRG); - listBoxMonthly1 = new ListBox(); - listBoxMonthly1.addItem("day(s)"); - listBoxMonthly1.addItem("week(s)"); - panelMonthly.add(listBoxMonthly1); + + + radioNumberOfRepetitions = Forms.radio("Number of repetitions"); + radioNumberOfRepetitions.setName("Number of repetitons"); + radioNumberOfRepetitions.setValue(Boolean.FALSE); + radioNumberOfRepetitions.setOriginalValue(Boolean.FALSE); + radioNumberOfRepetitions.setToolTip("Set a number of repetitions"); + + radioRepetitionEndDate = Forms.radio("Repetition end date"); + radioRepetitionEndDate.setBoxLabel("Repetition end date"); + radioRepetitionEndDate.setName("Repetition end date"); + radioRepetitionEndDate.setValue(Boolean.FALSE); + radioRepetitionEndDate.setToolTip("Set a repetition end date"); + + + RepeatMultiEventPeriodRG = Forms.radioGroup("Multi-event periodRG"); + RepeatMultiEventPeriodRG.setSelectionRequired(Boolean.FALSE); + RepeatMultiEventPeriodRG.setOrientation(Style.Orientation.VERTICAL); + RepeatMultiEventPeriodRG.add(radioNumberOfRepetitions); + RepeatMultiEventPeriodRG.add(radioRepetitionEndDate); + panelMonthly.add(RepeatMultiEventPeriodRG); + numberOfRepetitions = Forms.textarea("", false); + numberOfRepetitions.setName("numberOfRepetitions"); + numberOfRepetitions.setId("numberOfRepetitions"); + numberOfRepetitions.setMaxLength(255); + numberOfRepetitions.setHeight(19); + + repetitionEndDate = Forms.date("", true); + repetitionEndDate.setName("RepetitionEndDateField"); + repetitionEndDate.setData("", new Date()); + + radioNumberOfRepetitions.addListener(Events.OnChange, new Listener() { + @Override + public void handleEvent(FieldEvent event) { + numberOfRepetitions.enable(); + repetitionEndDate.disable(); + } + }); - listBoxMonthly2 = new ListBox(); - for(int i=1;i<=30;i++) listBoxMonthly2.addItem(""+i); - panelMonthly.add(listBoxMonthly2); + radioRepetitionEndDate.addListener(Events.OnChange, new Listener() { + @Override + public void handleEvent(FieldEvent event) { + repetitionEndDate.enable(); + numberOfRepetitions.disable(); + } + }); + + /* monthlyRepSettings = new FieldSet(); + monthlyRepSettings.setExpanded(true); + monthlyRepSettings.setBorders(true); + monthlyRepSettings.setHeadingHtml("End of monthly repetition event"); + monthlyRepSettings.setAutoHeight(true); + monthlyRepSettings.setVisible(true);*/ + + + VerticalPanel verticalPanel = new VerticalPanel(); + VerticalPanel verticalPanel1 = new VerticalPanel(); + VerticalPanel verticalPanel2 = new VerticalPanel(); + VerticalPanel verticalPanel3 = new VerticalPanel(); + verticalPanel3.setHeight(5); + verticalPanel1.add(numberOfRepetitions); + verticalPanel2.add(repetitionEndDate); + + verticalPanel.add(verticalPanel1); + verticalPanel.add(verticalPanel3); + verticalPanel.add(verticalPanel2); + + HorizontalPanel horizontalPanel = new HorizontalPanel(); + horizontalPanel.add(RepeatMultiEventPeriodRG); + horizontalPanel.add(verticalPanel); + panelMonthly.add(new HTML("
")); + panelMonthly.add(horizontalPanel); + // verticalPanel1.setHeight(verticalPanel.getHeight()/2); + //verticalPanel2.setHeight(verticalPanel.getHeight()/2); } private void createYearlyPanel() { @@ -365,20 +605,83 @@ private void createYearlyPanel() { yearlySameDayOfWeekRB, yearlySameDateRB); yearlyVariantRG.setSelectionRequired(Boolean.FALSE); - panelYearly.add(yearlyVariantRG); - listBoxYearly1 = new ListBox(); - listBoxYearly1.addItem("day(s)"); - listBoxYearly1.addItem("week(s)"); - listBoxYearly1.addItem("month(s)"); - panelYearly.add(listBoxYearly1); + radioYearlyNumberOfRepetitions = Forms.radio("Number of repetitions"); + radioYearlyNumberOfRepetitions.setName("Number of repetitionsYearly"); + radioYearlyNumberOfRepetitions.setValue(Boolean.FALSE); + radioYearlyNumberOfRepetitions.setOriginalValue(Boolean.FALSE); + radioYearlyNumberOfRepetitions.setToolTip("Set a number of repetitons"); + + yearlyNumberOfRepetitions = Forms.textarea("", false); + yearlyNumberOfRepetitions.setName("numberOfRepetitionsyearly"); + yearlyNumberOfRepetitions.setId("numberOfRepetitionsyearly"); + yearlyNumberOfRepetitions.setMaxLength(255); + yearlyNumberOfRepetitions.setHeight(19); + + radioYearlyRepetitionEndDate = Forms.radio("Repetition end date"); + radioYearlyRepetitionEndDate.setBoxLabel("Repetition end date"); + radioYearlyRepetitionEndDate.setName("Repetition end dateyearly"); + radioYearlyRepetitionEndDate.setValue(Boolean.FALSE); + radioYearlyRepetitionEndDate.setToolTip("Set a repetition end date"); + + yearlyRepetitionEndDate = Forms.date("", true); + yearlyRepetitionEndDate.setName("RepetitionEndDateFieldyearly"); + yearlyNumberOfRepetitions.disable(); + yearlyRepetitionEndDate.disable(); + + radioYearlyNumberOfRepetitions.addListener(Events.OnChange, new Listener() { + @Override + public void handleEvent(FieldEvent event) { + yearlyNumberOfRepetitions.enable(); + yearlyRepetitionEndDate.disable(); + } + }); - listBoxYearly2 = new ListBox(); - for(int i=1;i<=30;i++) listBoxYearly2.addItem(""+i); - panelYearly.add(listBoxYearly2); + radioYearlyRepetitionEndDate.addListener(Events.OnChange, new Listener() { + @Override + public void handleEvent(FieldEvent event) { + + yearlyRepetitionEndDate.enable(); + yearlyNumberOfRepetitions.disable(); + } + }); + + RepeatYearlyMultiEventPeriodRG = Forms.radioGroup("Multi-event periodRGyearly", + "Multi-event periodRGyearly", + Style.Orientation.VERTICAL, + radioYearlyNumberOfRepetitions, + radioYearlyRepetitionEndDate); + RepeatYearlyMultiEventPeriodRG.setSelectionRequired(Boolean.TRUE); + RepeatYearlyMultiEventPeriodRG.enable(); + + + //panelMonthly.add(RepeatMultiEventPeriodRG); + VerticalPanel verticalPanel = new VerticalPanel(); + + VerticalPanel verticalPanel1 = new VerticalPanel(); + VerticalPanel verticalPanel2 = new VerticalPanel(); + verticalPanel1.setHeight(23); + verticalPanel1.setWidth(150); + verticalPanel1.add(yearlyNumberOfRepetitions); + verticalPanel2.setHeight(23); + verticalPanel2.setWidth(150); + verticalPanel2.add(yearlyRepetitionEndDate); + VerticalPanel verticalPanel3 = new VerticalPanel(); + verticalPanel3.setHeight(5); + + verticalPanel.add(verticalPanel1); + verticalPanel.add(verticalPanel3); + verticalPanel.add(verticalPanel2); + + HorizontalPanel horizontalPanel = new HorizontalPanel(); + horizontalPanel.add(RepeatYearlyMultiEventPeriodRG); + horizontalPanel.add(verticalPanel); + + panelYearly.add(new HTML("
")); + panelYearly.add(horizontalPanel); } /** @@ -463,6 +766,16 @@ public FieldSet getPanelYearly() { return panelYearly; } + @Override + public FieldSet getMonthlyRepSettings() { + return monthlyRepSettings; + } + + @Override + public FieldSet getYearlyRepSettings() { + return yearlyRepSettings; + } + @Override public FieldSet getPanelMonthly() { return panelMonthly; @@ -471,8 +784,12 @@ public FieldSet getPanelMonthly() { @Override public FieldSet getPanelWeekly() { return panelWeekly; - } + } + @Override + public FieldSet getPanelDaily() { + return panelDaily; + } /** * * @return @@ -508,36 +825,15 @@ public RadioGroup getYearlyVariantRG() { } @Override - public RadioGroup getMontlyVariantRG() { - return montlyVariantRG; + public RadioGroup getRepeatMultiEventPeriodRG() { + return RepeatMultiEventPeriodRG; } - - - - @Override - public ListBox getListBoxWeekly() { - return listBoxWeekly; - } - - @Override - public ListBox getListBoxMonthly1() { - return listBoxMonthly1; - } - - @Override - public ListBox getListBoxMonthly2() { - return listBoxMonthly2; - } - @Override - public ListBox getListBoxYearly1() { - return listBoxYearly1; - } - @Override - public ListBox getListBoxYearly2() { - return listBoxYearly2; - } - + @Override + public RadioGroup getMontlyVariantRG() { + return montlyVariantRG; + } + @Override public Radio getYearlySameDayOfWeekRB() { return yearlySameDayOfWeekRB; @@ -561,4 +857,82 @@ public Radio getRadioMonthlySameDayOfWeek() { return radioMonthlySameDayOfWeek; } + @Override + public Radio getRadioNumberOfRepetitions() { + return radioNumberOfRepetitions; + } + + @Override + public Radio getRadioRepetitionEndDate() { + return radioRepetitionEndDate; + } + + @Override + public Radio getYearlyRadioNumberOfRepetitions() { + return radioYearlyNumberOfRepetitions; + } + + @Override + public Radio getYearlyRadioRepetitionEndDate() { + return radioYearlyRepetitionEndDate; + } + + @Override + public Radio getDailyRadioNumberOfRepetitions() { + return radioDailyNumberOfRepetitions; + } + + @Override + public Radio getDailyRadioRepetitionEndDate() { + return radioDailyRepetitionEndDate; + } + + @Override + public Radio getWeeklyRadioNumberOfRepetitions() { + return radioWeeklyNumberOfRepetitions; + } + + @Override + public Radio getWeeklyRadioRepetitionEndDate() { + return radioWeeklyRepetitionEndDate; + } + @Override + public TextArea getNumberOfRepetitions() { + return numberOfRepetitions; + } + + @Override + public DateField getRepetitionEndDate() { + return repetitionEndDate; + } + + @Override + public TextArea getWeeklyNumberOfRepetitions() { + return weeklyNumberOfRepetitions; + } + + @Override + public DateField getWeeklyRepetitionEndDate() { + return weeklyRepetitionEndDate; + } + + @Override + public TextArea getDailyNumberOfRepetitions() { + return dailyNumberOfRepetitions; + } + + @Override + public DateField getDailyRepetitionEndDate() { + return dailyRepetitionEndDate; + } + + @Override + public TextArea getYearlyNumberOfRepetitions() { + return yearlyNumberOfRepetitions; + } + + @Override + public DateField getYearlyRepetitionEndDate() { + return yearlyRepetitionEndDate; + } } \ No newline at end of file From 32bd9decfe9cd548cb00d6838af2980479715da8 Mon Sep 17 00:00:00 2001 From: Seal98 Date: Thu, 3 Aug 2017 22:46:57 +0300 Subject: [PATCH 26/39] (issue#852) creating events for several days Adding the event for several days into the database as a single event for several days (for Weeklt type) --- .../calendar/CalendarEventPresenter.java | 51 +++++++++++-------- .../server/service/PersonalEventService.java | 5 +- .../org/sigmah/shared/dto/calendar/Event.java | 4 +- 3 files changed, 37 insertions(+), 23 deletions(-) diff --git a/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java b/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java index 7fee6af45..d10560fc6 100644 --- a/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java +++ b/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java @@ -640,11 +640,12 @@ private void onSaveAction() { final Date beginEventIntervalDate = view.getEventDateStartField().getValue(); properties.put(Event.DATE, beginEventIntervalDate); - + Date endEventIntervalDate = (view.getEventDateEndField() != null ? view.getEventDateEndField().getValue() : null); if (endEventIntervalDate == null) { endEventIntervalDate = beginEventIntervalDate; } + properties.put(Event.DATE_END, endEventIntervalDate); //Window.alert("Date start: " +beginEventIntervalDate.getYear()+"." +beginEventIntervalDate.getMonth() // + "." + beginEventIntervalDate.getDate() + " | Date end: " +endEventIntervalDate.getYear()+"." +endEventIntervalDate.getMonth() // + "." + endEventIntervalDate.getDate());//temp for checker @@ -697,15 +698,15 @@ private void processAddEvent(Date endEventIntervalDate, final Date beginEventInt long lengthDailyEvent=((endEventIntervalDate.getTime()-beginEventIntervalDate.getTime())/milisPerDay)+1; if(view.getDailyRadioNumberOfRepetitions().getValue() == true){ count = parseInt(view.getDailyNumberOfRepetitions().getValue()); - Window.alert("Count1 = "+count); + // Window.alert("Count1 = "+count); } else{ endEventIntervalDateRadio = view.getDailyRepetitionEndDate().getValue(); count = (((endEventIntervalDateRadio.getTime() - beginEventIntervalDate.getTime())/milisPerDay)+1)/lengthDailyEvent; } diffInMilis = endEventIntervalDateRadio.getTime() - beginEventIntervalDate.getTime(); - if(count==0) count=1; - Window.alert("Count2 = "+count); + if(count<=0) count=1; + //Window.alert("Count2 = "+count); processDailyEvents(count,lengthDailyEvent, milisPerDay, beginEventIntervalDate, endEventIntervalDateRadio, endEventIntervalDate, startDate, endDate, properties, eventSummary, eventDescription); } else if (isWeeklyRepeatEvent) { if(view.getWeeklyRadioNumberOfRepetitions().getValue() == true){ @@ -899,7 +900,7 @@ public void onCommandSuccess(final CreateResult result) { properties.put(Event.REFERENCE_ID, (Integer) result.getEntity().getId()); updateEvent(event, properties); addDailySeriesEvent((Integer) result.getEntity().getId(), daysInterval, lengthDailyEvent, calBeginNextEventDateLong, milisPerDay, startDate, endDate, eventSummary, eventDescription); - addDailySeriesEventNew((Integer) result.getEntity().getId(), daysInterval, lengthDailyEvent, calBeginNextEventDateLong, milisPerDay, startDate, endDate, eventSummary, eventDescription); + // addDailySeriesEventNew((Integer) result.getEntity().getId(), daysInterval, lengthDailyEvent, calBeginNextEventDateLong, milisPerDay, startDate, endDate, eventSummary, eventDescription); } }, view.getCancelButton(), view.getSaveButton()); } @@ -947,6 +948,7 @@ private void addDailySeriesEvent(Integer ids, long daysInterval, long lengthDail for (int i = 1; i < daysInterval; i++) { calBeginNextEventDateLong += (milisPerDay*lengthDailyEvent); + long calEndNextEventDateLong = milisPerDay*(lengthDailyEvent-1); //calBeginNextEventDate = new Date(calBeginNextEventDateLong); Map dailyProperties = new HashMap(); @@ -954,7 +956,8 @@ private void addDailySeriesEvent(Integer ids, long daysInterval, long lengthDail dailyProperties.put(Event.SUMMARY, view.getEventSummaryField().getValue()); dailyProperties.put(Event.DATE, new Date(calBeginNextEventDateLong)); - + dailyProperties.put(Event.DATE_END, new Date(calEndNextEventDateLong)); + setFullDayEvent(startDate, endDate, new Date(calBeginNextEventDateLong), dailyProperties); String newSummary = eventSummary; @@ -986,23 +989,23 @@ private void processWeeklyEvents(final Date beginEventIntervalDate, final Date e long milisPerDay = 86400000; long weekDiff = ((endEventIntervalDateRadio.getTime() - beginEventIntervalDate.getTime()+milisPerDay) / (milisPerDay*7)); int weeksInterval = (int) weekDiff; - if(weeksInterval == 0) weeksInterval = 1; + if((((endEventIntervalDateRadio.getTime() - beginEventIntervalDate.getTime()+milisPerDay) % (milisPerDay*7)) >= ((endEventIntervalDate.getTime() - beginEventIntervalDate.getTime()+milisPerDay))) && (view.getWeeklyRadioNumberOfRepetitions().getValue() == true)) weeksInterval++; + if(weeksInterval <= 0) weeksInterval = 1; // if(view.getWeeklyRadioNumberOfRepetitions().getValue() == true) weeksInterval--; long calBeginNextEventDateLong = beginEventIntervalDate.getTime(); + long calEndNextEventDateLong = endEventIntervalDate.getTime(); long daysInterval = ((endEventIntervalDate.getTime() - beginEventIntervalDate.getTime())/milisPerDay)+1; - Window.alert("WeeksInterva = "+weekDiff+" | daysInterval = "+daysInterval); - //Date calBeginNextEventDate = beginEventIntervalDate; + // Window.alert("WeeksInterva = "+weekDiff+" | daysInterval = "+daysInterval); - // if (weeksInterval > 1) { properties.put(Event.SUMMARY, (String) properties.get(Event.SUMMARY) + " (Weekly event 1 of " + weeksInterval + ")"); properties.put(Event.DESCRIPTION, (String) properties.get(Event.DESCRIPTION) + " (Weekly event 1 of " + weeksInterval + ")"); properties.put(Event.EVENT_TYPE, "W"); - //} - addPersonalEventWeekly(properties, weeksInterval, calBeginNextEventDateLong,daysInterval, startDate, endDate, eventSummary, eventDescription); + if(view.getAllDayCheckbox().getValue() == false) properties.put(Event.DATE_END, new Date(calBeginNextEventDateLong)); + addPersonalEventWeekly(properties, weeksInterval, calBeginNextEventDateLong, calEndNextEventDateLong, daysInterval, startDate, endDate, eventSummary, eventDescription); } - private void addPersonalEventWeekly(final Map properties, final int weeksInterval, final long calBeginNextEventDateLong, final long daysInterval, final Date startDate, final Date endDate, final String eventSummary, final String eventDescription) { + private void addPersonalEventWeekly(final Map properties, final int weeksInterval, final long calBeginNextEventDateLong, final long calEndNextEventDateLong, final long daysInterval, final Date startDate, final Date endDate, final String eventSummary, final String eventDescription) { final CreateEntity createEntity = new CreateEntity(PersonalEventDTO.ENTITY_NAME, properties); @@ -1023,9 +1026,9 @@ public void onCommandSuccess(final CreateResult result) { updateEvent(event, properties); properties.put(Event.REFERENCE_ID, (Integer) result.getEntity().getId()); long milisPerDay = 86400000; - addDailySeriesEventNew2((Integer)properties.get(Event.REFERENCE_ID), weeksInterval, calBeginNextEventDateLong, milisPerDay*7, startDate, endDate, eventSummary, eventDescription); - - addWeeklySeriesEvent(properties, (String) result.getEntity().getId(), daysInterval, weeksInterval, calBeginNextEventDateLong, milisPerDay, startDate, endDate, eventSummary, eventDescription); + addDailySeriesEventNew2((Integer)properties.get(Event.REFERENCE_ID), weeksInterval, calBeginNextEventDateLong, calEndNextEventDateLong, milisPerDay*7, startDate, endDate, eventSummary, eventDescription); + if(view.getAllDayCheckbox().getValue() == false) addWeeklySeriesEvent(properties, (String) result.getEntity().getId(), daysInterval, weeksInterval, calBeginNextEventDateLong, milisPerDay, startDate, endDate, eventSummary, eventDescription); + // addWeeklySeriesEvent(properties, (String) result.getEntity().getId(), daysInterval, weeksInterval, calBeginNextEventDateLong, milisPerDay, startDate, endDate, eventSummary, eventDescription); } }, view.getCancelButton(), view.getSaveButton()); } @@ -1045,12 +1048,13 @@ private void addWeeklySeriesEvent(final Map properties, St calBeginNextEventDateLong += (milisPerDay*7); } } - private void addDailySeriesEventNew2(Integer ids, int daysInterval, long calBeginNextEventDateLong, long milisPerWeek, final Date startDate, final Date endDate, String eventSummary, String eventDescription) { + private void addDailySeriesEventNew2(Integer ids, int daysInterval, long calBeginNextEventDateLong, long calEndNextEventDateLong, long milisPerWeek, final Date startDate, final Date endDate, String eventSummary, String eventDescription) { //Date calBeginNextEventDate; for (int i = 1; i < daysInterval; i++) { calBeginNextEventDateLong += milisPerWeek; + calEndNextEventDateLong += milisPerWeek; //calBeginNextEventDate = new Date(calBeginNextEventDateLong); Map dailyProperties = new HashMap(); @@ -1058,7 +1062,11 @@ private void addDailySeriesEventNew2(Integer ids, int daysInterval, long calBegi dailyProperties.put(Event.SUMMARY, view.getEventSummaryField().getValue()); dailyProperties.put(Event.DATE, new Date(calBeginNextEventDateLong)); + + if(view.getAllDayCheckbox().getValue() == true) dailyProperties.put(Event.DATE_END, new Date(calEndNextEventDateLong)); + else dailyProperties.put(Event.DATE_END, new Date(calBeginNextEventDateLong)); + setFullDayEvent(startDate, endDate, new Date(calBeginNextEventDateLong), dailyProperties); String newSummary = eventSummary; @@ -1067,7 +1075,8 @@ private void addDailySeriesEventNew2(Integer ids, int daysInterval, long calBegi newDescription += " (Weekly event " + (i + 1) + " of " + daysInterval + ")"; dailyProperties.put(Event.SUMMARY, newSummary); dailyProperties.put(Event.DESCRIPTION, newDescription); - dailyProperties.put(Event.EVENT_TYPE, "W"); + if(view.getAllDayCheckbox().getValue() == true) dailyProperties.put(Event.EVENT_TYPE, "WF"); + else dailyProperties.put(Event.EVENT_TYPE, "W"); dailyProperties.put(Event.REFERENCE_ID, ids); addPersonalEvent(dailyProperties); @@ -1086,7 +1095,8 @@ private void addDailySeriesEventNew(Integer ids, long daysInterval, long calBegi dailyProperties.put(Event.SUMMARY, view.getEventSummaryField().getValue()); dailyProperties.put(Event.DATE, new Date(calBeginNextEventDateLong)); - + dailyProperties.put(Event.DATE_END, new Date(calBeginNextEventDateLong)); + setFullDayEvent(startDate, endDate, new Date(calBeginNextEventDateLong), dailyProperties); String newSummary = eventSummary; @@ -1157,6 +1167,7 @@ private void processMonthlyEvents(final Date beginEventIntervalDate, Date endEve monthInterval = monthEnd - monthStart + 1; } if(view.getRadioNumberOfRepetitions().getValue() == true) monthInterval--; + if(monthInterval <= 0) monthInterval = 1; properties.put(Event.SUMMARY, (String) properties.get(Event.SUMMARY) + " (Monthly event 1 of " + monthInterval + ")"); properties.put(Event.DESCRIPTION, (String) properties.get(Event.DESCRIPTION) + " (Monthly event 1 of " + monthInterval + ")"); if (isMonthlySameDayOfWeek) { @@ -1315,7 +1326,7 @@ private void processYearEvents(final Date beginEventIntervalDate, Date endEventI int yearEnd = endEventIntervalDate.getYear(); int yearInterval = yearEnd - yearStart + 1; if(view.getYearlyRadioNumberOfRepetitions().getValue() == true) yearInterval--; - + if(yearInterval <= 0) yearInterval = 1; properties.put(Event.SUMMARY, (String) properties.get(Event.SUMMARY) + " (Yearly event 1 of " + yearInterval + ")"); properties.put(Event.DESCRIPTION, (String) properties.get(Event.DESCRIPTION) + " (Yearly " + (isYearlySameDayOfWeek ? "same Day of a week " : "same Date ") + "event 1 of " + yearInterval + ")"); if (isYearlySameDayOfWeek) { diff --git a/src/main/java/org/sigmah/server/service/PersonalEventService.java b/src/main/java/org/sigmah/server/service/PersonalEventService.java index d57c22100..ac5e70722 100644 --- a/src/main/java/org/sigmah/server/service/PersonalEventService.java +++ b/src/main/java/org/sigmah/server/service/PersonalEventService.java @@ -95,6 +95,7 @@ private static void fillEvent(PersonalEvent event, PropertyMap properties) { event.setReferenceId((Integer) properties.get(Event.REFERENCE_ID)); final Date day = (Date) properties.get(Event.DATE); + final Date dayEnd = (Date) properties.get(Event.DATE_END); final Serializable startHourSerialized = properties.get(Event.START_TIME); final Serializable endHourSerialized = properties.get(Event.END_TIME); @@ -104,14 +105,14 @@ private static void fillEvent(PersonalEvent event, PropertyMap properties) { if (endHourSerialized != null && endHourSerialized instanceof Long) { final Date endHour = new Date((Long) endHourSerialized); - event.setEndDate(endHour); + event.setEndDate(new Date(dayEnd.getTime()+(endHour.getTime()-day.getTime()))); } else { event.setEndDate(null); } } else { event.setStartDate(new Date(day.getYear(), day.getMonth(), day.getDate())); - event.setEndDate(new Date(day.getYear(), day.getMonth(), day.getDate() + 1)); + event.setEndDate(new Date(dayEnd.getYear(), dayEnd.getMonth(), dayEnd.getDate())); } } diff --git a/src/main/java/org/sigmah/shared/dto/calendar/Event.java b/src/main/java/org/sigmah/shared/dto/calendar/Event.java index 10a9199ec..9af382eed 100644 --- a/src/main/java/org/sigmah/shared/dto/calendar/Event.java +++ b/src/main/java/org/sigmah/shared/dto/calendar/Event.java @@ -44,6 +44,7 @@ public class Event implements Serializable { public static final String CALENDAR_ID = "calendarId"; public static final String SUMMARY = "summary"; public static final String DATE = "date"; + public static final String DATE_END = "dateEnd"; public static final String START_TIME = "startDate"; public static final String END_TIME = "endDate"; public static final String DESCRIPTION = "description"; @@ -112,6 +113,7 @@ public void fillValues(Map values) { setReferenceId((Integer) values.get(Event.REFERENCE_ID)); final Date day = (Date) values.get(Event.DATE); + final Date dayEnd = (Date) values.get(Event.DATE_END); final Object startHourSerialized = values.get(Event.START_TIME); final Object endHourSerialized = values.get(Event.END_TIME); @@ -128,7 +130,7 @@ public void fillValues(Map values) { } else { setDtstart(new Date(day.getYear(), day.getMonth(), day.getDate())); - setDtend(new Date(day.getYear(), day.getMonth(), day.getDate() + 1)); + setDtend(new Date(dayEnd.getYear(), dayEnd.getMonth(), dayEnd.getDate() + 1)); } } From e600cf8c75e36c28963ef0b4af39ab0266e0b37f Mon Sep 17 00:00:00 2001 From: Seal98 Date: Fri, 4 Aug 2017 01:20:16 +0300 Subject: [PATCH 27/39] (issue#852) creating events for several days The same for other types of events --- .../calendar/CalendarEventPresenter.java | 180 ++++++++++-------- .../org/sigmah/shared/dto/calendar/Event.java | 2 +- 2 files changed, 102 insertions(+), 80 deletions(-) diff --git a/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java b/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java index d10560fc6..7d61047a2 100644 --- a/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java +++ b/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java @@ -873,8 +873,13 @@ private void processDailyEvents(long count, long lengthDailyEvent, long milisPer properties.put(Event.SUMMARY, (String) properties.get(Event.SUMMARY) + " (Daily event 1 of " + count + ")"); properties.put(Event.DESCRIPTION, (String) properties.get(Event.DESCRIPTION) + " (Daily event 1 of " + count + ")"); - properties.put(Event.EVENT_TYPE, "D"); - + if(view.getAllDayCheckbox().getValue() == true) { + properties.put(Event.EVENT_TYPE, "DF"); + properties.put(Event.DATE_END, new Date(calBeginNextEventDateLong + milisPerDay*(lengthDailyEvent-1)));} + else{ + properties.put(Event.EVENT_TYPE, "D"); + properties.put(Event.DATE_END, new Date(calBeginNextEventDateLong)); + } addPersonalEventDaily(properties, count, lengthDailyEvent, calBeginNextEventDateLong, milisPerDay, startDate, endDate, eventSummary, eventDescription); } @@ -900,7 +905,7 @@ public void onCommandSuccess(final CreateResult result) { properties.put(Event.REFERENCE_ID, (Integer) result.getEntity().getId()); updateEvent(event, properties); addDailySeriesEvent((Integer) result.getEntity().getId(), daysInterval, lengthDailyEvent, calBeginNextEventDateLong, milisPerDay, startDate, endDate, eventSummary, eventDescription); - // addDailySeriesEventNew((Integer) result.getEntity().getId(), daysInterval, lengthDailyEvent, calBeginNextEventDateLong, milisPerDay, startDate, endDate, eventSummary, eventDescription); + if(view.getAllDayCheckbox().getValue() == false) addDailySeriesEventNew((Integer) result.getEntity().getId(), daysInterval, lengthDailyEvent, calBeginNextEventDateLong, milisPerDay, startDate, endDate, eventSummary, eventDescription); } }, view.getCancelButton(), view.getSaveButton()); } @@ -918,7 +923,7 @@ private void addDailySeriesEventNew(Integer ids, long daysInterval, long lengthD dailyProperties.put(Event.SUMMARY, view.getEventSummaryField().getValue()); dailyProperties.put(Event.DATE, new Date(calBeginNextEventDateLong)); - + dailyProperties.put(Event.DATE_END, new Date(calBeginNextEventDateLong)); setFullDayEvent(startDate, endDate, new Date(calBeginNextEventDateLong), dailyProperties); String newSummary = eventSummary; @@ -948,7 +953,7 @@ private void addDailySeriesEvent(Integer ids, long daysInterval, long lengthDail for (int i = 1; i < daysInterval; i++) { calBeginNextEventDateLong += (milisPerDay*lengthDailyEvent); - long calEndNextEventDateLong = milisPerDay*(lengthDailyEvent-1); + long calEndNextEventDateLong = calBeginNextEventDateLong + milisPerDay*(lengthDailyEvent-1); //calBeginNextEventDate = new Date(calBeginNextEventDateLong); Map dailyProperties = new HashMap(); @@ -956,7 +961,13 @@ private void addDailySeriesEvent(Integer ids, long daysInterval, long lengthDail dailyProperties.put(Event.SUMMARY, view.getEventSummaryField().getValue()); dailyProperties.put(Event.DATE, new Date(calBeginNextEventDateLong)); - dailyProperties.put(Event.DATE_END, new Date(calEndNextEventDateLong)); + if(view.getAllDayCheckbox().getValue() == true) { + dailyProperties.put(Event.EVENT_TYPE, "DF"); + dailyProperties.put(Event.DATE_END, new Date(calEndNextEventDateLong));} + else{ + dailyProperties.put(Event.EVENT_TYPE, "D"); + dailyProperties.put(Event.DATE_END, new Date(calBeginNextEventDateLong)); + } setFullDayEvent(startDate, endDate, new Date(calBeginNextEventDateLong), dailyProperties); @@ -966,7 +977,6 @@ private void addDailySeriesEvent(Integer ids, long daysInterval, long lengthDail newDescription += " (Daily event " + (i + 1) + " of " + daysInterval + ")"; dailyProperties.put(Event.SUMMARY, newSummary); dailyProperties.put(Event.DESCRIPTION, newDescription); - dailyProperties.put(Event.EVENT_TYPE, "D"); dailyProperties.put(Event.REFERENCE_ID, ids); addPersonalEvent(dailyProperties); @@ -1151,7 +1161,13 @@ private void setFullDayEvent(final Date startDate, final Date endDate, Date calB * @param eventDescription the value of eventDescription */ private void processMonthlyEvents(final Date beginEventIntervalDate, Date endEventIntervalDate, final Date endEventIntervalDateRadio, final Map properties, Boolean isMonthlySameDayOfWeek, final Date startDate, final Date endDate, String eventSummary, String eventDescription) { - long milisDiff =endEventIntervalDate.getTime() - beginEventIntervalDate.getTime(); + properties.put(Event.EVENT_TYPE, "M"); + if(view.getAllDayCheckbox().getValue() == true) { + properties.put(Event.DATE_END, endEventIntervalDate); + properties.put(Event.EVENT_TYPE, "MF");} + else properties.put(Event.DATE_END, beginEventIntervalDate); + Date endEventIntervalDate1 = endEventIntervalDate; + long milisDiff =endEventIntervalDate.getTime() - beginEventIntervalDate.getTime(); endEventIntervalDate = endEventIntervalDateRadio; // Window.alert(beginEventIntervalDate1.getDate() + "."+beginEventIntervalDate1.getMonth()+"."+beginEventIntervalDate1.getYear()+" | "+ endEventIntervalDate1.getDate()+"."+endEventIntervalDate1.getMonth()+"."+endEventIntervalDate1.getYear()); int yearStart = beginEventIntervalDate.getYear(); @@ -1170,22 +1186,22 @@ private void processMonthlyEvents(final Date beginEventIntervalDate, Date endEve if(monthInterval <= 0) monthInterval = 1; properties.put(Event.SUMMARY, (String) properties.get(Event.SUMMARY) + " (Monthly event 1 of " + monthInterval + ")"); properties.put(Event.DESCRIPTION, (String) properties.get(Event.DESCRIPTION) + " (Monthly event 1 of " + monthInterval + ")"); - if (isMonthlySameDayOfWeek) { - properties.put(Event.EVENT_TYPE, "M1"); - } else { - properties.put(Event.EVENT_TYPE, "M2"); - } - + // if (isMonthlySameDayOfWeek) { + // properties.put(Event.EVENT_TYPE, "M1"); + // } else { + // properties.put(Event.EVENT_TYPE, "M2"); + // } + //addPersonalEventMonthly(properties, monthInterval, beginEventIntervalDate, endEventIntervalDate, startDate, endDate, eventSummary, eventDescription, isMonthlySameDayOfWeek); //Window.alert("MultiEvent = "+beginEventIntervalDate1.getDate() + "."+beginEventIntervalDate1.getMonth()+"."+beginEventIntervalDate1.getYear()+" | "+ endEventIntervalDate1.getDate()+"."+endEventIntervalDate1.getMonth()+"."+endEventIntervalDate1.getYear()); //Window.alert("EndDateRadio = "+endEventIntervalDateRadio.getDate() + "."+endEventIntervalDateRadio.getMonth()+"."+endEventIntervalDateRadio.getYear()); - addPersonalEventMonthly(properties, monthInterval, beginEventIntervalDate, milisDiff, startDate, endDate, eventSummary, eventDescription, isMonthlySameDayOfWeek); + addPersonalEventMonthly(endEventIntervalDate1, properties, monthInterval, beginEventIntervalDate, milisDiff, startDate, endDate, eventSummary, eventDescription, isMonthlySameDayOfWeek); } //private void addPersonalEventMonthly(final Map properties, final int monthInterval, final Date beginEventIntervalDate, final Date endEventIntervalDate, final Date startDate, final Date endDate, final String eventSummary, final String eventDescription, final boolean isMonthlySameDayOfWeek) { - private void addPersonalEventMonthly(final Map properties, final int monthInterval, final Date beginEventIntervalDate, final long milisDiff, final Date startDate, final Date endDate, final String eventSummary, final String eventDescription, final boolean isMonthlySameDayOfWeek) { + private void addPersonalEventMonthly(final Date endEventIntervalDate, final Map properties, final int monthInterval, final Date beginEventIntervalDate, final long milisDiff, final Date startDate, final Date endDate, final String eventSummary, final String eventDescription, final boolean isMonthlySameDayOfWeek) { final CreateEntity createEntity = new CreateEntity(PersonalEventDTO.ENTITY_NAME, properties); dispatch.execute(createEntity, new CommandResultHandler() { @@ -1205,15 +1221,18 @@ public void onCommandSuccess(final CreateResult result) { properties.put(Event.REFERENCE_ID, (Integer) result.getEntity().getId()); long milisPerDay = 86400000; long daysInterval = milisDiff/milisPerDay+1; - Window.alert("DaysInterval = "+daysInterval); + // Window.alert("DaysInterval = "+daysInterval); // addDailySeriesEventNew4((Integer)properties.get(Event.REFERENCE_ID), milisPerDay*7, beginEventIntervalDate, milisPerDay, startDate, endDate, eventSummary, eventDescription); - addMonthlySeriesEvent((String) result.getEntity().getId(), monthInterval, beginEventIntervalDate, startDate, endDate, eventSummary, eventDescription, isMonthlySameDayOfWeek); - addMonthlySeriesEventNew((String) result.getEntity().getId(), monthInterval,daysInterval, beginEventIntervalDate, startDate, endDate, eventSummary, eventDescription, isMonthlySameDayOfWeek); - + addMonthlySeriesEvent(endEventIntervalDate, (String) result.getEntity().getId(), monthInterval, beginEventIntervalDate, startDate, endDate, eventSummary, eventDescription, isMonthlySameDayOfWeek); + if(view.getAllDayCheckbox().getValue() == true) { + properties.put(Event.DATE_END, endEventIntervalDate); + properties.put(Event.EVENT_TYPE, "MF");} + else addMonthlySeriesEventNew(endEventIntervalDate, (String) result.getEntity().getId(), monthInterval,daysInterval, beginEventIntervalDate, startDate, endDate, eventSummary, eventDescription, isMonthlySameDayOfWeek); + } }, view.getCancelButton(), view.getSaveButton()); } - private void addMonthlySeriesEventNew(String ids, int monthInterval, final long daysInterval, Date beginEventIntervalDate, final Date startDate, final Date endDate, String eventSummary, String eventDescription, final boolean isMonthlySameDayOfWeek) { + private void addMonthlySeriesEventNew(final Date endEventIntervalDate, String ids, int monthInterval, final long daysInterval, Date beginEventIntervalDate, final Date startDate, final Date endDate, String eventSummary, String eventDescription, final boolean isMonthlySameDayOfWeek) { Date calBeginNextEventDate = beginEventIntervalDate; long milisPerDay = 86400000; for (int i = 0; i < monthInterval; i++) { @@ -1225,7 +1244,11 @@ private void addMonthlySeriesEventNew(String ids, int monthInterval, final long monthlyProperties.put(Event.SUMMARY, view.getEventSummaryField().getValue()); monthlyProperties.put(Event.DATE, calBeginNextEventDate); - + monthlyProperties.put(Event.EVENT_TYPE, "M"); + if(view.getAllDayCheckbox().getValue() == true) { + monthlyProperties.put(Event.DATE_END, endEventIntervalDate); + monthlyProperties.put(Event.EVENT_TYPE, "MF");} + else monthlyProperties.put(Event.DATE_END, beginEventIntervalDate); setFullDayEvent(startDate, endDate, calBeginNextEventDate, monthlyProperties); String newSummary = eventSummary; @@ -1234,20 +1257,17 @@ private void addMonthlySeriesEventNew(String ids, int monthInterval, final long newDescription += " (Monthly " + (isMonthlySameDayOfWeek ? "same Day of a week " : "same Date ") + "event " + (i + 1) + " of " + monthInterval + ")"; monthlyProperties.put(Event.SUMMARY, newSummary); monthlyProperties.put(Event.DESCRIPTION, newDescription); - if (isMonthlySameDayOfWeek) { - monthlyProperties.put(Event.EVENT_TYPE, "M1"); - } else { - monthlyProperties.put(Event.EVENT_TYPE, "M2"); - } + monthlyProperties.put(Event.REFERENCE_ID, ids); - addMonthlySeriesEventNew2((Integer)monthlyProperties.get(Event.REFERENCE_ID), daysInterval, calBeginNextEventDate.getTime(), milisPerDay, startDate, endDate, eventSummary, eventDescription, i, isMonthlySameDayOfWeek, monthInterval); + addMonthlySeriesEventNew2(endEventIntervalDate, (Integer)monthlyProperties.get(Event.REFERENCE_ID), daysInterval, calBeginNextEventDate.getTime(), milisPerDay, startDate, endDate, eventSummary, eventDescription, i, isMonthlySameDayOfWeek, monthInterval); calBeginNextEventDate = getMonthlySameDayOfWeek2(beginEventIntervalDate, calBeginNextEventDate, i, isMonthlySameDayOfWeek); } } - private void addMonthlySeriesEventNew2(Integer ids, long daysInterval, long calBeginNextEventDateLong1, long milisPerDay, final Date startDate, final Date endDate, String eventSummary, String eventDescription, int j, final boolean isMonthlySameDayOfWeek, final int monthInterval) { + private void addMonthlySeriesEventNew2(final Date endEventIntervalDate, Integer ids, long daysInterval, long calBeginNextEventDateLong1, long milisPerDay, final Date startDate, final Date endDate, String eventSummary, String eventDescription, int j, final boolean isMonthlySameDayOfWeek, final int monthInterval) { //Date calBeginNextEventDate; long calBeginNextEventDateLong = calBeginNextEventDateLong1; + long diff = endEventIntervalDate.getTime()-calBeginNextEventDateLong; for (int i = 1; i < daysInterval; i++) { calBeginNextEventDateLong += milisPerDay; //calBeginNextEventDate = getMonthlySameDate(beginEventIntervalDate, calBeginNextEventDate, i); @@ -1257,7 +1277,12 @@ private void addMonthlySeriesEventNew2(Integer ids, long daysInterval, long calB monthlyProperties.put(Event.SUMMARY, view.getEventSummaryField().getValue()); monthlyProperties.put(Event.DATE, new Date(calBeginNextEventDateLong)); - + monthlyProperties.put(Event.EVENT_TYPE, "M"); + if(view.getAllDayCheckbox().getValue() == true) { + monthlyProperties.put(Event.DATE_END, new Date(calBeginNextEventDateLong + diff)); + monthlyProperties.put(Event.EVENT_TYPE, "MF");} + else monthlyProperties.put(Event.DATE_END, new Date(calBeginNextEventDateLong)); + setFullDayEvent(startDate, endDate, new Date(calBeginNextEventDateLong), monthlyProperties); String newSummary = eventSummary; @@ -1266,19 +1291,16 @@ private void addMonthlySeriesEventNew2(Integer ids, long daysInterval, long calB newDescription += " (Monthly " + (isMonthlySameDayOfWeek ? "same Day of a week " : "same Date ") + "event " + (j + 1) + " of " + monthInterval + ")"; monthlyProperties.put(Event.SUMMARY, newSummary); monthlyProperties.put(Event.DESCRIPTION, newDescription); - if (isMonthlySameDayOfWeek) { - monthlyProperties.put(Event.EVENT_TYPE, "M1"); - } else { - monthlyProperties.put(Event.EVENT_TYPE, "M2"); - } + monthlyProperties.put(Event.REFERENCE_ID, ids); addPersonalEvent(monthlyProperties); } } //private void addMonthlySeriesEvent(String ids, int monthInterval, Date beginEventIntervalDate, Date endEventIntervalDate, final Date startDate, final Date endDate, String eventSummary, String eventDescription, final boolean isMonthlySameDayOfWeek) { - private void addMonthlySeriesEvent(String ids, int monthInterval, Date beginEventIntervalDate, final Date startDate, final Date endDate, String eventSummary, String eventDescription, final boolean isMonthlySameDayOfWeek) { + private void addMonthlySeriesEvent(Date endEventIntervalDate, String ids, int monthInterval, Date beginEventIntervalDate, final Date startDate, final Date endDate, String eventSummary, String eventDescription, final boolean isMonthlySameDayOfWeek) { Date calBeginNextEventDate = beginEventIntervalDate; + long diff = endEventIntervalDate.getTime()-beginEventIntervalDate.getTime(); for (int i = 1; i < monthInterval; i++) { //calBeginNextEventDate = getMonthlySameDate(beginEventIntervalDate, calBeginNextEventDate, i); calBeginNextEventDate = getMonthlySameDayOfWeek2(beginEventIntervalDate, calBeginNextEventDate, i, isMonthlySameDayOfWeek); @@ -1288,7 +1310,12 @@ private void addMonthlySeriesEvent(String ids, int monthInterval, Date beginEven monthlyProperties.put(Event.SUMMARY, view.getEventSummaryField().getValue()); monthlyProperties.put(Event.DATE, calBeginNextEventDate); - + monthlyProperties.put(Event.EVENT_TYPE, "M"); + if(view.getAllDayCheckbox().getValue() == true) { + monthlyProperties.put(Event.DATE_END, new Date(calBeginNextEventDate.getTime() + diff)); + monthlyProperties.put(Event.EVENT_TYPE, "MF");} + else monthlyProperties.put(Event.DATE_END, new Date(calBeginNextEventDate.getTime())); + setFullDayEvent(startDate, endDate, calBeginNextEventDate, monthlyProperties); String newSummary = eventSummary; @@ -1297,11 +1324,7 @@ private void addMonthlySeriesEvent(String ids, int monthInterval, Date beginEven newDescription += " (Monthly " + (isMonthlySameDayOfWeek ? "same Day of a week " : "same Date ") + "event " + (i + 1) + " of " + monthInterval + ")"; monthlyProperties.put(Event.SUMMARY, newSummary); monthlyProperties.put(Event.DESCRIPTION, newDescription); - if (isMonthlySameDayOfWeek) { - monthlyProperties.put(Event.EVENT_TYPE, "M1"); - } else { - monthlyProperties.put(Event.EVENT_TYPE, "M2"); - } + monthlyProperties.put(Event.REFERENCE_ID, ids); addPersonalEvent(monthlyProperties); } @@ -1320,6 +1343,11 @@ private void addMonthlySeriesEvent(String ids, int monthInterval, Date beginEven * @param eventDescription the value of eventDescription */ private void processYearEvents(final Date beginEventIntervalDate, Date endEventIntervalDate, final Date endEventIntervalDateRadio, final Map properties, Boolean isYearlySameDayOfWeek, final Date startDate, final Date endDate, String eventSummary, String eventDescription) { + properties.put(Event.EVENT_TYPE, "Y"); + if(view.getAllDayCheckbox().getValue() == true) { + properties.put(Event.DATE_END, endEventIntervalDate); + properties.put(Event.EVENT_TYPE, "YF");} + else properties.put(Event.DATE_END, beginEventIntervalDate); long milisDiff =endEventIntervalDate.getTime() - beginEventIntervalDate.getTime(); endEventIntervalDate = endEventIntervalDateRadio; int yearStart = beginEventIntervalDate.getYear(); @@ -1329,11 +1357,6 @@ private void processYearEvents(final Date beginEventIntervalDate, Date endEventI if(yearInterval <= 0) yearInterval = 1; properties.put(Event.SUMMARY, (String) properties.get(Event.SUMMARY) + " (Yearly event 1 of " + yearInterval + ")"); properties.put(Event.DESCRIPTION, (String) properties.get(Event.DESCRIPTION) + " (Yearly " + (isYearlySameDayOfWeek ? "same Day of a week " : "same Date ") + "event 1 of " + yearInterval + ")"); - if (isYearlySameDayOfWeek) { - properties.put(Event.EVENT_TYPE, "Y1"); - } else { - properties.put(Event.EVENT_TYPE, "Y2"); - } addPersonalEventYearly(milisDiff, properties, yearInterval, beginEventIntervalDate, endEventIntervalDate, startDate, endDate, eventSummary, eventDescription, isYearlySameDayOfWeek); @@ -1361,12 +1384,12 @@ public void onCommandSuccess(final CreateResult result) { long milisPerDay = 86400000; long daysInterval = milisDiff/milisPerDay+1; - addYearlySeriesEvent((String) result.getEntity().getId(), yearInterval, beginEventIntervalDate, endEventIntervalDate, startDate, endDate, eventSummary, eventDescription, isYearlySameDayOfWeek); - addYearlySeriesEventNew((String) result.getEntity().getId(), yearInterval,daysInterval, beginEventIntervalDate, startDate, endDate, eventSummary, eventDescription, isYearlySameDayOfWeek); + addYearlySeriesEvent(milisDiff, (String) result.getEntity().getId(), yearInterval, beginEventIntervalDate, endEventIntervalDate, startDate, endDate, eventSummary, eventDescription, isYearlySameDayOfWeek); + if(view.getAllDayCheckbox().getValue() == false) addYearlySeriesEventNew(milisDiff, (String) result.getEntity().getId(), yearInterval,daysInterval, beginEventIntervalDate, startDate, endDate, eventSummary, eventDescription, isYearlySameDayOfWeek); } }, view.getCancelButton(), view.getSaveButton()); } - private void addYearlySeriesEventNew(String ids, int yearInterval, final long daysInterval, Date beginEventIntervalDate, final Date startDate, final Date endDate, String eventSummary, String eventDescription, final boolean isYearlySameDayOfWeek) { + private void addYearlySeriesEventNew(final long milisDiff, String ids, int yearInterval, final long daysInterval, Date beginEventIntervalDate, final Date startDate, final Date endDate, String eventSummary, String eventDescription, final boolean isYearlySameDayOfWeek) { Date calBeginNextEventDate = beginEventIntervalDate; long milisPerDay = 86400000; for (int i = 0; i < yearInterval; i++) { @@ -1387,48 +1410,46 @@ private void addYearlySeriesEventNew(String ids, int yearInterval, final long da newDescription += " (Yearly " + (isYearlySameDayOfWeek ? "same Day of a week " : "same Date ") + "event " + (i + 1) + " of " + yearInterval + ")"; monthlyProperties.put(Event.SUMMARY, newSummary); monthlyProperties.put(Event.DESCRIPTION, newDescription); - if (isYearlySameDayOfWeek) { - monthlyProperties.put(Event.EVENT_TYPE, "Y1"); - } else { - monthlyProperties.put(Event.EVENT_TYPE, "Y2"); - } + monthlyProperties.put(Event.REFERENCE_ID, ids); - addYearlySeriesEventNew2((Integer)monthlyProperties.get(Event.REFERENCE_ID), daysInterval, calBeginNextEventDate.getTime(), milisPerDay, startDate, endDate, eventSummary, eventDescription, i, isYearlySameDayOfWeek, yearInterval); + addYearlySeriesEventNew2(milisDiff, (Integer)monthlyProperties.get(Event.REFERENCE_ID), daysInterval, calBeginNextEventDate.getTime(), milisPerDay, startDate, endDate, eventSummary, eventDescription, i, isYearlySameDayOfWeek, yearInterval); calBeginNextEventDate = getYearlySameDayOfWeek(beginEventIntervalDate, calBeginNextEventDate, i, isYearlySameDayOfWeek); } } - private void addYearlySeriesEventNew2(Integer ids, long daysInterval, long calBeginNextEventDateLong1, long milisPerDay, final Date startDate, final Date endDate, String eventSummary, String eventDescription, int j, final boolean isYearlySameDayOfWeek, final int yearInterval) { + private void addYearlySeriesEventNew2(final long milisDiff, Integer ids, long daysInterval, long calBeginNextEventDateLong1, long milisPerDay, final Date startDate, final Date endDate, String eventSummary, String eventDescription, int j, final boolean isYearlySameDayOfWeek, final int yearInterval) { //Date calBeginNextEventDate; long calBeginNextEventDateLong = calBeginNextEventDateLong1; for (int i = 1; i < daysInterval; i++) { calBeginNextEventDateLong += milisPerDay; //calBeginNextEventDate = getMonthlySameDate(beginEventIntervalDate, calBeginNextEventDate, i); - Map monthlyProperties = new HashMap(); - monthlyProperties.put(Event.CALENDAR_ID, calendarWrapper); - monthlyProperties.put(Event.SUMMARY, view.getEventSummaryField().getValue()); - - monthlyProperties.put(Event.DATE, new Date(calBeginNextEventDateLong)); + Map yearlyProperties = new HashMap(); + yearlyProperties.put(Event.CALENDAR_ID, calendarWrapper); + yearlyProperties.put(Event.SUMMARY, view.getEventSummaryField().getValue()); - setFullDayEvent(startDate, endDate, new Date(calBeginNextEventDateLong), monthlyProperties); + yearlyProperties.put(Event.DATE, new Date(calBeginNextEventDateLong)); + + yearlyProperties.put(Event.EVENT_TYPE, "Y"); + if(view.getAllDayCheckbox().getValue() == true) { + yearlyProperties.put(Event.DATE_END, new Date(calBeginNextEventDateLong + milisDiff)); + yearlyProperties.put(Event.EVENT_TYPE, "YF");} + else yearlyProperties.put(Event.DATE_END, new Date(calBeginNextEventDateLong)); + + setFullDayEvent(startDate, endDate, new Date(calBeginNextEventDateLong), yearlyProperties); String newSummary = eventSummary; String newDescription = eventDescription; newSummary += " (Yearly event " + (j + 1) + " of " + yearInterval + ")"; newDescription += " (Yearly " + (isYearlySameDayOfWeek ? "same Day of a week " : "same Date ") + "event " + (j + 1) + " of " + yearInterval + ")"; - monthlyProperties.put(Event.SUMMARY, newSummary); - monthlyProperties.put(Event.DESCRIPTION, newDescription); - if (isYearlySameDayOfWeek) { - monthlyProperties.put(Event.EVENT_TYPE, "Y1"); - } else { - monthlyProperties.put(Event.EVENT_TYPE, "Y2"); - } - monthlyProperties.put(Event.REFERENCE_ID, ids); - addPersonalEvent(monthlyProperties); + yearlyProperties.put(Event.SUMMARY, newSummary); + yearlyProperties.put(Event.DESCRIPTION, newDescription); + + yearlyProperties.put(Event.REFERENCE_ID, ids); + addPersonalEvent(yearlyProperties); } } - private void addYearlySeriesEvent(String ids, int yearInterval, Date beginEventIntervalDate, Date endEventIntervalDate, final Date startDate, final Date endDate, String eventSummary, String eventDescription, final boolean isYearlySameDayOfWeek) { + private void addYearlySeriesEvent(final long milisDiff, String ids, int yearInterval, Date beginEventIntervalDate, Date endEventIntervalDate, final Date startDate, final Date endDate, String eventSummary, String eventDescription, final boolean isYearlySameDayOfWeek) { Date calBeginNextEventDate = beginEventIntervalDate; for (int i = 1; i < yearInterval; i++) { calBeginNextEventDate = getYearlySameDayOfWeek(beginEventIntervalDate, calBeginNextEventDate, i, isYearlySameDayOfWeek); @@ -1438,7 +1459,12 @@ private void addYearlySeriesEvent(String ids, int yearInterval, Date beginEventI yearlyProperties.put(Event.SUMMARY, view.getEventSummaryField().getValue()); yearlyProperties.put(Event.DATE, calBeginNextEventDate); - + yearlyProperties.put(Event.EVENT_TYPE, "Y"); + if(view.getAllDayCheckbox().getValue() == true) { + yearlyProperties.put(Event.DATE_END, new Date(calBeginNextEventDate.getTime() + milisDiff)); + yearlyProperties.put(Event.EVENT_TYPE, "YF");} + else yearlyProperties.put(Event.DATE_END, calBeginNextEventDate); + setFullDayEvent(startDate, endDate, calBeginNextEventDate, yearlyProperties); String newSummary = eventSummary; @@ -1447,11 +1473,7 @@ private void addYearlySeriesEvent(String ids, int yearInterval, Date beginEventI newDescription += " (Yearly " + (isYearlySameDayOfWeek ? "same Day of a week " : "same Date ") + "event " + (i + 1) + " of " + yearInterval + ")"; yearlyProperties.put(Event.SUMMARY, newSummary); yearlyProperties.put(Event.DESCRIPTION, newDescription); - if (isYearlySameDayOfWeek) { - yearlyProperties.put(Event.EVENT_TYPE, "Y1"); - } else { - yearlyProperties.put(Event.EVENT_TYPE, "Y2"); - } + yearlyProperties.put(Event.REFERENCE_ID, ids); addPersonalEvent(yearlyProperties); } diff --git a/src/main/java/org/sigmah/shared/dto/calendar/Event.java b/src/main/java/org/sigmah/shared/dto/calendar/Event.java index 9af382eed..dcd86f0c5 100644 --- a/src/main/java/org/sigmah/shared/dto/calendar/Event.java +++ b/src/main/java/org/sigmah/shared/dto/calendar/Event.java @@ -130,7 +130,7 @@ public void fillValues(Map values) { } else { setDtstart(new Date(day.getYear(), day.getMonth(), day.getDate())); - setDtend(new Date(dayEnd.getYear(), dayEnd.getMonth(), dayEnd.getDate() + 1)); + setDtend(new Date(dayEnd.getYear(), dayEnd.getMonth(), dayEnd.getDate())); } } From d5bb616b840cb61375abcc1e399b18658847b584 Mon Sep 17 00:00:00 2001 From: Seal98 Date: Mon, 7 Aug 2017 12:37:55 +0300 Subject: [PATCH 28/39] (issue#852) Full day multi day events as single event Made changes to -create in database day multi day events as single event (one record) -show full day multi day events as single long event on monthly calendar view --- .../calendar/CalendarEventPresenter.java | 15 +- .../presenter/calendar/CalendarPresenter.java | 34 +- .../client/ui/widget/CalendarWidget.java | 505 +++++++++++++++++- .../sigmah/client/util/FormattingImpl.java | 12 + .../sigmah/client/util/FormattingUtil.java | 28 + .../calendar/PersonalCalendarHandler.java | 34 +- .../shared/command/result/Calendar.java | 9 + 7 files changed, 602 insertions(+), 35 deletions(-) create mode 100644 src/main/java/org/sigmah/client/util/FormattingImpl.java create mode 100644 src/main/java/org/sigmah/client/util/FormattingUtil.java diff --git a/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java b/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java index 7d61047a2..a488688bd 100644 --- a/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java +++ b/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java @@ -1578,14 +1578,25 @@ private void updateEvent(final Event event, final Map properties) { final Calendar calendar = wrapper.getCalendar(); event.setParent(calendar); - +//ak +if(calendar.getEvents()!=null && !event.getEventType().contains("F")){ List events = calendar.getEvents().get(day); if (events == null) { events = new ArrayList(); calendar.getEvents().put(day, events); } events.add(event); - +} +if(calendar.getFullDayEvents()!=null && (event.getEventType().contains("F") + || (event.getDtstart().getHours()==event.getDtend().getHours() + && event.getDtstart().getMinutes()==event.getDtend().getMinutes()))){ + List fullDayevents = calendar.getFullDayEvents().get(day); + if (fullDayevents == null) { + fullDayevents = new ArrayList(); + calendar.getFullDayEvents().put(day, fullDayevents); + } + fullDayevents.add(event); +} // -- // Sends an update event on the event bus. // -- diff --git a/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarPresenter.java b/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarPresenter.java index 904812105..342aabbba 100644 --- a/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarPresenter.java +++ b/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarPresenter.java @@ -168,6 +168,11 @@ public void onCommandSuccess(final VoidResult result) { final List oldEventList = event.getParent().getEvents().get(event.getKey()); oldEventList.remove(event); + //ak + final List oldFullDayEventList + = event.getParent().getFullDayEvents().get(event.getKey()); + oldFullDayEventList.remove(event); + //ak calendar.refresh(); } }); @@ -212,7 +217,8 @@ public void deleteChain(final Event event, final CalendarWidget calendarWidget) ? ((PersonalCalendarIdentifier) calendarIdentifier).getId() : null; final Map> eventMap = event.getParent().getEvents(); - + final Map> fullDayEventMap = event.getParent().getFullDayEvents(); + int mainId = event.getIdentifier(); int refId = 0; if (event.getReferenceId() != null) { @@ -239,6 +245,27 @@ else if(next.getReferenceId() == null && next.getIdentifier().intValue() == main } } } + //ak + for (final Date key : fullDayEventMap.keySet()) { + for (final Event next : fullDayEventMap.get(key)) { + if (refId != 0) { + if (next.getReferenceId() != null && (next.getReferenceId().intValue() == refId)) { + deleteEventFunction1(next, parentId, fullDayEventMap, key); + } + else if((next.getReferenceId() == null) && (next.getIdentifier().intValue() == refId)){ + deleteEventFunction1(next, parentId, fullDayEventMap, key); + } + } else { + if (next.getReferenceId() != null && (next.getReferenceId().intValue() == mainId)) { + deleteEventFunction1(next, parentId, fullDayEventMap, key); + } + else if(next.getReferenceId() == null && next.getIdentifier().intValue() == mainId){ + deleteEventFunction2(next, parentId, fullDayEventMap, key, mainId); + } + } + } + } + //ak } else { dispatch.execute(new Delete(PersonalEventDTO.ENTITY_NAME, mainId, parentId), new CommandResultHandler() { @@ -252,6 +279,11 @@ public void onCommandSuccess(final VoidResult result) { final List oldEventList = event.getParent().getEvents().get(event.getKey()); oldEventList.remove(event); + //ak + final List oldFullDayEventList + = event.getParent().getFullDayEvents().get(event.getKey()); + oldFullDayEventList.remove(event); + //ak calendar.refresh(); } }); diff --git a/src/main/java/org/sigmah/client/ui/widget/CalendarWidget.java b/src/main/java/org/sigmah/client/ui/widget/CalendarWidget.java index bb9c0f1b8..600230a2b 100644 --- a/src/main/java/org/sigmah/client/ui/widget/CalendarWidget.java +++ b/src/main/java/org/sigmah/client/ui/widget/CalendarWidget.java @@ -22,6 +22,7 @@ * #L% */ +import com.google.gwt.core.client.GWT; import java.util.ArrayList; import java.util.Comparator; import java.util.Date; @@ -44,6 +45,8 @@ import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.ClickHandler; import com.google.gwt.i18n.client.DateTimeFormat; +import com.google.gwt.i18n.client.NumberFormat; +import com.google.gwt.user.client.DOM; import com.google.gwt.user.client.Window; import com.google.gwt.user.client.ui.Anchor; import com.google.gwt.user.client.ui.Composite; @@ -51,9 +54,15 @@ import com.google.gwt.user.client.ui.FlexTable; import com.google.gwt.user.client.ui.FlowPanel; import com.google.gwt.user.client.ui.Grid; +import com.google.gwt.user.client.ui.HTML; import com.google.gwt.user.client.ui.InlineLabel; import com.google.gwt.user.client.ui.Label; import com.google.gwt.user.client.ui.PopupPanel.PositionCallback; +import com.google.gwt.user.client.ui.RootPanel; +import com.google.gwt.user.client.ui.SimplePanel; +import com.google.gwt.user.client.ui.Widget; +import org.sigmah.client.ui.view.zone.MessageBannerView; +import org.sigmah.client.util.FormattingUtil; /** * This widget displays a calendar. @@ -422,15 +431,16 @@ public static boolean isSameDay(Date date1, Date date2) { * The calendar instance. * @return The map with each event with the right key. */ - public static Map> normalize(final Calendar calendar) { + //public static Map> normalize(final Calendar calendar) { + public static Map> normalize(final Map> eventMap) { - final Map> eventMap = calendar.getEvents(); +// final Map> eventMap = calendar.getEvents(); final Map> eventMapNormalized = new HashMap>(); - boolean isActivityCalendar = false; - if (calendar.getIdentifier() instanceof ActivityCalendarIdentifier) { - isActivityCalendar = true; - } +// boolean isActivityCalendar = false; +// if (calendar.getIdentifier() instanceof ActivityCalendarIdentifier) { +// isActivityCalendar = true; +// } for (final Date key : eventMap.keySet()) { for (final Event event : eventMap.get(key)) { @@ -438,7 +448,8 @@ public static Map> normalize(final Calendar calendar) { // Activities events have different startDate from the key date // They shouldn't be placed in their startDate list - if (!isSameDay(normalizedKeyDate, event.getDtstart()) && !isActivityCalendar) { + //if (!isSameDay(normalizedKeyDate, event.getDtstart()) && !isActivityCalendar) { + if (!isSameDay(normalizedKeyDate, event.getDtstart())) { normalizedKeyDate = new Date(event.getDtstart().getYear(), event.getDtstart().getMonth(), event.getDtstart().getDate()); } @@ -521,10 +532,38 @@ public String getHeading() { * Render the calendar. */ public void refresh() { + // + final FlexTable grid = (FlexTable) getWidget(); + grid.removeAllRows(); + // drawEmptyCells(); if (isAttached()) { calibrateCalendar(); + + /* + // final FlexTable grid = (FlexTable) getWidget(); + Window.alert("create pageMessagePanel2"); + final FlowPanel cell = (FlowPanel) grid.getWidget(1, 1); + /// + final FlowPanel pageMessagePanel2 = new FlowPanel(); + pageMessagePanel2.addStyleName("calendar-fullday-event-1"); + pageMessagePanel2.setVisible(true); + pageMessagePanel2.setWidth(String.valueOf(cell.getOffsetWidth()*5) + "px"); + // pageMessagePanel.setWidth(String.valueOf(cell.getOffsetHeight()/2) + "px"); + //pageMessagePanel.setHeight("10"); + HTML pageMessageLabel2 = new HTML(); + pageMessageLabel2.addStyleName("calendar-event-label"); + pageMessageLabel2.setHTML("==calendar-event-label==>"); + pageMessagePanel2.add(pageMessageLabel2); + //RootPanel.getBodyElement().appendChild(pageMessagePanel2); + RootPanel.get().add(pageMessagePanel2); + grid.setWidget(1, 1, pageMessagePanel2); + //// + // Window.alert("call placeItemInGrid2"); + //----------- ORABGE TEST + placeItemInGrid2(pageMessagePanel2, 1, 5,2, 2); + */ drawEvents(); } if (listener != null) @@ -584,10 +623,14 @@ public void drawEvents() { final int columns = displayMode.getColumns() + (displayWeekNumber ? 1 : 0); Date date = displayMode.getStartDate(startDate, firstDayOfWeek); - + for (int y = displayHeaders; y < rows; y++) { for (int x = displayWeekNumber ? 1 : 0; x < columns; x++) { + drawEvents(y, x, date); + if (displayMode.equals(displayMode.MONTH)){ + drawFullDayEvents(y, x, date); + } date.setDate(date.getDate() + 1); } } @@ -608,6 +651,7 @@ private void drawCell(int row, int column, Date date, int currentMonth) { final FlexTable grid = (FlexTable) getWidget(); grid.getCellFormatter().setStyleName(row, column, "calendar-cell"); + FlowPanel cell = (FlowPanel) grid.getWidget(row, column); if (cell == null) { @@ -629,7 +673,29 @@ private void drawCell(int row, int column, Date date, int currentMonth) { cell.add(header); } - + private void placeItemInGrid(Widget panel, int colStart, int colEnd, + int row, int cellPosition) { + int paddingTop = 10 + 3; + int height = 20; + + float left = (float) colStart / (float) 7 * 100f + .5f; + + float width = ((float) (colEnd - colStart + 1) / (float) 7) * 100f - 1f; + + float top = 100 + + (row * 5) + + 25 + paddingTop + + (cellPosition * (height + paddingTop)); +// System.out.println( calculatedWeekDayHeaderHeight + " + (" + row + +// " * " + calculatedCellOffsetHeight + ") + " + +// calculatedDayHeaderHeight + " + " + paddingTop + " + (" + +// cellPosition+"*("+height+"+"+paddingTop + "));"); + + DOM.setStyleAttribute(panel.getElement(), "position", "absolute"); + DOM.setStyleAttribute(panel.getElement(), "top", top + "px"); + DOM.setStyleAttribute(panel.getElement(), "left", left + "%"); + DOM.setStyleAttribute(panel.getElement(), "width", width + "%"); + } /** * Display the events for the cell located at column, row * @@ -649,7 +715,7 @@ private void drawEvents(int row, int column, final Date date) { throw new NullPointerException("The specified cell (" + row + ',' + column + ") doesn't exist."); // Displaying events - final TreeSet sortedEvents = new TreeSet(new Comparator() { + final TreeSet sortedHourEvents = new TreeSet(new Comparator() { @Override public int compare(Event o1, Event o2) { @@ -679,17 +745,59 @@ else if (o1Start > o2Start) } }); - for (final Calendar calendar : calendars) { - final Map> eventMap = normalize(calendar); + // Displaying full day events + final TreeSet sortedFullDayEvents = new TreeSet(new Comparator() { + + @Override + public int compare(Event o1, Event o2) { + int compare = 0; + + if (o1 == null && o2 == null) + return 0; + else if (o2 == null) + return 1; + else if (o1 == null) + return -1; + + if (compare == 0 && o1.getDtstart() != null && o2.getDtstart() != null) { + long o1Start = o1.getDtstart().getTime(); + long o2Start = o2.getDtstart().getTime(); - final List events = eventMap.get(date); + if (o1Start < o2Start) + compare = -1; + else if (o1Start > o2Start) + compare = 1; + } - if (events != null) { - sortedEvents.addAll(events); + if (compare == 0 && o1.getSummary() != null && o2.getSummary() != null) + compare = o1.getSummary().compareTo(o2.getSummary()); + + return compare; } + }); + + for (final Calendar calendar : calendars) { + if (!(calendar.getIdentifier() instanceof ActivityCalendarIdentifier)) { + if(calendar.getEvents()!=null){ + final Map> eventMap = normalize(calendar.getEvents()); + final List events = eventMap.get(date); + if (events != null) { + sortedHourEvents.addAll(events); + } + } + if(calendar.getFullDayEvents()!=null){ + final Map> fullDayEventMap = normalize(calendar.getFullDayEvents()); + final List fullDayEvents = fullDayEventMap.get(date); + if (fullDayEvents != null) { + sortedFullDayEvents.addAll(fullDayEvents); + } + } + } + } - final Iterator iterator = sortedEvents.iterator(); + final Iterator iterator = sortedHourEvents.iterator(); + for (int i = 0; iterator.hasNext() && i < eventLimit; i++) { final Event event = iterator.next(); @@ -715,8 +823,9 @@ else if (o1Start > o2Start) final InlineLabel dateLabel = new InlineLabel(eventDate.toString()); dateLabel.addStyleName("calendar-event-date"); - final InlineLabel eventLabel = new InlineLabel(event.getSummary()); - eventLabel.addStyleName("calendar-event-label"); + //final InlineLabel eventLabel = new InlineLabel(event.getReferenceId()==null?event.getSummary():"--->>"); + final InlineLabel eventLabel = new InlineLabel(row + "; " + event.getReferenceId()==null?event.getSummary():event.getSummary() + "->>"); + eventLabel.addStyleName("calendar-event-label"); if (fullDayEvent) flowPanel.addStyleName("calendar-fullday-event-" + event.getParent().getStyle()); @@ -774,7 +883,9 @@ public void onClick(ClickEvent clickEvent) { @Override public void onClick(ClickEvent clickEvent) { delegate.deleteChain(event, CalendarWidget.this); - detailPopup.hide(); + refresh(); + detailPopup.hide(); + } }); @@ -807,11 +918,12 @@ public void setPosition(int offsetWidth, int offsetHeight) { } }); - cell.add(flowPanel); + cell.add(flowPanel); } - if (eventLimit != UNDEFINED && sortedEvents.size() > eventLimit) { - final Anchor eventLabel = new Anchor("\u25BC"); + if (eventLimit != UNDEFINED && sortedHourEvents.size() > eventLimit) { + final Anchor eventLabel = new Anchor("\u25BC +" + (sortedHourEvents.size()-1) + " events"); + eventLabel.setTitle("Click to view all events of the day."); final Date thisDate = new Date(date.getTime()); eventLabel.addClickHandler(new ClickHandler() { @@ -867,4 +979,353 @@ private static int getWeekNumber(Date date, int firstDay) { final double diff = Math.floor((thursday.getTime() - monday.getTime()) / (1000 * 60 * 60 * 24)); return (int) Math.ceil(diff / 7.0); } + + private void placeItemInGrid2(Widget panel, int colStart, int colEnd, + int row, int cellPosition) { + final FlexTable grid = (FlexTable) getWidget(); + FlowPanel cell = (FlowPanel) grid.getWidget(1, 1); + calculatedCellOffsetHeight = cell.getElement().getClientHeight();//OffsetHeight(); + float calculatedCellOffsetWidth = cell.getElement().getOffsetWidth();; + NumberFormat percFormat = NumberFormat.getFormat("."); + + int paddingTop = appointmentPaddingTop() + 3; + int height = appointmentHeight(); +//float left = (float) colStart / (float) DAYS_IN_A_WEEK * 100f + .5f + float left = (float) colStart / (float) DAYS_IN_A_WEEK * 50f + .5f + cellPosition*5; + + float width = ((float) (colEnd - colStart) / (float) DAYS_IN_A_WEEK) * 100f - 1f; + float width33 = (colEnd - colStart)* 100f; + ////////////////////////// +int cellLeft= cell.getElement().getAbsoluteLeft(); +int cellRight= cell.getElement().getAbsoluteRight(); +int cellTop= cell.getElement().getAbsoluteTop(); +int cellBottom= cell.getElement().getAbsoluteBottom(); +int cellWidth = cell.getElement().getOffsetWidth(); +/* +Window.alert("cellWidth=" + cellWidth+ "; cellRight=" + cellRight + ";cellLeft=" + cellLeft + +";cellTop=" + cellTop); +*/ +int width2 = ((colEnd - colStart)+1) * cellWidth/7;//(cellRight-cellLeft); +int left2 = colStart * cellLeft; + + //////////////////// +// float top = calculatedWeekDayHeaderHeight +// + (row * calculatedCellOffsetHeight) +// + calculatedDayHeaderHeight + paddingTop +// + (cellPosition * (height + paddingTop)); +float top = (row * (height + paddingTop))+ cellPosition * 3; + +// final FlexTable grid = (FlexTable) getWidget(); + +cell = (FlowPanel) grid.getWidget(row, colStart); +float topNew = ( (cellBottom - cellTop)/6 * row ); + top = cell.getAbsoluteTop();// x row +top = 10; +//Window.alert("panel.getElement().getId()" + panel.getElement().getId()); +//Window.alert("panel.getElement().getId()" + panel.getElement().getClassName()); +/* +Window.alert("row=" + row+ "; top=" + top + ";left=" + percFormat.format(left) +";width=" + percFormat.format(width)); +Window.alert("width33=" + width33+ "; topNew=" + topNew + ";left2=" + left2 +";width2=" + width2); +*/ +//Window.alert("calculatedWeekDayHeaderHeight=" + calculatedWeekDayHeaderHeight +// + "; -->calculatedCellOffsetHeight=" + calculatedCellOffsetHeight +// +"; height=" + height); + +//Window.alert( calculatedWeekDayHeaderHeight + " + (" + row + +//" * " + calculatedCellOffsetHeight + ") + " + +//calculatedDayHeaderHeight + " + " + paddingTop + " + (" + +//cellPosition+"*("+height+"+"+paddingTop + "));"); + + +// final FlexTable grid = (FlexTable) getWidget(); +// +// final FlowPanel cell = (FlowPanel) grid.getWidget(row, column); + + //DOM.setStyleAttribute(panel.getElement(), "position", "absolute"); + DOM.setStyleAttribute(panel.getElement(), "position", "relative"); + DOM.setStyleAttribute(panel.getElement(), "top", top + "px"); + // DOM.setStyleAttribute(panel.getElement(), "top", topNew + "%"); +// DOM.setStyleAttribute(panel.getElement(), "left", left + "%"); + DOM.setStyleAttribute(panel.getElement(), "width", width33 + "%"); + //DOM.setStyleAttribute(panel.getElement(), "left2", left2 + "px"); + //DOM.setStyleAttribute(panel.getElement(), "width2", width2 + "px"); + DOM.setStyleAttribute(panel.getElement(), "border-radius" ,"20px 20px 20px 20px"); + DOM.setStyleAttribute(panel.getElement(), "border-color" ,"#EE9329"); + DOM.setStyleAttribute(panel.getElement(), "border-style" ,"solid"); + DOM.setStyleAttribute(panel.getElement(), "border-width" ,"2px"); + + } + private static int appointmentPaddingTop() { + return 1 + (Math.abs(FormattingUtil.getBorderOffset()) * 3); + } + + private static int appointmentHeight() { + // TODO: calculate appointment height dynamically + return 40; + } + /** + * Multiple calculated ("cached") values reused during + * laying out the month view elements. + */ + private int DAYS_IN_A_WEEK = 7; + private int calculatedWeekDayHeaderHeight; + private int calculatedDayHeaderHeight; + /** + * Height of each Cell (day), including the day's header. + */ + private float calculatedCellOffsetHeight; + + /** + * Height of each Cell (day), excluding the day's header. + */ + private float calculatedCellHeight; + + /** + * Display full day events with started date + * + * @param row + * @param column + * @param date + */ + private void drawFullDayEvents(int row, int column,final Date date) { + + // Displaying full day events + final TreeSet sortedFullDayEvents = new TreeSet(new Comparator() { + + @Override + public int compare(Event o1, Event o2) { + int compare = 0; + + if (o1 == null && o2 == null) + return 0; + else if (o2 == null) + return 1; + else if (o1 == null) + return -1; + + if (compare == 0 && o1.getDtstart() != null && o2.getDtstart() != null) { + long o1Start = o1.getDtstart().getTime(); + long o2Start = o2.getDtstart().getTime(); + + if (o1Start < o2Start) + compare = -1; + else if (o1Start > o2Start) + compare = 1; + } + + if (compare == 0 && o1.getSummary() != null && o2.getSummary() != null) + compare = o1.getSummary().compareTo(o2.getSummary()); + + return compare; + } + }); + + for (final Calendar calendar : calendars) { + if (!(calendar.getIdentifier() instanceof ActivityCalendarIdentifier)) { + if(calendar.getFullDayEvents()!=null){ + final Map> fullDayEventMap = normalize(calendar.getFullDayEvents()); + final List fullDayEvents = fullDayEventMap.get(date); + if (fullDayEvents != null) { + sortedFullDayEvents.addAll(fullDayEvents); + } + } + } + + } + + final Iterator iterator = sortedFullDayEvents.iterator(); + //ak + eventLimit = 1;//999 + for (int i = 0; iterator.hasNext() && i < eventLimit; i++) { + final Event event = iterator.next(); + + final ClickableFlowPanel flowPanel = new ClickableFlowPanel(); + flowPanel.addStyleName("calendar-event"); + + boolean fullDayEvent = false; + + final StringBuilder eventDate = new StringBuilder(); + eventDate.append(hourFormatter.format(event.getDtstart())); + if (event.getDtend() != null) { + eventDate.append(" "); + eventDate.append(hourFormatter.format(event.getDtend())); + +//-- if (event.getDtstart().getDate() != event.getDtend().getDate() +//-- || event.getDtstart().getMonth() != event.getDtend().getMonth() +//-- || event.getDtstart().getYear() != event.getDtend().getYear()) { + fullDayEvent = true; + flowPanel.addStyleName("calendar-fullday-event"); +//-- } + } + + final InlineLabel dateLabel = new InlineLabel(eventDate.toString()); + dateLabel.addStyleName("calendar-event-date"); + + final InlineLabel eventLabel = new InlineLabel(event.getSummary()); + //final InlineLabel eventLabel = new InlineLabel(event.getDtstart().getDate() + "; " + (event.getReferenceId()==null?event.getSummary():event.getSummary()) + "+>>"); + eventLabel.addStyleName("calendar-event-label"); + + if (fullDayEvent) + flowPanel.addStyleName("calendar-fullday-event-" + event.getParent().getStyle()); + else + eventLabel.addStyleName("calendar-event-" + event.getParent().getStyle()); + + if (!fullDayEvent) + flowPanel.add(dateLabel); + flowPanel.add(eventLabel);//ak + //flowPanel.setTitle(event.getSummary()); + + final DecoratedPopupPanel detailPopup = new DecoratedPopupPanel(true); + + final Grid popupContent = new Grid(event.getParent().isEditable() ? 6 : 3, 1); + popupContent.setText(0, 0, event.getSummary()); + popupContent.getCellFormatter().addStyleName(0, 0, "calendar-popup-header"); + + if (!fullDayEvent) { + popupContent.getCellFormatter().addStyleName(1, 0, "calendar-popup-date"); + popupContent.getCellFormatter().addStyleName(1, 0, "calendar-event-" + event.getParent().getStyle()); + popupContent.setText(1, 0, eventDate.toString()); + } else + popupContent.setText(1, 0, ""); + + if (event.getDescription() != null && !"".equals(event.getDescription())) { + popupContent.getCellFormatter().addStyleName(2, 0, "calendar-popup-description"); + popupContent.setText(2, 0, event.getDescription()); + } else + popupContent.setText(2, 0, ""); + + if (event.getParent().isEditable() + && ProfileUtils.isGranted(authentication, GlobalPermissionEnum.EDIT_PROJECT_AGENDA)) { + + final Anchor editAnchor = new Anchor(I18N.CONSTANTS.calendarEditEvent()); + editAnchor.addClickHandler(new ClickHandler() { + + @Override + public void onClick(ClickEvent clickEvent) { + delegate.edit(event, CalendarWidget.this); + } + }); + + final Anchor deleteAnchor = new Anchor(I18N.CONSTANTS.calendarDeleteEvent()); + deleteAnchor.addClickHandler(new ClickHandler() { + + @Override + public void onClick(ClickEvent clickEvent) { + delegate.delete(event, CalendarWidget.this); + refresh(); + detailPopup.hide(); + } + }); + + final Anchor deleteChainAnchor = new Anchor("Delete chain"); + deleteChainAnchor.addClickHandler(new ClickHandler() { + + @Override + public void onClick(ClickEvent clickEvent) { + delegate.deleteChain(event, CalendarWidget.this); + refresh(); + detailPopup.hide(); + + } + }); + + popupContent.setWidget(3, 0, editAnchor); + popupContent.setWidget(4, 0, deleteAnchor); + popupContent.setWidget(5, 0, deleteChainAnchor); + } + + detailPopup.setWidget(popupContent); + + flowPanel.addClickHandler(new ClickHandler() { + + @Override + public void onClick(ClickEvent event) { + final int left = flowPanel.getAbsoluteLeft() - 10; + final int bottom = Window.getClientHeight() - flowPanel.getAbsoluteTop(); + + detailPopup.setWidth((getCellWidth(CELL_DEFAULT_WIDTH) + 20) + "px"); + + // Show the popup + detailPopup.setPopupPositionAndShow(new PositionCallback() { + + @Override + public void setPosition(int offsetWidth, int offsetHeight) { + detailPopup.getElement().getStyle().setPropertyPx("left", left); + detailPopup.getElement().getStyle().setProperty("top", ""); + detailPopup.getElement().getStyle().setPropertyPx("bottom", bottom); + } + }); + } + }); + +//--- cell.add(flowPanel); + // RootPanel.get().add(pageMessagePanel2); + final FlexTable grid = (FlexTable) getWidget(); + grid.setWidget(row, column, flowPanel); + // RootPanel.get().add(flowPanel); + // grid.add(flowPanel); + + + long diff = event.getDtend().getTime() - event.getDtstart().getTime(); + long diffDays = diff / (24 * 60 * 60 * 1000)+1; + int daysdiff = (int) diffDays; + //--+ Window.alert("eventLabel=" + eventLabel.getTitle() +"; " + eventLabel.getText() + ";COLUMN=" +column+ "; DAYS = " + daysdiff); + //Window.alert("column =" + column + "; daysdiff=" + daysdiff ); + if(column + daysdiff-1 < 8){ + //--+ Window.alert("Short"); + placeItemInGrid2(flowPanel, column, column + daysdiff, row, i); + }else{ + //--+ Window.alert("Long1"); + // Window.alert("daysdiff - (7-column)="+ (daysdiff - (7-column))); + placeItemInGrid2(flowPanel, column, 8, row, i); + ClickableFlowPanel flowPanel2 = new ClickableFlowPanel(); + flowPanel2.addStyleName("calendar-fullday-event-2");// + event.getParent().getStyle()); + //flowPanel2 = flowPanel; + final InlineLabel dateLabel2 = new InlineLabel("<<--");// + event.getSummary()); + flowPanel2.add(dateLabel2); + grid.setWidget(row+1, 1, flowPanel2); + //--+ Window.alert("Long2"); + //--+ Window.alert("daysdiff - (8-column)="+ (daysdiff - (8-column))); + placeItemInGrid2(flowPanel2, 1,1+ daysdiff - (8-column), row+1, i); + } +// private void placeItemInGrid2(Widget panel, int colStart, int colEnd,int row, int cellPosition) { + } +/* + if (eventLimit != UNDEFINED && sortedHourEvents.size() > eventLimit) { + final Anchor eventLabel = new Anchor("\u25BC +" + (sortedHourEvents.size()-1) + " events"); + eventLabel.setTitle("Click to view all events of the day."); + final Date thisDate = new Date(date.getTime()); + eventLabel.addClickHandler(new ClickHandler() { + + @Override + public void onClick(ClickEvent event) { + startDate = thisDate; + setDisplayMode(DisplayMode.WEEK); + } + }); + eventLabel.addStyleName("calendar-event-limit"); + cell.add(eventLabel); + } + */ + } + + /** + * Calculates the height of each day cell in the Month grid. It excludes the + * height of each day's header, as well as the overall header that shows the + * weekday labels. + */ +// private void calculateCellHeight() { +// +// int gridHeight = monthCalendarGrid.getOffsetHeight(); +// int weekdayRowHeight = monthCalendarGrid.getRowFormatter() +// .getElement(0).getOffsetHeight(); +// int dayHeaderHeight = dayLabels.get(0).getOffsetHeight(); +// +// calculatedCellOffsetHeight = (float) (gridHeight - weekdayRowHeight) +// / monthViewRequiredRows; +// calculatedCellHeight = calculatedCellOffsetHeight - dayHeaderHeight; +// calculatedWeekDayHeaderHeight = weekdayRowHeight; +// calculatedDayHeaderHeight = dayHeaderHeight; +// } + } diff --git a/src/main/java/org/sigmah/client/util/FormattingImpl.java b/src/main/java/org/sigmah/client/util/FormattingImpl.java new file mode 100644 index 000000000..e13a13242 --- /dev/null +++ b/src/main/java/org/sigmah/client/util/FormattingImpl.java @@ -0,0 +1,12 @@ +package org.sigmah.client.util; + +/** + * + * @author Your Name + */ + public class FormattingImpl { + + public int getBorderOffset() { + return -1; + } +} \ No newline at end of file diff --git a/src/main/java/org/sigmah/client/util/FormattingUtil.java b/src/main/java/org/sigmah/client/util/FormattingUtil.java new file mode 100644 index 000000000..cef8c7f2e --- /dev/null +++ b/src/main/java/org/sigmah/client/util/FormattingUtil.java @@ -0,0 +1,28 @@ +package org.sigmah.client.util; + +import com.google.gwt.core.client.GWT; + +/** + * + * @author Your Name + */ +public class FormattingUtil { + + /** + * Implementation of formatting class. Holds browser-specific + * values, loaded by GWT deferred binding. + */ + private static FormattingImpl impl = GWT.create(FormattingImpl.class); + + /** + * All CSS2 compliant browsers count the border height in the + * overall height of an Element. This method returns an offset + * value that should be added to the height or width of an item + * before setting its size. This will ensure consistent sizing + * across compliant and non-compliant browsers. + * @return + */ + public static int getBorderOffset() { + return impl.getBorderOffset(); + } +} diff --git a/src/main/java/org/sigmah/server/handler/calendar/PersonalCalendarHandler.java b/src/main/java/org/sigmah/server/handler/calendar/PersonalCalendarHandler.java index 5ad9c0267..2f0846165 100644 --- a/src/main/java/org/sigmah/server/handler/calendar/PersonalCalendarHandler.java +++ b/src/main/java/org/sigmah/server/handler/calendar/PersonalCalendarHandler.java @@ -84,16 +84,24 @@ public Calendar getCalendar(CalendarIdentifier identifier, EntityManager em) { if (events != null) { final HashMap> eventMap = new HashMap>(); - + final HashMap> fullDayEventMap = new HashMap>(); + for (final PersonalEvent event : events) { final Date key = normalize(event.getStartDate()); - List list = eventMap.get(key); - if (list == null) { - list = new ArrayList(); - eventMap.put(key, list); + List eventList = eventMap.get(key); + + if (eventList == null) { + eventList = new ArrayList(); + eventMap.put(key, eventList); } + List fullDayList = fullDayEventMap.get(key); + + if (fullDayList == null) { + fullDayList = new ArrayList(); + fullDayEventMap.put(key, fullDayList); + } final Event calendarEvent = new Event(); calendarEvent.setIdentifier(event.getId()); calendarEvent.setParent(calendar); @@ -104,13 +112,19 @@ public Calendar getCalendar(CalendarIdentifier identifier, EntityManager em) { calendarEvent.setEventType(event.getEventType()); if (event.getEndDate() != null) calendarEvent.setDtend(new Date(event.getEndDate().getTime())); - - list.add(calendarEvent); - } + + if(event.getEventType()!=null && event.getEventType().contains("F") + || (event.getStartDate().getHours()==event.getEndDate().getHours() + && event.getStartDate().getMinutes()==event.getEndDate().getMinutes())){ + fullDayList.add(calendarEvent); + }else{ + eventList.add(calendarEvent); + } calendar.setEvents(eventMap); - } - + calendar.setFullDayEvents(fullDayEventMap); + } + } return calendar; } diff --git a/src/main/java/org/sigmah/shared/command/result/Calendar.java b/src/main/java/org/sigmah/shared/command/result/Calendar.java index 3947da4de..475771e8b 100644 --- a/src/main/java/org/sigmah/shared/command/result/Calendar.java +++ b/src/main/java/org/sigmah/shared/command/result/Calendar.java @@ -43,6 +43,7 @@ public class Calendar implements Result { private CalendarType type; private String name; private Map> events; + private Map> fullDayEvents; private Collection tasks; private int style; private boolean editable; @@ -130,4 +131,12 @@ public boolean isEditable() { public void setEditable(boolean editable) { this.editable = editable; } + + public void setFullDayEvents(Map> fullDayEvents) { + this.fullDayEvents = fullDayEvents; + } + + public Map> getFullDayEvents() { + return fullDayEvents; + } } From 939e0a5efb49edfa3fad5346d7289e5b2edec53a Mon Sep 17 00:00:00 2001 From: Seal98 Date: Tue, 15 Aug 2017 21:24:47 +0300 Subject: [PATCH 29/39] (issue#852) Show Full day events on monthly and weekly calendar views Implemented: -on the Monthly calendar view are shown Full day events. If number of events exceeds limit then anchor to weekly calendar view is shown with counter of all events in the day. -the anchor has tool tip with detailed information -added tool tip to Full day event with detailed information -on the Weekly calendar view are shown all Full day events in the week. The events are shown one under the other without overlapping. --- .../calendar/CalendarEventPresenter.java | 261 +- .../client/ui/widget/CalendarWidget.java | 2449 +++++++++-------- 2 files changed, 1381 insertions(+), 1329 deletions(-) diff --git a/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java b/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java index a488688bd..fc14bcdec 100644 --- a/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java +++ b/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java @@ -53,7 +53,6 @@ import com.allen_sauer.gwt.log.client.Log; import com.extjs.gxt.ui.client.event.ButtonEvent; import com.extjs.gxt.ui.client.event.SelectionListener; -import com.google.gwt.user.client.Window; import com.extjs.gxt.ui.client.widget.form.CheckBox; import com.extjs.gxt.ui.client.widget.form.DateField; import com.extjs.gxt.ui.client.widget.form.FieldSet; @@ -63,7 +62,6 @@ import com.extjs.gxt.ui.client.widget.form.TextField; import com.extjs.gxt.ui.client.widget.form.Time; import com.extjs.gxt.ui.client.widget.form.TimeField; -import com.google.gwt.user.client.ui.ListBox; import com.google.inject.ImplementedBy; import com.google.inject.Inject; import com.google.inject.Singleton; @@ -514,15 +512,14 @@ private void prepareEditView() { view.getDailyNumberOfRepetitions().setValue("1"); view.getDailyRepetitionEndDate().setValue(new Date()); } - if(event.getDtend().getDate() - event.getDtstart().getDate() == 1){ - view.getAllDayCheckbox().setValue(true); - view.getEventStartTimeField().hide(); - view.getEventEndTimeField().hide(); - } - else{ - view.getAllDayCheckbox().setValue(false); - view.getEventStartTimeField().show(); - view.getEventEndTimeField().show(); + if (event.getDtend().getDate() - event.getDtstart().getDate() == 1) { + view.getAllDayCheckbox().setValue(true); + view.getEventStartTimeField().hide(); + view.getEventEndTimeField().hide(); + } else { + view.getAllDayCheckbox().setValue(false); + view.getEventStartTimeField().show(); + view.getEventEndTimeField().show(); } if (!isFullDayEvent(event)) { @@ -690,47 +687,45 @@ private void processAddEvent(Date endEventIntervalDate, final Date beginEventInt Boolean isMonthlySameDayOfWeek = view.getRadioMonthlySameDayOfWeek().getValue(); Boolean isYearlySameDayOfWeek = view.getYearlySameDayOfWeekRB().getValue(); - // Date endEventIntervalDate = (view.getEventDateEndField() != null ? view.getEventDateEndField().getValue() : null); - Date endEventIntervalDateRadio=view.getEventDateStartField().getValue(); + // Date endEventIntervalDate = (view.getEventDateEndField() != null ? view.getEventDateEndField().getValue() : null); + Date endEventIntervalDateRadio = view.getEventDateStartField().getValue(); if (isDailyRepeatEvent) { - long count=0; - long lengthDailyEvent=((endEventIntervalDate.getTime()-beginEventIntervalDate.getTime())/milisPerDay)+1; - if(view.getDailyRadioNumberOfRepetitions().getValue() == true){ + long count = 0; + long lengthDailyEvent = ((endEventIntervalDate.getTime() - beginEventIntervalDate.getTime()) / milisPerDay) + 1; + if (view.getDailyRadioNumberOfRepetitions().getValue() == true) { count = parseInt(view.getDailyNumberOfRepetitions().getValue()); - // Window.alert("Count1 = "+count); - } - else{ - endEventIntervalDateRadio = view.getDailyRepetitionEndDate().getValue(); - count = (((endEventIntervalDateRadio.getTime() - beginEventIntervalDate.getTime())/milisPerDay)+1)/lengthDailyEvent; + // Window.alert("Count1 = "+count); + } else { + endEventIntervalDateRadio = view.getDailyRepetitionEndDate().getValue(); + count = (((endEventIntervalDateRadio.getTime() - beginEventIntervalDate.getTime()) / milisPerDay) + 1) / lengthDailyEvent; } diffInMilis = endEventIntervalDateRadio.getTime() - beginEventIntervalDate.getTime(); - if(count<=0) count=1; + if (count <= 0) { + count = 1; + } //Window.alert("Count2 = "+count); - processDailyEvents(count,lengthDailyEvent, milisPerDay, beginEventIntervalDate, endEventIntervalDateRadio, endEventIntervalDate, startDate, endDate, properties, eventSummary, eventDescription); + processDailyEvents(count, lengthDailyEvent, milisPerDay, beginEventIntervalDate, endEventIntervalDateRadio, endEventIntervalDate, startDate, endDate, properties, eventSummary, eventDescription); } else if (isWeeklyRepeatEvent) { - if(view.getWeeklyRadioNumberOfRepetitions().getValue() == true){ - endEventIntervalDateRadio.setDate(beginEventIntervalDate.getDate() + parseInt(view.getWeeklyNumberOfRepetitions().getValue())*7); - } - else{ - endEventIntervalDateRadio = view.getWeeklyRepetitionEndDate().getValue(); + if (view.getWeeklyRadioNumberOfRepetitions().getValue() == true) { + endEventIntervalDateRadio.setDate(beginEventIntervalDate.getDate() + parseInt(view.getWeeklyNumberOfRepetitions().getValue()) * 7); + } else { + endEventIntervalDateRadio = view.getWeeklyRepetitionEndDate().getValue(); } diffInMilis = endEventIntervalDateRadio.getTime() - beginEventIntervalDate.getTime(); - processWeeklyEvents(beginEventIntervalDate,endEventIntervalDate, endEventIntervalDateRadio, startDate, endDate, properties, eventSummary, eventDescription); + processWeeklyEvents(beginEventIntervalDate, endEventIntervalDate, endEventIntervalDateRadio, startDate, endDate, properties, eventSummary, eventDescription); } else if (isMonthlyRepeatEvent) { - if(view.getRadioNumberOfRepetitions().getValue() == true){ - endEventIntervalDateRadio.setMonth(beginEventIntervalDate.getMonth() + parseInt(view.getNumberOfRepetitions().getValue())); - } - else{ - endEventIntervalDateRadio = view.getRepetitionEndDate().getValue(); + if (view.getRadioNumberOfRepetitions().getValue() == true) { + endEventIntervalDateRadio.setMonth(beginEventIntervalDate.getMonth() + parseInt(view.getNumberOfRepetitions().getValue())); + } else { + endEventIntervalDateRadio = view.getRepetitionEndDate().getValue(); } processMonthlyEvents(beginEventIntervalDate, endEventIntervalDate, endEventIntervalDateRadio, properties, isMonthlySameDayOfWeek, startDate, endDate, eventSummary, eventDescription); } else if (isYearlyRepeatEvent) { - if(view.getYearlyRadioNumberOfRepetitions().getValue() == true){ - endEventIntervalDateRadio.setYear(beginEventIntervalDate.getYear() + parseInt(view.getYearlyNumberOfRepetitions().getValue())); - } - else{ - endEventIntervalDateRadio = view.getYearlyRepetitionEndDate().getValue(); + if (view.getYearlyRadioNumberOfRepetitions().getValue() == true) { + endEventIntervalDateRadio.setYear(beginEventIntervalDate.getYear() + parseInt(view.getYearlyNumberOfRepetitions().getValue())); + } else { + endEventIntervalDateRadio = view.getYearlyRepetitionEndDate().getValue(); } processYearEvents(beginEventIntervalDate, endEventIntervalDate, endEventIntervalDateRadio, properties, isYearlySameDayOfWeek, startDate, endDate, eventSummary, eventDescription); } else { @@ -787,19 +782,18 @@ private Date createEndDateProperty(Boolean isFulllDayEvent, final Date beginEven } private void processOnceEvent(final Date beginEventIntervalDate1, long diffInMilis, long milisPerDay, final Date startDate, final Date endDate, final Map properties, String eventSummary, String eventDescription) { - long daysDiff = diffInMilis / milisPerDay + 1; - long beginEventIntervalDate = beginEventIntervalDate1.getTime(); + long daysDiff = diffInMilis / milisPerDay + 1; + long beginEventIntervalDate = beginEventIntervalDate1.getTime(); properties.put(Event.SUMMARY, (String) properties.get(Event.SUMMARY)); properties.put(Event.DESCRIPTION, (String) properties.get(Event.DESCRIPTION)); // Window.alert("DaysDiff = "+daysDiff); - if(daysDiff == 1) addPersonalEvent(properties); - else{ + if (daysDiff == 1) { + addPersonalEvent(properties); + } else { properties.put(Event.SUMMARY, (String) properties.get(Event.SUMMARY) + " (Once event 1 of " + daysDiff + ")"); properties.put(Event.DESCRIPTION, (String) properties.get(Event.DESCRIPTION) + " (Once event 1 of " + daysDiff + ")"); properties.put(Event.EVENT_TYPE, "O"); addPersonalEventOnce(properties, daysDiff, beginEventIntervalDate, milisPerDay, startDate, endDate, eventSummary, eventDescription); - - } } private void addPersonalEventOnce(final Map properties, final long daysInterval, final long calBeginNextEventDateLong, final long milisPerDay, final Date startDate, final Date endDate, final String eventSummary, final String eventDescription) { @@ -870,16 +864,15 @@ private void processDailyEvents(long count, long lengthDailyEvent, long milisPer long calBeginNextEventDateLong = beginEventIntervalDate.getTime(); //Date calBeginNextEventDate = beginEventIntervalDate; - - properties.put(Event.SUMMARY, (String) properties.get(Event.SUMMARY) + " (Daily event 1 of " + count + ")"); - properties.put(Event.DESCRIPTION, (String) properties.get(Event.DESCRIPTION) + " (Daily event 1 of " + count + ")"); - if(view.getAllDayCheckbox().getValue() == true) { - properties.put(Event.EVENT_TYPE, "DF"); - properties.put(Event.DATE_END, new Date(calBeginNextEventDateLong + milisPerDay*(lengthDailyEvent-1)));} - else{ - properties.put(Event.EVENT_TYPE, "D"); - properties.put(Event.DATE_END, new Date(calBeginNextEventDateLong)); - } + properties.put(Event.SUMMARY, (String) properties.get(Event.SUMMARY) + " (Daily event 1 of " + count + ")"); + properties.put(Event.DESCRIPTION, (String) properties.get(Event.DESCRIPTION) + " (Daily event 1 of " + count + ")"); + if (view.getAllDayCheckbox().getValue() == true) { + properties.put(Event.EVENT_TYPE, "DF"); + properties.put(Event.DATE_END, new Date(calBeginNextEventDateLong + milisPerDay * (lengthDailyEvent - 1))); + } else { + properties.put(Event.EVENT_TYPE, "D"); + properties.put(Event.DATE_END, new Date(calBeginNextEventDateLong)); + } addPersonalEventDaily(properties, count, lengthDailyEvent, calBeginNextEventDateLong, milisPerDay, startDate, endDate, eventSummary, eventDescription); } @@ -905,7 +898,9 @@ public void onCommandSuccess(final CreateResult result) { properties.put(Event.REFERENCE_ID, (Integer) result.getEntity().getId()); updateEvent(event, properties); addDailySeriesEvent((Integer) result.getEntity().getId(), daysInterval, lengthDailyEvent, calBeginNextEventDateLong, milisPerDay, startDate, endDate, eventSummary, eventDescription); - if(view.getAllDayCheckbox().getValue() == false) addDailySeriesEventNew((Integer) result.getEntity().getId(), daysInterval, lengthDailyEvent, calBeginNextEventDateLong, milisPerDay, startDate, endDate, eventSummary, eventDescription); + if (view.getAllDayCheckbox().getValue() == false) { + addDailySeriesEventNew((Integer) result.getEntity().getId(), daysInterval, lengthDailyEvent, calBeginNextEventDateLong, milisPerDay, startDate, endDate, eventSummary, eventDescription); + } } }, view.getCancelButton(), view.getSaveButton()); } @@ -961,12 +956,12 @@ private void addDailySeriesEvent(Integer ids, long daysInterval, long lengthDail dailyProperties.put(Event.SUMMARY, view.getEventSummaryField().getValue()); dailyProperties.put(Event.DATE, new Date(calBeginNextEventDateLong)); - if(view.getAllDayCheckbox().getValue() == true) { + if (view.getAllDayCheckbox().getValue() == true) { dailyProperties.put(Event.EVENT_TYPE, "DF"); - dailyProperties.put(Event.DATE_END, new Date(calEndNextEventDateLong));} - else{ - dailyProperties.put(Event.EVENT_TYPE, "D"); - dailyProperties.put(Event.DATE_END, new Date(calBeginNextEventDateLong)); + dailyProperties.put(Event.DATE_END, new Date(calEndNextEventDateLong)); + } else { + dailyProperties.put(Event.EVENT_TYPE, "D"); + dailyProperties.put(Event.DATE_END, new Date(calBeginNextEventDateLong)); } setFullDayEvent(startDate, endDate, new Date(calBeginNextEventDateLong), dailyProperties); @@ -999,18 +994,26 @@ private void processWeeklyEvents(final Date beginEventIntervalDate, final Date e long milisPerDay = 86400000; long weekDiff = ((endEventIntervalDateRadio.getTime() - beginEventIntervalDate.getTime()+milisPerDay) / (milisPerDay*7)); int weeksInterval = (int) weekDiff; - if((((endEventIntervalDateRadio.getTime() - beginEventIntervalDate.getTime()+milisPerDay) % (milisPerDay*7)) >= ((endEventIntervalDate.getTime() - beginEventIntervalDate.getTime()+milisPerDay))) && (view.getWeeklyRadioNumberOfRepetitions().getValue() == true)) weeksInterval++; - if(weeksInterval <= 0) weeksInterval = 1; + if ((((endEventIntervalDateRadio.getTime() - beginEventIntervalDate.getTime() + milisPerDay) % (milisPerDay * 7)) >= ((endEventIntervalDate.getTime() - beginEventIntervalDate.getTime() + milisPerDay))) + && (view.getWeeklyRadioNumberOfRepetitions().getValue() == true)) { + weeksInterval++; + } + if (weeksInterval <= 0) { + weeksInterval = 1; + } // if(view.getWeeklyRadioNumberOfRepetitions().getValue() == true) weeksInterval--; long calBeginNextEventDateLong = beginEventIntervalDate.getTime(); - long calEndNextEventDateLong = endEventIntervalDate.getTime(); - long daysInterval = ((endEventIntervalDate.getTime() - beginEventIntervalDate.getTime())/milisPerDay)+1; - // Window.alert("WeeksInterva = "+weekDiff+" | daysInterval = "+daysInterval); - - properties.put(Event.SUMMARY, (String) properties.get(Event.SUMMARY) + " (Weekly event 1 of " + weeksInterval + ")"); - properties.put(Event.DESCRIPTION, (String) properties.get(Event.DESCRIPTION) + " (Weekly event 1 of " + weeksInterval + ")"); - properties.put(Event.EVENT_TYPE, "W"); - if(view.getAllDayCheckbox().getValue() == false) properties.put(Event.DATE_END, new Date(calBeginNextEventDateLong)); + long calEndNextEventDateLong = endEventIntervalDate.getTime(); + long daysInterval = ((endEventIntervalDate.getTime() - beginEventIntervalDate.getTime()) / milisPerDay) + 1; + // Window.alert("WeeksInterva = "+weekDiff+" | daysInterval = "+daysInterval); + + //ak properties.put(Event.SUMMARY, (String) properties.get(Event.SUMMARY) + " (Weekly event 1 of " + weeksInterval + ")"); + properties.put(Event.SUMMARY, (String) properties.get(Event.SUMMARY)); + properties.put(Event.DESCRIPTION, (String) properties.get(Event.DESCRIPTION) + " (Weekly event 1 of " + weeksInterval + ")"); + properties.put(Event.EVENT_TYPE, "W"); + if (view.getAllDayCheckbox().getValue() == false) { + properties.put(Event.DATE_END, new Date(calBeginNextEventDateLong)); + } addPersonalEventWeekly(properties, weeksInterval, calBeginNextEventDateLong, calEndNextEventDateLong, daysInterval, startDate, endDate, eventSummary, eventDescription); } @@ -1030,15 +1033,16 @@ public void onCommandFailure(final Throwable caught) { public void onCommandSuccess(final CreateResult result) { // Creating events. - final Event event = new Event(); event.setIdentifier((Integer) result.getEntity().getId()); updateEvent(event, properties); properties.put(Event.REFERENCE_ID, (Integer) result.getEntity().getId()); long milisPerDay = 86400000; - addDailySeriesEventNew2((Integer)properties.get(Event.REFERENCE_ID), weeksInterval, calBeginNextEventDateLong, calEndNextEventDateLong, milisPerDay*7, startDate, endDate, eventSummary, eventDescription); - if(view.getAllDayCheckbox().getValue() == false) addWeeklySeriesEvent(properties, (String) result.getEntity().getId(), daysInterval, weeksInterval, calBeginNextEventDateLong, milisPerDay, startDate, endDate, eventSummary, eventDescription); - // addWeeklySeriesEvent(properties, (String) result.getEntity().getId(), daysInterval, weeksInterval, calBeginNextEventDateLong, milisPerDay, startDate, endDate, eventSummary, eventDescription); + addDailySeriesEventNew2((Integer) properties.get(Event.REFERENCE_ID), weeksInterval, calBeginNextEventDateLong, calEndNextEventDateLong, milisPerDay * 7, startDate, endDate, eventSummary, eventDescription); + if (view.getAllDayCheckbox().getValue() == false) { + addWeeklySeriesEvent(properties, (String) result.getEntity().getId(), daysInterval, weeksInterval, calBeginNextEventDateLong, milisPerDay, startDate, endDate, eventSummary, eventDescription); + } + // addWeeklySeriesEvent(properties, (String) result.getEntity().getId(), daysInterval, weeksInterval, calBeginNextEventDateLong, milisPerDay, startDate, endDate, eventSummary, eventDescription); } }, view.getCancelButton(), view.getSaveButton()); } @@ -1073,15 +1077,17 @@ private void addDailySeriesEventNew2(Integer ids, int daysInterval, long calBegi dailyProperties.put(Event.DATE, new Date(calBeginNextEventDateLong)); - if(view.getAllDayCheckbox().getValue() == true) dailyProperties.put(Event.DATE_END, new Date(calEndNextEventDateLong)); - else dailyProperties.put(Event.DATE_END, new Date(calBeginNextEventDateLong)); - - + if (view.getAllDayCheckbox().getValue() == true) { + dailyProperties.put(Event.DATE_END, new Date(calEndNextEventDateLong)); + } else { + dailyProperties.put(Event.DATE_END, new Date(calBeginNextEventDateLong)); + } + setFullDayEvent(startDate, endDate, new Date(calBeginNextEventDateLong), dailyProperties); String newSummary = eventSummary; String newDescription = eventDescription; - newSummary += " (Weekly event " + (i + 1) + " of " + daysInterval + ")"; + // ak newSummary += " (Weekly event " + (i + 1) + " of " + daysInterval + ")"; newDescription += " (Weekly event " + (i + 1) + " of " + daysInterval + ")"; dailyProperties.put(Event.SUMMARY, newSummary); dailyProperties.put(Event.DESCRIPTION, newDescription); @@ -1111,7 +1117,7 @@ private void addDailySeriesEventNew(Integer ids, long daysInterval, long calBegi String newSummary = eventSummary; String newDescription = eventDescription; - newSummary += " (Weekly event " + (j + 1) + " of " + weeksInterval + ")"; + //ak newSummary += " (Weekly event " + (j + 1) + " of " + weeksInterval + ")"; newDescription += " (Weekly event " + (j + 1) + " of " + weeksInterval + ")"; dailyProperties.put(Event.SUMMARY, newSummary); dailyProperties.put(Event.DESCRIPTION, newDescription); @@ -1162,10 +1168,12 @@ private void setFullDayEvent(final Date startDate, final Date endDate, Date calB */ private void processMonthlyEvents(final Date beginEventIntervalDate, Date endEventIntervalDate, final Date endEventIntervalDateRadio, final Map properties, Boolean isMonthlySameDayOfWeek, final Date startDate, final Date endDate, String eventSummary, String eventDescription) { properties.put(Event.EVENT_TYPE, "M"); - if(view.getAllDayCheckbox().getValue() == true) { - properties.put(Event.DATE_END, endEventIntervalDate); - properties.put(Event.EVENT_TYPE, "MF");} - else properties.put(Event.DATE_END, beginEventIntervalDate); + if (view.getAllDayCheckbox().getValue() == true) { + properties.put(Event.DATE_END, endEventIntervalDate); + properties.put(Event.EVENT_TYPE, "MF"); + } else { + properties.put(Event.DATE_END, beginEventIntervalDate); + } Date endEventIntervalDate1 = endEventIntervalDate; long milisDiff =endEventIntervalDate.getTime() - beginEventIntervalDate.getTime(); endEventIntervalDate = endEventIntervalDateRadio; @@ -1182,11 +1190,15 @@ private void processMonthlyEvents(final Date beginEventIntervalDate, Date endEve } else { monthInterval = monthEnd - monthStart + 1; } - if(view.getRadioNumberOfRepetitions().getValue() == true) monthInterval--; - if(monthInterval <= 0) monthInterval = 1; - properties.put(Event.SUMMARY, (String) properties.get(Event.SUMMARY) + " (Monthly event 1 of " + monthInterval + ")"); - properties.put(Event.DESCRIPTION, (String) properties.get(Event.DESCRIPTION) + " (Monthly event 1 of " + monthInterval + ")"); - // if (isMonthlySameDayOfWeek) { + if (view.getRadioNumberOfRepetitions().getValue() == true) { + monthInterval--; + } + if (monthInterval <= 0) { + monthInterval = 1; + } + properties.put(Event.SUMMARY, (String) properties.get(Event.SUMMARY) + " (Monthly event 1 of " + monthInterval + ")"); + properties.put(Event.DESCRIPTION, (String) properties.get(Event.DESCRIPTION) + " (Monthly event 1 of " + monthInterval + ")"); + // if (isMonthlySameDayOfWeek) { // properties.put(Event.EVENT_TYPE, "M1"); // } else { // properties.put(Event.EVENT_TYPE, "M2"); @@ -1238,17 +1250,18 @@ private void addMonthlySeriesEventNew(final Date endEventIntervalDate, String id for (int i = 0; i < monthInterval; i++) { //calBeginNextEventDate = getMonthlySameDate(beginEventIntervalDate, calBeginNextEventDate, i); - Map monthlyProperties = new HashMap(); monthlyProperties.put(Event.CALENDAR_ID, calendarWrapper); monthlyProperties.put(Event.SUMMARY, view.getEventSummaryField().getValue()); monthlyProperties.put(Event.DATE, calBeginNextEventDate); - monthlyProperties.put(Event.EVENT_TYPE, "M"); - if(view.getAllDayCheckbox().getValue() == true) { + monthlyProperties.put(Event.EVENT_TYPE, "M"); + if (view.getAllDayCheckbox().getValue() == true) { monthlyProperties.put(Event.DATE_END, endEventIntervalDate); - monthlyProperties.put(Event.EVENT_TYPE, "MF");} - else monthlyProperties.put(Event.DATE_END, beginEventIntervalDate); + monthlyProperties.put(Event.EVENT_TYPE, "MF"); + } else { + monthlyProperties.put(Event.DATE_END, beginEventIntervalDate); + } setFullDayEvent(startDate, endDate, calBeginNextEventDate, monthlyProperties); String newSummary = eventSummary; @@ -1259,7 +1272,7 @@ private void addMonthlySeriesEventNew(final Date endEventIntervalDate, String id monthlyProperties.put(Event.DESCRIPTION, newDescription); monthlyProperties.put(Event.REFERENCE_ID, ids); - addMonthlySeriesEventNew2(endEventIntervalDate, (Integer)monthlyProperties.get(Event.REFERENCE_ID), daysInterval, calBeginNextEventDate.getTime(), milisPerDay, startDate, endDate, eventSummary, eventDescription, i, isMonthlySameDayOfWeek, monthInterval); + addMonthlySeriesEventNew2(endEventIntervalDate, (Integer) monthlyProperties.get(Event.REFERENCE_ID), daysInterval, calBeginNextEventDate.getTime(), milisPerDay, startDate, endDate, eventSummary, eventDescription, i, isMonthlySameDayOfWeek, monthInterval); calBeginNextEventDate = getMonthlySameDayOfWeek2(beginEventIntervalDate, calBeginNextEventDate, i, isMonthlySameDayOfWeek); } } @@ -1277,11 +1290,13 @@ private void addMonthlySeriesEventNew2(final Date endEventIntervalDate, Integer monthlyProperties.put(Event.SUMMARY, view.getEventSummaryField().getValue()); monthlyProperties.put(Event.DATE, new Date(calBeginNextEventDateLong)); - monthlyProperties.put(Event.EVENT_TYPE, "M"); - if(view.getAllDayCheckbox().getValue() == true) { + monthlyProperties.put(Event.EVENT_TYPE, "M"); + if (view.getAllDayCheckbox().getValue() == true) { monthlyProperties.put(Event.DATE_END, new Date(calBeginNextEventDateLong + diff)); - monthlyProperties.put(Event.EVENT_TYPE, "MF");} - else monthlyProperties.put(Event.DATE_END, new Date(calBeginNextEventDateLong)); + monthlyProperties.put(Event.EVENT_TYPE, "MF"); + } else { + monthlyProperties.put(Event.DATE_END, new Date(calBeginNextEventDateLong)); + } setFullDayEvent(startDate, endDate, new Date(calBeginNextEventDateLong), monthlyProperties); @@ -1311,10 +1326,12 @@ private void addMonthlySeriesEvent(Date endEventIntervalDate, String ids, int mo monthlyProperties.put(Event.DATE, calBeginNextEventDate); monthlyProperties.put(Event.EVENT_TYPE, "M"); - if(view.getAllDayCheckbox().getValue() == true) { + if (view.getAllDayCheckbox().getValue() == true) { monthlyProperties.put(Event.DATE_END, new Date(calBeginNextEventDate.getTime() + diff)); - monthlyProperties.put(Event.EVENT_TYPE, "MF");} - else monthlyProperties.put(Event.DATE_END, new Date(calBeginNextEventDate.getTime())); + monthlyProperties.put(Event.EVENT_TYPE, "MF"); + } else { + monthlyProperties.put(Event.DATE_END, new Date(calBeginNextEventDate.getTime())); + } setFullDayEvent(startDate, endDate, calBeginNextEventDate, monthlyProperties); @@ -1344,20 +1361,26 @@ private void addMonthlySeriesEvent(Date endEventIntervalDate, String ids, int mo */ private void processYearEvents(final Date beginEventIntervalDate, Date endEventIntervalDate, final Date endEventIntervalDateRadio, final Map properties, Boolean isYearlySameDayOfWeek, final Date startDate, final Date endDate, String eventSummary, String eventDescription) { properties.put(Event.EVENT_TYPE, "Y"); - if(view.getAllDayCheckbox().getValue() == true) { - properties.put(Event.DATE_END, endEventIntervalDate); - properties.put(Event.EVENT_TYPE, "YF");} - else properties.put(Event.DATE_END, beginEventIntervalDate); - long milisDiff =endEventIntervalDate.getTime() - beginEventIntervalDate.getTime(); - endEventIntervalDate = endEventIntervalDateRadio; + if (view.getAllDayCheckbox().getValue() == true) { + properties.put(Event.DATE_END, endEventIntervalDate); + properties.put(Event.EVENT_TYPE, "YF"); + } else { + properties.put(Event.DATE_END, beginEventIntervalDate); + } + long milisDiff = endEventIntervalDate.getTime() - beginEventIntervalDate.getTime(); + endEventIntervalDate = endEventIntervalDateRadio; int yearStart = beginEventIntervalDate.getYear(); int yearEnd = endEventIntervalDate.getYear(); int yearInterval = yearEnd - yearStart + 1; - if(view.getYearlyRadioNumberOfRepetitions().getValue() == true) yearInterval--; - if(yearInterval <= 0) yearInterval = 1; - properties.put(Event.SUMMARY, (String) properties.get(Event.SUMMARY) + " (Yearly event 1 of " + yearInterval + ")"); - properties.put(Event.DESCRIPTION, (String) properties.get(Event.DESCRIPTION) + " (Yearly " + (isYearlySameDayOfWeek ? "same Day of a week " : "same Date ") + "event 1 of " + yearInterval + ")"); - + if (view.getYearlyRadioNumberOfRepetitions().getValue() == true) { + yearInterval--; + } + if (yearInterval <= 0) { + yearInterval = 1; + } + properties.put(Event.SUMMARY, (String) properties.get(Event.SUMMARY) + " (Yearly event 1 of " + yearInterval + ")"); + properties.put(Event.DESCRIPTION, (String) properties.get(Event.DESCRIPTION) + " (Yearly " + (isYearlySameDayOfWeek ? "same Day of a week " : "same Date ") + "event 1 of " + yearInterval + ")"); + addPersonalEventYearly(milisDiff, properties, yearInterval, beginEventIntervalDate, endEventIntervalDate, startDate, endDate, eventSummary, eventDescription, isYearlySameDayOfWeek); @@ -1590,12 +1613,12 @@ private void updateEvent(final Event event, final Map properties) { if(calendar.getFullDayEvents()!=null && (event.getEventType().contains("F") || (event.getDtstart().getHours()==event.getDtend().getHours() && event.getDtstart().getMinutes()==event.getDtend().getMinutes()))){ - List fullDayevents = calendar.getFullDayEvents().get(day); - if (fullDayevents == null) { - fullDayevents = new ArrayList(); - calendar.getFullDayEvents().put(day, fullDayevents); + List fullDayEvents = calendar.getFullDayEvents().get(day); + if (fullDayEvents == null) { + fullDayEvents = new ArrayList(); + calendar.getFullDayEvents().put(day, fullDayEvents); } - fullDayevents.add(event); + fullDayEvents.add(event); } // -- // Sends an update event on the event bus. diff --git a/src/main/java/org/sigmah/client/ui/widget/CalendarWidget.java b/src/main/java/org/sigmah/client/ui/widget/CalendarWidget.java index 600230a2b..57cbd17e9 100644 --- a/src/main/java/org/sigmah/client/ui/widget/CalendarWidget.java +++ b/src/main/java/org/sigmah/client/ui/widget/CalendarWidget.java @@ -21,8 +21,6 @@ * . * #L% */ - -import com.google.gwt.core.client.GWT; import java.util.ArrayList; import java.util.Comparator; import java.util.Date; @@ -54,438 +52,434 @@ import com.google.gwt.user.client.ui.FlexTable; import com.google.gwt.user.client.ui.FlowPanel; import com.google.gwt.user.client.ui.Grid; -import com.google.gwt.user.client.ui.HTML; import com.google.gwt.user.client.ui.InlineLabel; import com.google.gwt.user.client.ui.Label; import com.google.gwt.user.client.ui.PopupPanel.PositionCallback; -import com.google.gwt.user.client.ui.RootPanel; -import com.google.gwt.user.client.ui.SimplePanel; import com.google.gwt.user.client.ui.Widget; -import org.sigmah.client.ui.view.zone.MessageBannerView; import org.sigmah.client.util.FormattingUtil; /** * This widget displays a calendar. - * + * * @author Raphaël Calabro (rcalabro@ideia.fr) */ @SuppressWarnings("deprecation") public class CalendarWidget extends Composite { - public static final int CELL_DEFAULT_WIDTH = 150; - public static final int CELL_DEFAULT_HEIGHT = 80; - - public interface CalendarListener { - - void afterRefresh(); - - } - - public interface Delegate { - - void edit(Event event, CalendarWidget calendarWidget); - - void delete(Event event, CalendarWidget calendarWidget); - - void deleteChain(Event event, CalendarWidget calendarWidget); - - } - - /** - * Types of displays availables for a calendar. - * - * @author rca - */ - public static enum DisplayMode { - DAY(1, 1) { - - @Override - public Date getStartDate(Date date, int firstDay) { - return new Date(date.getYear(), date.getMonth(), date.getDate()); - } - - @Override - public void nextDate(Date currentDate) { - currentDate.setDate(currentDate.getDate() + 1); - } - - @Override - public void previousDate(Date currentDate) { - currentDate.setDate(currentDate.getDate() - 1); - } - - @Override - public void firstDay(Date currentDate, Date today, int firstDay) { - currentDate.setYear(today.getYear()); - currentDate.setMonth(today.getMonth()); - currentDate.setDate(today.getDate()); - } - - @Override - public String getStyleName() { - return "calendar-day"; - } - }, - WEEK(7, 1) { - - @Override - public Date getStartDate(Date date, int firstDay) { - return getFirstDateOfWeek(date, firstDay); - } - - @Override - public void nextDate(Date currentDate) { - currentDate.setDate(currentDate.getDate() + 7); - } - - @Override - public void previousDate(Date currentDate) { - currentDate.setDate(currentDate.getDate() - 7); - } - - @Override - public void firstDay(Date currentDate, Date today, int firstDay) { - int decal = (today.getDay() + 7 - firstDay) % 7; - currentDate.setYear(today.getYear()); - currentDate.setMonth(today.getMonth()); - currentDate.setDate(today.getDate() - decal); - final Date date = getFirstDateOfWeek(today, firstDay); - currentDate.setTime(date.getTime()); - } - - @Override - public String getStyleName() { - return "calendar-week"; - } - }, - MONTH(7, 6) { - - @Override - public Date getStartDate(Date date, int firstDay) { - Date firstDayOfMonth = new Date(date.getYear(), date.getMonth(), 1); - return getFirstDateOfWeek(firstDayOfMonth, firstDay); - } + public static final int CELL_DEFAULT_WIDTH = 150; + public static final int CELL_DEFAULT_HEIGHT = 80; + + public interface CalendarListener { + + void afterRefresh(); + + } - @Override - public void nextDate(Date currentDate) { - currentDate.setMonth(currentDate.getMonth() + 1); - } - - @Override - public void previousDate(Date currentDate) { - currentDate.setMonth(currentDate.getMonth() - 1); - } - - @Override - public void firstDay(Date currentDate, Date today, int firstDay) { - currentDate.setYear(today.getYear()); - currentDate.setMonth(today.getMonth()); - currentDate.setDate(1); - } - - @Override - public String getStyleName() { - return "calendar-month"; - } - }; - - private int columns; - private int rows; - - private DisplayMode(int columns, int rows) { - this.columns = columns; - this.rows = rows; - } - - public int getRows() { - return rows; - } - - public int getColumns() { - return columns; - } - - public abstract Date getStartDate(Date date, int firstDay); - - public abstract void nextDate(Date currentDate); - - public abstract void previousDate(Date currentDate); - - public abstract void firstDay(Date currentDate, Date today, int firstDay); - - public abstract String getStyleName(); - } - - public final static int NO_HEADERS = 0; - public final static int COLUMN_HEADERS = 1; - public final static int ALL_HEADERS = 2; - - private final static int UNDEFINED = -1; - private final static int EVENT_HEIGHT = 16; - private int eventLimit = UNDEFINED; - - private int firstDayOfWeek; - private DisplayMode displayMode = DisplayMode.MONTH; - private int displayHeaders = ALL_HEADERS; - private boolean displayWeekNumber = true; - - private List calendars; - - private Date today; - private Date startDate; - - private DateTimeFormat titleFormatter = DateTimeFormat.getFormat("MMMM y"); - private DateTimeFormat headerFormatter = DateTimeFormat.getFormat("EEEE"); - private DateTimeFormat dayFormatter = DateTimeFormat.getFormat("d"); - private DateTimeFormat hourFormatter = DateTimeFormat.getFormat("HH:mm"); - - private CalendarListener listener; - private Delegate delegate; - - private final Authentication authentication; - - public CalendarWidget(int displayHeaders, boolean displayWeekNumber, Authentication authentication) { - this.calendars = new ArrayList(); - this.displayHeaders = displayHeaders; - this.displayWeekNumber = displayWeekNumber; - this.authentication = authentication; - - // final SimplePanel container; - - final FlexTable grid = new FlexTable(); - grid.addStyleName("calendar"); - grid.addStyleName(displayMode.getStyleName()); - - initWidget(grid); - - final Date now = new Date(); - today = new Date(now.getYear(), now.getMonth(), now.getDate()); - startDate = new Date(0, 0, 0); - - today(); - } - - public void setDelegate(Delegate delegate) { - this.delegate = delegate; - } - - public void setListener(CalendarListener listener) { - this.listener = listener; - } - - public void next() { - displayMode.nextDate(startDate); - refresh(); - } - - public void previous() { - displayMode.previousDate(startDate); - refresh(); - } - - public final void today() { - displayMode.firstDay(startDate, today, firstDayOfWeek); - refresh(); - } - - /** - * Retrieves the current start date of the calendar. - * - * @return the current start date of the calendar. - */ - public Date getStartDate() { - return startDate; - } - - public void addCalendar(Calendar calendar) { - calendars.add(calendar); - refresh(); - } - - public List getCalendars() { - return calendars; - } - - public void setCalendars(List calendars) { - this.calendars = calendars; - refresh(); - } - - /** - * Defines the formatter used to display the title of the calendar.
- *
- * The default format is "MonthName FullYear " (pattern : "N y"). - * - * @param titleFormatter - * The formatter to use to display the title of the calendar. - */ - public void setTitleFormatter(DateTimeFormat titleFormatter) { - this.titleFormatter = titleFormatter; - refresh(); - } - - /** - * Defines the formatter used to display the title of each column.
- *
- * The default format is "WeekName" (pattern : "E"). - * - * @param headerFormatter - * The formatter to use to display the title of each column. - */ - public void setHeaderFormatter(DateTimeFormat headerFormatter) { - this.headerFormatter = headerFormatter; - refresh(); - } - - /** - * Defines the formatter used to display the title of each cell.
- *
- * The default format is "DayNumber" (pattern : "d"). - * - * @param dayFormatter - * The formatter to use to display the title of each cell. - */ - public void setDayFormatter(DateTimeFormat dayFormatter) { - this.dayFormatter = dayFormatter; - refresh(); - } - - /** - * Defines the display mode of the calendar and perform a redraw. - * - * @param displayMode - * Style of the calendar (day, week or month). - * @see CalendarWidget.DisplayMode - */ - public void setDisplayMode(DisplayMode displayMode) { - final FlexTable grid = (FlexTable) getWidget(); - - clear(); - - // Resetting the CSS style - grid.removeStyleName(this.displayMode.getStyleName()); - - this.displayMode = displayMode; - - // Applying the CSS style associated with the new display mode - grid.addStyleName(displayMode.getStyleName()); - - refresh(); - } - - /** - * Defines the first day of the week and refresh the calendar. - * - * @param firstDayOfWeek - * The first day of the week as an int (Sunday = 0, Saturday = 6) - */ - public void setFirstDayOfWeek(int firstDayOfWeek) { - this.firstDayOfWeek = firstDayOfWeek; - refresh(); - } - - public int getDisplayHeaders() { - return displayHeaders; - } - - public void setDisplayHeaders(int displayHeaders) { - clear(); - this.displayHeaders = displayHeaders; - refresh(); - } - - public boolean isDisplayWeekNumber() { - return displayWeekNumber; - } - - public void setDisplayWeekNumber(boolean displayWeekNumber) { - clear(); - this.displayWeekNumber = displayWeekNumber; - refresh(); - } - - /** - * Removes all rows. Must be when the structure of the calendar has been changed (display mode) - */ - private void clear() { - final FlexTable grid = (FlexTable) getWidget(); - grid.clear(); - grid.removeAllRows(); - } - - /** - * @param date1 - * @param date2 - * @return boolean indicating if date1 and date2 are on the same day - */ - public static boolean isSameDay(Date date1, Date date2) { - DateTimeFormat fmt = DateTimeFormat.getFormat("yyyyMMdd"); - return fmt.format(date1).equals(fmt.format(date2)); - } - - /** - * Normalizes the given {@code calendar}'s events map (needed particularly when there is a timezone difference between - * the client and the server). - * - * @param calendar - * The calendar instance. - * @return The map with each event with the right key. - */ - //public static Map> normalize(final Calendar calendar) { - public static Map> normalize(final Map> eventMap) { + public interface Delegate { + + void edit(Event event, CalendarWidget calendarWidget); + + void delete(Event event, CalendarWidget calendarWidget); + + void deleteChain(Event event, CalendarWidget calendarWidget); + + } + + /** + * Types of displays availables for a calendar. + * + * @author rca + */ + public static enum DisplayMode { + DAY(1, 1) { + + @Override + public Date getStartDate(Date date, int firstDay) { + return new Date(date.getYear(), date.getMonth(), date.getDate()); + } + + @Override + public void nextDate(Date currentDate) { + currentDate.setDate(currentDate.getDate() + 1); + } + + @Override + public void previousDate(Date currentDate) { + currentDate.setDate(currentDate.getDate() - 1); + } + + @Override + public void firstDay(Date currentDate, Date today, int firstDay) { + currentDate.setYear(today.getYear()); + currentDate.setMonth(today.getMonth()); + currentDate.setDate(today.getDate()); + } + + @Override + public String getStyleName() { + return "calendar-day"; + } + }, + WEEK(7, 1) { + + @Override + public Date getStartDate(Date date, int firstDay) { + return getFirstDateOfWeek(date, firstDay); + } + + @Override + public void nextDate(Date currentDate) { + currentDate.setDate(currentDate.getDate() + 7); + } + + @Override + public void previousDate(Date currentDate) { + currentDate.setDate(currentDate.getDate() - 7); + } + + @Override + public void firstDay(Date currentDate, Date today, int firstDay) { + int decal = (today.getDay() + 7 - firstDay) % 7; + currentDate.setYear(today.getYear()); + currentDate.setMonth(today.getMonth()); + currentDate.setDate(today.getDate() - decal); + final Date date = getFirstDateOfWeek(today, firstDay); + currentDate.setTime(date.getTime()); + } + + @Override + public String getStyleName() { + return "calendar-week"; + } + }, + MONTH(7, 6) { + + @Override + public Date getStartDate(Date date, int firstDay) { + Date firstDayOfMonth = new Date(date.getYear(), date.getMonth(), 1); + return getFirstDateOfWeek(firstDayOfMonth, firstDay); + } + + @Override + public void nextDate(Date currentDate) { + currentDate.setMonth(currentDate.getMonth() + 1); + } + + @Override + public void previousDate(Date currentDate) { + currentDate.setMonth(currentDate.getMonth() - 1); + } + + @Override + public void firstDay(Date currentDate, Date today, int firstDay) { + currentDate.setYear(today.getYear()); + currentDate.setMonth(today.getMonth()); + currentDate.setDate(1); + } + + @Override + public String getStyleName() { + return "calendar-month"; + } + }; + + private int columns; + private int rows; + + private DisplayMode(int columns, int rows) { + this.columns = columns; + this.rows = rows; + } + + public int getRows() { + return rows; + } + + public int getColumns() { + return columns; + } + + public abstract Date getStartDate(Date date, int firstDay); + + public abstract void nextDate(Date currentDate); + + public abstract void previousDate(Date currentDate); + + public abstract void firstDay(Date currentDate, Date today, int firstDay); + + public abstract String getStyleName(); + } + + public final static int NO_HEADERS = 0; + public final static int COLUMN_HEADERS = 1; + public final static int ALL_HEADERS = 2; + + private final static int UNDEFINED = -1; + private final static int EVENT_HEIGHT = 16; + private int eventLimit = UNDEFINED; + + private int firstDayOfWeek; + private DisplayMode displayMode = DisplayMode.MONTH; + private int displayHeaders = ALL_HEADERS; + private boolean displayWeekNumber = true; + + private List calendars; + + private Date today; + private Date startDate; + + private DateTimeFormat titleFormatter = DateTimeFormat.getFormat("MMMM y"); + private DateTimeFormat headerFormatter = DateTimeFormat.getFormat("EEEE"); + private DateTimeFormat dayFormatter = DateTimeFormat.getFormat("d"); + private DateTimeFormat hourFormatter = DateTimeFormat.getFormat("HH:mm"); + + private CalendarListener listener; + private Delegate delegate; + + private final Authentication authentication; + + public CalendarWidget(int displayHeaders, boolean displayWeekNumber, Authentication authentication) { + this.calendars = new ArrayList(); + this.displayHeaders = displayHeaders; + this.displayWeekNumber = displayWeekNumber; + this.authentication = authentication; + + // final SimplePanel container; + final FlexTable grid = new FlexTable(); + grid.addStyleName("calendar"); + grid.addStyleName(displayMode.getStyleName()); + + initWidget(grid); + + final Date now = new Date(); + today = new Date(now.getYear(), now.getMonth(), now.getDate()); + startDate = new Date(0, 0, 0); + + today(); + } + + public void setDelegate(Delegate delegate) { + this.delegate = delegate; + } + + public void setListener(CalendarListener listener) { + this.listener = listener; + } + + public void next() { + displayMode.nextDate(startDate); + refresh(); + } + + public void previous() { + displayMode.previousDate(startDate); + refresh(); + } + + public final void today() { + displayMode.firstDay(startDate, today, firstDayOfWeek); + refresh(); + } + + /** + * Retrieves the current start date of the calendar. + * + * @return the current start date of the calendar. + */ + public Date getStartDate() { + return startDate; + } + + public void addCalendar(Calendar calendar) { + calendars.add(calendar); + refresh(); + } + + public List getCalendars() { + return calendars; + } + + public void setCalendars(List calendars) { + this.calendars = calendars; + refresh(); + } + + /** + * Defines the formatter used to display the title of the calendar.
+ *
+ * The default format is "MonthName FullYear " + * (pattern : "N y"). + * + * @param titleFormatter The formatter to use to display the title of the + * calendar. + */ + public void setTitleFormatter(DateTimeFormat titleFormatter) { + this.titleFormatter = titleFormatter; + refresh(); + } + + /** + * Defines the formatter used to display the title of each column.
+ *
+ * The default format is "WeekName" (pattern : "E"). + * + * @param headerFormatter The formatter to use to display the title of each + * column. + */ + public void setHeaderFormatter(DateTimeFormat headerFormatter) { + this.headerFormatter = headerFormatter; + refresh(); + } + + /** + * Defines the formatter used to display the title of each cell.
+ *
+ * The default format is "DayNumber" (pattern : "d"). + * + * @param dayFormatter The formatter to use to display the title of each + * cell. + */ + public void setDayFormatter(DateTimeFormat dayFormatter) { + this.dayFormatter = dayFormatter; + refresh(); + } + + /** + * Defines the display mode of the calendar and perform a redraw. + * + * @param displayMode Style of the calendar (day, week or month). + * @see CalendarWidget.DisplayMode + */ + public void setDisplayMode(DisplayMode displayMode) { + final FlexTable grid = (FlexTable) getWidget(); + + clear(); + + // Resetting the CSS style + grid.removeStyleName(this.displayMode.getStyleName()); + + this.displayMode = displayMode; + + // Applying the CSS style associated with the new display mode + grid.addStyleName(displayMode.getStyleName()); + + refresh(); + } + + /** + * Defines the first day of the week and refresh the calendar. + * + * @param firstDayOfWeek The first day of the week as an int (Sunday = 0, + * Saturday = 6) + */ + public void setFirstDayOfWeek(int firstDayOfWeek) { + this.firstDayOfWeek = firstDayOfWeek; + refresh(); + } + + public int getDisplayHeaders() { + return displayHeaders; + } + + public void setDisplayHeaders(int displayHeaders) { + clear(); + this.displayHeaders = displayHeaders; + refresh(); + } + + public boolean isDisplayWeekNumber() { + return displayWeekNumber; + } + + public void setDisplayWeekNumber(boolean displayWeekNumber) { + clear(); + this.displayWeekNumber = displayWeekNumber; + refresh(); + } + + /** + * Removes all rows. Must be when the structure of the calendar has been + * changed (display mode) + */ + private void clear() { + final FlexTable grid = (FlexTable) getWidget(); + grid.clear(); + grid.removeAllRows(); + } + + /** + * @param date1 + * @param date2 + * @return boolean indicating if date1 and date2 are on the same day + */ + public static boolean isSameDay(Date date1, Date date2) { + DateTimeFormat fmt = DateTimeFormat.getFormat("yyyyMMdd"); + return fmt.format(date1).equals(fmt.format(date2)); + } + + /** + * Normalizes the given {@code calendar}'s events map (needed particularly + * when there is a timezone difference between the client and the server). + * + * @param calendar The calendar instance. + * @return The map with each event with the right key. + */ + //public static Map> normalize(final Calendar calendar) { + public static Map> normalize(final Map> eventMap) { // final Map> eventMap = calendar.getEvents(); - final Map> eventMapNormalized = new HashMap>(); + final Map> eventMapNormalized = new HashMap>(); // boolean isActivityCalendar = false; // if (calendar.getIdentifier() instanceof ActivityCalendarIdentifier) { // isActivityCalendar = true; // } - - for (final Date key : eventMap.keySet()) { - for (final Event event : eventMap.get(key)) { - Date normalizedKeyDate = new Date(key.getYear(), key.getMonth(), key.getDate()); - - // Activities events have different startDate from the key date - // They shouldn't be placed in their startDate list - //if (!isSameDay(normalizedKeyDate, event.getDtstart()) && !isActivityCalendar) { - if (!isSameDay(normalizedKeyDate, event.getDtstart())) { - normalizedKeyDate = new Date(event.getDtstart().getYear(), event.getDtstart().getMonth(), event.getDtstart().getDate()); - } - - if (eventMapNormalized.get(normalizedKeyDate) == null) { - eventMapNormalized.put(normalizedKeyDate, new ArrayList()); - } - eventMapNormalized.get(normalizedKeyDate).add(event); - } - } - - return eventMapNormalized; - } - - /** - * Calculates the number of events that can be displayed in a cell. - */ - public void calibrateCalendar() { - final FlexTable grid = (FlexTable) getWidget(); - - final Element row = grid.getRowFormatter().getElement(displayHeaders); - row.setId("calendar-row-calibration"); - - final Element cell = grid.getCellFormatter().getElement(displayHeaders, displayWeekNumber ? 1 : 0); - cell.setId("calendar-cell-calibration"); - - eventLimit = (getCellHeight(CELL_DEFAULT_HEIGHT) / EVENT_HEIGHT) - 2; - if (eventLimit < 0) - eventLimit = 0; - } - - /** - * Calculates the height of the cell identified by "calendar-cell-calibration". - * - * @return height of a cell. - */ - private native int getCellHeight(int defaultHeight) /*-{ + for (final Date key : eventMap.keySet()) { + for (final Event event : eventMap.get(key)) { + Date normalizedKeyDate = new Date(key.getYear(), key.getMonth(), key.getDate()); + + // Activities events have different startDate from the key date + // They shouldn't be placed in their startDate list + //if (!isSameDay(normalizedKeyDate, event.getDtstart()) && !isActivityCalendar) { + if (!isSameDay(normalizedKeyDate, event.getDtstart())) { + normalizedKeyDate = new Date(event.getDtstart().getYear(), event.getDtstart().getMonth(), event.getDtstart().getDate()); + } + + if (eventMapNormalized.get(normalizedKeyDate) == null) { + eventMapNormalized.put(normalizedKeyDate, new ArrayList()); + } + eventMapNormalized.get(normalizedKeyDate).add(event); + } + } + + return eventMapNormalized; + } + + /** + * Calculates the number of events that can be displayed in a cell. + */ + public void calibrateCalendar() { + final FlexTable grid = (FlexTable) getWidget(); + + final Element row = grid.getRowFormatter().getElement(displayHeaders); + row.setId("calendar-row-calibration"); + + final Element cell = grid.getCellFormatter().getElement(displayHeaders, displayWeekNumber ? 1 : 0); + cell.setId("calendar-cell-calibration"); + + eventLimit = (getCellHeight(CELL_DEFAULT_HEIGHT) / EVENT_HEIGHT) - 2; + if (eventLimit < 0) { + eventLimit = 0; + } + } + + /** + * Calculates the height of the cell identified by + * "calendar-cell-calibration". + * + * @return height of a cell. + */ + private native int getCellHeight(int defaultHeight) /*-{ var height = 0; if (!$wnd.getComputedStyle) @@ -499,12 +493,13 @@ private native int getCellHeight(int defaultHeight) /*-{ return height; }-*/; - /** - * Calculates the width of the cell identified by "calendar-cell-calibration". - * - * @return width of a cell. - */ - private native int getCellWidth(int defaultWidth) /*-{ + /** + * Calculates the width of the cell identified by + * "calendar-cell-calibration". + * + * @return width of a cell. + */ + private native int getCellWidth(int defaultWidth) /*-{ var width = 0; if (!$wnd.getComputedStyle) @@ -518,802 +513,658 @@ private native int getCellWidth(int defaultWidth) /*-{ return width; }-*/; - /** - * Retrieves the current heading of the calendar. - * - * @return The heading value. - */ - public String getHeading() { - final String title = titleFormatter.format(startDate); - return Character.toUpperCase(title.charAt(0)) + title.substring(1); - } - - /** - * Render the calendar. - */ - public void refresh() { - // - final FlexTable grid = (FlexTable) getWidget(); - grid.removeAllRows(); - // - drawEmptyCells(); - - if (isAttached()) { - calibrateCalendar(); - - /* - // final FlexTable grid = (FlexTable) getWidget(); - Window.alert("create pageMessagePanel2"); - final FlowPanel cell = (FlowPanel) grid.getWidget(1, 1); - /// - final FlowPanel pageMessagePanel2 = new FlowPanel(); - pageMessagePanel2.addStyleName("calendar-fullday-event-1"); - pageMessagePanel2.setVisible(true); - pageMessagePanel2.setWidth(String.valueOf(cell.getOffsetWidth()*5) + "px"); - // pageMessagePanel.setWidth(String.valueOf(cell.getOffsetHeight()/2) + "px"); - //pageMessagePanel.setHeight("10"); - HTML pageMessageLabel2 = new HTML(); - pageMessageLabel2.addStyleName("calendar-event-label"); - pageMessageLabel2.setHTML("==calendar-event-label==>"); - pageMessagePanel2.add(pageMessageLabel2); - //RootPanel.getBodyElement().appendChild(pageMessagePanel2); - RootPanel.get().add(pageMessagePanel2); - grid.setWidget(1, 1, pageMessagePanel2); - //// - // Window.alert("call placeItemInGrid2"); - //----------- ORABGE TEST - placeItemInGrid2(pageMessagePanel2, 1, 5,2, 2); - */ - drawEvents(); - } - if (listener != null) - listener.afterRefresh(); - } - - /** - * Render the whole calendar but do not render the events. - */ - public void drawEmptyCells() { - final FlexTable grid = (FlexTable) getWidget(); - - final int rows = displayMode.getRows() + displayHeaders; - final int columns = displayMode.getColumns() + (displayWeekNumber ? 1 : 0); - - Date date = displayMode.getStartDate(startDate, firstDayOfWeek); - - // Column headers - if (displayHeaders != NO_HEADERS) { - if (displayHeaders == ALL_HEADERS) { - // Header of the calendar - final Label calendarHeader = new Label(getHeading()); - calendarHeader.addStyleName("calendar-header"); - grid.setWidget(0, 0, calendarHeader); - grid.getFlexCellFormatter().setColSpan(0, 0, columns + (displayWeekNumber ? 1 : 0)); - } - - final Date currentHeader = new Date(date.getTime()); - for (int x = displayWeekNumber ? 1 : 0; x < columns; x++) { - final Label columnHeader = new Label(headerFormatter.format(currentHeader)); - columnHeader.addStyleName("calendar-column-header"); - grid.setWidget(displayHeaders == ALL_HEADERS ? 1 : 0, x, columnHeader); - - currentHeader.setDate(currentHeader.getDate() + 1); - } - } - - int currentMonth = startDate.getMonth(); - for (int y = displayHeaders; y < rows; y++) { - if (displayWeekNumber) { - grid.getCellFormatter().addStyleName(y, 0, "calendar-row-header"); - grid.setText(y, 0, Integer.toString(getWeekNumber(date, firstDayOfWeek))); - } - - for (int x = displayWeekNumber ? 1 : 0; x < columns; x++) { - drawCell(y, x, date, currentMonth); - date.setDate(date.getDate() + 1); - } - } - } - - /** - * Render the events for every cells. - */ - public void drawEvents() { - final int rows = displayMode.getRows() + displayHeaders; - final int columns = displayMode.getColumns() + (displayWeekNumber ? 1 : 0); - - Date date = displayMode.getStartDate(startDate, firstDayOfWeek); - - for (int y = displayHeaders; y < rows; y++) { - for (int x = displayWeekNumber ? 1 : 0; x < columns; x++) { - - drawEvents(y, x, date); - if (displayMode.equals(displayMode.MONTH)){ - drawFullDayEvents(y, x, date); - } - date.setDate(date.getDate() + 1); - } - } - } - - /** - * Render the cell located at column, row - * - * @param row - * @param column - * @param date - * @param currentMonth - */ - private void drawCell(int row, int column, Date date, int currentMonth) { - final Label header = new Label(dayFormatter.format(date)); - header.addStyleName("calendar-cell-header"); - - final FlexTable grid = (FlexTable) getWidget(); - - grid.getCellFormatter().setStyleName(row, column, "calendar-cell"); - - - FlowPanel cell = (FlowPanel) grid.getWidget(row, column); - if (cell == null) { - // New cell - cell = new FlowPanel(); - cell.setWidth("100%"); - - grid.setWidget(row, column, cell); - - } else { - // Reusing an existing cell - cell.clear(); - } - - if (currentMonth != date.getMonth()) - grid.getCellFormatter().addStyleName(row, column, "calendar-cell-other-month"); - if (date.equals(today)) - grid.getCellFormatter().addStyleName(row, column, "calendar-cell-today"); - - cell.add(header); - } - private void placeItemInGrid(Widget panel, int colStart, int colEnd, - int row, int cellPosition) { - int paddingTop = 10 + 3; - int height = 20; - - float left = (float) colStart / (float) 7 * 100f + .5f; - - float width = ((float) (colEnd - colStart + 1) / (float) 7) * 100f - 1f; - - float top = 100 - + (row * 5) - + 25 + paddingTop - + (cellPosition * (height + paddingTop)); -// System.out.println( calculatedWeekDayHeaderHeight + " + (" + row + -// " * " + calculatedCellOffsetHeight + ") + " + -// calculatedDayHeaderHeight + " + " + paddingTop + " + (" + -// cellPosition+"*("+height+"+"+paddingTop + "));"); - - DOM.setStyleAttribute(panel.getElement(), "position", "absolute"); - DOM.setStyleAttribute(panel.getElement(), "top", top + "px"); - DOM.setStyleAttribute(panel.getElement(), "left", left + "%"); - DOM.setStyleAttribute(panel.getElement(), "width", width + "%"); - } - /** - * Display the events for the cell located at column, row - * - * @param row - * @param column - * @param date - * @param currentMonth - */ - private void drawEvents(int row, int column, final Date date) { - final FlexTable grid = (FlexTable) getWidget(); - - // final VerticalPanel cell = (VerticalPanel) grid.getWidget(row, - // column); - final FlowPanel cell = (FlowPanel) grid.getWidget(row, column); - - if (cell == null) - throw new NullPointerException("The specified cell (" + row + ',' + column + ") doesn't exist."); - - // Displaying events - final TreeSet sortedHourEvents = new TreeSet(new Comparator() { - - @Override - public int compare(Event o1, Event o2) { - int compare = 0; - - if (o1 == null && o2 == null) - return 0; - else if (o2 == null) - return 1; - else if (o1 == null) - return -1; - - if (compare == 0 && o1.getDtstart() != null && o2.getDtstart() != null) { - long o1Start = o1.getDtstart().getTime(); - long o2Start = o2.getDtstart().getTime(); - - if (o1Start < o2Start) - compare = -1; - else if (o1Start > o2Start) - compare = 1; - } - - if (compare == 0 && o1.getSummary() != null && o2.getSummary() != null) - compare = o1.getSummary().compareTo(o2.getSummary()); - - return compare; - } - }); - - // Displaying full day events - final TreeSet sortedFullDayEvents = new TreeSet(new Comparator() { - - @Override - public int compare(Event o1, Event o2) { - int compare = 0; - - if (o1 == null && o2 == null) - return 0; - else if (o2 == null) - return 1; - else if (o1 == null) - return -1; - - if (compare == 0 && o1.getDtstart() != null && o2.getDtstart() != null) { - long o1Start = o1.getDtstart().getTime(); - long o2Start = o2.getDtstart().getTime(); - - if (o1Start < o2Start) - compare = -1; - else if (o1Start > o2Start) - compare = 1; - } - - if (compare == 0 && o1.getSummary() != null && o2.getSummary() != null) - compare = o1.getSummary().compareTo(o2.getSummary()); - - return compare; - } - }); - - for (final Calendar calendar : calendars) { - if (!(calendar.getIdentifier() instanceof ActivityCalendarIdentifier)) { - if(calendar.getEvents()!=null){ - final Map> eventMap = normalize(calendar.getEvents()); - final List events = eventMap.get(date); - if (events != null) { - sortedHourEvents.addAll(events); - } - } - if(calendar.getFullDayEvents()!=null){ - final Map> fullDayEventMap = normalize(calendar.getFullDayEvents()); - final List fullDayEvents = fullDayEventMap.get(date); - if (fullDayEvents != null) { - sortedFullDayEvents.addAll(fullDayEvents); - } + /** + * Retrieves the current heading of the calendar. + * + * @return The heading value. + */ + public String getHeading() { + final String title = titleFormatter.format(startDate); + return Character.toUpperCase(title.charAt(0)) + title.substring(1); + } + + /** + * Render the calendar. + */ + public void refresh() { + final FlexTable grid = (FlexTable) getWidget(); + grid.removeAllRows(); + drawEmptyCells(); + + if (isAttached()) { + calibrateCalendar(); + drawEvents(); + } + if (listener != null) { + listener.afterRefresh(); + } + } + + /** + * Render the whole calendar but do not render the events. + */ + public void drawEmptyCells() { + final FlexTable grid = (FlexTable) getWidget(); + + final int rows = displayMode.getRows() + displayHeaders; + final int columns = displayMode.getColumns() + (displayWeekNumber ? 1 : 0); + + Date date = displayMode.getStartDate(startDate, firstDayOfWeek); + + // Column headers + if (displayHeaders != NO_HEADERS) { + if (displayHeaders == ALL_HEADERS) { + // Header of the calendar + final Label calendarHeader = new Label(getHeading()); + calendarHeader.addStyleName("calendar-header"); + grid.setWidget(0, 0, calendarHeader); + grid.getFlexCellFormatter().setColSpan(0, 0, columns + (displayWeekNumber ? 1 : 0)); + } + + final Date currentHeader = new Date(date.getTime()); + for (int x = displayWeekNumber ? 1 : 0; x < columns; x++) { + final Label columnHeader = new Label(headerFormatter.format(currentHeader)); + columnHeader.addStyleName("calendar-column-header"); + grid.setWidget(displayHeaders == ALL_HEADERS ? 1 : 0, x, columnHeader); + + currentHeader.setDate(currentHeader.getDate() + 1); + } + } + + int currentMonth = startDate.getMonth(); + for (int y = displayHeaders; y < rows; y++) { + if (displayWeekNumber) { + grid.getCellFormatter().addStyleName(y, 0, "calendar-row-header"); + grid.setText(y, 0, Integer.toString(getWeekNumber(date, firstDayOfWeek))); + } + + for (int x = displayWeekNumber ? 1 : 0; x < columns; x++) { + drawCell(y, x, date, currentMonth); + date.setDate(date.getDate() + 1); + } + } + } + + /** + * Render the events for every cells. + */ + public void drawEvents() { + final int rows = displayMode.getRows() + displayHeaders; + final int columns = displayMode.getColumns() + (displayWeekNumber ? 1 : 0); + + Date date = displayMode.getStartDate(startDate, firstDayOfWeek); + List alreadyShownWeekViewEvents = new ArrayList(); + int[][] theShiftVecorOfFullDayEvents = new int[8][10]; + + for (int y = displayHeaders; y < rows; y++) { + for (int x = displayWeekNumber ? 1 : 0; x < columns; x++) { + + if (displayMode.equals(displayMode.MONTH)) { + drawFullDayEvents(y, x, date); + drawEvents(y, x, date, -1); + } else { + drawFullDayEventsForWeek(1, x, date, alreadyShownWeekViewEvents, theShiftVecorOfFullDayEvents); + drawEvents(1, x, date, getLastFDPanelInCellCounter(theShiftVecorOfFullDayEvents, x)); + } + date.setDate(date.getDate() + 1); + } + if (displayMode.equals(displayMode.WEEK)) { + break; + } + } + } + + private int getLastFDPanelInCellCounter(int[][] theShiftVecorOfFullDayEvents, int theDayColumn) { + int theFDEventInColumnMaxlength = theShiftVecorOfFullDayEvents[theDayColumn].length; + int theLastFDEventInCellPosition = 0; + for (int position = theFDEventInColumnMaxlength; position >= 0; position--) { + if (theShiftVecorOfFullDayEvents[theDayColumn][position] > 0) { + theLastFDEventInCellPosition = position; + break; + } + } + return theLastFDEventInCellPosition; + } + + /** + * Render the cell located at column, row + * + * @param row + * @param column + * @param date + * @param currentMonth + */ + private void drawCell(int row, int column, Date date, int currentMonth) { + final Label header = new Label(dayFormatter.format(date)); + header.addStyleName("calendar-cell-header"); + + final FlexTable grid = (FlexTable) getWidget(); + + grid.getCellFormatter().setStyleName(row, column, "calendar-cell"); + + FlowPanel cell = (FlowPanel) grid.getWidget(row, column); + if (cell == null) { + // New cell + cell = new FlowPanel(); + cell.setWidth("100%"); + + grid.setWidget(row, column, cell); + + } else { + // Reusing an existing cell + cell.clear(); + } + + if (currentMonth != date.getMonth()) { + grid.getCellFormatter().addStyleName(row, column, "calendar-cell-other-month"); + } + if (date.equals(today)) { + grid.getCellFormatter().addStyleName(row, column, "calendar-cell-today"); + } + + cell.add(header); + } + + /** + * Display the events for the cell located at column, + * row + * + * @param row + * @param column + * @param date + * @param currentMonth + */ + private void drawEvents(int row, int column, final Date date, int startDrawPosition) { + final FlexTable grid = (FlexTable) getWidget(); + int fullDayEventCounter = 0; + + // final VerticalPanel cell = (VerticalPanel) grid.getWidget(row, + // column); + final FlowPanel cell = (FlowPanel) grid.getWidget(row, column); + + if (cell == null) { + throw new NullPointerException("The specified cell (" + row + ',' + column + ") doesn't exist."); + } + + // Displaying events + TreeSet sortedHourEvents = sortedFullDayEventsSet(); + // Displaying full day events + TreeSet sortedFullDayEvents = sortedFullDayEventsSet(); + + for (final Calendar calendar : calendars) { + if (!(calendar.getIdentifier() instanceof ActivityCalendarIdentifier)) { + if (calendar.getEvents() != null) { + final Map> eventMap = normalize(calendar.getEvents()); + final List events = eventMap.get(date); + if (events != null) { + sortedHourEvents.addAll(events); + } + } + if (calendar.getFullDayEvents() != null) { + final Map> fullDayEventMap = normalize(calendar.getFullDayEvents()); + for (Map.Entry> entry : fullDayEventMap.entrySet()) { + Date key = entry.getKey(); + List value = entry.getValue(); + for (Iterator iterator = value.iterator(); iterator.hasNext();) { + Event next = iterator.next(); + Date theStartEventDate = next.getDtstart(); + Date theEndEventDate = next.getDtend(); + if (date.after(theStartEventDate) && date.before(theEndEventDate) + || date.equals(theStartEventDate) + || date.equals(theEndEventDate)) { + fullDayEventCounter++; } } - } - - final Iterator iterator = sortedHourEvents.iterator(); - - for (int i = 0; iterator.hasNext() && i < eventLimit; i++) { - final Event event = iterator.next(); - - final ClickableFlowPanel flowPanel = new ClickableFlowPanel(); - flowPanel.addStyleName("calendar-event"); - - boolean fullDayEvent = false; - - final StringBuilder eventDate = new StringBuilder(); - eventDate.append(hourFormatter.format(event.getDtstart())); - if (event.getDtend() != null) { - eventDate.append(" "); - eventDate.append(hourFormatter.format(event.getDtend())); - - if (event.getDtstart().getDate() != event.getDtend().getDate() - || event.getDtstart().getMonth() != event.getDtend().getMonth() - || event.getDtstart().getYear() != event.getDtend().getYear()) { - fullDayEvent = true; - flowPanel.addStyleName("calendar-fullday-event"); - } - } - - final InlineLabel dateLabel = new InlineLabel(eventDate.toString()); - dateLabel.addStyleName("calendar-event-date"); - - //final InlineLabel eventLabel = new InlineLabel(event.getReferenceId()==null?event.getSummary():"--->>"); - final InlineLabel eventLabel = new InlineLabel(row + "; " + event.getReferenceId()==null?event.getSummary():event.getSummary() + "->>"); - eventLabel.addStyleName("calendar-event-label"); - - if (fullDayEvent) - flowPanel.addStyleName("calendar-fullday-event-" + event.getParent().getStyle()); - else - eventLabel.addStyleName("calendar-event-" + event.getParent().getStyle()); - - if (!fullDayEvent) - flowPanel.add(dateLabel); - flowPanel.add(eventLabel); - - final DecoratedPopupPanel detailPopup = new DecoratedPopupPanel(true); - - final Grid popupContent = new Grid(event.getParent().isEditable() ? 6 : 3, 1); - popupContent.setText(0, 0, event.getSummary()); - popupContent.getCellFormatter().addStyleName(0, 0, "calendar-popup-header"); - - if (!fullDayEvent) { - popupContent.getCellFormatter().addStyleName(1, 0, "calendar-popup-date"); - popupContent.getCellFormatter().addStyleName(1, 0, "calendar-event-" + event.getParent().getStyle()); - popupContent.setText(1, 0, eventDate.toString()); - } else - popupContent.setText(1, 0, ""); - - if (event.getDescription() != null && !"".equals(event.getDescription())) { - popupContent.getCellFormatter().addStyleName(2, 0, "calendar-popup-description"); - popupContent.setText(2, 0, event.getDescription()); - } else - popupContent.setText(2, 0, ""); - - if (event.getParent().isEditable() - && ProfileUtils.isGranted(authentication, GlobalPermissionEnum.EDIT_PROJECT_AGENDA)) { - - final Anchor editAnchor = new Anchor(I18N.CONSTANTS.calendarEditEvent()); - editAnchor.addClickHandler(new ClickHandler() { - - @Override - public void onClick(ClickEvent clickEvent) { - delegate.edit(event, CalendarWidget.this); - } - }); - - final Anchor deleteAnchor = new Anchor(I18N.CONSTANTS.calendarDeleteEvent()); - deleteAnchor.addClickHandler(new ClickHandler() { - - @Override - public void onClick(ClickEvent clickEvent) { - delegate.delete(event, CalendarWidget.this); - detailPopup.hide(); - } - }); - - final Anchor deleteChainAnchor = new Anchor("Delete chain"); - deleteChainAnchor.addClickHandler(new ClickHandler() { - - @Override - public void onClick(ClickEvent clickEvent) { - delegate.deleteChain(event, CalendarWidget.this); - refresh(); - detailPopup.hide(); - - } - }); - - popupContent.setWidget(3, 0, editAnchor); - popupContent.setWidget(4, 0, deleteAnchor); - popupContent.setWidget(5, 0, deleteChainAnchor); - } - - detailPopup.setWidget(popupContent); - - flowPanel.addClickHandler(new ClickHandler() { - - @Override - public void onClick(ClickEvent event) { - final int left = flowPanel.getAbsoluteLeft() - 10; - final int bottom = Window.getClientHeight() - flowPanel.getAbsoluteTop(); - - detailPopup.setWidth((getCellWidth(CELL_DEFAULT_WIDTH) + 20) + "px"); - - // Show the popup - detailPopup.setPopupPositionAndShow(new PositionCallback() { - - @Override - public void setPosition(int offsetWidth, int offsetHeight) { - detailPopup.getElement().getStyle().setPropertyPx("left", left); - detailPopup.getElement().getStyle().setProperty("top", ""); - detailPopup.getElement().getStyle().setPropertyPx("bottom", bottom); - } - }); - } - }); - - cell.add(flowPanel); - } - - if (eventLimit != UNDEFINED && sortedHourEvents.size() > eventLimit) { - final Anchor eventLabel = new Anchor("\u25BC +" + (sortedHourEvents.size()-1) + " events"); - eventLabel.setTitle("Click to view all events of the day."); - final Date thisDate = new Date(date.getTime()); - eventLabel.addClickHandler(new ClickHandler() { - - @Override - public void onClick(ClickEvent event) { - startDate = thisDate; - setDisplayMode(DisplayMode.WEEK); - } - }); - eventLabel.addStyleName("calendar-event-limit"); - cell.add(eventLabel); - } - } - - /** - * Returns the first date of the week that includes the given date. - * - * @param day - * A date - * @param firstDay - * The first day of the week (such as {@link #SUNDAY}, {@link #MONDAY} or anything else). - * @return The first date of the week that includes day, as a {@link Date}. - */ - private static Date getFirstDateOfWeek(Date day, int firstDay) { - final int decal = (day.getDay() + 7 - firstDay) % 7; - return new Date(day.getYear(), day.getMonth(), day.getDate() - decal); - } - - /** - * Calculates the number of the week that includes the given date. - * - * @param date - * A date - * @param firstDay - * The first day of the week (such as {@link #SUNDAY}, {@link #MONDAY} or anything else). - * @return The number of the week that includes date. - */ - private static int getWeekNumber(Date date, int firstDay) { - int daysToThursday = 4 - date.getDay(); - - if (date.getDay() < firstDay) - daysToThursday -= 7; - - final Date thursday = new Date(date.getYear(), date.getMonth(), date.getDate() + daysToThursday); - - final Date januaryFourth = new Date(thursday.getYear(), 0, 4); - final int daysToMonday = 1 - januaryFourth.getDay(); // Essayer avec le - // 1er jour de - // la - // semaine - final Date monday = new Date(thursday.getYear(), 0, 4 + daysToMonday); - - final double diff = Math.floor((thursday.getTime() - monday.getTime()) / (1000 * 60 * 60 * 24)); - return (int) Math.ceil(diff / 7.0); - } - - private void placeItemInGrid2(Widget panel, int colStart, int colEnd, - int row, int cellPosition) { - final FlexTable grid = (FlexTable) getWidget(); - FlowPanel cell = (FlowPanel) grid.getWidget(1, 1); - calculatedCellOffsetHeight = cell.getElement().getClientHeight();//OffsetHeight(); - float calculatedCellOffsetWidth = cell.getElement().getOffsetWidth();; - NumberFormat percFormat = NumberFormat.getFormat("."); - - int paddingTop = appointmentPaddingTop() + 3; - int height = appointmentHeight(); -//float left = (float) colStart / (float) DAYS_IN_A_WEEK * 100f + .5f - float left = (float) colStart / (float) DAYS_IN_A_WEEK * 50f + .5f + cellPosition*5; - - float width = ((float) (colEnd - colStart) / (float) DAYS_IN_A_WEEK) * 100f - 1f; - float width33 = (colEnd - colStart)* 100f; - ////////////////////////// -int cellLeft= cell.getElement().getAbsoluteLeft(); -int cellRight= cell.getElement().getAbsoluteRight(); -int cellTop= cell.getElement().getAbsoluteTop(); -int cellBottom= cell.getElement().getAbsoluteBottom(); -int cellWidth = cell.getElement().getOffsetWidth(); -/* -Window.alert("cellWidth=" + cellWidth+ "; cellRight=" + cellRight + ";cellLeft=" + cellLeft - +";cellTop=" + cellTop); -*/ -int width2 = ((colEnd - colStart)+1) * cellWidth/7;//(cellRight-cellLeft); -int left2 = colStart * cellLeft; - - //////////////////// -// float top = calculatedWeekDayHeaderHeight -// + (row * calculatedCellOffsetHeight) -// + calculatedDayHeaderHeight + paddingTop -// + (cellPosition * (height + paddingTop)); -float top = (row * (height + paddingTop))+ cellPosition * 3; - -// final FlexTable grid = (FlexTable) getWidget(); - -cell = (FlowPanel) grid.getWidget(row, colStart); -float topNew = ( (cellBottom - cellTop)/6 * row ); - top = cell.getAbsoluteTop();// x row -top = 10; -//Window.alert("panel.getElement().getId()" + panel.getElement().getId()); -//Window.alert("panel.getElement().getId()" + panel.getElement().getClassName()); -/* -Window.alert("row=" + row+ "; top=" + top + ";left=" + percFormat.format(left) +";width=" + percFormat.format(width)); -Window.alert("width33=" + width33+ "; topNew=" + topNew + ";left2=" + left2 +";width2=" + width2); -*/ -//Window.alert("calculatedWeekDayHeaderHeight=" + calculatedWeekDayHeaderHeight -// + "; -->calculatedCellOffsetHeight=" + calculatedCellOffsetHeight -// +"; height=" + height); + } + final List fullDayEvents = fullDayEventMap.get(date); + if (fullDayEvents != null) { + sortedFullDayEvents.addAll(fullDayEvents); + } + } + } + + } + + final Iterator iterator = sortedHourEvents.iterator(); + + for (int i = 0; iterator.hasNext() && i < eventLimit; i++) { + final Event event = iterator.next(); + + final ClickableFlowPanel flowPanel = new ClickableFlowPanel(); + flowPanel.addStyleName("calendar-event"); + + boolean fullDayEvent = false; + + final StringBuilder eventDate = new StringBuilder(); + eventDate.append(hourFormatter.format(event.getDtstart())); + if (event.getDtend() != null) { + eventDate.append(" "); + eventDate.append(hourFormatter.format(event.getDtend())); -//Window.alert( calculatedWeekDayHeaderHeight + " + (" + row + -//" * " + calculatedCellOffsetHeight + ") + " + -//calculatedDayHeaderHeight + " + " + paddingTop + " + (" + -//cellPosition+"*("+height+"+"+paddingTop + "));"); - - -// final FlexTable grid = (FlexTable) getWidget(); -// -// final FlowPanel cell = (FlowPanel) grid.getWidget(row, column); - - //DOM.setStyleAttribute(panel.getElement(), "position", "absolute"); - DOM.setStyleAttribute(panel.getElement(), "position", "relative"); - DOM.setStyleAttribute(panel.getElement(), "top", top + "px"); - // DOM.setStyleAttribute(panel.getElement(), "top", topNew + "%"); -// DOM.setStyleAttribute(panel.getElement(), "left", left + "%"); - DOM.setStyleAttribute(panel.getElement(), "width", width33 + "%"); - //DOM.setStyleAttribute(panel.getElement(), "left2", left2 + "px"); - //DOM.setStyleAttribute(panel.getElement(), "width2", width2 + "px"); - DOM.setStyleAttribute(panel.getElement(), "border-radius" ,"20px 20px 20px 20px"); - DOM.setStyleAttribute(panel.getElement(), "border-color" ,"#EE9329"); - DOM.setStyleAttribute(panel.getElement(), "border-style" ,"solid"); - DOM.setStyleAttribute(panel.getElement(), "border-width" ,"2px"); - - } - private static int appointmentPaddingTop() { - return 1 + (Math.abs(FormattingUtil.getBorderOffset()) * 3); - } - - private static int appointmentHeight() { - // TODO: calculate appointment height dynamically - return 40; - } - /** - * Multiple calculated ("cached") values reused during - * laying out the month view elements. - */ - private int DAYS_IN_A_WEEK = 7; - private int calculatedWeekDayHeaderHeight; - private int calculatedDayHeaderHeight; - /** - * Height of each Cell (day), including the day's header. - */ - private float calculatedCellOffsetHeight; - - /** - * Height of each Cell (day), excluding the day's header. - */ - private float calculatedCellHeight; - - /** - * Display full day events with started date - * - * @param row - * @param column - * @param date - */ - private void drawFullDayEvents(int row, int column,final Date date) { - - // Displaying full day events - final TreeSet sortedFullDayEvents = new TreeSet(new Comparator() { - - @Override - public int compare(Event o1, Event o2) { - int compare = 0; - - if (o1 == null && o2 == null) - return 0; - else if (o2 == null) - return 1; - else if (o1 == null) - return -1; - - if (compare == 0 && o1.getDtstart() != null && o2.getDtstart() != null) { - long o1Start = o1.getDtstart().getTime(); - long o2Start = o2.getDtstart().getTime(); - - if (o1Start < o2Start) - compare = -1; - else if (o1Start > o2Start) - compare = 1; - } - - if (compare == 0 && o1.getSummary() != null && o2.getSummary() != null) - compare = o1.getSummary().compareTo(o2.getSummary()); - - return compare; - } - }); - - for (final Calendar calendar : calendars) { - if (!(calendar.getIdentifier() instanceof ActivityCalendarIdentifier)) { - if(calendar.getFullDayEvents()!=null){ - final Map> fullDayEventMap = normalize(calendar.getFullDayEvents()); - final List fullDayEvents = fullDayEventMap.get(date); - if (fullDayEvents != null) { - sortedFullDayEvents.addAll(fullDayEvents); - } - } + if (event.getDtstart().getDate() != event.getDtend().getDate() + || event.getDtstart().getMonth() != event.getDtend().getMonth() + || event.getDtstart().getYear() != event.getDtend().getYear()) { + fullDayEvent = true; + flowPanel.addStyleName("calendar-fullday-event"); + } + } + + final InlineLabel dateLabel = new InlineLabel(eventDate.toString()); + dateLabel.addStyleName("calendar-event-date"); + + //final InlineLabel eventLabel = new InlineLabel(event.getReferenceId()==null?event.getSummary():"--->>"); + final InlineLabel eventLabel = new InlineLabel(row + "; " + event.getReferenceId() == null ? event.getSummary() : event.getSummary() + "->>"); + eventLabel.addStyleName("calendar-event-label"); + + if (fullDayEvent) { + flowPanel.addStyleName("calendar-fullday-event-" + event.getParent().getStyle()); + } else { + eventLabel.addStyleName("calendar-event-" + event.getParent().getStyle()); + } + + if (!fullDayEvent) { + flowPanel.add(dateLabel); + } + flowPanel.add(eventLabel); + + final DecoratedPopupPanel detailPopup = new DecoratedPopupPanel(true); + + final Grid popupContent = new Grid(event.getParent().isEditable() ? 6 : 3, 1); + popupContent.setText(0, 0, event.getSummary()); + popupContent.getCellFormatter().addStyleName(0, 0, "calendar-popup-header"); + + if (!fullDayEvent) { + popupContent.getCellFormatter().addStyleName(1, 0, "calendar-popup-date"); + popupContent.getCellFormatter().addStyleName(1, 0, "calendar-event-" + event.getParent().getStyle()); + popupContent.setText(1, 0, eventDate.toString()); + } else { + popupContent.setText(1, 0, ""); + } + + if (event.getDescription() != null && !"".equals(event.getDescription())) { + popupContent.getCellFormatter().addStyleName(2, 0, "calendar-popup-description"); + popupContent.setText(2, 0, event.getDescription()); + } else { + popupContent.setText(2, 0, ""); + } + + if (event.getParent().isEditable() + && ProfileUtils.isGranted(authentication, GlobalPermissionEnum.EDIT_PROJECT_AGENDA)) { + + final Anchor editAnchor = new Anchor(I18N.CONSTANTS.calendarEditEvent()); + editAnchor.addClickHandler(new ClickHandler() { + + @Override + public void onClick(ClickEvent clickEvent) { + delegate.edit(event, CalendarWidget.this); + } + }); + + final Anchor deleteAnchor = new Anchor(I18N.CONSTANTS.calendarDeleteEvent()); + deleteAnchor.addClickHandler(new ClickHandler() { + + @Override + public void onClick(ClickEvent clickEvent) { + delegate.delete(event, CalendarWidget.this); + detailPopup.hide(); + } + }); + + final Anchor deleteChainAnchor = new Anchor("Delete chain"); + deleteChainAnchor.addClickHandler(new ClickHandler() { + + @Override + public void onClick(ClickEvent clickEvent) { + delegate.deleteChain(event, CalendarWidget.this); + refresh(); + detailPopup.hide(); + + } + }); + + popupContent.setWidget(3, 0, editAnchor); + popupContent.setWidget(4, 0, deleteAnchor); + popupContent.setWidget(5, 0, deleteChainAnchor); + } + + detailPopup.setWidget(popupContent); + + flowPanel.addClickHandler(new ClickHandler() { + + @Override + public void onClick(ClickEvent event) { + final int left = flowPanel.getAbsoluteLeft() - 10; + final int bottom = Window.getClientHeight() - flowPanel.getAbsoluteTop(); + + detailPopup.setWidth((getCellWidth(CELL_DEFAULT_WIDTH) + 20) + "px"); + + // Show the popup + detailPopup.setPopupPositionAndShow(new PositionCallback() { + + @Override + public void setPosition(int offsetWidth, int offsetHeight) { + detailPopup.getElement().getStyle().setPropertyPx("left", left); + detailPopup.getElement().getStyle().setProperty("top", ""); + detailPopup.getElement().getStyle().setPropertyPx("bottom", bottom); } + }); + } + }); + + if (startDrawPosition != -1) { + int height = 12; + int top = startDrawPosition > 0 ? (startDrawPosition - 1) * height : 0; + DOM.setStyleAttribute(flowPanel.getElement(), "position", "relative"); + DOM.setStyleAttribute(flowPanel.getElement(), "top", top + "px"); + // startDrawPosition ++; + } + cell.add(flowPanel); + } + + // if (eventLimit != UNDEFINED && (fullDayEventCounter + sortedHourEvents.size()) > eventLimit) { + if (startDrawPosition == -1 && eventLimit != UNDEFINED && (fullDayEventCounter + sortedHourEvents.size()) > 1) { + //final Anchor eventLabel = new Anchor("\u25BC +" + (sortedHourEvents.size()-eventLimit) + " st:" + fullDayEventCounter +" fd events"); + final Anchor eventLabel = new Anchor("\u25BC " + (sortedHourEvents.size() + fullDayEventCounter) + " events"); + // eventLabel.setTitle("Click to view all events of the day."); + final Date thisDate = new Date(date.getTime()); + String theDateString = DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.YEAR_MONTH_WEEKDAY_DAY).format(thisDate); + eventLabel.setTitle(theDateString + "\nClick to view all events of the day:" + + "\nShort time events: " + sortedHourEvents.size() + + "\nFull day events: " + fullDayEventCounter); + + eventLabel.addClickHandler(new ClickHandler() { + + @Override + public void onClick(ClickEvent event) { + startDate = thisDate; + setDisplayMode(DisplayMode.WEEK); + } + }); + eventLabel.addStyleName("calendar-event-limit"); + DOM.setStyleAttribute(eventLabel.getElement(), "border-color", "#1c61d9"); + DOM.setStyleAttribute(eventLabel.getElement(), "border-style", "solid"); + DOM.setStyleAttribute(eventLabel.getElement(), "border-width", "1px"); + cell.add(eventLabel); + } + } + + /** + * Returns the first date of the week that includes the given date. + * + * @param day A date + * @param firstDay The first day of the week (such as + * {@link #SUNDAY}, {@link #MONDAY} or anything else). + * @return The first date of the week that includes day, as a + * {@link Date}. + */ + private static Date getFirstDateOfWeek(Date day, int firstDay) { + final int decal = (day.getDay() + 7 - firstDay) % 7; + return new Date(day.getYear(), day.getMonth(), day.getDate() - decal); + } + + /** + * Calculates the number of the week that includes the given date. + * + * @param date A date + * @param firstDay The first day of the week (such as + * {@link #SUNDAY}, {@link #MONDAY} or anything else). + * @return The number of the week that includes date. + */ + private static int getWeekNumber(Date date, int firstDay) { + int daysToThursday = 4 - date.getDay(); + + if (date.getDay() < firstDay) { + daysToThursday -= 7; + } + + final Date thursday = new Date(date.getYear(), date.getMonth(), date.getDate() + daysToThursday); + + final Date januaryFourth = new Date(thursday.getYear(), 0, 4); + final int daysToMonday = 1 - januaryFourth.getDay(); // Essayer avec le + // 1er jour de + // la + // semaine + final Date monday = new Date(thursday.getYear(), 0, 4 + daysToMonday); + + final double diff = Math.floor((thursday.getTime() - monday.getTime()) / (1000 * 60 * 60 * 24)); + return (int) Math.ceil(diff / 7.0); + } + + private void placeItemInGridMonth(Widget panel, int colStart, int colEnd, + int row, int cellPosition) { + final FlexTable grid = (FlexTable) getWidget(); + // FlowPanel cell = (FlowPanel) grid.getWidget(1, 1); + FlowPanel cell = (FlowPanel) grid.getWidget(row, colStart); + cell.add(panel);//sssss + calculatedCellOffsetHeight = cell.getElement().getClientHeight();//OffsetHeight(); + + int height = appointmentHeight(); + height = 12; + //float width = ((float) (colEnd - colStart) / (float) DAYS_IN_A_WEEK) * 100f - 1f; + float width = (colEnd - colStart) * 100f; + + float top = 0; + + cell = (FlowPanel) grid.getWidget(row, colStart); + + setFullDayEventStyle(panel, top, width, height); + } + + private static int appointmentPaddingTop() { + return 1 + (Math.abs(FormattingUtil.getBorderOffset()) * 3); + } + + private static int appointmentHeight() { + // TODO: calculate appointment height dynamically + return 12; + } + /** + * Multiple calculated ("cached") values reused during laying out + * the month view elements. + */ + private int DAYS_IN_A_WEEK = 7; + private int calculatedWeekDayHeaderHeight; + private int calculatedDayHeaderHeight; + /** + * Height of each Cell (day), including the day's header. + */ + private float calculatedCellOffsetHeight; - } - - final Iterator iterator = sortedFullDayEvents.iterator(); - //ak - eventLimit = 1;//999 - for (int i = 0; iterator.hasNext() && i < eventLimit; i++) { - final Event event = iterator.next(); - - final ClickableFlowPanel flowPanel = new ClickableFlowPanel(); - flowPanel.addStyleName("calendar-event"); - - boolean fullDayEvent = false; - - final StringBuilder eventDate = new StringBuilder(); - eventDate.append(hourFormatter.format(event.getDtstart())); - if (event.getDtend() != null) { - eventDate.append(" "); - eventDate.append(hourFormatter.format(event.getDtend())); - -//-- if (event.getDtstart().getDate() != event.getDtend().getDate() -//-- || event.getDtstart().getMonth() != event.getDtend().getMonth() -//-- || event.getDtstart().getYear() != event.getDtend().getYear()) { - fullDayEvent = true; - flowPanel.addStyleName("calendar-fullday-event"); -//-- } - } - - final InlineLabel dateLabel = new InlineLabel(eventDate.toString()); - dateLabel.addStyleName("calendar-event-date"); - - final InlineLabel eventLabel = new InlineLabel(event.getSummary()); - //final InlineLabel eventLabel = new InlineLabel(event.getDtstart().getDate() + "; " + (event.getReferenceId()==null?event.getSummary():event.getSummary()) + "+>>"); - eventLabel.addStyleName("calendar-event-label"); - - if (fullDayEvent) - flowPanel.addStyleName("calendar-fullday-event-" + event.getParent().getStyle()); - else - eventLabel.addStyleName("calendar-event-" + event.getParent().getStyle()); - - if (!fullDayEvent) - flowPanel.add(dateLabel); - flowPanel.add(eventLabel);//ak - //flowPanel.setTitle(event.getSummary()); - - final DecoratedPopupPanel detailPopup = new DecoratedPopupPanel(true); - - final Grid popupContent = new Grid(event.getParent().isEditable() ? 6 : 3, 1); - popupContent.setText(0, 0, event.getSummary()); - popupContent.getCellFormatter().addStyleName(0, 0, "calendar-popup-header"); - - if (!fullDayEvent) { - popupContent.getCellFormatter().addStyleName(1, 0, "calendar-popup-date"); - popupContent.getCellFormatter().addStyleName(1, 0, "calendar-event-" + event.getParent().getStyle()); - popupContent.setText(1, 0, eventDate.toString()); - } else - popupContent.setText(1, 0, ""); - - if (event.getDescription() != null && !"".equals(event.getDescription())) { - popupContent.getCellFormatter().addStyleName(2, 0, "calendar-popup-description"); - popupContent.setText(2, 0, event.getDescription()); - } else - popupContent.setText(2, 0, ""); - - if (event.getParent().isEditable() - && ProfileUtils.isGranted(authentication, GlobalPermissionEnum.EDIT_PROJECT_AGENDA)) { - - final Anchor editAnchor = new Anchor(I18N.CONSTANTS.calendarEditEvent()); - editAnchor.addClickHandler(new ClickHandler() { - - @Override - public void onClick(ClickEvent clickEvent) { - delegate.edit(event, CalendarWidget.this); - } - }); - - final Anchor deleteAnchor = new Anchor(I18N.CONSTANTS.calendarDeleteEvent()); - deleteAnchor.addClickHandler(new ClickHandler() { - - @Override - public void onClick(ClickEvent clickEvent) { - delegate.delete(event, CalendarWidget.this); - refresh(); - detailPopup.hide(); - } - }); - - final Anchor deleteChainAnchor = new Anchor("Delete chain"); - deleteChainAnchor.addClickHandler(new ClickHandler() { - - @Override - public void onClick(ClickEvent clickEvent) { - delegate.deleteChain(event, CalendarWidget.this); - refresh(); - detailPopup.hide(); - - } - }); - - popupContent.setWidget(3, 0, editAnchor); - popupContent.setWidget(4, 0, deleteAnchor); - popupContent.setWidget(5, 0, deleteChainAnchor); - } - - detailPopup.setWidget(popupContent); - - flowPanel.addClickHandler(new ClickHandler() { - - @Override - public void onClick(ClickEvent event) { - final int left = flowPanel.getAbsoluteLeft() - 10; - final int bottom = Window.getClientHeight() - flowPanel.getAbsoluteTop(); - - detailPopup.setWidth((getCellWidth(CELL_DEFAULT_WIDTH) + 20) + "px"); - - // Show the popup - detailPopup.setPopupPositionAndShow(new PositionCallback() { - - @Override - public void setPosition(int offsetWidth, int offsetHeight) { - detailPopup.getElement().getStyle().setPropertyPx("left", left); - detailPopup.getElement().getStyle().setProperty("top", ""); - detailPopup.getElement().getStyle().setPropertyPx("bottom", bottom); - } - }); - } - }); - -//--- cell.add(flowPanel); - // RootPanel.get().add(pageMessagePanel2); - final FlexTable grid = (FlexTable) getWidget(); - grid.setWidget(row, column, flowPanel); - // RootPanel.get().add(flowPanel); - // grid.add(flowPanel); - - - long diff = event.getDtend().getTime() - event.getDtstart().getTime(); - long diffDays = diff / (24 * 60 * 60 * 1000)+1; - int daysdiff = (int) diffDays; - //--+ Window.alert("eventLabel=" + eventLabel.getTitle() +"; " + eventLabel.getText() + ";COLUMN=" +column+ "; DAYS = " + daysdiff); - //Window.alert("column =" + column + "; daysdiff=" + daysdiff ); - if(column + daysdiff-1 < 8){ - //--+ Window.alert("Short"); - placeItemInGrid2(flowPanel, column, column + daysdiff, row, i); - }else{ - //--+ Window.alert("Long1"); - // Window.alert("daysdiff - (7-column)="+ (daysdiff - (7-column))); - placeItemInGrid2(flowPanel, column, 8, row, i); - ClickableFlowPanel flowPanel2 = new ClickableFlowPanel(); - flowPanel2.addStyleName("calendar-fullday-event-2");// + event.getParent().getStyle()); - //flowPanel2 = flowPanel; - final InlineLabel dateLabel2 = new InlineLabel("<<--");// + event.getSummary()); - flowPanel2.add(dateLabel2); - grid.setWidget(row+1, 1, flowPanel2); - //--+ Window.alert("Long2"); - //--+ Window.alert("daysdiff - (8-column)="+ (daysdiff - (8-column))); - placeItemInGrid2(flowPanel2, 1,1+ daysdiff - (8-column), row+1, i); - } -// private void placeItemInGrid2(Widget panel, int colStart, int colEnd,int row, int cellPosition) { - } -/* - if (eventLimit != UNDEFINED && sortedHourEvents.size() > eventLimit) { - final Anchor eventLabel = new Anchor("\u25BC +" + (sortedHourEvents.size()-1) + " events"); - eventLabel.setTitle("Click to view all events of the day."); - final Date thisDate = new Date(date.getTime()); - eventLabel.addClickHandler(new ClickHandler() { - - @Override - public void onClick(ClickEvent event) { - startDate = thisDate; - setDisplayMode(DisplayMode.WEEK); - } - }); - eventLabel.addStyleName("calendar-event-limit"); - cell.add(eventLabel); - } - */ - } - - /** - * Calculates the height of each day cell in the Month grid. It excludes the - * height of each day's header, as well as the overall header that shows the - * weekday labels. - */ + /** + * Height of each Cell (day), excluding the day's header. + */ + private float calculatedCellHeight; + + /** + * Display full day events with started date + * + * @param row + * @param column + * @param date + */ + private void drawFullDayEvents(int row, int column, final Date date) { + + TreeSet sortedFullDayEvents = sortedFullDayEventsSet(); + + for (final Calendar calendar : calendars) { + if (!(calendar.getIdentifier() instanceof ActivityCalendarIdentifier)) { + if (calendar.getFullDayEvents() != null) { + final Map> fullDayEventMap = normalize(calendar.getFullDayEvents()); + final List fullDayEvents = fullDayEventMap.get(date); + if (fullDayEvents != null) { + sortedFullDayEvents.addAll(fullDayEvents); + } + } + } + } + + final Iterator iterator = sortedFullDayEvents.iterator(); + //ak + eventLimit = 1;//999 + for (int i = 0; iterator.hasNext() && i < eventLimit; i++) { + final Event event = iterator.next(); + final ClickableFlowPanel flowPanelFullDayFirst = createFullDayPanel(event); + final ClickableFlowPanel flowPanelFullDayContinue = createFullDayPanel(event); + final FlexTable grid = (FlexTable) getWidget(); + long diff = event.getDtend().getTime() - event.getDtstart().getTime(); + long diffDays = diff / (24 * 60 * 60 * 1000) + 1; + int daysdiff = (int) diffDays; + + //String theDateString = DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.YEAR_MONTH_WEEKDAY_DAY).format(thisDate); + flowPanelFullDayFirst.setTitle(createToolTipForFullDayEvent(daysdiff, event)); + + if (column + daysdiff - 1 < 8) { + placeItemInGridMonth(flowPanelFullDayFirst, column, column + daysdiff, row, i); + } else { + placeItemInGridMonth(flowPanelFullDayFirst, column, 8, row, i); + if (row <= 5) { + flowPanelFullDayContinue.setTitle(createToolTipForFullDayEvent(daysdiff, event)); + placeItemInGridMonth(flowPanelFullDayContinue, 1, 1 + daysdiff - (8 - column), row + 1, i); + } + } + } + } + + private static String createToolTipForFullDayEvent(int daysdiff, final Event event) { + return daysdiff + " full day" + (daysdiff > 1 ? "s" : "") + " event." + + (event.getDtstart().equals(event.getDtend()) + ? DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.YEAR_MONTH_WEEKDAY_DAY).format(event.getDtstart()) + : ("\nFrom " + DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.YEAR_MONTH_WEEKDAY_DAY).format(event.getDtstart()) + + " to " + DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.YEAR_MONTH_WEEKDAY_DAY).format(event.getDtend()))) + + "\n" + event.getDescription(); + } + + /** + * @param event + * @return + */ + private ClickableFlowPanel createFullDayPanel(final Event event) { + final ClickableFlowPanel flowPanel = new ClickableFlowPanel(); + flowPanel.addStyleName("calendar-event"); + + boolean fullDayEvent = false; + + final StringBuilder eventDate = new StringBuilder(); + eventDate.append(hourFormatter.format(event.getDtstart())); + if (event.getDtend() != null) { + eventDate.append(" "); + eventDate.append(hourFormatter.format(event.getDtend())); + fullDayEvent = true; + flowPanel.addStyleName("calendar-fullday-event"); + } + + final InlineLabel dateLabel = new InlineLabel(eventDate.toString()); + dateLabel.addStyleName("calendar-event-date"); + + final InlineLabel eventLabel = new InlineLabel(event.getSummary()); + //final InlineLabel eventLabel = new InlineLabel(event.getDtstart().getDate() + "; " + (event.getReferenceId()==null?event.getSummary():event.getSummary()) + "+>>"); + eventLabel.addStyleName("calendar-event-label"); + + if (fullDayEvent) { + flowPanel.addStyleName("calendar-fullday-event-" + event.getParent().getStyle()); + } else { + eventLabel.addStyleName("calendar-event-" + event.getParent().getStyle()); + } + + if (!fullDayEvent) { + flowPanel.add(dateLabel); + } + flowPanel.add(eventLabel);//ak + //flowPanel.setTitle(event.getSummary()); + + final DecoratedPopupPanel detailPopup = new DecoratedPopupPanel(true); + + final Grid popupContent = new Grid(event.getParent().isEditable() ? 6 : 3, 1); + popupContent.setText(0, 0, event.getSummary()); + popupContent.getCellFormatter().addStyleName(0, 0, "calendar-popup-header"); + + if (!fullDayEvent) { + popupContent.getCellFormatter().addStyleName(1, 0, "calendar-popup-date"); + popupContent.getCellFormatter().addStyleName(1, 0, "calendar-event-" + event.getParent().getStyle()); + popupContent.setText(1, 0, eventDate.toString()); + } else { + popupContent.setText(1, 0, ""); + } + + if (event.getDescription() != null && !"".equals(event.getDescription())) { + popupContent.getCellFormatter().addStyleName(2, 0, "calendar-popup-description"); + popupContent.setText(2, 0, event.getDescription()); + } else { + popupContent.setText(2, 0, ""); + } + + if (event.getParent().isEditable() + && ProfileUtils.isGranted(authentication, GlobalPermissionEnum.EDIT_PROJECT_AGENDA)) { + + final Anchor editAnchor = new Anchor(I18N.CONSTANTS.calendarEditEvent()); + editAnchor.addClickHandler(new ClickHandler() { + + @Override + public void onClick(ClickEvent clickEvent) { + delegate.edit(event, CalendarWidget.this); + } + }); + + final Anchor deleteAnchor = new Anchor(I18N.CONSTANTS.calendarDeleteEvent()); + deleteAnchor.addClickHandler(new ClickHandler() { + + @Override + public void onClick(ClickEvent clickEvent) { + delegate.delete(event, CalendarWidget.this); + refresh(); + detailPopup.hide(); + } + }); + + final Anchor deleteChainAnchor = new Anchor("Delete chain"); + deleteChainAnchor.addClickHandler(new ClickHandler() { + + @Override + public void onClick(ClickEvent clickEvent) { + delegate.deleteChain(event, CalendarWidget.this); + refresh(); + detailPopup.hide(); + + } + }); + + popupContent.setWidget(3, 0, editAnchor); + popupContent.setWidget(4, 0, deleteAnchor); + popupContent.setWidget(5, 0, deleteChainAnchor); + } + + detailPopup.setWidget(popupContent); + + flowPanel.addClickHandler(new ClickHandler() { + + @Override + public void onClick(ClickEvent event) { + final int left = flowPanel.getAbsoluteLeft() - 10; + final int bottom = Window.getClientHeight() - flowPanel.getAbsoluteTop(); + + detailPopup.setWidth((getCellWidth(CELL_DEFAULT_WIDTH) + 20) + "px"); + + // Show the popup + detailPopup.setPopupPositionAndShow(new PositionCallback() { + + @Override + public void setPosition(int offsetWidth, int offsetHeight) { + detailPopup.getElement().getStyle().setPropertyPx("left", left); + detailPopup.getElement().getStyle().setProperty("top", ""); + detailPopup.getElement().getStyle().setPropertyPx("bottom", bottom); + } + }); + } + }); + return flowPanel; + } + + /** + * Calculates the height of each day cell in the Month grid. It excludes the + * height of each day's header, as well as the overall header that shows the + * weekday labels. + */ // private void calculateCellHeight() { // // int gridHeight = monthCalendarGrid.getOffsetHeight(); @@ -1327,5 +1178,183 @@ public void onClick(ClickEvent event) { // calculatedWeekDayHeaderHeight = weekdayRowHeight; // calculatedDayHeaderHeight = dayHeaderHeight; // } - + private TreeSet sortedFullDayEventsSet() { + // Displaying full day events + final TreeSet sortedFullDayEvents = new TreeSet(new Comparator() { + + @Override + public int compare(Event o1, Event o2) { + int compare = 0; + + if (o1 == null && o2 == null) { + return 0; + } else if (o2 == null) { + return 1; + } else if (o1 == null) { + return -1; + } + + if (compare == 0 && o1.getDtstart() != null && o2.getDtstart() != null) { + long o1Start = o1.getDtstart().getTime(); + long o2Start = o2.getDtstart().getTime(); + + if (o1Start < o2Start) { + compare = -1; + } else if (o1Start > o2Start) { + compare = 1; + } + } + + if (compare == 0 && o1.getSummary() != null && o2.getSummary() != null) { + compare = o1.getSummary().compareTo(o2.getSummary()); + } + + return compare; + } + }); + return sortedFullDayEvents; + } + + /** + * Display full day events with started date + * + * @param row + * @param column + * @param date + */ + private void drawFullDayEventsForWeek(int row, int column, final Date date, + List alreadyShownWeekViewEvents, + int[][] theShiftVecorOfFullDayEvents) { + + int theLastFDPanelInCellCounter = getLastFDPanelInCellCounter(theShiftVecorOfFullDayEvents, column); + // Window.alert("START column = " + column + "; theLastFullRaw =" + theLastFDPanelInCellCounter); + TreeSet sortedFullDayEvents = sortedFullDayEventsSet(); + int eventCounter = 0; + int longFullDayEventShownCounter = 0; + + for (final Calendar calendar : calendars) { + if (!(calendar.getIdentifier() instanceof ActivityCalendarIdentifier)) { + if (calendar.getFullDayEvents() != null) { + final Map> fullDayEventMap = normalize(calendar.getFullDayEvents()); + for (Map.Entry> entry : fullDayEventMap.entrySet()) { + Date key = entry.getKey(); + List value = entry.getValue(); + for (Iterator iterator = value.iterator(); iterator.hasNext();) { + Event next = iterator.next(); + if (!alreadyShownWeekViewEvents.contains(next)) { + Date theStartEventDate = next.getDtstart(); + Date theEndEventDate = next.getDtend(); + if (date.after(theStartEventDate) && date.before(theEndEventDate) + || date.equals(theStartEventDate) + || date.equals(theEndEventDate)) { + // In between + eventCounter++; + sortedFullDayEvents.add(next); + alreadyShownWeekViewEvents.add(next); + } + } else { + Date theStartEventDate = next.getDtstart(); + Date theEndEventDate = next.getDtend(); + if (date.after(theStartEventDate) && date.before(theEndEventDate) + || date.equals(theStartEventDate) + || date.equals(theEndEventDate)) { + + longFullDayEventShownCounter++; +// sortedFullDayEvents.add(next); +// alreadyShownWeekViewEvents.add(next); + } + } + } + } + } + } + } + + final Iterator iterator = sortedFullDayEvents.iterator(); + //ak + int eventLimit = 10;//999 + int counterIvent = 0; + boolean foundRowToPlace = false; + int theRowToPlace = 0; + int last = theLastFDPanelInCellCounter; + for (int i = 0; iterator.hasNext() && i < eventLimit; i++) { + last = last + 1; + final Event event = iterator.next(); + + final ClickableFlowPanel fullDayFlowPanel = createFullDayPanel(event); + final FlexTable grid = (FlexTable) getWidget(); + ///ssss1 grid.setWidget(row, column, flowPanelFullDayFirst); + // RootPanel.get().add(flowPanelFullDayFirst); + // grid.add(flowPanelFullDayFirst); + + Date theStartEventDate = event.getDtstart(); + long startDTForWeekleView = 0; + long diff = event.getDtend().getTime() - event.getDtstart().getTime(); + if (date.after(theStartEventDate)) { + diff = theStartEventDate.getTime() - event.getDtstart().getTime(); + } + + long diffDays = diff / (24 * 60 * 60 * 1000) + 1; + int daysdiff = (int) diffDays; + + fullDayFlowPanel.setTitle(createToolTipForFullDayEvent(daysdiff, event)); + //to show full day long event if it longer then 1 week + while (column + daysdiff - 1 >= 8) { + daysdiff--; + } + + if (column + daysdiff - 1 < 8) { + for (int day = column; day < column + daysdiff; day++) { + theShiftVecorOfFullDayEvents[day][last] += 1; + } + longFullDayEventShownCounter = theRowToPlace;// + counterIvent; + + int theLastFullDayLinePlace44 = getLastFDPanelInCellCounter(theShiftVecorOfFullDayEvents, column); + + placeItemInGridWeek(fullDayFlowPanel, column, column + daysdiff, counterIvent, theLastFDPanelInCellCounter); + + } + counterIvent++; + } + + } + + private void placeItemInGridWeek(Widget panel, int colStart, int colEnd, + int row, int cellPosition) { + final FlexTable grid = (FlexTable) getWidget(); + //sss1FlowPanel cell = (FlowPanel) grid.getWidget(1, 1); + FlowPanel cell = (FlowPanel) grid.getWidget(1, colStart);//row + cell.add(panel);//sssss 111 +// calculatedCellOffsetHeight = cell.getElement().getClientHeight();//OffsetHeight(); +// float calculatedCellOffsetWidth = cell.getElement().getOffsetWidth();; +// NumberFormat percFormat = NumberFormat.getFormat("."); +// +// int paddingTop = appointmentPaddingTop() + 3; + int height = appointmentHeight();//12 + //float left = (float) colStart / (float) DAYS_IN_A_WEEK * 100f + .5f + //float left = (float) colStart / (float) DAYS_IN_A_WEEK * 50f + .5f + cellPosition * 5; + //float width = ((float) (colEnd - colStart) / (float) DAYS_IN_A_WEEK) * 100f - 1f; + float width = (colEnd - colStart) * 100f; +// float top = (row * (height + paddingTop)) + cellPosition * 3; + float top = cellPosition * height + cellPosition * 2; + + setFullDayEventStyle(panel, top, width, height); + } + + private void setFullDayEventStyle(Widget panel, float top, float width, int height) { + //final FlexTable grid = (FlexTable) getWidget(); + //cell = (FlowPanel) grid.getWidget(row, colStart); + //cell = (FlowPanel) grid.getWidget(1, colStart); + + DOM.setStyleAttribute(panel.getElement(), "position", "relative"); + DOM.setStyleAttribute(panel.getElement(), "top", top + "px"); + DOM.setStyleAttribute(panel.getElement(), "width", width + "%"); + DOM.setStyleAttribute(panel.getElement(), "height", height + "px"); + DOM.setStyleAttribute(panel.getElement(), "border-radius", "20px 20px 20px 20px"); + DOM.setStyleAttribute(panel.getElement(), "border-color", "#1c61d9"); + DOM.setStyleAttribute(panel.getElement(), "border-style", "solid"); + DOM.setStyleAttribute(panel.getElement(), "border-width", "1px"); + DOM.setStyleAttribute(panel.getElement(), "background-color", "rgba(28,97,217,0.3)"); + DOM.setStyleAttribute(panel.getElement(), "background", "linear-gradient(-90deg, #0000, #1c61d9)"); + } } From 9a545257c0e11f3711272b9e83d2bd3e21c19efa Mon Sep 17 00:00:00 2001 From: Seal98 Date: Tue, 15 Aug 2017 22:44:25 +0300 Subject: [PATCH 30/39] index on iss852: 939e0a5 (issue#852) Show Full day events on monthly and weekly calendar views Implemented: -on the Monthly calendar view are shown Full day events. If number of events exceeds limit then anchor to weekly calendar view is shown with counter of all events in the day. -the anchor has tool tip with detailed information -added tool tip to Full day event with detailed information -on the Weekly calendar view are shown all Full day events in the week. The events are shown one under the other without overlapping. From 6deb4ecab76cfca337cd32731129f0dc248eb7df Mon Sep 17 00:00:00 2001 From: Seal98 Date: Thu, 17 Aug 2017 01:08:35 +0300 Subject: [PATCH 31/39] [WIP] non-fullday events (issue#852) Adding non-fulday events for several days into the database using only one road --- .../calendar/CalendarEventPresenter.java | 347 ++++-------------- .../client/ui/widget/CalendarWidget.java | 3 +- .../org/sigmah/shared/dto/calendar/Event.java | 2 +- 3 files changed, 74 insertions(+), 278 deletions(-) diff --git a/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java b/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java index fc14bcdec..0cb393089 100644 --- a/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java +++ b/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java @@ -459,6 +459,7 @@ private void prepareEditView() { view.getForm().clearState(); view.getEventSummaryField().setValue(event.getSummary()); view.getEventDateStartField().setValue(event.getKey()); + view.getEventDateEndField().setValue(event.getDtend()); if (view.getRepeatEventPeriodRG() != null) { view.getRepeatEventPeriodRG().clear(); view.getRepeatEventPeriodRG().clearInvalid(); @@ -485,8 +486,6 @@ private void prepareEditView() { view.getRadioMonthlySameDate().hide(); view.getRadioMonthlySameDayOfWeek().hide(); - view.getEventDateEndField().clear(); - view.getEventDateEndField().hide(); view.getRadioNumberOfRepetitions().setValue(true); view.getNumberOfRepetitions().enable(); @@ -512,7 +511,7 @@ private void prepareEditView() { view.getDailyNumberOfRepetitions().setValue("1"); view.getDailyRepetitionEndDate().setValue(new Date()); } - if (event.getDtend().getDate() - event.getDtstart().getDate() == 1) { + if (event.getEventType().contains("F")) { view.getAllDayCheckbox().setValue(true); view.getEventStartTimeField().hide(); view.getEventEndTimeField().hide(); @@ -521,7 +520,7 @@ private void prepareEditView() { view.getEventStartTimeField().show(); view.getEventEndTimeField().show(); } - if (!isFullDayEvent(event)) { + if (!event.getEventType().contains("F")) { final Time startTime = event.getDtstart() != null ? view.getEventStartTimeField().findModel(event.getDtstart()) : null; view.getEventStartTimeField().setValue(startTime); @@ -654,14 +653,36 @@ private void onSaveAction() { Date endDate = createEndDateProperty(isFullDayEvent, beginEventIntervalDate, properties); properties.put(Event.DESCRIPTION, view.getEventDescriptionField().getValue()); - + + if (event == null) { processAddEvent(endEventIntervalDate, beginEventIntervalDate, startDate, endDate, properties, eventSummary, eventDescription); } else { + properties.put(Event.EVENT_TYPE, event.getEventType()); properties.put(Event.REFERENCE_ID, event.getReferenceId()); + + if(view.getAllDayCheckbox().getValue() == true){ + if(event.getEventType() != null){ + if("O".equals(event.getEventType())) properties.put(Event.EVENT_TYPE,"OF"); + else if("D".equals(event.getEventType())) properties.put(Event.EVENT_TYPE,"DF"); + else if("W".equals(event.getEventType())) properties.put(Event.EVENT_TYPE,"WF"); + else if("M".equals(event.getEventType())) properties.put(Event.EVENT_TYPE,"MF"); + else if("Y".equals(event.getEventType())) properties.put(Event.EVENT_TYPE,"YF"); + } + } + else{ + if(event.getEventType() != null){ + if("OF".equals(event.getEventType())) properties.put(Event.EVENT_TYPE,"O"); + else if("DF".equals(event.getEventType())) properties.put(Event.EVENT_TYPE,"D"); + else if("WF".equals(event.getEventType())) properties.put(Event.EVENT_TYPE,"W"); + else if("MF".equals(event.getEventType())) properties.put(Event.EVENT_TYPE,"M"); + else if("YF".equals(event.getEventType())) properties.put(Event.EVENT_TYPE,"Y"); + } + } editPersonalEvent(event, properties); } + } /** @@ -790,9 +811,12 @@ private void processOnceEvent(final Date beginEventIntervalDate1, long diffInMil if (daysDiff == 1) { addPersonalEvent(properties); } else { - properties.put(Event.SUMMARY, (String) properties.get(Event.SUMMARY) + " (Once event 1 of " + daysDiff + ")"); - properties.put(Event.DESCRIPTION, (String) properties.get(Event.DESCRIPTION) + " (Once event 1 of " + daysDiff + ")"); + properties.put(Event.SUMMARY, (String) properties.get(Event.SUMMARY) + " (Once event)"); + properties.put(Event.DESCRIPTION, (String) properties.get(Event.DESCRIPTION) + " (Once event)"); properties.put(Event.EVENT_TYPE, "O"); + if (view.getAllDayCheckbox().getValue() == true) { + properties.put(Event.EVENT_TYPE, "OF"); + } addPersonalEventOnce(properties, daysDiff, beginEventIntervalDate, milisPerDay, startDate, endDate, eventSummary, eventDescription); } } @@ -815,39 +839,11 @@ public void onCommandSuccess(final CreateResult result) { event.setIdentifier((Integer) result.getEntity().getId()); properties.put(Event.REFERENCE_ID, (Integer) result.getEntity().getId()); updateEvent(event, properties); - addOnceSeriesEvent((Integer) result.getEntity().getId(), daysInterval, calBeginNextEventDateLong, milisPerDay, startDate, endDate, eventSummary, eventDescription); + // addOnceSeriesEvent((Integer) result.getEntity().getId(), daysInterval, calBeginNextEventDateLong, milisPerDay, startDate, endDate, eventSummary, eventDescription); } }, view.getCancelButton(), view.getSaveButton()); } - - private void addOnceSeriesEvent(Integer ids, long daysInterval, long calBeginNextEventDateLong, long milisPerDay, final Date startDate, final Date endDate, String eventSummary, String eventDescription) { - //Date calBeginNextEventDate; - - for (int i = 1; i < daysInterval; i++) { - - calBeginNextEventDateLong += milisPerDay; - //calBeginNextEventDate = new Date(calBeginNextEventDateLong); - - Map dailyProperties = new HashMap(); - dailyProperties.put(Event.CALENDAR_ID, calendarWrapper); - dailyProperties.put(Event.SUMMARY, view.getEventSummaryField().getValue()); - dailyProperties.put(Event.DATE, new Date(calBeginNextEventDateLong)); - - setFullDayEvent(startDate, endDate, new Date(calBeginNextEventDateLong), dailyProperties); - - String newSummary = eventSummary; - String newDescription = eventDescription; - newSummary += " (Once event " + (i + 1) + " of " + daysInterval + ")"; - newDescription += " (Once event " + (i + 1) + " of " + daysInterval + ")"; - dailyProperties.put(Event.SUMMARY, newSummary); - dailyProperties.put(Event.DESCRIPTION, newDescription); - dailyProperties.put(Event.EVENT_TYPE, "O"); - dailyProperties.put(Event.REFERENCE_ID, ids); - - addPersonalEvent(dailyProperties); - } - } /** * Add new Daily calendar events processing. * @@ -868,11 +864,10 @@ private void processDailyEvents(long count, long lengthDailyEvent, long milisPer properties.put(Event.DESCRIPTION, (String) properties.get(Event.DESCRIPTION) + " (Daily event 1 of " + count + ")"); if (view.getAllDayCheckbox().getValue() == true) { properties.put(Event.EVENT_TYPE, "DF"); - properties.put(Event.DATE_END, new Date(calBeginNextEventDateLong + milisPerDay * (lengthDailyEvent - 1))); } else { properties.put(Event.EVENT_TYPE, "D"); - properties.put(Event.DATE_END, new Date(calBeginNextEventDateLong)); } + properties.put(Event.DATE_END, new Date(calBeginNextEventDateLong + milisPerDay * (lengthDailyEvent - 1))); addPersonalEventDaily(properties, count, lengthDailyEvent, calBeginNextEventDateLong, milisPerDay, startDate, endDate, eventSummary, eventDescription); } @@ -898,43 +893,12 @@ public void onCommandSuccess(final CreateResult result) { properties.put(Event.REFERENCE_ID, (Integer) result.getEntity().getId()); updateEvent(event, properties); addDailySeriesEvent((Integer) result.getEntity().getId(), daysInterval, lengthDailyEvent, calBeginNextEventDateLong, milisPerDay, startDate, endDate, eventSummary, eventDescription); - if (view.getAllDayCheckbox().getValue() == false) { - addDailySeriesEventNew((Integer) result.getEntity().getId(), daysInterval, lengthDailyEvent, calBeginNextEventDateLong, milisPerDay, startDate, endDate, eventSummary, eventDescription); - } + // if (view.getAllDayCheckbox().getValue() == false) { + // addDailySeriesEventNew((Integer) result.getEntity().getId(), daysInterval, lengthDailyEvent, calBeginNextEventDateLong, milisPerDay, startDate, endDate, eventSummary, eventDescription); + // } } }, view.getCancelButton(), view.getSaveButton()); } - private void addDailySeriesEventNew(Integer ids, long daysInterval, long lengthDailyEvent, long calBeginNextEventDateLong1, long milisPerDay, final Date startDate, final Date endDate, String eventSummary, String eventDescription) { - //Date calBeginNextEventDate; - long calBeginNextEventDateLong = calBeginNextEventDateLong1; - for (int i = 0; i < daysInterval; i++) { - - for(int j=1;j dailyProperties = new HashMap(); - dailyProperties.put(Event.CALENDAR_ID, calendarWrapper); - dailyProperties.put(Event.SUMMARY, view.getEventSummaryField().getValue()); - - dailyProperties.put(Event.DATE, new Date(calBeginNextEventDateLong)); - dailyProperties.put(Event.DATE_END, new Date(calBeginNextEventDateLong)); - setFullDayEvent(startDate, endDate, new Date(calBeginNextEventDateLong), dailyProperties); - - String newSummary = eventSummary; - String newDescription = eventDescription; - newSummary += " (Daily event " + (i + 1) + " of " + daysInterval + ")"; - newDescription += " (Daily event " + (i + 1) + " of " + daysInterval + ")"; - dailyProperties.put(Event.SUMMARY, newSummary); - dailyProperties.put(Event.DESCRIPTION, newDescription); - dailyProperties.put(Event.EVENT_TYPE, "D"); - dailyProperties.put(Event.REFERENCE_ID, ids); - - addPersonalEvent(dailyProperties); - } - calBeginNextEventDateLong += milisPerDay; - } - } private void processAddEventError(final Throwable caught) { if (Log.isErrorEnabled()) { Log.error(I18N.CONSTANTS.calendarAddEventError(), caught); @@ -958,12 +922,10 @@ private void addDailySeriesEvent(Integer ids, long daysInterval, long lengthDail dailyProperties.put(Event.DATE, new Date(calBeginNextEventDateLong)); if (view.getAllDayCheckbox().getValue() == true) { dailyProperties.put(Event.EVENT_TYPE, "DF"); - dailyProperties.put(Event.DATE_END, new Date(calEndNextEventDateLong)); } else { dailyProperties.put(Event.EVENT_TYPE, "D"); - dailyProperties.put(Event.DATE_END, new Date(calBeginNextEventDateLong)); } - + dailyProperties.put(Event.DATE_END, new Date(calEndNextEventDateLong)); setFullDayEvent(startDate, endDate, new Date(calBeginNextEventDateLong), dailyProperties); String newSummary = eventSummary; @@ -1010,10 +972,14 @@ private void processWeeklyEvents(final Date beginEventIntervalDate, final Date e //ak properties.put(Event.SUMMARY, (String) properties.get(Event.SUMMARY) + " (Weekly event 1 of " + weeksInterval + ")"); properties.put(Event.SUMMARY, (String) properties.get(Event.SUMMARY)); properties.put(Event.DESCRIPTION, (String) properties.get(Event.DESCRIPTION) + " (Weekly event 1 of " + weeksInterval + ")"); - properties.put(Event.EVENT_TYPE, "W"); - if (view.getAllDayCheckbox().getValue() == false) { + if (view.getAllDayCheckbox().getValue() == true) { + properties.put(Event.EVENT_TYPE, "WF"); + } else { + properties.put(Event.EVENT_TYPE, "W"); + } + /* if (view.getAllDayCheckbox().getValue() == false) { properties.put(Event.DATE_END, new Date(calBeginNextEventDateLong)); - } + }*/ addPersonalEventWeekly(properties, weeksInterval, calBeginNextEventDateLong, calEndNextEventDateLong, daysInterval, startDate, endDate, eventSummary, eventDescription); } @@ -1039,29 +1005,14 @@ public void onCommandSuccess(final CreateResult result) { properties.put(Event.REFERENCE_ID, (Integer) result.getEntity().getId()); long milisPerDay = 86400000; addDailySeriesEventNew2((Integer) properties.get(Event.REFERENCE_ID), weeksInterval, calBeginNextEventDateLong, calEndNextEventDateLong, milisPerDay * 7, startDate, endDate, eventSummary, eventDescription); - if (view.getAllDayCheckbox().getValue() == false) { + /* if (view.getAllDayCheckbox().getValue() == false) { addWeeklySeriesEvent(properties, (String) result.getEntity().getId(), daysInterval, weeksInterval, calBeginNextEventDateLong, milisPerDay, startDate, endDate, eventSummary, eventDescription); - } + }*/ // addWeeklySeriesEvent(properties, (String) result.getEntity().getId(), daysInterval, weeksInterval, calBeginNextEventDateLong, milisPerDay, startDate, endDate, eventSummary, eventDescription); } }, view.getCancelButton(), view.getSaveButton()); } - private void addWeeklySeriesEvent(final Map properties, String ids, long daysInterval, int weeksInterval, long calBeginNextEventDateLong, long milisPerDay, final Date startDate, final Date endDate, String eventSummary, String eventDescription) { - for (int i = 0; i < weeksInterval; i++) { - - Map weeklyProperties = new HashMap(); - weeklyProperties.put(Event.CALENDAR_ID, calendarWrapper); - weeklyProperties.put(Event.SUMMARY, view.getEventSummaryField().getValue()); - weeklyProperties.put(Event.EVENT_TYPE, "W"); - weeklyProperties.put(Event.REFERENCE_ID, ids); - //int daysInterval = 4; - // addPersonalEvent(weeklyProperties); - - addDailySeriesEventNew((Integer)properties.get(Event.REFERENCE_ID), daysInterval, calBeginNextEventDateLong, milisPerDay, startDate, endDate, eventSummary, eventDescription, i, weeksInterval); - calBeginNextEventDateLong += (milisPerDay*7); - } - } private void addDailySeriesEventNew2(Integer ids, int daysInterval, long calBeginNextEventDateLong, long calEndNextEventDateLong, long milisPerWeek, final Date startDate, final Date endDate, String eventSummary, String eventDescription) { //Date calBeginNextEventDate; @@ -1077,56 +1028,28 @@ private void addDailySeriesEventNew2(Integer ids, int daysInterval, long calBegi dailyProperties.put(Event.DATE, new Date(calBeginNextEventDateLong)); - if (view.getAllDayCheckbox().getValue() == true) { + // if (view.getAllDayCheckbox().getValue() == true) { dailyProperties.put(Event.DATE_END, new Date(calEndNextEventDateLong)); - } else { - dailyProperties.put(Event.DATE_END, new Date(calBeginNextEventDateLong)); - } + // } else { + // dailyProperties.put(Event.DATE_END, new Date(calBeginNextEventDateLong)); + //} setFullDayEvent(startDate, endDate, new Date(calBeginNextEventDateLong), dailyProperties); String newSummary = eventSummary; String newDescription = eventDescription; - // ak newSummary += " (Weekly event " + (i + 1) + " of " + daysInterval + ")"; newDescription += " (Weekly event " + (i + 1) + " of " + daysInterval + ")"; dailyProperties.put(Event.SUMMARY, newSummary); dailyProperties.put(Event.DESCRIPTION, newDescription); - if(view.getAllDayCheckbox().getValue() == true) dailyProperties.put(Event.EVENT_TYPE, "WF"); + if(view.getAllDayCheckbox().getValue() == true) { + dailyProperties.put(Event.EVENT_TYPE, "WF"); + } else dailyProperties.put(Event.EVENT_TYPE, "W"); dailyProperties.put(Event.REFERENCE_ID, ids); addPersonalEvent(dailyProperties); } } - private void addDailySeriesEventNew(Integer ids, long daysInterval, long calBeginNextEventDateLong, long milisPerDay, final Date startDate, final Date endDate, String eventSummary, String eventDescription, final int j, final int weeksInterval) { - //Date calBeginNextEventDate; - - for (int i = 1; i < daysInterval; i++) { - - calBeginNextEventDateLong += milisPerDay; - //calBeginNextEventDate = new Date(calBeginNextEventDateLong); - - Map dailyProperties = new HashMap(); - dailyProperties.put(Event.CALENDAR_ID, calendarWrapper); - dailyProperties.put(Event.SUMMARY, view.getEventSummaryField().getValue()); - - dailyProperties.put(Event.DATE, new Date(calBeginNextEventDateLong)); - dailyProperties.put(Event.DATE_END, new Date(calBeginNextEventDateLong)); - - setFullDayEvent(startDate, endDate, new Date(calBeginNextEventDateLong), dailyProperties); - - String newSummary = eventSummary; - String newDescription = eventDescription; - //ak newSummary += " (Weekly event " + (j + 1) + " of " + weeksInterval + ")"; - newDescription += " (Weekly event " + (j + 1) + " of " + weeksInterval + ")"; - dailyProperties.put(Event.SUMMARY, newSummary); - dailyProperties.put(Event.DESCRIPTION, newDescription); - dailyProperties.put(Event.EVENT_TYPE, "W"); - dailyProperties.put(Event.REFERENCE_ID, ids); - - addPersonalEvent(dailyProperties); - } - } /** * Set date and time values for Full day events. * @@ -1169,11 +1092,10 @@ private void setFullDayEvent(final Date startDate, final Date endDate, Date calB private void processMonthlyEvents(final Date beginEventIntervalDate, Date endEventIntervalDate, final Date endEventIntervalDateRadio, final Map properties, Boolean isMonthlySameDayOfWeek, final Date startDate, final Date endDate, String eventSummary, String eventDescription) { properties.put(Event.EVENT_TYPE, "M"); if (view.getAllDayCheckbox().getValue() == true) { - properties.put(Event.DATE_END, endEventIntervalDate); properties.put(Event.EVENT_TYPE, "MF"); } else { - properties.put(Event.DATE_END, beginEventIntervalDate); } + properties.put(Event.DATE_END, endEventIntervalDate); Date endEventIntervalDate1 = endEventIntervalDate; long milisDiff =endEventIntervalDate.getTime() - beginEventIntervalDate.getTime(); endEventIntervalDate = endEventIntervalDateRadio; @@ -1236,81 +1158,14 @@ public void onCommandSuccess(final CreateResult result) { // Window.alert("DaysInterval = "+daysInterval); // addDailySeriesEventNew4((Integer)properties.get(Event.REFERENCE_ID), milisPerDay*7, beginEventIntervalDate, milisPerDay, startDate, endDate, eventSummary, eventDescription); addMonthlySeriesEvent(endEventIntervalDate, (String) result.getEntity().getId(), monthInterval, beginEventIntervalDate, startDate, endDate, eventSummary, eventDescription, isMonthlySameDayOfWeek); - if(view.getAllDayCheckbox().getValue() == true) { - properties.put(Event.DATE_END, endEventIntervalDate); - properties.put(Event.EVENT_TYPE, "MF");} - else addMonthlySeriesEventNew(endEventIntervalDate, (String) result.getEntity().getId(), monthInterval,daysInterval, beginEventIntervalDate, startDate, endDate, eventSummary, eventDescription, isMonthlySameDayOfWeek); + // if(view.getAllDayCheckbox().getValue() == true) { + // properties.put(Event.DATE_END, endEventIntervalDate); + // properties.put(Event.EVENT_TYPE, "MF");} + //else addMonthlySeriesEventNew(endEventIntervalDate, (String) result.getEntity().getId(), monthInterval,daysInterval, beginEventIntervalDate, startDate, endDate, eventSummary, eventDescription, isMonthlySameDayOfWeek); } }, view.getCancelButton(), view.getSaveButton()); } - private void addMonthlySeriesEventNew(final Date endEventIntervalDate, String ids, int monthInterval, final long daysInterval, Date beginEventIntervalDate, final Date startDate, final Date endDate, String eventSummary, String eventDescription, final boolean isMonthlySameDayOfWeek) { - Date calBeginNextEventDate = beginEventIntervalDate; - long milisPerDay = 86400000; - for (int i = 0; i < monthInterval; i++) { - //calBeginNextEventDate = getMonthlySameDate(beginEventIntervalDate, calBeginNextEventDate, i); - - Map monthlyProperties = new HashMap(); - monthlyProperties.put(Event.CALENDAR_ID, calendarWrapper); - monthlyProperties.put(Event.SUMMARY, view.getEventSummaryField().getValue()); - - monthlyProperties.put(Event.DATE, calBeginNextEventDate); - monthlyProperties.put(Event.EVENT_TYPE, "M"); - if (view.getAllDayCheckbox().getValue() == true) { - monthlyProperties.put(Event.DATE_END, endEventIntervalDate); - monthlyProperties.put(Event.EVENT_TYPE, "MF"); - } else { - monthlyProperties.put(Event.DATE_END, beginEventIntervalDate); - } - setFullDayEvent(startDate, endDate, calBeginNextEventDate, monthlyProperties); - - String newSummary = eventSummary; - String newDescription = eventDescription; - newSummary += " (Monthly event " + (i + 1) + " of " + monthInterval + ")"; - newDescription += " (Monthly " + (isMonthlySameDayOfWeek ? "same Day of a week " : "same Date ") + "event " + (i + 1) + " of " + monthInterval + ")"; - monthlyProperties.put(Event.SUMMARY, newSummary); - monthlyProperties.put(Event.DESCRIPTION, newDescription); - - monthlyProperties.put(Event.REFERENCE_ID, ids); - addMonthlySeriesEventNew2(endEventIntervalDate, (Integer) monthlyProperties.get(Event.REFERENCE_ID), daysInterval, calBeginNextEventDate.getTime(), milisPerDay, startDate, endDate, eventSummary, eventDescription, i, isMonthlySameDayOfWeek, monthInterval); - calBeginNextEventDate = getMonthlySameDayOfWeek2(beginEventIntervalDate, calBeginNextEventDate, i, isMonthlySameDayOfWeek); - } - } - - private void addMonthlySeriesEventNew2(final Date endEventIntervalDate, Integer ids, long daysInterval, long calBeginNextEventDateLong1, long milisPerDay, final Date startDate, final Date endDate, String eventSummary, String eventDescription, int j, final boolean isMonthlySameDayOfWeek, final int monthInterval) { - //Date calBeginNextEventDate; - long calBeginNextEventDateLong = calBeginNextEventDateLong1; - long diff = endEventIntervalDate.getTime()-calBeginNextEventDateLong; - for (int i = 1; i < daysInterval; i++) { - calBeginNextEventDateLong += milisPerDay; - //calBeginNextEventDate = getMonthlySameDate(beginEventIntervalDate, calBeginNextEventDate, i); - - Map monthlyProperties = new HashMap(); - monthlyProperties.put(Event.CALENDAR_ID, calendarWrapper); - monthlyProperties.put(Event.SUMMARY, view.getEventSummaryField().getValue()); - - monthlyProperties.put(Event.DATE, new Date(calBeginNextEventDateLong)); - monthlyProperties.put(Event.EVENT_TYPE, "M"); - if (view.getAllDayCheckbox().getValue() == true) { - monthlyProperties.put(Event.DATE_END, new Date(calBeginNextEventDateLong + diff)); - monthlyProperties.put(Event.EVENT_TYPE, "MF"); - } else { - monthlyProperties.put(Event.DATE_END, new Date(calBeginNextEventDateLong)); - } - - setFullDayEvent(startDate, endDate, new Date(calBeginNextEventDateLong), monthlyProperties); - - String newSummary = eventSummary; - String newDescription = eventDescription; - newSummary += " (Monthly event " + (j + 1) + " of " + monthInterval + ")"; - newDescription += " (Monthly " + (isMonthlySameDayOfWeek ? "same Day of a week " : "same Date ") + "event " + (j + 1) + " of " + monthInterval + ")"; - monthlyProperties.put(Event.SUMMARY, newSummary); - monthlyProperties.put(Event.DESCRIPTION, newDescription); - - monthlyProperties.put(Event.REFERENCE_ID, ids); - addPersonalEvent(monthlyProperties); - } - } //private void addMonthlySeriesEvent(String ids, int monthInterval, Date beginEventIntervalDate, Date endEventIntervalDate, final Date startDate, final Date endDate, String eventSummary, String eventDescription, final boolean isMonthlySameDayOfWeek) { private void addMonthlySeriesEvent(Date endEventIntervalDate, String ids, int monthInterval, Date beginEventIntervalDate, final Date startDate, final Date endDate, String eventSummary, String eventDescription, final boolean isMonthlySameDayOfWeek) { @@ -1326,12 +1181,10 @@ private void addMonthlySeriesEvent(Date endEventIntervalDate, String ids, int mo monthlyProperties.put(Event.DATE, calBeginNextEventDate); monthlyProperties.put(Event.EVENT_TYPE, "M"); - if (view.getAllDayCheckbox().getValue() == true) { + monthlyProperties.put(Event.DATE_END, new Date(calBeginNextEventDate.getTime() + diff)); - monthlyProperties.put(Event.EVENT_TYPE, "MF"); - } else { - monthlyProperties.put(Event.DATE_END, new Date(calBeginNextEventDate.getTime())); - } + if (view.getAllDayCheckbox().getValue() == true) {monthlyProperties.put(Event.EVENT_TYPE, "MF");} + setFullDayEvent(startDate, endDate, calBeginNextEventDate, monthlyProperties); @@ -1362,11 +1215,9 @@ private void addMonthlySeriesEvent(Date endEventIntervalDate, String ids, int mo private void processYearEvents(final Date beginEventIntervalDate, Date endEventIntervalDate, final Date endEventIntervalDateRadio, final Map properties, Boolean isYearlySameDayOfWeek, final Date startDate, final Date endDate, String eventSummary, String eventDescription) { properties.put(Event.EVENT_TYPE, "Y"); if (view.getAllDayCheckbox().getValue() == true) { - properties.put(Event.DATE_END, endEventIntervalDate); properties.put(Event.EVENT_TYPE, "YF"); - } else { - properties.put(Event.DATE_END, beginEventIntervalDate); } + properties.put(Event.DATE_END, endEventIntervalDate); long milisDiff = endEventIntervalDate.getTime() - beginEventIntervalDate.getTime(); endEventIntervalDate = endEventIntervalDateRadio; int yearStart = beginEventIntervalDate.getYear(); @@ -1408,70 +1259,11 @@ public void onCommandSuccess(final CreateResult result) { long daysInterval = milisDiff/milisPerDay+1; addYearlySeriesEvent(milisDiff, (String) result.getEntity().getId(), yearInterval, beginEventIntervalDate, endEventIntervalDate, startDate, endDate, eventSummary, eventDescription, isYearlySameDayOfWeek); - if(view.getAllDayCheckbox().getValue() == false) addYearlySeriesEventNew(milisDiff, (String) result.getEntity().getId(), yearInterval,daysInterval, beginEventIntervalDate, startDate, endDate, eventSummary, eventDescription, isYearlySameDayOfWeek); + // if(view.getAllDayCheckbox().getValue() == false) addYearlySeriesEventNew(milisDiff, (String) result.getEntity().getId(), yearInterval,daysInterval, beginEventIntervalDate, startDate, endDate, eventSummary, eventDescription, isYearlySameDayOfWeek); } }, view.getCancelButton(), view.getSaveButton()); } - private void addYearlySeriesEventNew(final long milisDiff, String ids, int yearInterval, final long daysInterval, Date beginEventIntervalDate, final Date startDate, final Date endDate, String eventSummary, String eventDescription, final boolean isYearlySameDayOfWeek) { - Date calBeginNextEventDate = beginEventIntervalDate; - long milisPerDay = 86400000; - for (int i = 0; i < yearInterval; i++) { - //calBeginNextEventDate = getMonthlySameDate(beginEventIntervalDate, calBeginNextEventDate, i); - - - Map monthlyProperties = new HashMap(); - monthlyProperties.put(Event.CALENDAR_ID, calendarWrapper); - monthlyProperties.put(Event.SUMMARY, view.getEventSummaryField().getValue()); - - monthlyProperties.put(Event.DATE, calBeginNextEventDate); - - setFullDayEvent(startDate, endDate, calBeginNextEventDate, monthlyProperties); - - String newSummary = eventSummary; - String newDescription = eventDescription; - newSummary += " (Yearly event " + (i + 1) + " of " + yearInterval + ")"; - newDescription += " (Yearly " + (isYearlySameDayOfWeek ? "same Day of a week " : "same Date ") + "event " + (i + 1) + " of " + yearInterval + ")"; - monthlyProperties.put(Event.SUMMARY, newSummary); - monthlyProperties.put(Event.DESCRIPTION, newDescription); - - monthlyProperties.put(Event.REFERENCE_ID, ids); - addYearlySeriesEventNew2(milisDiff, (Integer)monthlyProperties.get(Event.REFERENCE_ID), daysInterval, calBeginNextEventDate.getTime(), milisPerDay, startDate, endDate, eventSummary, eventDescription, i, isYearlySameDayOfWeek, yearInterval); - calBeginNextEventDate = getYearlySameDayOfWeek(beginEventIntervalDate, calBeginNextEventDate, i, isYearlySameDayOfWeek); - } - } - - private void addYearlySeriesEventNew2(final long milisDiff, Integer ids, long daysInterval, long calBeginNextEventDateLong1, long milisPerDay, final Date startDate, final Date endDate, String eventSummary, String eventDescription, int j, final boolean isYearlySameDayOfWeek, final int yearInterval) { - //Date calBeginNextEventDate; - long calBeginNextEventDateLong = calBeginNextEventDateLong1; - for (int i = 1; i < daysInterval; i++) { - calBeginNextEventDateLong += milisPerDay; - //calBeginNextEventDate = getMonthlySameDate(beginEventIntervalDate, calBeginNextEventDate, i); - - Map yearlyProperties = new HashMap(); - yearlyProperties.put(Event.CALENDAR_ID, calendarWrapper); - yearlyProperties.put(Event.SUMMARY, view.getEventSummaryField().getValue()); - - yearlyProperties.put(Event.DATE, new Date(calBeginNextEventDateLong)); - - yearlyProperties.put(Event.EVENT_TYPE, "Y"); - if(view.getAllDayCheckbox().getValue() == true) { - yearlyProperties.put(Event.DATE_END, new Date(calBeginNextEventDateLong + milisDiff)); - yearlyProperties.put(Event.EVENT_TYPE, "YF");} - else yearlyProperties.put(Event.DATE_END, new Date(calBeginNextEventDateLong)); - - setFullDayEvent(startDate, endDate, new Date(calBeginNextEventDateLong), yearlyProperties); - - String newSummary = eventSummary; - String newDescription = eventDescription; - newSummary += " (Yearly event " + (j + 1) + " of " + yearInterval + ")"; - newDescription += " (Yearly " + (isYearlySameDayOfWeek ? "same Day of a week " : "same Date ") + "event " + (j + 1) + " of " + yearInterval + ")"; - yearlyProperties.put(Event.SUMMARY, newSummary); - yearlyProperties.put(Event.DESCRIPTION, newDescription); - - yearlyProperties.put(Event.REFERENCE_ID, ids); - addPersonalEvent(yearlyProperties); - } - } + private void addYearlySeriesEvent(final long milisDiff, String ids, int yearInterval, Date beginEventIntervalDate, Date endEventIntervalDate, final Date startDate, final Date endDate, String eventSummary, String eventDescription, final boolean isYearlySameDayOfWeek) { Date calBeginNextEventDate = beginEventIntervalDate; for (int i = 1; i < yearInterval; i++) { @@ -1483,10 +1275,11 @@ private void addYearlySeriesEvent(final long milisDiff, String ids, int yearInte yearlyProperties.put(Event.DATE, calBeginNextEventDate); yearlyProperties.put(Event.EVENT_TYPE, "Y"); + if(view.getAllDayCheckbox().getValue() == true) { + yearlyProperties.put(Event.EVENT_TYPE, "YF");} + yearlyProperties.put(Event.DATE_END, new Date(calBeginNextEventDate.getTime() + milisDiff)); - yearlyProperties.put(Event.EVENT_TYPE, "YF");} - else yearlyProperties.put(Event.DATE_END, calBeginNextEventDate); setFullDayEvent(startDate, endDate, calBeginNextEventDate, yearlyProperties); @@ -1578,6 +1371,7 @@ private void updateEvent(final Event event, final Map properties) { event.setReferenceId((Integer) properties.get(Event.REFERENCE_ID)); final Date day = (Date) properties.get(Event.DATE); + final Date dayEnd = (Date) properties.get(Event.DATE_END); final Object startHourSerialized = properties.get(Event.START_TIME); final Object endHourSerialized = properties.get(Event.END_TIME); @@ -1585,7 +1379,8 @@ private void updateEvent(final Event event, final Map properties) { final Date startHour = new Date((Long) startHourSerialized); event.setDtstart(startHour); if (endHourSerialized != null) { - final Date endHour = new Date((Long) endHourSerialized); + final Date endHour = new Date((Long) endHourSerialized+((dayEnd.getTime()-day.getTime()))); + //86400000 event.setDtend(endHour); } else { event.setDtend(null); @@ -1593,7 +1388,7 @@ private void updateEvent(final Event event, final Map properties) { } else { event.setDtstart(new Date(day.getYear(), day.getMonth(), day.getDate())); - event.setDtend(new Date(day.getYear(), day.getMonth(), day.getDate() + 1)); + event.setDtend(new Date(dayEnd.getYear(), dayEnd.getMonth(), dayEnd.getDate())); } // Adding the new event to the calendar diff --git a/src/main/java/org/sigmah/client/ui/widget/CalendarWidget.java b/src/main/java/org/sigmah/client/ui/widget/CalendarWidget.java index 57cbd17e9..6e6f99494 100644 --- a/src/main/java/org/sigmah/client/ui/widget/CalendarWidget.java +++ b/src/main/java/org/sigmah/client/ui/widget/CalendarWidget.java @@ -1131,7 +1131,8 @@ public void onClick(ClickEvent clickEvent) { popupContent.setWidget(3, 0, editAnchor); popupContent.setWidget(4, 0, deleteAnchor); - popupContent.setWidget(5, 0, deleteChainAnchor); + if(!"O".equals(event.getEventType()) && !"OF".equals(event.getEventType())){ + popupContent.setWidget(5, 0, deleteChainAnchor);} } detailPopup.setWidget(popupContent); diff --git a/src/main/java/org/sigmah/shared/dto/calendar/Event.java b/src/main/java/org/sigmah/shared/dto/calendar/Event.java index dcd86f0c5..81c0eb970 100644 --- a/src/main/java/org/sigmah/shared/dto/calendar/Event.java +++ b/src/main/java/org/sigmah/shared/dto/calendar/Event.java @@ -122,7 +122,7 @@ public void fillValues(Map values) { setDtstart(startHour); if (endHourSerialized instanceof Long) { - final Date endHour = new Date((Long) endHourSerialized); + final Date endHour = new Date((Long) endHourSerialized+((dayEnd.getTime()-day.getTime()))); setDtend(endHour); } else { setDtend(null); From 6c51881dc2a8c037503573a08878f84192ffc3cf Mon Sep 17 00:00:00 2001 From: Seal98 Date: Sat, 19 Aug 2017 14:21:00 +0300 Subject: [PATCH 32/39] (issue#852) cleaning, hided delete chain link Code cleaning. Delete chain link is hided after clicking on the once event --- .../calendar/CalendarEventPresenter.java | 377 ++++++++---------- .../ui/view/calendar/CalendarEventView.java | 4 +- .../client/ui/widget/CalendarWidget.java | 17 +- 3 files changed, 181 insertions(+), 217 deletions(-) diff --git a/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java b/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java index 0cb393089..f9d8ae04c 100644 --- a/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java +++ b/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java @@ -74,8 +74,10 @@ */ @Singleton public class CalendarEventPresenter extends AbstractPagePresenter { + private Event event; private CalendarWrapper calendarWrapper; + /** * Description of the view managed by this presenter. */ @@ -177,7 +179,7 @@ public static interface View extends ViewInterface { * @return */ FieldSet getYearlyRepSettings(); - + /** * * @return @@ -243,7 +245,7 @@ public static interface View extends ViewInterface { * @return */ RadioGroup getRepeatMultiEventPeriodRG(); - + /** * * @return @@ -255,111 +257,109 @@ public static interface View extends ViewInterface { * @return */ Radio getRadioMonthlySameDayOfWeek(); - + /** * * @return */ Radio getRadioRepetitionEndDate(); - + /** * * @return */ - Radio getRadioNumberOfRepetitions(); - + Radio getRadioNumberOfRepetitions(); + /** * * @return */ Radio getDailyRadioRepetitionEndDate(); - + /** * * @return */ - Radio getDailyRadioNumberOfRepetitions(); - + Radio getDailyRadioNumberOfRepetitions(); + /** * * @return */ Radio getWeeklyRadioRepetitionEndDate(); - + /** * * @return */ - Radio getWeeklyRadioNumberOfRepetitions(); - + Radio getWeeklyRadioNumberOfRepetitions(); + /** * * @return */ Radio getYearlyRadioRepetitionEndDate(); - + /** * * @return */ - Radio getYearlyRadioNumberOfRepetitions(); - + Radio getYearlyRadioNumberOfRepetitions(); + /** * * @return */ TextArea getNumberOfRepetitions(); - + /** * * @return */ - DateField getRepetitionEndDate(); - + DateField getRepetitionEndDate(); + /** * * @return */ TextArea getWeeklyNumberOfRepetitions(); - + /** * * @return */ - DateField getWeeklyRepetitionEndDate(); - + DateField getWeeklyRepetitionEndDate(); + /** * * @return */ TextArea getYearlyNumberOfRepetitions(); - + /** * * @return */ - DateField getYearlyRepetitionEndDate(); - + DateField getYearlyRepetitionEndDate(); + /** * * @return */ TextArea getDailyNumberOfRepetitions(); - + /** * * @return */ - DateField getDailyRepetitionEndDate(); - + DateField getDailyRepetitionEndDate(); + // void setShowAddEventView(boolean showAddEventView); } /** * The edited calendar event, or {@code null} if creation. */ - - /** * Presenters's initialization. * @@ -459,7 +459,7 @@ private void prepareEditView() { view.getForm().clearState(); view.getEventSummaryField().setValue(event.getSummary()); view.getEventDateStartField().setValue(event.getKey()); - view.getEventDateEndField().setValue(event.getDtend()); + view.getEventDateEndField().setValue(event.getDtend()); if (view.getRepeatEventPeriodRG() != null) { view.getRepeatEventPeriodRG().clear(); view.getRepeatEventPeriodRG().clearInvalid(); @@ -472,11 +472,11 @@ private void prepareEditView() { view.getPanelYearly().hide(); view.getYearlyVariantRG().hide(); - + view.getPanelWeekly().hide(); - - view.getPanelDaily().hide(); - + + view.getPanelDaily().hide(); + view.getYearlyVariantRG().hide(); view.getMontlyVariantRG().hide(); view.getRepeatEventPeriodRG().hide(); @@ -486,7 +486,6 @@ private void prepareEditView() { view.getRadioMonthlySameDate().hide(); view.getRadioMonthlySameDayOfWeek().hide(); - view.getRadioNumberOfRepetitions().setValue(true); view.getNumberOfRepetitions().enable(); view.getRepetitionEndDate().disable(); @@ -498,18 +497,18 @@ private void prepareEditView() { view.getYearlyRepetitionEndDate().disable(); view.getYearlyNumberOfRepetitions().setValue("1"); view.getYearlyRepetitionEndDate().setValue(new Date()); - + view.getWeeklyRadioNumberOfRepetitions().setValue(true); view.getWeeklyNumberOfRepetitions().enable(); view.getWeeklyRepetitionEndDate().disable(); view.getWeeklyNumberOfRepetitions().setValue("1"); view.getWeeklyRepetitionEndDate().setValue(new Date()); - + view.getDailyRadioNumberOfRepetitions().setValue(true); view.getDailyNumberOfRepetitions().enable(); view.getDailyRepetitionEndDate().disable(); view.getDailyNumberOfRepetitions().setValue("1"); - view.getDailyRepetitionEndDate().setValue(new Date()); + view.getDailyRepetitionEndDate().setValue(new Date()); } if (event.getEventType().contains("F")) { view.getAllDayCheckbox().setValue(true); @@ -545,8 +544,8 @@ private void prepareAddView() { view.getPanelYearly().hide(); view.getPanelWeekly().hide(); view.getPanelDaily().hide(); - // view.getMonthlyRepSettings().hide(); - // view.getYearlyRepSettings().hide(); + // view.getMonthlyRepSettings().hide(); + // view.getYearlyRepSettings().hide(); } view.getEventStartTimeField().show(); view.getEventEndTimeField().show(); @@ -559,19 +558,19 @@ private void prepareAddView() { view.getYearlySameDayOfWeekRB().enable(); view.getRadioMonthlySameDate().enable(); view.getRadioMonthlySameDayOfWeek().enable(); - + view.getRepeatMultiEventPeriodRG().enable(); view.getRadioNumberOfRepetitions().enable(); view.getRadioRepetitionEndDate().enable(); view.getNumberOfRepetitions().enable(); view.getRepetitionEndDate().enable(); - + view.getRepeatMultiEventPeriodRG().show(); view.getRadioNumberOfRepetitions().show(); view.getRadioRepetitionEndDate().show(); view.getNumberOfRepetitions().show(); view.getRepetitionEndDate().show(); - + view.getYearlyVariantRG().show(); view.getMontlyVariantRG().show(); view.getRepeatEventPeriodRG().show(); @@ -584,19 +583,19 @@ private void prepareAddView() { view.getAllDayCheckbox().setValue(true); view.getEventStartTimeField().hide(); view.getEventEndTimeField().hide(); - + view.getRadioNumberOfRepetitions().setValue(true); view.getNumberOfRepetitions().enable(); view.getRepetitionEndDate().disable(); view.getNumberOfRepetitions().setValue("1"); view.getRepetitionEndDate().setValue(new Date()); - + view.getYearlyRadioNumberOfRepetitions().setValue(true); view.getYearlyNumberOfRepetitions().enable(); view.getYearlyRepetitionEndDate().disable(); view.getYearlyNumberOfRepetitions().setValue("1"); - view.getYearlyRepetitionEndDate().setValue(new Date()); - + view.getYearlyRepetitionEndDate().setValue(new Date()); + view.getWeeklyRadioNumberOfRepetitions().setValue(true); view.getWeeklyNumberOfRepetitions().enable(); view.getWeeklyRepetitionEndDate().disable(); @@ -607,7 +606,7 @@ private void prepareAddView() { view.getDailyNumberOfRepetitions().enable(); view.getDailyRepetitionEndDate().disable(); view.getDailyNumberOfRepetitions().setValue("1"); - view.getDailyRepetitionEndDate().setValue(new Date()); + view.getDailyRepetitionEndDate().setValue(new Date()); } // --------------------------------------------------------------------------------------------------------------- @@ -636,53 +635,62 @@ private void onSaveAction() { final Date beginEventIntervalDate = view.getEventDateStartField().getValue(); properties.put(Event.DATE, beginEventIntervalDate); - + Date endEventIntervalDate = (view.getEventDateEndField() != null ? view.getEventDateEndField().getValue() : null); if (endEventIntervalDate == null) { endEventIntervalDate = beginEventIntervalDate; } properties.put(Event.DATE_END, endEventIntervalDate); //Window.alert("Date start: " +beginEventIntervalDate.getYear()+"." +beginEventIntervalDate.getMonth() - // + "." + beginEventIntervalDate.getDate() + " | Date end: " +endEventIntervalDate.getYear()+"." +endEventIntervalDate.getMonth() - // + "." + endEventIntervalDate.getDate());//temp for checker + // + "." + beginEventIntervalDate.getDate() + " | Date end: " +endEventIntervalDate.getYear()+"." +endEventIntervalDate.getMonth() + // + "." + endEventIntervalDate.getDate());//temp for checker Boolean isFullDayEvent = view.getAllDayCheckbox().getValue(); - // Window.alert("isAllDayEvent=" + isFullDayEvent);//temp for checker - + // Window.alert("isAllDayEvent=" + isFullDayEvent);//temp for checker Date startDate = createStartDateProperty(isFullDayEvent, beginEventIntervalDate, properties); Date endDate = createEndDateProperty(isFullDayEvent, beginEventIntervalDate, properties); properties.put(Event.DESCRIPTION, view.getEventDescriptionField().getValue()); - - + if (event == null) { processAddEvent(endEventIntervalDate, beginEventIntervalDate, startDate, endDate, properties, eventSummary, eventDescription); } else { - + properties.put(Event.EVENT_TYPE, event.getEventType()); properties.put(Event.REFERENCE_ID, event.getReferenceId()); - if(view.getAllDayCheckbox().getValue() == true){ - if(event.getEventType() != null){ - if("O".equals(event.getEventType())) properties.put(Event.EVENT_TYPE,"OF"); - else if("D".equals(event.getEventType())) properties.put(Event.EVENT_TYPE,"DF"); - else if("W".equals(event.getEventType())) properties.put(Event.EVENT_TYPE,"WF"); - else if("M".equals(event.getEventType())) properties.put(Event.EVENT_TYPE,"MF"); - else if("Y".equals(event.getEventType())) properties.put(Event.EVENT_TYPE,"YF"); - } - } - else{ - if(event.getEventType() != null){ - if("OF".equals(event.getEventType())) properties.put(Event.EVENT_TYPE,"O"); - else if("DF".equals(event.getEventType())) properties.put(Event.EVENT_TYPE,"D"); - else if("WF".equals(event.getEventType())) properties.put(Event.EVENT_TYPE,"W"); - else if("MF".equals(event.getEventType())) properties.put(Event.EVENT_TYPE,"M"); - else if("YF".equals(event.getEventType())) properties.put(Event.EVENT_TYPE,"Y"); - } - } + if (view.getAllDayCheckbox().getValue() == true) { + if (event.getEventType() != null) { + if ("O".equals(event.getEventType())) { + properties.put(Event.EVENT_TYPE, "OF"); + } else if ("D".equals(event.getEventType())) { + properties.put(Event.EVENT_TYPE, "DF"); + } else if ("W".equals(event.getEventType())) { + properties.put(Event.EVENT_TYPE, "WF"); + } else if ("M".equals(event.getEventType())) { + properties.put(Event.EVENT_TYPE, "MF"); + } else if ("Y".equals(event.getEventType())) { + properties.put(Event.EVENT_TYPE, "YF"); + } + } + } else { + if (event.getEventType() != null) { + if ("OF".equals(event.getEventType())) { + properties.put(Event.EVENT_TYPE, "O"); + } else if ("DF".equals(event.getEventType())) { + properties.put(Event.EVENT_TYPE, "D"); + } else if ("WF".equals(event.getEventType())) { + properties.put(Event.EVENT_TYPE, "W"); + } else if ("MF".equals(event.getEventType())) { + properties.put(Event.EVENT_TYPE, "M"); + } else if ("YF".equals(event.getEventType())) { + properties.put(Event.EVENT_TYPE, "Y"); + } + } + } editPersonalEvent(event, properties); } - + } /** @@ -710,7 +718,7 @@ private void processAddEvent(Date endEventIntervalDate, final Date beginEventInt Boolean isYearlySameDayOfWeek = view.getYearlySameDayOfWeekRB().getValue(); // Date endEventIntervalDate = (view.getEventDateEndField() != null ? view.getEventDateEndField().getValue() : null); Date endEventIntervalDateRadio = view.getEventDateStartField().getValue(); - + if (isDailyRepeatEvent) { long count = 0; long lengthDailyEvent = ((endEventIntervalDate.getTime() - beginEventIntervalDate.getTime()) / milisPerDay) + 1; @@ -807,7 +815,7 @@ private void processOnceEvent(final Date beginEventIntervalDate1, long diffInMil long beginEventIntervalDate = beginEventIntervalDate1.getTime(); properties.put(Event.SUMMARY, (String) properties.get(Event.SUMMARY)); properties.put(Event.DESCRIPTION, (String) properties.get(Event.DESCRIPTION)); - // Window.alert("DaysDiff = "+daysDiff); + // Window.alert("DaysDiff = "+daysDiff); if (daysDiff == 1) { addPersonalEvent(properties); } else { @@ -820,7 +828,8 @@ private void processOnceEvent(final Date beginEventIntervalDate1, long diffInMil addPersonalEventOnce(properties, daysDiff, beginEventIntervalDate, milisPerDay, startDate, endDate, eventSummary, eventDescription); } } - private void addPersonalEventOnce(final Map properties, final long daysInterval, final long calBeginNextEventDateLong, final long milisPerDay, final Date startDate, final Date endDate, final String eventSummary, final String eventDescription) { + + private void addPersonalEventOnce(final Map properties, final long daysInterval, final long calBeginNextEventDateLong, final long milisPerDay, final Date startDate, final Date endDate, final String eventSummary, final String eventDescription) { final CreateEntity createEntity = new CreateEntity(PersonalEventDTO.ENTITY_NAME, properties); @@ -839,7 +848,7 @@ public void onCommandSuccess(final CreateResult result) { event.setIdentifier((Integer) result.getEntity().getId()); properties.put(Event.REFERENCE_ID, (Integer) result.getEntity().getId()); updateEvent(event, properties); - // addOnceSeriesEvent((Integer) result.getEntity().getId(), daysInterval, calBeginNextEventDateLong, milisPerDay, startDate, endDate, eventSummary, eventDescription); + // addOnceSeriesEvent((Integer) result.getEntity().getId(), daysInterval, calBeginNextEventDateLong, milisPerDay, startDate, endDate, eventSummary, eventDescription); } }, view.getCancelButton(), view.getSaveButton()); } @@ -867,13 +876,12 @@ private void processDailyEvents(long count, long lengthDailyEvent, long milisPer } else { properties.put(Event.EVENT_TYPE, "D"); } - properties.put(Event.DATE_END, new Date(calBeginNextEventDateLong + milisPerDay * (lengthDailyEvent - 1))); + properties.put(Event.DATE_END, new Date(calBeginNextEventDateLong + milisPerDay * (lengthDailyEvent - 1))); addPersonalEventDaily(properties, count, lengthDailyEvent, calBeginNextEventDateLong, milisPerDay, startDate, endDate, eventSummary, eventDescription); } - - private void addPersonalEventDaily(final Map properties, final long daysInterval,final long lengthDailyEvent, final long calBeginNextEventDateLong, final long milisPerDay, final Date startDate, final Date endDate, final String eventSummary, final String eventDescription) { + private void addPersonalEventDaily(final Map properties, final long daysInterval, final long lengthDailyEvent, final long calBeginNextEventDateLong, final long milisPerDay, final Date startDate, final Date endDate, final String eventSummary, final String eventDescription) { final CreateEntity createEntity = new CreateEntity(PersonalEventDTO.ENTITY_NAME, properties); @@ -893,12 +901,13 @@ public void onCommandSuccess(final CreateResult result) { properties.put(Event.REFERENCE_ID, (Integer) result.getEntity().getId()); updateEvent(event, properties); addDailySeriesEvent((Integer) result.getEntity().getId(), daysInterval, lengthDailyEvent, calBeginNextEventDateLong, milisPerDay, startDate, endDate, eventSummary, eventDescription); - // if (view.getAllDayCheckbox().getValue() == false) { - // addDailySeriesEventNew((Integer) result.getEntity().getId(), daysInterval, lengthDailyEvent, calBeginNextEventDateLong, milisPerDay, startDate, endDate, eventSummary, eventDescription); - // } + // if (view.getAllDayCheckbox().getValue() == false) { + // addDailySeriesEventNew((Integer) result.getEntity().getId(), daysInterval, lengthDailyEvent, calBeginNextEventDateLong, milisPerDay, startDate, endDate, eventSummary, eventDescription); + // } } }, view.getCancelButton(), view.getSaveButton()); } + private void processAddEventError(final Throwable caught) { if (Log.isErrorEnabled()) { Log.error(I18N.CONSTANTS.calendarAddEventError(), caught); @@ -908,11 +917,11 @@ private void processAddEventError(final Throwable caught) { private void addDailySeriesEvent(Integer ids, long daysInterval, long lengthDailyEvent, long calBeginNextEventDateLong1, long milisPerDay, final Date startDate, final Date endDate, String eventSummary, String eventDescription) { //Date calBeginNextEventDate; - long calBeginNextEventDateLong = calBeginNextEventDateLong1; + long calBeginNextEventDateLong = calBeginNextEventDateLong1; for (int i = 1; i < daysInterval; i++) { - calBeginNextEventDateLong += (milisPerDay*lengthDailyEvent); - long calEndNextEventDateLong = calBeginNextEventDateLong + milisPerDay*(lengthDailyEvent-1); + calBeginNextEventDateLong += (milisPerDay * lengthDailyEvent); + long calEndNextEventDateLong = calBeginNextEventDateLong + milisPerDay * (lengthDailyEvent - 1); //calBeginNextEventDate = new Date(calBeginNextEventDateLong); Map dailyProperties = new HashMap(); @@ -925,7 +934,7 @@ private void addDailySeriesEvent(Integer ids, long daysInterval, long lengthDail } else { dailyProperties.put(Event.EVENT_TYPE, "D"); } - dailyProperties.put(Event.DATE_END, new Date(calEndNextEventDateLong)); + dailyProperties.put(Event.DATE_END, new Date(calEndNextEventDateLong)); setFullDayEvent(startDate, endDate, new Date(calBeginNextEventDateLong), dailyProperties); String newSummary = eventSummary; @@ -935,7 +944,7 @@ private void addDailySeriesEvent(Integer ids, long daysInterval, long lengthDail dailyProperties.put(Event.SUMMARY, newSummary); dailyProperties.put(Event.DESCRIPTION, newDescription); dailyProperties.put(Event.REFERENCE_ID, ids); - + addPersonalEvent(dailyProperties); } } @@ -954,32 +963,30 @@ private void addDailySeriesEvent(Integer ids, long daysInterval, long lengthDail */ private void processWeeklyEvents(final Date beginEventIntervalDate, final Date endEventIntervalDate, final Date endEventIntervalDateRadio, final Date startDate, final Date endDate, final Map properties, String eventSummary, String eventDescription) { long milisPerDay = 86400000; - long weekDiff = ((endEventIntervalDateRadio.getTime() - beginEventIntervalDate.getTime()+milisPerDay) / (milisPerDay*7)); + long weekDiff = ((endEventIntervalDateRadio.getTime() - beginEventIntervalDate.getTime() + milisPerDay) / (milisPerDay * 7)); int weeksInterval = (int) weekDiff; - if ((((endEventIntervalDateRadio.getTime() - beginEventIntervalDate.getTime() + milisPerDay) % (milisPerDay * 7)) >= ((endEventIntervalDate.getTime() - beginEventIntervalDate.getTime() + milisPerDay))) + if ((((endEventIntervalDateRadio.getTime() - beginEventIntervalDate.getTime() + milisPerDay) % (milisPerDay * 7)) >= ((endEventIntervalDate.getTime() - beginEventIntervalDate.getTime() + milisPerDay))) && (view.getWeeklyRadioNumberOfRepetitions().getValue() == true)) { weeksInterval++; } if (weeksInterval <= 0) { weeksInterval = 1; } - // if(view.getWeeklyRadioNumberOfRepetitions().getValue() == true) weeksInterval--; + if (endEventIntervalDate.getTime() - beginEventIntervalDate.getTime() == 0) { + weeksInterval--; + } + long calBeginNextEventDateLong = beginEventIntervalDate.getTime(); long calEndNextEventDateLong = endEventIntervalDate.getTime(); long daysInterval = ((endEventIntervalDate.getTime() - beginEventIntervalDate.getTime()) / milisPerDay) + 1; - // Window.alert("WeeksInterva = "+weekDiff+" | daysInterval = "+daysInterval); - //ak properties.put(Event.SUMMARY, (String) properties.get(Event.SUMMARY) + " (Weekly event 1 of " + weeksInterval + ")"); properties.put(Event.SUMMARY, (String) properties.get(Event.SUMMARY)); properties.put(Event.DESCRIPTION, (String) properties.get(Event.DESCRIPTION) + " (Weekly event 1 of " + weeksInterval + ")"); - if (view.getAllDayCheckbox().getValue() == true) { - properties.put(Event.EVENT_TYPE, "WF"); - } else { - properties.put(Event.EVENT_TYPE, "W"); - } - /* if (view.getAllDayCheckbox().getValue() == false) { - properties.put(Event.DATE_END, new Date(calBeginNextEventDateLong)); - }*/ + if (view.getAllDayCheckbox().getValue() == true) { + properties.put(Event.EVENT_TYPE, "WF"); + } else { + properties.put(Event.EVENT_TYPE, "W"); + } addPersonalEventWeekly(properties, weeksInterval, calBeginNextEventDateLong, calEndNextEventDateLong, daysInterval, startDate, endDate, eventSummary, eventDescription); } @@ -1005,35 +1012,25 @@ public void onCommandSuccess(final CreateResult result) { properties.put(Event.REFERENCE_ID, (Integer) result.getEntity().getId()); long milisPerDay = 86400000; addDailySeriesEventNew2((Integer) properties.get(Event.REFERENCE_ID), weeksInterval, calBeginNextEventDateLong, calEndNextEventDateLong, milisPerDay * 7, startDate, endDate, eventSummary, eventDescription); - /* if (view.getAllDayCheckbox().getValue() == false) { - addWeeklySeriesEvent(properties, (String) result.getEntity().getId(), daysInterval, weeksInterval, calBeginNextEventDateLong, milisPerDay, startDate, endDate, eventSummary, eventDescription); - }*/ - // addWeeklySeriesEvent(properties, (String) result.getEntity().getId(), daysInterval, weeksInterval, calBeginNextEventDateLong, milisPerDay, startDate, endDate, eventSummary, eventDescription); } }, view.getCancelButton(), view.getSaveButton()); } - private void addDailySeriesEventNew2(Integer ids, int daysInterval, long calBeginNextEventDateLong, long calEndNextEventDateLong, long milisPerWeek, final Date startDate, final Date endDate, String eventSummary, String eventDescription) { - //Date calBeginNextEventDate; - + private void addDailySeriesEventNew2(Integer ids, int daysInterval, long calBeginNextEventDateLong, long calEndNextEventDateLong, long milisPerWeek, final Date startDate, final Date endDate, String eventSummary, String eventDescription) { + for (int i = 1; i < daysInterval; i++) { calBeginNextEventDateLong += milisPerWeek; calEndNextEventDateLong += milisPerWeek; - //calBeginNextEventDate = new Date(calBeginNextEventDateLong); Map dailyProperties = new HashMap(); dailyProperties.put(Event.CALENDAR_ID, calendarWrapper); dailyProperties.put(Event.SUMMARY, view.getEventSummaryField().getValue()); dailyProperties.put(Event.DATE, new Date(calBeginNextEventDateLong)); - - // if (view.getAllDayCheckbox().getValue() == true) { - dailyProperties.put(Event.DATE_END, new Date(calEndNextEventDateLong)); - // } else { - // dailyProperties.put(Event.DATE_END, new Date(calBeginNextEventDateLong)); - //} - + + dailyProperties.put(Event.DATE_END, new Date(calEndNextEventDateLong)); + setFullDayEvent(startDate, endDate, new Date(calBeginNextEventDateLong), dailyProperties); String newSummary = eventSummary; @@ -1041,15 +1038,17 @@ private void addDailySeriesEventNew2(Integer ids, int daysInterval, long calBegi newDescription += " (Weekly event " + (i + 1) + " of " + daysInterval + ")"; dailyProperties.put(Event.SUMMARY, newSummary); dailyProperties.put(Event.DESCRIPTION, newDescription); - if(view.getAllDayCheckbox().getValue() == true) { + if (view.getAllDayCheckbox().getValue() == true) { dailyProperties.put(Event.EVENT_TYPE, "WF"); + } else { + dailyProperties.put(Event.EVENT_TYPE, "W"); } - else dailyProperties.put(Event.EVENT_TYPE, "W"); dailyProperties.put(Event.REFERENCE_ID, ids); - + addPersonalEvent(dailyProperties); } } + /** * Set date and time values for Full day events. * @@ -1089,17 +1088,16 @@ private void setFullDayEvent(final Date startDate, final Date endDate, Date calB * @param eventSummary the value of eventSummary * @param eventDescription the value of eventDescription */ - private void processMonthlyEvents(final Date beginEventIntervalDate, Date endEventIntervalDate, final Date endEventIntervalDateRadio, final Map properties, Boolean isMonthlySameDayOfWeek, final Date startDate, final Date endDate, String eventSummary, String eventDescription) { - properties.put(Event.EVENT_TYPE, "M"); + private void processMonthlyEvents(final Date beginEventIntervalDate, Date endEventIntervalDate, final Date endEventIntervalDateRadio, final Map properties, Boolean isMonthlySameDayOfWeek, final Date startDate, final Date endDate, String eventSummary, String eventDescription) { + properties.put(Event.EVENT_TYPE, "M"); if (view.getAllDayCheckbox().getValue() == true) { properties.put(Event.EVENT_TYPE, "MF"); } else { } - properties.put(Event.DATE_END, endEventIntervalDate); - Date endEventIntervalDate1 = endEventIntervalDate; - long milisDiff =endEventIntervalDate.getTime() - beginEventIntervalDate.getTime(); - endEventIntervalDate = endEventIntervalDateRadio; - // Window.alert(beginEventIntervalDate1.getDate() + "."+beginEventIntervalDate1.getMonth()+"."+beginEventIntervalDate1.getYear()+" | "+ endEventIntervalDate1.getDate()+"."+endEventIntervalDate1.getMonth()+"."+endEventIntervalDate1.getYear()); + properties.put(Event.DATE_END, endEventIntervalDate); + Date endEventIntervalDate1 = endEventIntervalDate; + long milisDiff = endEventIntervalDate.getTime() - beginEventIntervalDate.getTime(); + endEventIntervalDate = endEventIntervalDateRadio; int yearStart = beginEventIntervalDate.getYear(); int yearEnd = endEventIntervalDate.getYear(); int yearInterval = yearEnd - yearStart; @@ -1120,21 +1118,10 @@ private void processMonthlyEvents(final Date beginEventIntervalDate, Date endEve } properties.put(Event.SUMMARY, (String) properties.get(Event.SUMMARY) + " (Monthly event 1 of " + monthInterval + ")"); properties.put(Event.DESCRIPTION, (String) properties.get(Event.DESCRIPTION) + " (Monthly event 1 of " + monthInterval + ")"); - // if (isMonthlySameDayOfWeek) { - // properties.put(Event.EVENT_TYPE, "M1"); - // } else { - // properties.put(Event.EVENT_TYPE, "M2"); - // } - - //addPersonalEventMonthly(properties, monthInterval, beginEventIntervalDate, endEventIntervalDate, startDate, endDate, eventSummary, eventDescription, isMonthlySameDayOfWeek); - //Window.alert("MultiEvent = "+beginEventIntervalDate1.getDate() + "."+beginEventIntervalDate1.getMonth()+"."+beginEventIntervalDate1.getYear()+" | "+ endEventIntervalDate1.getDate()+"."+endEventIntervalDate1.getMonth()+"."+endEventIntervalDate1.getYear()); - //Window.alert("EndDateRadio = "+endEventIntervalDateRadio.getDate() + "."+endEventIntervalDateRadio.getMonth()+"."+endEventIntervalDateRadio.getYear()); - addPersonalEventMonthly(endEventIntervalDate1, properties, monthInterval, beginEventIntervalDate, milisDiff, startDate, endDate, eventSummary, eventDescription, isMonthlySameDayOfWeek); } - //private void addPersonalEventMonthly(final Map properties, final int monthInterval, final Date beginEventIntervalDate, final Date endEventIntervalDate, final Date startDate, final Date endDate, final String eventSummary, final String eventDescription, final boolean isMonthlySameDayOfWeek) { private void addPersonalEventMonthly(final Date endEventIntervalDate, final Map properties, final int monthInterval, final Date beginEventIntervalDate, final long milisDiff, final Date startDate, final Date endDate, final String eventSummary, final String eventDescription, final boolean isMonthlySameDayOfWeek) { final CreateEntity createEntity = new CreateEntity(PersonalEventDTO.ENTITY_NAME, properties); @@ -1154,25 +1141,16 @@ public void onCommandSuccess(final CreateResult result) { updateEvent(event, properties); properties.put(Event.REFERENCE_ID, (Integer) result.getEntity().getId()); long milisPerDay = 86400000; - long daysInterval = milisDiff/milisPerDay+1; - // Window.alert("DaysInterval = "+daysInterval); - // addDailySeriesEventNew4((Integer)properties.get(Event.REFERENCE_ID), milisPerDay*7, beginEventIntervalDate, milisPerDay, startDate, endDate, eventSummary, eventDescription); + long daysInterval = milisDiff / milisPerDay + 1; addMonthlySeriesEvent(endEventIntervalDate, (String) result.getEntity().getId(), monthInterval, beginEventIntervalDate, startDate, endDate, eventSummary, eventDescription, isMonthlySameDayOfWeek); - // if(view.getAllDayCheckbox().getValue() == true) { - // properties.put(Event.DATE_END, endEventIntervalDate); - // properties.put(Event.EVENT_TYPE, "MF");} - //else addMonthlySeriesEventNew(endEventIntervalDate, (String) result.getEntity().getId(), monthInterval,daysInterval, beginEventIntervalDate, startDate, endDate, eventSummary, eventDescription, isMonthlySameDayOfWeek); - } }, view.getCancelButton(), view.getSaveButton()); } - - //private void addMonthlySeriesEvent(String ids, int monthInterval, Date beginEventIntervalDate, Date endEventIntervalDate, final Date startDate, final Date endDate, String eventSummary, String eventDescription, final boolean isMonthlySameDayOfWeek) { + private void addMonthlySeriesEvent(Date endEventIntervalDate, String ids, int monthInterval, Date beginEventIntervalDate, final Date startDate, final Date endDate, String eventSummary, String eventDescription, final boolean isMonthlySameDayOfWeek) { Date calBeginNextEventDate = beginEventIntervalDate; - long diff = endEventIntervalDate.getTime()-beginEventIntervalDate.getTime(); + long diff = endEventIntervalDate.getTime() - beginEventIntervalDate.getTime(); for (int i = 1; i < monthInterval; i++) { - //calBeginNextEventDate = getMonthlySameDate(beginEventIntervalDate, calBeginNextEventDate, i); calBeginNextEventDate = getMonthlySameDayOfWeek2(beginEventIntervalDate, calBeginNextEventDate, i, isMonthlySameDayOfWeek); Map monthlyProperties = new HashMap(); @@ -1182,10 +1160,11 @@ private void addMonthlySeriesEvent(Date endEventIntervalDate, String ids, int mo monthlyProperties.put(Event.DATE, calBeginNextEventDate); monthlyProperties.put(Event.EVENT_TYPE, "M"); - monthlyProperties.put(Event.DATE_END, new Date(calBeginNextEventDate.getTime() + diff)); - if (view.getAllDayCheckbox().getValue() == true) {monthlyProperties.put(Event.EVENT_TYPE, "MF");} + monthlyProperties.put(Event.DATE_END, new Date(calBeginNextEventDate.getTime() + diff)); + if (view.getAllDayCheckbox().getValue() == true) { + monthlyProperties.put(Event.EVENT_TYPE, "MF"); + } - setFullDayEvent(startDate, endDate, calBeginNextEventDate, monthlyProperties); String newSummary = eventSummary; @@ -1213,11 +1192,11 @@ private void addMonthlySeriesEvent(Date endEventIntervalDate, String ids, int mo * @param eventDescription the value of eventDescription */ private void processYearEvents(final Date beginEventIntervalDate, Date endEventIntervalDate, final Date endEventIntervalDateRadio, final Map properties, Boolean isYearlySameDayOfWeek, final Date startDate, final Date endDate, String eventSummary, String eventDescription) { - properties.put(Event.EVENT_TYPE, "Y"); + properties.put(Event.EVENT_TYPE, "Y"); if (view.getAllDayCheckbox().getValue() == true) { properties.put(Event.EVENT_TYPE, "YF"); } - properties.put(Event.DATE_END, endEventIntervalDate); + properties.put(Event.DATE_END, endEventIntervalDate); long milisDiff = endEventIntervalDate.getTime() - beginEventIntervalDate.getTime(); endEventIntervalDate = endEventIntervalDateRadio; int yearStart = beginEventIntervalDate.getYear(); @@ -1232,7 +1211,6 @@ private void processYearEvents(final Date beginEventIntervalDate, Date endEventI properties.put(Event.SUMMARY, (String) properties.get(Event.SUMMARY) + " (Yearly event 1 of " + yearInterval + ")"); properties.put(Event.DESCRIPTION, (String) properties.get(Event.DESCRIPTION) + " (Yearly " + (isYearlySameDayOfWeek ? "same Day of a week " : "same Date ") + "event 1 of " + yearInterval + ")"); - addPersonalEventYearly(milisDiff, properties, yearInterval, beginEventIntervalDate, endEventIntervalDate, startDate, endDate, eventSummary, eventDescription, isYearlySameDayOfWeek); } @@ -1255,15 +1233,14 @@ public void onCommandSuccess(final CreateResult result) { event.setIdentifier((Integer) result.getEntity().getId()); properties.put(Event.REFERENCE_ID, (Integer) result.getEntity().getId()); updateEvent(event, properties); - long milisPerDay = 86400000; - long daysInterval = milisDiff/milisPerDay+1; - + long milisPerDay = 86400000; + long daysInterval = milisDiff / milisPerDay + 1; + addYearlySeriesEvent(milisDiff, (String) result.getEntity().getId(), yearInterval, beginEventIntervalDate, endEventIntervalDate, startDate, endDate, eventSummary, eventDescription, isYearlySameDayOfWeek); - // if(view.getAllDayCheckbox().getValue() == false) addYearlySeriesEventNew(milisDiff, (String) result.getEntity().getId(), yearInterval,daysInterval, beginEventIntervalDate, startDate, endDate, eventSummary, eventDescription, isYearlySameDayOfWeek); } }, view.getCancelButton(), view.getSaveButton()); } - + private void addYearlySeriesEvent(final long milisDiff, String ids, int yearInterval, Date beginEventIntervalDate, Date endEventIntervalDate, final Date startDate, final Date endDate, String eventSummary, String eventDescription, final boolean isYearlySameDayOfWeek) { Date calBeginNextEventDate = beginEventIntervalDate; for (int i = 1; i < yearInterval; i++) { @@ -1274,13 +1251,14 @@ private void addYearlySeriesEvent(final long milisDiff, String ids, int yearInte yearlyProperties.put(Event.SUMMARY, view.getEventSummaryField().getValue()); yearlyProperties.put(Event.DATE, calBeginNextEventDate); - yearlyProperties.put(Event.EVENT_TYPE, "Y"); - - if(view.getAllDayCheckbox().getValue() == true) { - yearlyProperties.put(Event.EVENT_TYPE, "YF");} - - yearlyProperties.put(Event.DATE_END, new Date(calBeginNextEventDate.getTime() + milisDiff)); - + yearlyProperties.put(Event.EVENT_TYPE, "Y"); + + if (view.getAllDayCheckbox().getValue() == true) { + yearlyProperties.put(Event.EVENT_TYPE, "YF"); + } + + yearlyProperties.put(Event.DATE_END, new Date(calBeginNextEventDate.getTime() + milisDiff)); + setFullDayEvent(startDate, endDate, calBeginNextEventDate, yearlyProperties); String newSummary = eventSummary; @@ -1289,7 +1267,7 @@ private void addYearlySeriesEvent(final long milisDiff, String ids, int yearInte newDescription += " (Yearly " + (isYearlySameDayOfWeek ? "same Day of a week " : "same Date ") + "event " + (i + 1) + " of " + yearInterval + ")"; yearlyProperties.put(Event.SUMMARY, newSummary); yearlyProperties.put(Event.DESCRIPTION, newDescription); - + yearlyProperties.put(Event.REFERENCE_ID, ids); addPersonalEvent(yearlyProperties); } @@ -1371,7 +1349,7 @@ private void updateEvent(final Event event, final Map properties) { event.setReferenceId((Integer) properties.get(Event.REFERENCE_ID)); final Date day = (Date) properties.get(Event.DATE); - final Date dayEnd = (Date) properties.get(Event.DATE_END); + final Date dayEnd = (Date) properties.get(Event.DATE_END); final Object startHourSerialized = properties.get(Event.START_TIME); final Object endHourSerialized = properties.get(Event.END_TIME); @@ -1379,7 +1357,7 @@ private void updateEvent(final Event event, final Map properties) { final Date startHour = new Date((Long) startHourSerialized); event.setDtstart(startHour); if (endHourSerialized != null) { - final Date endHour = new Date((Long) endHourSerialized+((dayEnd.getTime()-day.getTime()))); + final Date endHour = new Date((Long) endHourSerialized + ((dayEnd.getTime() - day.getTime()))); //86400000 event.setDtend(endHour); } else { @@ -1397,24 +1375,24 @@ private void updateEvent(final Event event, final Map properties) { event.setParent(calendar); //ak -if(calendar.getEvents()!=null && !event.getEventType().contains("F")){ - List events = calendar.getEvents().get(day); - if (events == null) { - events = new ArrayList(); - calendar.getEvents().put(day, events); + if (calendar.getEvents() != null && !event.getEventType().contains("F")) { + List events = calendar.getEvents().get(day); + if (events == null) { + events = new ArrayList(); + calendar.getEvents().put(day, events); + } + events.add(event); } - events.add(event); -} -if(calendar.getFullDayEvents()!=null && (event.getEventType().contains("F") - || (event.getDtstart().getHours()==event.getDtend().getHours() - && event.getDtstart().getMinutes()==event.getDtend().getMinutes()))){ - List fullDayEvents = calendar.getFullDayEvents().get(day); - if (fullDayEvents == null) { - fullDayEvents = new ArrayList(); - calendar.getFullDayEvents().put(day, fullDayEvents); + if (calendar.getFullDayEvents() != null && (event.getEventType().contains("F") + || (event.getDtstart().getHours() == event.getDtend().getHours() + && event.getDtstart().getMinutes() == event.getDtend().getMinutes()))) { + List fullDayEvents = calendar.getFullDayEvents().get(day); + if (fullDayEvents == null) { + fullDayEvents = new ArrayList(); + calendar.getFullDayEvents().put(day, fullDayEvents); + } + fullDayEvents.add(event); } - fullDayEvents.add(event); -} // -- // Sends an update event on the event bus. // -- @@ -1474,11 +1452,6 @@ public Date getMonthlySameDate(Date firstDate, Date nextDateOld, int numberMonth } - /* Window.alert("Date start: Month:" + firstDate.getMonth() - + " | " + firstDate.getDay() + "| Date:" + getDaysInMonth(nextDateNew.getYear(), nextDateNew.getMonth()) - + " ; " + firstDate.toLocaleString() + " : month " + numberMonths - + ": Result " + " | " + newDate.getDay() + " | " + newDate.toLocaleString());//temp for checker -*/ return newDate; } @@ -1517,15 +1490,8 @@ public Date getMonthlySameDayOfWeek2(Date firstDate, Date nextDateOld, int numbe if (isSameDayOfWeek) { Date newDate2 = getSameWeekDay(firstDate, newDate); //getSameWeekDay22 - //return newDate; newDate = newDate2; } - /* Window.alert("Monthly " + (isSameDayOfWeek ? "Same week DAY " : "Same DATE ") + "Date start: Month:" + firstDate.getMonth() + " | " + firstDate.getDay() - + "| " + getDaysInMonth(firstDate.getYear(), firstDate.getMonth()) - + " | " + firstDate.toLocaleString() + " | i= " + numberMonths + " | RESULT | Prev | " - + nextDateNew.getDay() + " | " + nextDateNew.toLocaleString() - + " || New | " + newDate.getDay() + " | " + newDate.toLocaleString());//temp for checker -*/ return newDate; } @@ -1546,9 +1512,6 @@ public Date getYearlySameDayOfWeek(Date firstDate, Date nextDateOld, int numberM nextDateNew.setDate(1); nextDateNew.setYear(nextDateOld.getYear()); nextDateNew.setMonth(nextDateOld.getMonth()); - // nextDateNew.setDate(nextDateOld.getDate()); - - // nextDateNew.setDate(1); nextDateNew.setYear(nextDateOld.getYear() + 1); int daysInNextDate = getDaysInMonth(nextDateNew.getYear(), nextDateNew.getMonth()); @@ -1570,12 +1533,6 @@ public Date getYearlySameDayOfWeek(Date firstDate, Date nextDateOld, int numberM nextDateNew = newDate; } - /* Window.alert("Yearly " + (isSameDayOfWeek ? "Same week DAY " : "Same DATE ") + "Date start: Month:" + firstDate.getMonth() + " | " + firstDate.getDay() - + "| " + getDaysInMonth(firstDate.getYear(), firstDate.getMonth()) - + " | " + firstDate.toLocaleString() + " | i= " + numberMonths + " | RESULT | Prev | " - + nextDateOld.getDay() + " | " + nextDateOld.toLocaleString() - + " || New | " + nextDateNew.getDay() + " | " + nextDateNew.toLocaleString());//temp for checker -*/ return nextDateNew; } @@ -1628,7 +1585,7 @@ private int getDaysInMonth(int year, int month) { case 1: return daysInMonth = (isLeapYear(year)) ? 29 : 28; default: - return daysInMonth;// = 31; + return daysInMonth; } } diff --git a/src/main/java/org/sigmah/client/ui/view/calendar/CalendarEventView.java b/src/main/java/org/sigmah/client/ui/view/calendar/CalendarEventView.java index 4cacd7524..e0d6ff9d6 100644 --- a/src/main/java/org/sigmah/client/ui/view/calendar/CalendarEventView.java +++ b/src/main/java/org/sigmah/client/ui/view/calendar/CalendarEventView.java @@ -344,7 +344,7 @@ private void createDailyPanel() { panelDaily = new FieldSet(); panelDaily.setExpanded(true); panelDaily.setBorders(true); - panelDaily.setHeadingHtml("End of daily repetition event"); + panelDaily.setHeadingHtml("Daily repeats settings"); panelDaily.setAutoHeight(true); panelDaily.setVisible(false); @@ -412,7 +412,7 @@ private void createWeeklyPanel() { panelWeekly = new FieldSet(); panelWeekly.setExpanded(true); panelWeekly.setBorders(true); - panelWeekly.setHeadingHtml("End of weekly repetition event"); + panelWeekly.setHeadingHtml("Weekly repeats settings"); panelWeekly.setAutoHeight(true); panelWeekly.setVisible(false); diff --git a/src/main/java/org/sigmah/client/ui/widget/CalendarWidget.java b/src/main/java/org/sigmah/client/ui/widget/CalendarWidget.java index 6e6f99494..3c6e68ede 100644 --- a/src/main/java/org/sigmah/client/ui/widget/CalendarWidget.java +++ b/src/main/java/org/sigmah/client/ui/widget/CalendarWidget.java @@ -825,7 +825,10 @@ public void onClick(ClickEvent clickEvent) { popupContent.setWidget(3, 0, editAnchor); popupContent.setWidget(4, 0, deleteAnchor); - popupContent.setWidget(5, 0, deleteChainAnchor); + if (event.getEventType().equals("O") || event.getEventType().equals("OF")) { + } else { + popupContent.setWidget(5, 0, deleteChainAnchor); + } } detailPopup.setWidget(popupContent); @@ -1131,8 +1134,12 @@ public void onClick(ClickEvent clickEvent) { popupContent.setWidget(3, 0, editAnchor); popupContent.setWidget(4, 0, deleteAnchor); - if(!"O".equals(event.getEventType()) && !"OF".equals(event.getEventType())){ - popupContent.setWidget(5, 0, deleteChainAnchor);} + // Window.alert(event.getEventType()); + if (event.getEventType().equals("O") || event.getEventType().equals("OF")) { + } else { + //Window.alert(event.getEventType()); + popupContent.setWidget(5, 0, deleteChainAnchor); + } } detailPopup.setWidget(popupContent); @@ -1228,7 +1235,7 @@ private void drawFullDayEventsForWeek(int row, int column, final Date date, int[][] theShiftVecorOfFullDayEvents) { int theLastFDPanelInCellCounter = getLastFDPanelInCellCounter(theShiftVecorOfFullDayEvents, column); - // Window.alert("START column = " + column + "; theLastFullRaw =" + theLastFDPanelInCellCounter); + // Window.alert("START column = " + column + "; theLastFullRaw =" + theLastFDPanelInCellCounter); TreeSet sortedFullDayEvents = sortedFullDayEventsSet(); int eventCounter = 0; int longFullDayEventShownCounter = 0; @@ -1299,7 +1306,7 @@ private void drawFullDayEventsForWeek(int row, int column, final Date date, int daysdiff = (int) diffDays; fullDayFlowPanel.setTitle(createToolTipForFullDayEvent(daysdiff, event)); - //to show full day long event if it longer then 1 week + //to show full day long event if it longer then 1 week while (column + daysdiff - 1 >= 8) { daysdiff--; } From d0c041344b475bb54f2b0d2871db0255d272bdaa Mon Sep 17 00:00:00 2001 From: Seal98 Date: Mon, 21 Aug 2017 11:46:25 +0300 Subject: [PATCH 33/39] (issue#852) Show non full day events when Date end is after Date start Implemented changes to show non full day events (hour-events) for the case when Date end is after Date start (multi-day events). --- .../calendar/CalendarEventPresenter.java | 67 +++-- .../presenter/calendar/CalendarPresenter.java | 76 +++-- .../client/ui/view/calendar/CalendarView.java | 24 +- .../client/ui/widget/CalendarWidget.java | 280 ++++++++++++++---- .../calendar/PersonalCalendarHandler.java | 5 +- 5 files changed, 320 insertions(+), 132 deletions(-) diff --git a/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java b/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java index f9d8ae04c..999cf9c57 100644 --- a/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java +++ b/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java @@ -647,13 +647,13 @@ private void onSaveAction() { Boolean isFullDayEvent = view.getAllDayCheckbox().getValue(); // Window.alert("isAllDayEvent=" + isFullDayEvent);//temp for checker - Date startDate = createStartDateProperty(isFullDayEvent, beginEventIntervalDate, properties); - Date endDate = createEndDateProperty(isFullDayEvent, beginEventIntervalDate, properties); + Date startDateTime = createStartDateTimeProperty(isFullDayEvent, beginEventIntervalDate, properties); + Date endDateTime = createEndDateTimeProperty(isFullDayEvent, beginEventIntervalDate, properties); properties.put(Event.DESCRIPTION, view.getEventDescriptionField().getValue()); if (event == null) { - processAddEvent(endEventIntervalDate, beginEventIntervalDate, startDate, endDate, properties, eventSummary, eventDescription); + processAddEvent(endEventIntervalDate, beginEventIntervalDate, startDateTime, endDateTime, properties, eventSummary, eventDescription); } else { properties.put(Event.EVENT_TYPE, event.getEventType()); @@ -698,8 +698,8 @@ private void onSaveAction() { * * @param endEventIntervalDate the value of endEventIntervalDate * @param beginEventIntervalDate the value of beginEventIntervalDate - * @param startDate the value of startDate - * @param endDate the value of endDate + * @param startDate the value of startDateTime + * @param endDate the value of endDateTime * @param properties the value of properties * @param eventSummary the value of eventSummary * @param eventDescription the value of eventDescription @@ -763,16 +763,16 @@ private void processAddEvent(Date endEventIntervalDate, final Date beginEventInt } /** - * Create Start event date property + * Create Start event date time property * - * @param isFulllDayEvent the value of isFullDayEvent + * @param isFullDayEvent the value of isFullDayEvent * @param beginEventIntervalDate the value of beginEventIntervalDate * @param properties the value of properties */ - private Date createStartDateProperty(Boolean isFulllDayEvent, final Date beginEventIntervalDate, final Map properties) { + private Date createStartDateTimeProperty(Boolean isFullDayEvent, final Date beginEventIntervalDate, final Map properties) { Date startDate = null; - if (!isFulllDayEvent) { + if (!isFullDayEvent) { startDate = view.getEventStartTimeField().getDateValue(); } if (startDate != null) { @@ -787,16 +787,16 @@ private Date createStartDateProperty(Boolean isFulllDayEvent, final Date beginEv } /** - * Create End event date property + * Create End event date time property * - * @param isFulllDayEvent the value of isFullDayEvent + * @param isFullDayEvent the value of isFullDayEvent * @param beginEventIntervalDate the value of beginEventIntervalDate * @param properties the value of properties */ - private Date createEndDateProperty(Boolean isFulllDayEvent, final Date beginEventIntervalDate, final Map properties) { + private Date createEndDateTimeProperty(Boolean isFullDayEvent, final Date beginEventIntervalDate, final Map properties) { Date endDate = null; - if (!isFulllDayEvent) { + if (!isFullDayEvent) { endDate = view.getEventEndTimeField().getDateValue(); } if (endDate != null) { @@ -816,15 +816,20 @@ private void processOnceEvent(final Date beginEventIntervalDate1, long diffInMil properties.put(Event.SUMMARY, (String) properties.get(Event.SUMMARY)); properties.put(Event.DESCRIPTION, (String) properties.get(Event.DESCRIPTION)); // Window.alert("DaysDiff = "+daysDiff); + if (view.getAllDayCheckbox().getValue() == true) { + properties.put(Event.EVENT_TYPE, "OF"); + } else { + properties.put(Event.EVENT_TYPE, "O"); + } if (daysDiff == 1) { addPersonalEvent(properties); } else { - properties.put(Event.SUMMARY, (String) properties.get(Event.SUMMARY) + " (Once event)"); - properties.put(Event.DESCRIPTION, (String) properties.get(Event.DESCRIPTION) + " (Once event)"); - properties.put(Event.EVENT_TYPE, "O"); - if (view.getAllDayCheckbox().getValue() == true) { - properties.put(Event.EVENT_TYPE, "OF"); - } + properties.put(Event.SUMMARY, (String) properties.get(Event.SUMMARY));// + " (Once event)"); + properties.put(Event.DESCRIPTION, (String) properties.get(Event.DESCRIPTION));// + " (Once event)"); +// properties.put(Event.EVENT_TYPE, "O"); +// if (view.getAllDayCheckbox().getValue() == true) { +// properties.put(Event.EVENT_TYPE, "OF"); +// } addPersonalEventOnce(properties, daysDiff, beginEventIntervalDate, milisPerDay, startDate, endDate, eventSummary, eventDescription); } } @@ -848,7 +853,7 @@ public void onCommandSuccess(final CreateResult result) { event.setIdentifier((Integer) result.getEntity().getId()); properties.put(Event.REFERENCE_ID, (Integer) result.getEntity().getId()); updateEvent(event, properties); - // addOnceSeriesEvent((Integer) result.getEntity().getId(), daysInterval, calBeginNextEventDateLong, milisPerDay, startDate, endDate, eventSummary, eventDescription); + // addOnceSeriesEvent((Integer) result.getEntity().getId(), daysInterval, calBeginNextEventDateLong, milisPerDay, startDateTime, endDateTime, eventSummary, eventDescription); } }, view.getCancelButton(), view.getSaveButton()); } @@ -859,8 +864,8 @@ public void onCommandSuccess(final CreateResult result) { * @param diffInMilis the value of diffInMilis * @param milisPerDay the value of milisPerDay * @param beginEventIntervalDate the value of beginEventIntervalDate - * @param startDate the value of startDate - * @param endDate the value of endDate + * @param startDate the value of startDateTime + * @param endDate the value of endDateTime * @param properties the value of properties * @param eventSummary the value of eventSummary * @param eventDescription the value of eventDescription @@ -902,7 +907,7 @@ public void onCommandSuccess(final CreateResult result) { updateEvent(event, properties); addDailySeriesEvent((Integer) result.getEntity().getId(), daysInterval, lengthDailyEvent, calBeginNextEventDateLong, milisPerDay, startDate, endDate, eventSummary, eventDescription); // if (view.getAllDayCheckbox().getValue() == false) { - // addDailySeriesEventNew((Integer) result.getEntity().getId(), daysInterval, lengthDailyEvent, calBeginNextEventDateLong, milisPerDay, startDate, endDate, eventSummary, eventDescription); + // addDailySeriesEventNew((Integer) result.getEntity().getId(), daysInterval, lengthDailyEvent, calBeginNextEventDateLong, milisPerDay, startDateTime, endDateTime, eventSummary, eventDescription); // } } }, view.getCancelButton(), view.getSaveButton()); @@ -955,8 +960,8 @@ private void addDailySeriesEvent(Integer ids, long daysInterval, long lengthDail * @param diffInMilis the value of diffInMilis * @param milisPerWeek the value of milisPerWeek * @param beginEventIntervalDate the value of beginEventIntervalDate - * @param startDate the value of startDate - * @param endDate the value of endDate + * @param startDate the value of startDateTime + * @param endDate the value of endDateTime * @param properties the value of properties * @param eventSummary the value of eventSummary * @param eventDescription the value of eventDescription @@ -1052,8 +1057,8 @@ private void addDailySeriesEventNew2(Integer ids, int daysInterval, long calBegi /** * Set date and time values for Full day events. * - * @param startDate the value of startDate - * @param endDate the value of endDate + * @param startDate the value of startDateTime + * @param endDate the value of endDateTime * @param calBeginNextEventDate the value of calBeginNextEventDate * @param thePeriodProperties the value of thePeriodProperties */ @@ -1083,8 +1088,8 @@ private void setFullDayEvent(final Date startDate, final Date endDate, Date calB * @param endEventIntervalDate the value of endEventIntervalDate * @param properties the value of properties * @param isMonthlySameDayOfWeek the value of isMonthlySameDayOfWeek - * @param startDate the value of startDate - * @param endDate the value of endDate + * @param startDate the value of startDateTime + * @param endDate the value of endDateTime * @param eventSummary the value of eventSummary * @param eventDescription the value of eventDescription */ @@ -1186,8 +1191,8 @@ private void addMonthlySeriesEvent(Date endEventIntervalDate, String ids, int mo * @param endEventIntervalDate the value of endEventIntervalDate * @param properties the value of properties * @param isYearlySameDayOfWeek the value of isYearlySameDayOfWeek - * @param startDate the value of startDate - * @param endDate the value of endDate + * @param startDate the value of startDateTime + * @param endDate the value of endDateTime * @param eventSummary the value of eventSummary * @param eventDescription the value of eventDescription */ diff --git a/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarPresenter.java b/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarPresenter.java index 342aabbba..e2c7c6237 100644 --- a/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarPresenter.java +++ b/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarPresenter.java @@ -55,6 +55,7 @@ import com.extjs.gxt.ui.client.event.SelectionListener; import com.extjs.gxt.ui.client.store.ListStore; import com.extjs.gxt.ui.client.widget.selection.AbstractStoreSelectionModel; +import com.google.gwt.user.client.Window; import com.google.inject.ImplementedBy; import com.google.inject.Inject; import java.util.Date; @@ -165,19 +166,26 @@ public void onCommandFailure(final Throwable caught) { @Override public void onCommandSuccess(final VoidResult result) { - final List oldEventList - = event.getParent().getEvents().get(event.getKey()); - oldEventList.remove(event); +// final List oldEventList +// = event.getParent().getEvents().get(event.getKey()); +// oldEventList.remove(event); //ak - final List oldFullDayEventList - = event.getParent().getFullDayEvents().get(event.getKey()); - oldFullDayEventList.remove(event); + if (event.getEventType().contains("F")) { + final List oldFullDayEventList + = event.getParent().getFullDayEvents().get(event.getKey()); + oldFullDayEventList.remove(event); + } else { + final List oldEventList + = event.getParent().getEvents().get(event.getKey()); + oldEventList.remove(event); + } //ak + Window.alert("12 refresh CalPres delete onCommandSuccess"); calendar.refresh(); } }); } - + public void deleteEventFunction1(final Event next, Integer parentId, final Map> eventMap, final Date key) { dispatch.execute(new Delete(PersonalEventDTO.ENTITY_NAME, next.getIdentifier(), parentId), new CommandResultHandler() { @@ -189,11 +197,12 @@ public void onCommandFailure(final Throwable caught) { @Override public void onCommandSuccess(final VoidResult result) { eventMap.get(key).remove(next); + Window.alert("11 refresh deleteEventFunction1 onCommandSuccess"); calendar.refresh(); } }); } - + public void deleteEventFunction2(final Event next, Integer parentId, final Map> eventMap, final Date key, int mainId) { dispatch.execute(new Delete(PersonalEventDTO.ENTITY_NAME, mainId, parentId), new CommandResultHandler() { @@ -205,11 +214,12 @@ public void onCommandFailure(final Throwable caught) { @Override public void onCommandSuccess(final VoidResult result) { eventMap.get(key).remove(next); + Window.alert("10 refresh deleteEventFunction2 onCommandSuccess"); calendar.refresh(); } }); } - + @Override public void deleteChain(final Event event, final CalendarWidget calendarWidget) { final CalendarIdentifier calendarIdentifier = event.getParent().getIdentifier(); @@ -217,8 +227,8 @@ public void deleteChain(final Event event, final CalendarWidget calendarWidget) ? ((PersonalCalendarIdentifier) calendarIdentifier).getId() : null; final Map> eventMap = event.getParent().getEvents(); - final Map> fullDayEventMap = event.getParent().getFullDayEvents(); - + final Map> fullDayEventMap = event.getParent().getFullDayEvents(); + int mainId = event.getIdentifier(); int refId = 0; if (event.getReferenceId() != null) { @@ -231,16 +241,14 @@ public void deleteChain(final Event event, final CalendarWidget calendarWidget) if (refId != 0) { if (next.getReferenceId() != null && (next.getReferenceId().intValue() == refId)) { deleteEventFunction1(next, parentId, eventMap, key); - } - else if((next.getReferenceId() == null) && (next.getIdentifier().intValue() == refId)){ + } else if ((next.getReferenceId() == null) && (next.getIdentifier().intValue() == refId)) { deleteEventFunction1(next, parentId, eventMap, key); } } else { if (next.getReferenceId() != null && (next.getReferenceId().intValue() == mainId)) { deleteEventFunction1(next, parentId, eventMap, key); - } - else if(next.getReferenceId() == null && next.getIdentifier().intValue() == mainId){ - deleteEventFunction2(next, parentId, eventMap, key, mainId); + } else if (next.getReferenceId() == null && next.getIdentifier().intValue() == mainId) { + deleteEventFunction2(next, parentId, eventMap, key, mainId); } } } @@ -251,16 +259,14 @@ else if(next.getReferenceId() == null && next.getIdentifier().intValue() == main if (refId != 0) { if (next.getReferenceId() != null && (next.getReferenceId().intValue() == refId)) { deleteEventFunction1(next, parentId, fullDayEventMap, key); - } - else if((next.getReferenceId() == null) && (next.getIdentifier().intValue() == refId)){ + } else if ((next.getReferenceId() == null) && (next.getIdentifier().intValue() == refId)) { deleteEventFunction1(next, parentId, fullDayEventMap, key); } } else { if (next.getReferenceId() != null && (next.getReferenceId().intValue() == mainId)) { deleteEventFunction1(next, parentId, fullDayEventMap, key); - } - else if(next.getReferenceId() == null && next.getIdentifier().intValue() == mainId){ - deleteEventFunction2(next, parentId, fullDayEventMap, key, mainId); + } else if (next.getReferenceId() == null && next.getIdentifier().intValue() == mainId) { + deleteEventFunction2(next, parentId, fullDayEventMap, key, mainId); } } } @@ -276,14 +282,21 @@ public void onCommandFailure(final Throwable caught) { @Override public void onCommandSuccess(final VoidResult result) { - final List oldEventList - = event.getParent().getEvents().get(event.getKey()); - oldEventList.remove(event); +// final List oldEventList +// = event.getParent().getEvents().get(event.getKey()); +// oldEventList.remove(event); //ak - final List oldFullDayEventList - = event.getParent().getFullDayEvents().get(event.getKey()); - oldFullDayEventList.remove(event); + if (event.getEventType().contains("F")) { + final List oldFullDayEventList + = event.getParent().getFullDayEvents().get(event.getKey()); + oldFullDayEventList.remove(event); + } else { + final List oldEventList + = event.getParent().getEvents().get(event.getKey()); + oldEventList.remove(event); + } //ak + Window.alert("9 refresh CalPres deleteChain onCommandSuccess"); calendar.refresh(); } }); @@ -409,12 +422,14 @@ public void componentSelected(final ButtonEvent event) { @Override public void onUpdate(final UpdateEvent event) { if (event.concern(UpdateEvent.CALENDAR_EVENT_UPDATE)) { + Window.alert("7 refresh CalPres Update event handler. "); calendar.refresh(); } if (event.concern(UpdateEvent.REMINDER_UPDATED)) { // TODO appel reloadEventsOfReminderType((ReminderType) event.getParam(0)); + Window.alert("6 refresh CalPres Update event handler. "); calendar.refresh(); } } @@ -428,8 +443,9 @@ public void onUpdate(final UpdateEvent event) { */ public void reload(final Map calendars, boolean editable) { Profiler.INSTANCE.markCheckpoint(Scenario.AGENDA, "Before refresh."); - + Window.alert("5 refresh CalPres reload. "); calendar.refresh(); + Profiler.INSTANCE.markCheckpoint(Scenario.AGENDA, "calendar.refresh ended."); this.projectId = calendars.get(CalendarType.Activity); @@ -444,6 +460,7 @@ public void reload(final Map calendars, boolean editable) */ @Override public void onViewRevealed() { + Window.alert("4 refresh onViewRevealed. "); calendar.refresh(); } @@ -474,6 +491,7 @@ private void reloadEvents(final Map calendars) { view.getCalendarsStore().removeAll(); if (ClientUtils.isEmpty(calendars)) { + Window.alert("3 refresh reloadEvents. "); calendar.refresh(); Profiler.INSTANCE.endScenario(Scenario.AGENDA); return; @@ -483,6 +501,7 @@ private void reloadEvents(final Map calendars) { @Override protected void onComplete() { + Window.alert("2 refresh onComplete. "); calendar.refresh(); Profiler.INSTANCE.endScenario(Scenario.AGENDA); } @@ -549,6 +568,7 @@ protected void onCommandSuccess(Calendar result) { result.setStyle(calendarType.getColorCode()); result.setType(calendarType); calendars.set(location, result); + Window.alert("1 refresh reloadEventsOfReminderType. "); calendar.refresh(); } } diff --git a/src/main/java/org/sigmah/client/ui/view/calendar/CalendarView.java b/src/main/java/org/sigmah/client/ui/view/calendar/CalendarView.java index ed2cd9154..957035cc6 100644 --- a/src/main/java/org/sigmah/client/ui/view/calendar/CalendarView.java +++ b/src/main/java/org/sigmah/client/ui/view/calendar/CalendarView.java @@ -7,7 +7,7 @@ * Copyright (C) 2010 - 2016 URD * %% * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Generamobhtl Public License as + * it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * @@ -52,8 +52,6 @@ import com.google.gwt.dom.client.Style.Unit; import com.google.gwt.i18n.client.LocaleInfo; import com.google.gwt.i18n.shared.DateTimeFormatInfo; -import com.google.gwt.user.client.DOM; -import com.google.gwt.user.client.ui.HTML; import com.google.gwt.user.client.ui.SimplePanel; import org.sigmah.client.ui.res.icon.IconImageBundle; @@ -182,12 +180,13 @@ private Component createCalendarsMainPanel() { // Next button - move forward from one unit of time (week / month) nextButton = Forms.button(I18N.CONSTANTS.next()); toolbar.add(nextButton); + toolbar.add(new SeparatorToolItem()); addEventButton = Forms.button(I18N.CONSTANTS.calendarAddEvent(), IconImageBundle.ICONS.add()); reminderAddButton = new Button(I18N.CONSTANTS.reminderPoint(), IconImageBundle.ICONS.add()); monitoredPointsAddButton = new Button(I18N.CONSTANTS.monitoredPoint(), IconImageBundle.ICONS.add()); - + calendarView.setTopComponent(toolbar); return calendarView; @@ -215,23 +214,10 @@ public void afterRefresh() { calendarView.setHeadingHtml(calendarWidget.getHeading()); } }); - calendarView.setScrollMode(Scroll.AUTOY); + calendarView.setScrollMode(Scroll.AUTOY);//ss calendarView.add(calendarWidget, Layouts.fitData(Margin.DOUBLE_TOP, Margin.DOUBLE_RIGHT, Margin.DOUBLE_BOTTOM, Margin.DOUBLE_LEFT)); - SimplePanel pageMessagePanel = new SimplePanel(); - pageMessagePanel.addStyleName("calendar-fullday-event-3"); - pageMessagePanel.setVisible(true); - pageMessagePanel.setWidth(String.valueOf(305) + "px"); - pageMessagePanel.setHeight(String.valueOf(500) + "px"); - - HTML pageMessageLabel = new HTML(); - pageMessageLabel.addStyleName("calendar-fullday-event-4"); - pageMessagePanel.add(pageMessageLabel); - DOM.setStyleAttribute(pageMessagePanel.getElement(), "position", "absolute"); - DOM.setStyleAttribute(pageMessagePanel.getElement(), "top", 100 + "px"); - DOM.setStyleAttribute(pageMessagePanel.getElement(), "left", 100 + "%"); - DOM.setStyleAttribute(pageMessagePanel.getElement(), "width", 55 + "%"); - calendarView.add(pageMessagePanel); + calendarView.add(calendarWidget, Layouts.fitData(Margin.DOUBLE_TOP, Margin.DOUBLE_RIGHT, Margin.DOUBLE_BOTTOM, Margin.DOUBLE_LEFT)); } /** diff --git a/src/main/java/org/sigmah/client/ui/widget/CalendarWidget.java b/src/main/java/org/sigmah/client/ui/widget/CalendarWidget.java index 3c6e68ede..bb633185d 100644 --- a/src/main/java/org/sigmah/client/ui/widget/CalendarWidget.java +++ b/src/main/java/org/sigmah/client/ui/widget/CalendarWidget.java @@ -43,7 +43,6 @@ import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.ClickHandler; import com.google.gwt.i18n.client.DateTimeFormat; -import com.google.gwt.i18n.client.NumberFormat; import com.google.gwt.user.client.DOM; import com.google.gwt.user.client.Window; import com.google.gwt.user.client.ui.Anchor; @@ -246,9 +245,13 @@ public CalendarWidget(int displayHeaders, boolean displayWeekNumber, Authenticat // final SimplePanel container; final FlexTable grid = new FlexTable(); +// getColumnFormatter().getElement( column ).setAttribute( "width", +// grid.getFlexCellFormatter().getElement(0, 0) grid.addStyleName("calendar"); grid.addStyleName(displayMode.getStyleName()); - +// VerticalPanel dialogContents = new VerticalPanel(); +// dialogContents.add(grid); +// initWidget(dialogContents); initWidget(grid); final Date now = new Date(); @@ -268,16 +271,19 @@ public void setListener(CalendarListener listener) { public void next() { displayMode.nextDate(startDate); + Window.alert("displayMode.nextDate(startDate);. "); refresh(); } public void previous() { displayMode.previousDate(startDate); + Window.alert("refresh previous"); refresh(); } public final void today() { displayMode.firstDay(startDate, today, firstDayOfWeek); + Window.alert("refresh today"); refresh(); } @@ -292,6 +298,7 @@ public Date getStartDate() { public void addCalendar(Calendar calendar) { calendars.add(calendar); + Window.alert("refresh addCalendar"); refresh(); } @@ -300,7 +307,19 @@ public List getCalendars() { } public void setCalendars(List calendars) { - this.calendars = calendars; + // this.calendars = calendars; +// Window.alert("SET setCalendars"); +// for (Calendar calendar : calendars) { +// if (!(calendar.getIdentifier() instanceof ActivityCalendarIdentifier)) { +// if (calendar.getEvents() != null) { +// //SSS final Map> eventMap = normalize(calendar.getEvents()); +// final Map> eventMap = normalizeHourEvents(calendar.getEvents()); +// calendar.setEvents(eventMap); +// } +// } +// } + this.calendars = calendars; + Window.alert("refresh setCalendars"); refresh(); } @@ -315,6 +334,7 @@ public void setCalendars(List calendars) { */ public void setTitleFormatter(DateTimeFormat titleFormatter) { this.titleFormatter = titleFormatter; + Window.alert("refresh setTitleFormatter"); refresh(); } @@ -328,6 +348,7 @@ public void setTitleFormatter(DateTimeFormat titleFormatter) { */ public void setHeaderFormatter(DateTimeFormat headerFormatter) { this.headerFormatter = headerFormatter; + Window.alert("refresh setHeaderFormatter"); refresh(); } @@ -341,6 +362,7 @@ public void setHeaderFormatter(DateTimeFormat headerFormatter) { */ public void setDayFormatter(DateTimeFormat dayFormatter) { this.dayFormatter = dayFormatter; + Window.alert("refresh setDayFormatter"); refresh(); } @@ -362,7 +384,7 @@ public void setDisplayMode(DisplayMode displayMode) { // Applying the CSS style associated with the new display mode grid.addStyleName(displayMode.getStyleName()); - +Window.alert("refresh setDisplayMode"); refresh(); } @@ -374,6 +396,7 @@ public void setDisplayMode(DisplayMode displayMode) { */ public void setFirstDayOfWeek(int firstDayOfWeek) { this.firstDayOfWeek = firstDayOfWeek; + Window.alert("refresh setFirstDayOfWeek"); refresh(); } @@ -384,6 +407,7 @@ public int getDisplayHeaders() { public void setDisplayHeaders(int displayHeaders) { clear(); this.displayHeaders = displayHeaders; + Window.alert("refresh setDisplayHeaders"); refresh(); } @@ -394,6 +418,7 @@ public boolean isDisplayWeekNumber() { public void setDisplayWeekNumber(boolean displayWeekNumber) { clear(); this.displayWeekNumber = displayWeekNumber; + Window.alert("refresh setDisplayWeekNumber"); refresh(); } @@ -455,6 +480,81 @@ public static Map> normalize(final Map> even return eventMapNormalized; } + public static Map> normalizeHourEvents(final Map> eventMap) { +Window.alert("normalizeHourEvents"); + final Map> hourEventMapNormalized = new HashMap>(); + + for (final Date key : eventMap.keySet()) { + for (final Event event : eventMap.get(key)) { + Date normalizedKeyDate = new Date(key.getYear(), key.getMonth(), key.getDate()); + if (!isSameDay(event.getDtstart(), event.getDtend())) { + Window.alert("! isSameDay" + event.getSummary()); + // if (event.getDtstart() != event.getDtend()) { + //1 + int daysdiff = calculateEventDurationInDays(event); + for (int i = 0; i < daysdiff; i++) { + long StartTime = event.getDtstart().getTime() + (24 * 60 * 60 * 1000) * i; + long EndTime = event.getDtstart().getTime() + (24 * 60 * 60 * 1000) * i; + + Date StartDate = new Date(StartTime); + + Date EndDate = new Date(EndTime); + EndDate.setHours(event.getDtend().getHours()); + EndDate.setMinutes(event.getDtend().getMinutes()); + + Event theNewEv = new Event(); + theNewEv.setDtstart(StartDate); + theNewEv.setDtend(EndDate); +// theNewEv.setIdentifier(event.getIdentifier()); +// theNewEv.setReferenceId(event.getReferenceId()); +// theNewEv.setParent(event.getParent()); + theNewEv.setSummary(event.getSummary());// + "-S-" + i); + theNewEv.setDescription(event.getDescription());// + "-D-" + i); +// theNewEv.setEventType(event.getEventType()); + //////////// + if (!isSameDay(normalizedKeyDate, theNewEv.getDtstart())) { + normalizedKeyDate = new Date(theNewEv.getDtstart().getYear(), theNewEv.getDtstart().getMonth(), theNewEv.getDtstart().getDate()); + } + + if (hourEventMapNormalized.get(normalizedKeyDate) == null) { + hourEventMapNormalized.put(normalizedKeyDate, new ArrayList()); + } + event.setSummary(theNewEv.getSummary()); + event.setDescription(theNewEv.getDescription()); + if (!hourEventMapNormalized.get(normalizedKeyDate).contains(event)) { + hourEventMapNormalized.get(normalizedKeyDate).add(event); + } + // ------------- +// if (!isSameDay(normalizedKeyDate, theNewEv.getDtstart())) { +// normalizedKeyDate = new Date(theNewEv.getDtstart().getYear(), theNewEv.getDtstart().getMonth(), theNewEv.getDtstart().getDate()); +// } +// +// if (hourEventMapNormalized.get(normalizedKeyDate) == null) { +// hourEventMapNormalized.put(normalizedKeyDate, new ArrayList()); +// } +// hourEventMapNormalized.get(normalizedKeyDate).add(theNewEv); + + /////// + } + } else { +Window.alert("THE SameDay " + event.getSummary()); + if (!isSameDay(normalizedKeyDate, event.getDtstart())) { + normalizedKeyDate = new Date(event.getDtstart().getYear(), event.getDtstart().getMonth(), event.getDtstart().getDate()); + } + + if (hourEventMapNormalized.get(normalizedKeyDate) == null) { + hourEventMapNormalized.put(normalizedKeyDate, new ArrayList()); + } + if (!hourEventMapNormalized.get(normalizedKeyDate).contains(event)) { + hourEventMapNormalized.get(normalizedKeyDate).add(event); + } + } + } + } + + return hourEventMapNormalized; + } + /** * Calculates the number of events that can be displayed in a cell. */ @@ -466,11 +566,13 @@ public void calibrateCalendar() { final Element cell = grid.getCellFormatter().getElement(displayHeaders, displayWeekNumber ? 1 : 0); cell.setId("calendar-cell-calibration"); - +//ss +// cell.setPropertyString(DEBUG_ID_PREFIX, DEBUG_ID_PREFIX);setAttribute("hight", "40px"); eventLimit = (getCellHeight(CELL_DEFAULT_HEIGHT) / EVENT_HEIGHT) - 2; if (eventLimit < 0) { eventLimit = 0; } + } /** @@ -687,14 +789,19 @@ private void drawEvents(int row, int column, final Date date, int startDrawPosit } // Displaying events - TreeSet sortedHourEvents = sortedFullDayEventsSet(); + TreeSet sortedHourEvents = createSortedEventsSet(); // Displaying full day events - TreeSet sortedFullDayEvents = sortedFullDayEventsSet(); + TreeSet sortedFullDayEvents = createSortedEventsSet(); for (final Calendar calendar : calendars) { if (!(calendar.getIdentifier() instanceof ActivityCalendarIdentifier)) { if (calendar.getEvents() != null) { - final Map> eventMap = normalize(calendar.getEvents()); + //SSS final Map> eventMap = normalize(calendar.getEvents()); + //ss + Map> eventMap = normalizeHourEvents(calendar.getEvents()); + // final Map> eventMap = normalize(eventMap2); + //final Map> eventMap = calendar.getEvents(); + final List events = eventMap.get(date); if (events != null) { sortedHourEvents.addAll(events); @@ -709,7 +816,8 @@ private void drawEvents(int row, int column, final Date date, int startDrawPosit Event next = iterator.next(); Date theStartEventDate = next.getDtstart(); Date theEndEventDate = next.getDtend(); - if (date.after(theStartEventDate) && date.before(theEndEventDate) + if (next.getEventType().contains("F") + && date.after(theStartEventDate) && date.before(theEndEventDate) || date.equals(theStartEventDate) || date.equals(theEndEventDate)) { fullDayEventCounter++; @@ -727,7 +835,11 @@ private void drawEvents(int row, int column, final Date date, int startDrawPosit } final Iterator iterator = sortedHourEvents.iterator(); - + if (startDrawPosition==-1){ + eventLimit = 1; + }else{ + eventLimit = 99; + } for (int i = 0; iterator.hasNext() && i < eventLimit; i++) { final Event event = iterator.next(); @@ -741,10 +853,11 @@ private void drawEvents(int row, int column, final Date date, int startDrawPosit if (event.getDtend() != null) { eventDate.append(" "); eventDate.append(hourFormatter.format(event.getDtend())); - - if (event.getDtstart().getDate() != event.getDtend().getDate() - || event.getDtstart().getMonth() != event.getDtend().getMonth() - || event.getDtstart().getYear() != event.getDtend().getYear()) { +//SS +// if (event.getDtstart().getDate() != event.getDtend().getDate() +// || event.getDtstart().getMonth() != event.getDtend().getMonth() +// || event.getDtstart().getYear() != event.getDtend().getYear()) { + if (event.getEventType().contains("F")) { fullDayEvent = true; flowPanel.addStyleName("calendar-fullday-event"); } @@ -765,6 +878,10 @@ private void drawEvents(int row, int column, final Date date, int startDrawPosit if (!fullDayEvent) { flowPanel.add(dateLabel); + + int daysdiff = calculateEventDurationInDays(event); + + flowPanel.setTitle(createTitleForHourEvent(daysdiff, event)); } flowPanel.add(eventLabel); @@ -817,6 +934,7 @@ public void onClick(ClickEvent clickEvent) { @Override public void onClick(ClickEvent clickEvent) { delegate.deleteChain(event, CalendarWidget.this); + Window.alert("refresh deleteChainAnchor onClick"); refresh(); detailPopup.hide(); @@ -888,10 +1006,41 @@ public void onClick(ClickEvent event) { DOM.setStyleAttribute(eventLabel.getElement(), "border-color", "#1c61d9"); DOM.setStyleAttribute(eventLabel.getElement(), "border-style", "solid"); DOM.setStyleAttribute(eventLabel.getElement(), "border-width", "1px"); + +// if (fullDayEventCounter > 0 +// +// +// sortedHourEvents.size() //-- DOM.setStyleAttribute(eventLabel.getElement(), "position", "relative"); + // DOM.setStyleAttribute(eventLabel.getElement(), "top", (cell.getOffsetHeight()-16) + "px"); + //-- DOM.setStyleAttribute(eventLabel.getElement(), "top", (cell.getAbsoluteTop() + 30) + "px"); + // Window.alert(cell.getTitle() + " cell.getOffsetHeight()="+cell.getOffsetHeight() + // + " - " + " cell.getAbsoluteTop())=" + cell.getAbsoluteTop() + // + " Label OffsetHeight = " + eventLabel.getElement().getOffsetHeight()+ + // " cell.getElement() OffsetHeight =" + cell.getElement().getOffsetHeight()+ + // " cell.getElement() AbsoluteBottom=" + cell.getElement().getAbsoluteBottom()+ + // " cell.getElement() ClientHeight =" + cell.getElement().getClientHeight() + // ) ; + int chiled = grid.getCellFormatter().getElement(row, column).getChildCount(); + + int gridHeight = grid.getOffsetHeight(); + int weekdayRowHeight = grid.getRowFormatter() + .getElement(0).getOffsetHeight(); +// Window.alert("chiled=" + chiled + " gridHeight =" + gridHeight +// + " weekdayRowHeight =" + weekdayRowHeight +// ); + cell.add(eventLabel); } } + + private static int calculateEventDurationInDays(final Event event) { + long diff = event.getDtend().getTime() - event.getDtstart().getTime(); + long diffDays = diff / (24 * 60 * 60 * 1000) + 1; + int daysdiff = (int) diffDays; + return daysdiff; + } + /** * Returns the first date of the week that includes the given date. * @@ -988,7 +1137,7 @@ private static int appointmentHeight() { */ private void drawFullDayEvents(int row, int column, final Date date) { - TreeSet sortedFullDayEvents = sortedFullDayEventsSet(); + TreeSet sortedFullDayEvents = createSortedEventsSet(); for (final Calendar calendar : calendars) { if (!(calendar.getIdentifier() instanceof ActivityCalendarIdentifier)) { @@ -1010,34 +1159,57 @@ private void drawFullDayEvents(int row, int column, final Date date) { final ClickableFlowPanel flowPanelFullDayFirst = createFullDayPanel(event); final ClickableFlowPanel flowPanelFullDayContinue = createFullDayPanel(event); final FlexTable grid = (FlexTable) getWidget(); - long diff = event.getDtend().getTime() - event.getDtstart().getTime(); - long diffDays = diff / (24 * 60 * 60 * 1000) + 1; - int daysdiff = (int) diffDays; + int daysdiff = calculateEventDurationInDays(event); //String theDateString = DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.YEAR_MONTH_WEEKDAY_DAY).format(thisDate); - flowPanelFullDayFirst.setTitle(createToolTipForFullDayEvent(daysdiff, event)); + flowPanelFullDayFirst.setTitle(createTitleForFullDayEvent(daysdiff, event)); if (column + daysdiff - 1 < 8) { placeItemInGridMonth(flowPanelFullDayFirst, column, column + daysdiff, row, i); } else { placeItemInGridMonth(flowPanelFullDayFirst, column, 8, row, i); if (row <= 5) { - flowPanelFullDayContinue.setTitle(createToolTipForFullDayEvent(daysdiff, event)); + flowPanelFullDayContinue.setTitle(createTitleForFullDayEvent(daysdiff, event)); placeItemInGridMonth(flowPanelFullDayContinue, 1, 1 + daysdiff - (8 - column), row + 1, i); } } } } - private static String createToolTipForFullDayEvent(int daysdiff, final Event event) { - return daysdiff + " full day" + (daysdiff > 1 ? "s" : "") + " event." + private static String createTitleForFullDayEvent(int daysdiff, final Event event) { + return "Event: " + event.getSummary() + + "\nDescr: " + event.getDescription() + + "\nDuration: " + daysdiff + " full day" + (daysdiff > 1 ? "s." : ".") + (event.getDtstart().equals(event.getDtend()) - ? DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.YEAR_MONTH_WEEKDAY_DAY).format(event.getDtstart()) + ? (DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.YEAR_MONTH_WEEKDAY_DAY).format(event.getDtstart())) : ("\nFrom " + DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.YEAR_MONTH_WEEKDAY_DAY).format(event.getDtstart()) - + " to " + DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.YEAR_MONTH_WEEKDAY_DAY).format(event.getDtend()))) - + "\n" + event.getDescription(); + + " to " + DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.YEAR_MONTH_WEEKDAY_DAY).format(event.getDtend()))); } + /** + * + * @param daysdiff the value of daysdiff + * @param event the value of event + * @return the java.lang.String + */ + private String createTitleForHourEvent(int daysdiff, final Event event) { + String duration = hourFormatter.format(new Date(event.getDtend().getTime()- event.getDtstart().getTime())); + long millis = event.getDtend().getTime()- event.getDtstart().getTime(); + long minute = (millis / (1000 * 60)) % 60; + long hour = (millis / (1000 * 60 * 60)) % 24; + return "Event: " + event.getSummary() + + "\nDescr: " + event.getDescription() + + "\nDuration: from " + hourFormatter.format(event.getDtstart()) + + " to " + hourFormatter.format(event.getDtend()) + // + " (" + duration + " hours" + (daysdiff > 0 ? " every day)" : ")") + + " (" + (hour > 0 ? (hour + " hours ") : "") + + (minute > 0 ? (minute + " minutes") : "") + (daysdiff > 0 ? " every day)" : ") ") + + (daysdiff > 1 ? (daysdiff + " days in row. ") : " ") + + (isSameDay(event.getDtstart(), event.getDtend()) + ? (DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.YEAR_MONTH_WEEKDAY_DAY).format(event.getDtstart())) + : ("\nFrom " + DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.YEAR_MONTH_WEEKDAY_DAY).format(event.getDtstart()) + + " to " + DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.YEAR_MONTH_WEEKDAY_DAY).format(event.getDtend()))); + } /** * @param event * @return @@ -1115,6 +1287,7 @@ public void onClick(ClickEvent clickEvent) { @Override public void onClick(ClickEvent clickEvent) { delegate.delete(event, CalendarWidget.this); + Window.alert("refresh deleteAnchor onClick "); refresh(); detailPopup.hide(); } @@ -1126,6 +1299,7 @@ public void onClick(ClickEvent clickEvent) { @Override public void onClick(ClickEvent clickEvent) { delegate.deleteChain(event, CalendarWidget.this); + Window.alert("refresh deleteChainAnchor onClick"); refresh(); detailPopup.hide(); @@ -1186,9 +1360,9 @@ public void setPosition(int offsetWidth, int offsetHeight) { // calculatedWeekDayHeaderHeight = weekdayRowHeight; // calculatedDayHeaderHeight = dayHeaderHeight; // } - private TreeSet sortedFullDayEventsSet() { - // Displaying full day events - final TreeSet sortedFullDayEvents = new TreeSet(new Comparator() { + private TreeSet createSortedEventsSet() { + + final TreeSet sortedEvents = new TreeSet(new Comparator() { @Override public int compare(Event o1, Event o2) { @@ -1220,7 +1394,7 @@ public int compare(Event o1, Event o2) { return compare; } }); - return sortedFullDayEvents; + return sortedEvents; } /** @@ -1236,7 +1410,7 @@ private void drawFullDayEventsForWeek(int row, int column, final Date date, int theLastFDPanelInCellCounter = getLastFDPanelInCellCounter(theShiftVecorOfFullDayEvents, column); // Window.alert("START column = " + column + "; theLastFullRaw =" + theLastFDPanelInCellCounter); - TreeSet sortedFullDayEvents = sortedFullDayEventsSet(); + TreeSet sortedFullDayEvents = createSortedEventsSet(); int eventCounter = 0; int longFullDayEventShownCounter = 0; @@ -1249,27 +1423,29 @@ private void drawFullDayEventsForWeek(int row, int column, final Date date, List value = entry.getValue(); for (Iterator iterator = value.iterator(); iterator.hasNext();) { Event next = iterator.next(); - if (!alreadyShownWeekViewEvents.contains(next)) { - Date theStartEventDate = next.getDtstart(); - Date theEndEventDate = next.getDtend(); - if (date.after(theStartEventDate) && date.before(theEndEventDate) - || date.equals(theStartEventDate) - || date.equals(theEndEventDate)) { - // In between - eventCounter++; - sortedFullDayEvents.add(next); - alreadyShownWeekViewEvents.add(next); - } - } else { - Date theStartEventDate = next.getDtstart(); - Date theEndEventDate = next.getDtend(); - if (date.after(theStartEventDate) && date.before(theEndEventDate) - || date.equals(theStartEventDate) - || date.equals(theEndEventDate)) { - - longFullDayEventShownCounter++; -// sortedFullDayEvents.add(next); + if (next.getEventType().contains("F")) { + if (!alreadyShownWeekViewEvents.contains(next)) { + Date theStartEventDate = next.getDtstart(); + Date theEndEventDate = next.getDtend(); + if (date.after(theStartEventDate) && date.before(theEndEventDate) + || date.equals(theStartEventDate) + || date.equals(theEndEventDate)) { + // In between + eventCounter++; + sortedFullDayEvents.add(next); + alreadyShownWeekViewEvents.add(next); + } + } else { + Date theStartEventDate = next.getDtstart(); + Date theEndEventDate = next.getDtend(); + if (date.after(theStartEventDate) && date.before(theEndEventDate) + || date.equals(theStartEventDate) + || date.equals(theEndEventDate)) { + + longFullDayEventShownCounter++; +// sortedEvents.add(next); // alreadyShownWeekViewEvents.add(next); + } } } } @@ -1280,7 +1456,7 @@ private void drawFullDayEventsForWeek(int row, int column, final Date date, final Iterator iterator = sortedFullDayEvents.iterator(); //ak - int eventLimit = 10;//999 + int eventLimit = 100;//999 int counterIvent = 0; boolean foundRowToPlace = false; int theRowToPlace = 0; @@ -1305,7 +1481,7 @@ private void drawFullDayEventsForWeek(int row, int column, final Date date, long diffDays = diff / (24 * 60 * 60 * 1000) + 1; int daysdiff = (int) diffDays; - fullDayFlowPanel.setTitle(createToolTipForFullDayEvent(daysdiff, event)); + fullDayFlowPanel.setTitle(createTitleForFullDayEvent(daysdiff, event)); //to show full day long event if it longer then 1 week while (column + daysdiff - 1 >= 8) { daysdiff--; diff --git a/src/main/java/org/sigmah/server/handler/calendar/PersonalCalendarHandler.java b/src/main/java/org/sigmah/server/handler/calendar/PersonalCalendarHandler.java index 2f0846165..dbce64c42 100644 --- a/src/main/java/org/sigmah/server/handler/calendar/PersonalCalendarHandler.java +++ b/src/main/java/org/sigmah/server/handler/calendar/PersonalCalendarHandler.java @@ -110,8 +110,9 @@ public Calendar getCalendar(CalendarIdentifier identifier, EntityManager em) { calendarEvent.setDtstart(new Date(event.getStartDate().getTime())); calendarEvent.setReferenceId(event.getReferenceId()); calendarEvent.setEventType(event.getEventType()); - if (event.getEndDate() != null) + if (event.getEndDate() != null){ calendarEvent.setDtend(new Date(event.getEndDate().getTime())); + } if(event.getEventType()!=null && event.getEventType().contains("F") || (event.getStartDate().getHours()==event.getEndDate().getHours() @@ -125,7 +126,7 @@ public Calendar getCalendar(CalendarIdentifier identifier, EntityManager em) { calendar.setFullDayEvents(fullDayEventMap); } } - return calendar; + return calendar; } @SuppressWarnings("deprecation") From 191d91ac15557e924dd9cd94320506f2d25c7e89 Mon Sep 17 00:00:00 2001 From: Seal98 Date: Mon, 21 Aug 2017 13:39:37 +0300 Subject: [PATCH 34/39] (issue#852) Removed series event counter from description, Codacy fixes. Removed adding series event counter info to event description (like "Weekly event 1 of 2"). Applied fixes for some issues reported by Codacy code checker. --- .../calendar/CalendarEventPresenter.java | 71 ++++++++++--------- .../ui/view/calendar/CalendarEventView.java | 24 ------- .../client/ui/widget/CalendarWidget.java | 66 ++++++++--------- 3 files changed, 70 insertions(+), 91 deletions(-) diff --git a/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java b/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java index 999cf9c57..83068689d 100644 --- a/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java +++ b/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java @@ -659,7 +659,7 @@ private void onSaveAction() { properties.put(Event.EVENT_TYPE, event.getEventType()); properties.put(Event.REFERENCE_ID, event.getReferenceId()); - if (view.getAllDayCheckbox().getValue() == true) { + if (view.getAllDayCheckbox().getValue()) { if (event.getEventType() != null) { if ("O".equals(event.getEventType())) { properties.put(Event.EVENT_TYPE, "OF"); @@ -722,7 +722,7 @@ private void processAddEvent(Date endEventIntervalDate, final Date beginEventInt if (isDailyRepeatEvent) { long count = 0; long lengthDailyEvent = ((endEventIntervalDate.getTime() - beginEventIntervalDate.getTime()) / milisPerDay) + 1; - if (view.getDailyRadioNumberOfRepetitions().getValue() == true) { + if (view.getDailyRadioNumberOfRepetitions().getValue()) { count = parseInt(view.getDailyNumberOfRepetitions().getValue()); // Window.alert("Count1 = "+count); } else { @@ -736,7 +736,7 @@ private void processAddEvent(Date endEventIntervalDate, final Date beginEventInt //Window.alert("Count2 = "+count); processDailyEvents(count, lengthDailyEvent, milisPerDay, beginEventIntervalDate, endEventIntervalDateRadio, endEventIntervalDate, startDate, endDate, properties, eventSummary, eventDescription); } else if (isWeeklyRepeatEvent) { - if (view.getWeeklyRadioNumberOfRepetitions().getValue() == true) { + if (view.getWeeklyRadioNumberOfRepetitions().getValue()) { endEventIntervalDateRadio.setDate(beginEventIntervalDate.getDate() + parseInt(view.getWeeklyNumberOfRepetitions().getValue()) * 7); } else { endEventIntervalDateRadio = view.getWeeklyRepetitionEndDate().getValue(); @@ -744,14 +744,14 @@ private void processAddEvent(Date endEventIntervalDate, final Date beginEventInt diffInMilis = endEventIntervalDateRadio.getTime() - beginEventIntervalDate.getTime(); processWeeklyEvents(beginEventIntervalDate, endEventIntervalDate, endEventIntervalDateRadio, startDate, endDate, properties, eventSummary, eventDescription); } else if (isMonthlyRepeatEvent) { - if (view.getRadioNumberOfRepetitions().getValue() == true) { + if (view.getRadioNumberOfRepetitions().getValue()) { endEventIntervalDateRadio.setMonth(beginEventIntervalDate.getMonth() + parseInt(view.getNumberOfRepetitions().getValue())); } else { endEventIntervalDateRadio = view.getRepetitionEndDate().getValue(); } processMonthlyEvents(beginEventIntervalDate, endEventIntervalDate, endEventIntervalDateRadio, properties, isMonthlySameDayOfWeek, startDate, endDate, eventSummary, eventDescription); } else if (isYearlyRepeatEvent) { - if (view.getYearlyRadioNumberOfRepetitions().getValue() == true) { + if (view.getYearlyRadioNumberOfRepetitions().getValue()) { endEventIntervalDateRadio.setYear(beginEventIntervalDate.getYear() + parseInt(view.getYearlyNumberOfRepetitions().getValue())); } else { endEventIntervalDateRadio = view.getYearlyRepetitionEndDate().getValue(); @@ -816,7 +816,7 @@ private void processOnceEvent(final Date beginEventIntervalDate1, long diffInMil properties.put(Event.SUMMARY, (String) properties.get(Event.SUMMARY)); properties.put(Event.DESCRIPTION, (String) properties.get(Event.DESCRIPTION)); // Window.alert("DaysDiff = "+daysDiff); - if (view.getAllDayCheckbox().getValue() == true) { + if (view.getAllDayCheckbox().getValue()) { properties.put(Event.EVENT_TYPE, "OF"); } else { properties.put(Event.EVENT_TYPE, "O"); @@ -827,7 +827,7 @@ private void processOnceEvent(final Date beginEventIntervalDate1, long diffInMil properties.put(Event.SUMMARY, (String) properties.get(Event.SUMMARY));// + " (Once event)"); properties.put(Event.DESCRIPTION, (String) properties.get(Event.DESCRIPTION));// + " (Once event)"); // properties.put(Event.EVENT_TYPE, "O"); -// if (view.getAllDayCheckbox().getValue() == true) { +// if (view.getAllDayCheckbox().getValue()) { // properties.put(Event.EVENT_TYPE, "OF"); // } addPersonalEventOnce(properties, daysDiff, beginEventIntervalDate, milisPerDay, startDate, endDate, eventSummary, eventDescription); @@ -874,9 +874,9 @@ private void processDailyEvents(long count, long lengthDailyEvent, long milisPer long calBeginNextEventDateLong = beginEventIntervalDate.getTime(); //Date calBeginNextEventDate = beginEventIntervalDate; - properties.put(Event.SUMMARY, (String) properties.get(Event.SUMMARY) + " (Daily event 1 of " + count + ")"); - properties.put(Event.DESCRIPTION, (String) properties.get(Event.DESCRIPTION) + " (Daily event 1 of " + count + ")"); - if (view.getAllDayCheckbox().getValue() == true) { + properties.put(Event.SUMMARY, (String) properties.get(Event.SUMMARY));// + " (Daily event 1 of " + count + ")"); + properties.put(Event.DESCRIPTION, (String) properties.get(Event.DESCRIPTION));// + " (Daily event 1 of " + count + ")"); + if (view.getAllDayCheckbox().getValue()) { properties.put(Event.EVENT_TYPE, "DF"); } else { properties.put(Event.EVENT_TYPE, "D"); @@ -934,7 +934,7 @@ private void addDailySeriesEvent(Integer ids, long daysInterval, long lengthDail dailyProperties.put(Event.SUMMARY, view.getEventSummaryField().getValue()); dailyProperties.put(Event.DATE, new Date(calBeginNextEventDateLong)); - if (view.getAllDayCheckbox().getValue() == true) { + if (view.getAllDayCheckbox().getValue()) { dailyProperties.put(Event.EVENT_TYPE, "DF"); } else { dailyProperties.put(Event.EVENT_TYPE, "D"); @@ -944,8 +944,8 @@ private void addDailySeriesEvent(Integer ids, long daysInterval, long lengthDail String newSummary = eventSummary; String newDescription = eventDescription; - newSummary += " (Daily event " + (i + 1) + " of " + daysInterval + ")"; - newDescription += " (Daily event " + (i + 1) + " of " + daysInterval + ")"; +// newSummary += " (Daily event " + (i + 1) + " of " + daysInterval + ")"; +// newDescription += " (Daily event " + (i + 1) + " of " + daysInterval + ")"; dailyProperties.put(Event.SUMMARY, newSummary); dailyProperties.put(Event.DESCRIPTION, newDescription); dailyProperties.put(Event.REFERENCE_ID, ids); @@ -971,7 +971,7 @@ private void processWeeklyEvents(final Date beginEventIntervalDate, final Date e long weekDiff = ((endEventIntervalDateRadio.getTime() - beginEventIntervalDate.getTime() + milisPerDay) / (milisPerDay * 7)); int weeksInterval = (int) weekDiff; if ((((endEventIntervalDateRadio.getTime() - beginEventIntervalDate.getTime() + milisPerDay) % (milisPerDay * 7)) >= ((endEventIntervalDate.getTime() - beginEventIntervalDate.getTime() + milisPerDay))) - && (view.getWeeklyRadioNumberOfRepetitions().getValue() == true)) { + && (view.getWeeklyRadioNumberOfRepetitions().getValue())) { weeksInterval++; } if (weeksInterval <= 0) { @@ -986,8 +986,8 @@ private void processWeeklyEvents(final Date beginEventIntervalDate, final Date e long daysInterval = ((endEventIntervalDate.getTime() - beginEventIntervalDate.getTime()) / milisPerDay) + 1; properties.put(Event.SUMMARY, (String) properties.get(Event.SUMMARY)); - properties.put(Event.DESCRIPTION, (String) properties.get(Event.DESCRIPTION) + " (Weekly event 1 of " + weeksInterval + ")"); - if (view.getAllDayCheckbox().getValue() == true) { + properties.put(Event.DESCRIPTION, (String) properties.get(Event.DESCRIPTION));// + " (Weekly event 1 of " + weeksInterval + ")"); + if (view.getAllDayCheckbox().getValue()) { properties.put(Event.EVENT_TYPE, "WF"); } else { properties.put(Event.EVENT_TYPE, "W"); @@ -1040,10 +1040,10 @@ private void addDailySeriesEventNew2(Integer ids, int daysInterval, long calBegi String newSummary = eventSummary; String newDescription = eventDescription; - newDescription += " (Weekly event " + (i + 1) + " of " + daysInterval + ")"; + // newDescription += " (Weekly event " + (i + 1) + " of " + daysInterval + ")"; dailyProperties.put(Event.SUMMARY, newSummary); dailyProperties.put(Event.DESCRIPTION, newDescription); - if (view.getAllDayCheckbox().getValue() == true) { + if (view.getAllDayCheckbox().getValue()) { dailyProperties.put(Event.EVENT_TYPE, "WF"); } else { dailyProperties.put(Event.EVENT_TYPE, "W"); @@ -1094,10 +1094,11 @@ private void setFullDayEvent(final Date startDate, final Date endDate, Date calB * @param eventDescription the value of eventDescription */ private void processMonthlyEvents(final Date beginEventIntervalDate, Date endEventIntervalDate, final Date endEventIntervalDateRadio, final Map properties, Boolean isMonthlySameDayOfWeek, final Date startDate, final Date endDate, String eventSummary, String eventDescription) { - properties.put(Event.EVENT_TYPE, "M"); - if (view.getAllDayCheckbox().getValue() == true) { + + if (view.getAllDayCheckbox().getValue()) { properties.put(Event.EVENT_TYPE, "MF"); } else { + properties.put(Event.EVENT_TYPE, "M"); } properties.put(Event.DATE_END, endEventIntervalDate); Date endEventIntervalDate1 = endEventIntervalDate; @@ -1115,14 +1116,14 @@ private void processMonthlyEvents(final Date beginEventIntervalDate, Date endEve } else { monthInterval = monthEnd - monthStart + 1; } - if (view.getRadioNumberOfRepetitions().getValue() == true) { + if (view.getRadioNumberOfRepetitions().getValue()) { monthInterval--; } if (monthInterval <= 0) { monthInterval = 1; } - properties.put(Event.SUMMARY, (String) properties.get(Event.SUMMARY) + " (Monthly event 1 of " + monthInterval + ")"); - properties.put(Event.DESCRIPTION, (String) properties.get(Event.DESCRIPTION) + " (Monthly event 1 of " + monthInterval + ")"); + properties.put(Event.SUMMARY, (String) properties.get(Event.SUMMARY));// + " (Monthly event 1 of " + monthInterval + ")"); + properties.put(Event.DESCRIPTION, (String) properties.get(Event.DESCRIPTION));// + " (Monthly event 1 of " + monthInterval + ")"); addPersonalEventMonthly(endEventIntervalDate1, properties, monthInterval, beginEventIntervalDate, milisDiff, startDate, endDate, eventSummary, eventDescription, isMonthlySameDayOfWeek); } @@ -1145,8 +1146,8 @@ public void onCommandSuccess(final CreateResult result) { event.setIdentifier((Integer) result.getEntity().getId()); updateEvent(event, properties); properties.put(Event.REFERENCE_ID, (Integer) result.getEntity().getId()); - long milisPerDay = 86400000; - long daysInterval = milisDiff / milisPerDay + 1; +// long milisPerDay = 86400000; +// long daysInterval = milisDiff / milisPerDay + 1; addMonthlySeriesEvent(endEventIntervalDate, (String) result.getEntity().getId(), monthInterval, beginEventIntervalDate, startDate, endDate, eventSummary, eventDescription, isMonthlySameDayOfWeek); } }, view.getCancelButton(), view.getSaveButton()); @@ -1166,7 +1167,7 @@ private void addMonthlySeriesEvent(Date endEventIntervalDate, String ids, int mo monthlyProperties.put(Event.EVENT_TYPE, "M"); monthlyProperties.put(Event.DATE_END, new Date(calBeginNextEventDate.getTime() + diff)); - if (view.getAllDayCheckbox().getValue() == true) { + if (view.getAllDayCheckbox().getValue()) { monthlyProperties.put(Event.EVENT_TYPE, "MF"); } @@ -1174,8 +1175,8 @@ private void addMonthlySeriesEvent(Date endEventIntervalDate, String ids, int mo String newSummary = eventSummary; String newDescription = eventDescription; - newSummary += " (Monthly event " + (i + 1) + " of " + monthInterval + ")"; - newDescription += " (Monthly " + (isMonthlySameDayOfWeek ? "same Day of a week " : "same Date ") + "event " + (i + 1) + " of " + monthInterval + ")"; + // newSummary += " (Monthly event " + (i + 1) + " of " + monthInterval + ")"; + // newDescription += " (Monthly " + (isMonthlySameDayOfWeek ? "same Day of a week " : "same Date ") + "event " + (i + 1) + " of " + monthInterval + ")"; monthlyProperties.put(Event.SUMMARY, newSummary); monthlyProperties.put(Event.DESCRIPTION, newDescription); @@ -1198,7 +1199,7 @@ private void addMonthlySeriesEvent(Date endEventIntervalDate, String ids, int mo */ private void processYearEvents(final Date beginEventIntervalDate, Date endEventIntervalDate, final Date endEventIntervalDateRadio, final Map properties, Boolean isYearlySameDayOfWeek, final Date startDate, final Date endDate, String eventSummary, String eventDescription) { properties.put(Event.EVENT_TYPE, "Y"); - if (view.getAllDayCheckbox().getValue() == true) { + if (view.getAllDayCheckbox().getValue()) { properties.put(Event.EVENT_TYPE, "YF"); } properties.put(Event.DATE_END, endEventIntervalDate); @@ -1207,14 +1208,14 @@ private void processYearEvents(final Date beginEventIntervalDate, Date endEventI int yearStart = beginEventIntervalDate.getYear(); int yearEnd = endEventIntervalDate.getYear(); int yearInterval = yearEnd - yearStart + 1; - if (view.getYearlyRadioNumberOfRepetitions().getValue() == true) { + if (view.getYearlyRadioNumberOfRepetitions().getValue()) { yearInterval--; } if (yearInterval <= 0) { yearInterval = 1; } - properties.put(Event.SUMMARY, (String) properties.get(Event.SUMMARY) + " (Yearly event 1 of " + yearInterval + ")"); - properties.put(Event.DESCRIPTION, (String) properties.get(Event.DESCRIPTION) + " (Yearly " + (isYearlySameDayOfWeek ? "same Day of a week " : "same Date ") + "event 1 of " + yearInterval + ")"); + properties.put(Event.SUMMARY, (String) properties.get(Event.SUMMARY));// + " (Yearly event 1 of " + yearInterval + ")"); + properties.put(Event.DESCRIPTION, (String) properties.get(Event.DESCRIPTION));// + " (Yearly " + (isYearlySameDayOfWeek ? "same Day of a week " : "same Date ") + "event 1 of " + yearInterval + ")"); addPersonalEventYearly(milisDiff, properties, yearInterval, beginEventIntervalDate, endEventIntervalDate, startDate, endDate, eventSummary, eventDescription, isYearlySameDayOfWeek); @@ -1258,7 +1259,7 @@ private void addYearlySeriesEvent(final long milisDiff, String ids, int yearInte yearlyProperties.put(Event.DATE, calBeginNextEventDate); yearlyProperties.put(Event.EVENT_TYPE, "Y"); - if (view.getAllDayCheckbox().getValue() == true) { + if (view.getAllDayCheckbox().getValue()) { yearlyProperties.put(Event.EVENT_TYPE, "YF"); } @@ -1268,8 +1269,8 @@ private void addYearlySeriesEvent(final long milisDiff, String ids, int yearInte String newSummary = eventSummary; String newDescription = eventDescription; - newSummary += " (Yearly event " + (i + 1) + " of " + yearInterval + ")"; - newDescription += " (Yearly " + (isYearlySameDayOfWeek ? "same Day of a week " : "same Date ") + "event " + (i + 1) + " of " + yearInterval + ")"; + // newSummary += " (Yearly event " + (i + 1) + " of " + yearInterval + ")"; + // newDescription += " (Yearly " + (isYearlySameDayOfWeek ? "same Day of a week " : "same Date ") + "event " + (i + 1) + " of " + yearInterval + ")"; yearlyProperties.put(Event.SUMMARY, newSummary); yearlyProperties.put(Event.DESCRIPTION, newDescription); diff --git a/src/main/java/org/sigmah/client/ui/view/calendar/CalendarEventView.java b/src/main/java/org/sigmah/client/ui/view/calendar/CalendarEventView.java index e0d6ff9d6..700e13af0 100644 --- a/src/main/java/org/sigmah/client/ui/view/calendar/CalendarEventView.java +++ b/src/main/java/org/sigmah/client/ui/view/calendar/CalendarEventView.java @@ -22,11 +22,9 @@ * #L% */ import com.extjs.gxt.ui.client.Style; -import com.extjs.gxt.ui.client.data.ChangeListener; import com.extjs.gxt.ui.client.event.Events; import com.extjs.gxt.ui.client.event.FieldEvent; import com.extjs.gxt.ui.client.event.Listener; -import com.extjs.gxt.ui.client.store.Store; import org.sigmah.client.i18n.I18N; import org.sigmah.client.ui.presenter.calendar.CalendarEventPresenter; import org.sigmah.client.ui.res.icon.IconImageBundle; @@ -37,7 +35,6 @@ import org.sigmah.client.ui.widget.popup.PopupWidget; import org.sigmah.shared.dto.calendar.Event; -import com.extjs.gxt.ui.client.widget.form.ComboBox.TriggerAction; import com.extjs.gxt.ui.client.widget.form.DateField; import com.extjs.gxt.ui.client.widget.form.Radio; import com.extjs.gxt.ui.client.widget.form.RadioGroup; @@ -45,33 +42,12 @@ import com.extjs.gxt.ui.client.widget.form.TextField; import com.extjs.gxt.ui.client.widget.form.TimeField; import com.extjs.gxt.ui.client.widget.form.CheckBox; -import com.extjs.gxt.ui.client.widget.form.ComboBox; import com.extjs.gxt.ui.client.widget.form.FieldSet; -import com.google.gwt.event.dom.client.ChangeEvent; -import com.google.gwt.user.client.Window; -import com.google.gwt.user.client.ui.ListBox; import com.google.inject.Singleton; -import com.google.gwt.core.client.EntryPoint; -import com.google.gwt.event.dom.client.ChangeHandler; -import com.google.gwt.user.client.ui.RootPanel; -import java.util.HashMap; -import java.util.Map; -import com.extjs.gxt.ui.client.data.BaseModelData; -import java.util.ArrayList; -import java.util.List; - -import com.extjs.gxt.ui.client.data.BaseModelData; -import com.extjs.gxt.ui.client.store.ListStore; import com.extjs.gxt.ui.client.widget.HorizontalPanel; -import com.extjs.gxt.ui.client.widget.LayoutContainer; import com.extjs.gxt.ui.client.widget.VerticalPanel; -import com.extjs.gxt.ui.client.widget.form.ComboBox; import com.extjs.gxt.ui.client.widget.form.ComboBox.TriggerAction; -import com.google.gwt.core.client.EntryPoint; -import com.google.gwt.user.client.Element; -import com.google.gwt.user.client.Random; import com.google.gwt.user.client.ui.HTML; -import com.google.gwt.user.client.ui.RootPanel; import java.util.Date; /* import com.gwtext.client.data.Record; diff --git a/src/main/java/org/sigmah/client/ui/widget/CalendarWidget.java b/src/main/java/org/sigmah/client/ui/widget/CalendarWidget.java index bb633185d..043eea785 100644 --- a/src/main/java/org/sigmah/client/ui/widget/CalendarWidget.java +++ b/src/main/java/org/sigmah/client/ui/widget/CalendarWidget.java @@ -67,6 +67,24 @@ public class CalendarWidget extends Composite { public static final int CELL_DEFAULT_WIDTH = 150; public static final int CELL_DEFAULT_HEIGHT = 80; + + /** + * Multiple calculated ("cached") values reused during laying out + * the month view elements. + */ + private static final int DAYS_IN_A_WEEK = 7; + private int calculatedWeekDayHeaderHeight; + private int calculatedDayHeaderHeight; + /** + * Height of each Cell (day), including the day's header. + */ + private float calculatedCellOffsetHeight; + + /** + * Height of each Cell (day), excluding the day's header. + */ + private float calculatedCellHeight; + public interface CalendarListener { @@ -119,7 +137,7 @@ public String getStyleName() { return "calendar-day"; } }, - WEEK(7, 1) { + WEEK(DAYS_IN_A_WEEK, 1) { @Override public Date getStartDate(Date date, int firstDay) { @@ -128,17 +146,17 @@ public Date getStartDate(Date date, int firstDay) { @Override public void nextDate(Date currentDate) { - currentDate.setDate(currentDate.getDate() + 7); + currentDate.setDate(currentDate.getDate() + DAYS_IN_A_WEEK); } @Override public void previousDate(Date currentDate) { - currentDate.setDate(currentDate.getDate() - 7); + currentDate.setDate(currentDate.getDate() - DAYS_IN_A_WEEK); } @Override public void firstDay(Date currentDate, Date today, int firstDay) { - int decal = (today.getDay() + 7 - firstDay) % 7; + int decal = (today.getDay() + DAYS_IN_A_WEEK - firstDay) % DAYS_IN_A_WEEK; currentDate.setYear(today.getYear()); currentDate.setMonth(today.getMonth()); currentDate.setDate(today.getDate() - decal); @@ -867,8 +885,9 @@ private void drawEvents(int row, int column, final Date date, int startDrawPosit dateLabel.addStyleName("calendar-event-date"); //final InlineLabel eventLabel = new InlineLabel(event.getReferenceId()==null?event.getSummary():"--->>"); - final InlineLabel eventLabel = new InlineLabel(row + "; " + event.getReferenceId() == null ? event.getSummary() : event.getSummary() + "->>"); - eventLabel.addStyleName("calendar-event-label"); + // final InlineLabel eventLabel = new InlineLabel(row + "; " + (!(event.getReferenceId() != null && event.getReferenceId().intValue() > 0)? event.getSummary() : event.getSummary() + "->>serial")); + final InlineLabel eventLabel = new InlineLabel(event.getSummary()); + eventLabel.addStyleName("calendar-event-label"); if (fullDayEvent) { flowPanel.addStyleName("calendar-fullday-event-" + event.getParent().getStyle()); @@ -1051,7 +1070,7 @@ private static int calculateEventDurationInDays(final Event event) { * {@link Date}. */ private static Date getFirstDateOfWeek(Date day, int firstDay) { - final int decal = (day.getDay() + 7 - firstDay) % 7; + final int decal = (day.getDay() + DAYS_IN_A_WEEK - firstDay) % DAYS_IN_A_WEEK; return new Date(day.getYear(), day.getMonth(), day.getDate() - decal); } @@ -1067,7 +1086,7 @@ private static int getWeekNumber(Date date, int firstDay) { int daysToThursday = 4 - date.getDay(); if (date.getDay() < firstDay) { - daysToThursday -= 7; + daysToThursday -= DAYS_IN_A_WEEK; } final Date thursday = new Date(date.getYear(), date.getMonth(), date.getDate() + daysToThursday); @@ -1111,22 +1130,6 @@ private static int appointmentHeight() { // TODO: calculate appointment height dynamically return 12; } - /** - * Multiple calculated ("cached") values reused during laying out - * the month view elements. - */ - private int DAYS_IN_A_WEEK = 7; - private int calculatedWeekDayHeaderHeight; - private int calculatedDayHeaderHeight; - /** - * Height of each Cell (day), including the day's header. - */ - private float calculatedCellOffsetHeight; - - /** - * Height of each Cell (day), excluding the day's header. - */ - private float calculatedCellHeight; /** * Display full day events with started date @@ -1140,13 +1143,12 @@ private void drawFullDayEvents(int row, int column, final Date date) { TreeSet sortedFullDayEvents = createSortedEventsSet(); for (final Calendar calendar : calendars) { - if (!(calendar.getIdentifier() instanceof ActivityCalendarIdentifier)) { - if (calendar.getFullDayEvents() != null) { - final Map> fullDayEventMap = normalize(calendar.getFullDayEvents()); - final List fullDayEvents = fullDayEventMap.get(date); - if (fullDayEvents != null) { - sortedFullDayEvents.addAll(fullDayEvents); - } + if (!(calendar.getIdentifier() instanceof ActivityCalendarIdentifier) + && calendar.getFullDayEvents() != null) { + final Map> fullDayEventMap = normalize(calendar.getFullDayEvents()); + final List fullDayEvents = fullDayEventMap.get(date); + if (fullDayEvents != null) { + sortedFullDayEvents.addAll(fullDayEvents); } } } @@ -1203,7 +1205,7 @@ private String createTitleForHourEvent(int daysdiff, final Event event) { + " to " + hourFormatter.format(event.getDtend()) // + " (" + duration + " hours" + (daysdiff > 0 ? " every day)" : ")") + " (" + (hour > 0 ? (hour + " hours ") : "") - + (minute > 0 ? (minute + " minutes") : "") + (daysdiff > 0 ? " every day)" : ") ") + + (minute > 0 ? (minute + " minutes") : "") + (daysdiff > 1 ? " every day)" : ") ") + (daysdiff > 1 ? (daysdiff + " days in row. ") : " ") + (isSameDay(event.getDtstart(), event.getDtend()) ? (DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.YEAR_MONTH_WEEKDAY_DAY).format(event.getDtstart())) From 22765b0383eceded2f778e8a9ca8d206f368972a Mon Sep 17 00:00:00 2001 From: Seal98 Date: Tue, 22 Aug 2017 01:41:46 +0300 Subject: [PATCH 35/39] (issue#852) Multi-day hour-interval events with repetition weekly etc. Implemented: -display Multi-day "hour interval" events (recurring weekly, monthly, yearly) with style different from style of Full-day events and Single day "hour interval" events -possibility to change event type from Full-day to "hour interval" event for Multi-day and One-day events. --- .../calendar/CalendarEventPresenter.java | 122 +++++++++++++----- .../presenter/calendar/CalendarPresenter.java | 22 ++-- .../client/ui/widget/CalendarWidget.java | 83 ++++++------ 3 files changed, 142 insertions(+), 85 deletions(-) diff --git a/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java b/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java index 83068689d..223925977 100644 --- a/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java +++ b/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java @@ -62,6 +62,7 @@ import com.extjs.gxt.ui.client.widget.form.TextField; import com.extjs.gxt.ui.client.widget.form.Time; import com.extjs.gxt.ui.client.widget.form.TimeField; +import com.google.gwt.user.client.Window; import com.google.inject.ImplementedBy; import com.google.inject.Inject; import com.google.inject.Singleton; @@ -619,7 +620,7 @@ private void prepareAddView() { */ @SuppressWarnings("deprecation") private void onSaveAction() { - + // Window.alert("onSaveAction"); if (!view.getForm().isValid()) { return; } @@ -649,7 +650,7 @@ private void onSaveAction() { // Window.alert("isAllDayEvent=" + isFullDayEvent);//temp for checker Date startDateTime = createStartDateTimeProperty(isFullDayEvent, beginEventIntervalDate, properties); Date endDateTime = createEndDateTimeProperty(isFullDayEvent, beginEventIntervalDate, properties); - + int daysdiff = calculateEventDurationInDays(beginEventIntervalDate, endEventIntervalDate); properties.put(Event.DESCRIPTION, view.getEventDescriptionField().getValue()); if (event == null) { @@ -659,32 +660,45 @@ private void onSaveAction() { properties.put(Event.EVENT_TYPE, event.getEventType()); properties.put(Event.REFERENCE_ID, event.getReferenceId()); - if (view.getAllDayCheckbox().getValue()) { + if (isFullDayEvent) { + // Window.alert("#3 isFullDayEvent event.getEventType() = " + event.getEventType()); if (event.getEventType() != null) { - if ("O".equals(event.getEventType())) { + if ("O".equals(event.getEventType()) + || "OH".equals(event.getEventType())) { properties.put(Event.EVENT_TYPE, "OF"); - } else if ("D".equals(event.getEventType())) { + } else if ("D".equals(event.getEventType()) + || "DH".equals(event.getEventType())) { properties.put(Event.EVENT_TYPE, "DF"); - } else if ("W".equals(event.getEventType())) { + } else if ("W".equals(event.getEventType()) + || "WH".equals(event.getEventType())) { properties.put(Event.EVENT_TYPE, "WF"); - } else if ("M".equals(event.getEventType())) { + } else if ("M".equals(event.getEventType()) + || "MH".equals(event.getEventType())) { properties.put(Event.EVENT_TYPE, "MF"); - } else if ("Y".equals(event.getEventType())) { + } else if ("Y".equals(event.getEventType()) + || "YH".equals(event.getEventType())) { properties.put(Event.EVENT_TYPE, "YF"); } } } else { +// Window.alert("#4 not full day event.getEventType() = " + event.getEventType() +// + " daysdiff=" + daysdiff); if (event.getEventType() != null) { if ("OF".equals(event.getEventType())) { - properties.put(Event.EVENT_TYPE, "O"); + properties.put(Event.EVENT_TYPE, ("O" + (daysdiff > 1 ? "H" : ""))); + //properties.put(Event.EVENT_TYPE, "O"); } else if ("DF".equals(event.getEventType())) { - properties.put(Event.EVENT_TYPE, "D"); + properties.put(Event.EVENT_TYPE, ("D" + (daysdiff > 1 ? "H" : ""))); + //properties.put(Event.EVENT_TYPE, "D"); } else if ("WF".equals(event.getEventType())) { - properties.put(Event.EVENT_TYPE, "W"); + properties.put(Event.EVENT_TYPE, ("W" + (daysdiff > 1 ? "H" : ""))); + //properties.put(Event.EVENT_TYPE, "W" ); } else if ("MF".equals(event.getEventType())) { - properties.put(Event.EVENT_TYPE, "M"); + properties.put(Event.EVENT_TYPE, ("M" + (daysdiff > 1 ? "H" : ""))); + //properties.put(Event.EVENT_TYPE, "M"); } else if ("YF".equals(event.getEventType())) { - properties.put(Event.EVENT_TYPE, "Y"); + properties.put(Event.EVENT_TYPE, ("Y" + (daysdiff > 1 ? "H" : ""))); + //properties.put(Event.EVENT_TYPE, "Y"); } } } @@ -819,7 +833,8 @@ private void processOnceEvent(final Date beginEventIntervalDate1, long diffInMil if (view.getAllDayCheckbox().getValue()) { properties.put(Event.EVENT_TYPE, "OF"); } else { - properties.put(Event.EVENT_TYPE, "O"); + properties.put(Event.EVENT_TYPE, ("O" + (daysDiff > 1 ? "H" : ""))); + //properties.put(Event.EVENT_TYPE, "O"); } if (daysDiff == 1) { addPersonalEvent(properties); @@ -873,13 +888,15 @@ public void onCommandSuccess(final CreateResult result) { private void processDailyEvents(long count, long lengthDailyEvent, long milisPerDay, final Date beginEventIntervalDate, final Date endEventIntervalDateRadio, final Date endEventIntervalDate, final Date startDate, final Date endDate, final Map properties, String eventSummary, String eventDescription) { long calBeginNextEventDateLong = beginEventIntervalDate.getTime(); //Date calBeginNextEventDate = beginEventIntervalDate; + long daysInterval = ((endEventIntervalDate.getTime() - beginEventIntervalDate.getTime()) / milisPerDay) + 1; properties.put(Event.SUMMARY, (String) properties.get(Event.SUMMARY));// + " (Daily event 1 of " + count + ")"); properties.put(Event.DESCRIPTION, (String) properties.get(Event.DESCRIPTION));// + " (Daily event 1 of " + count + ")"); if (view.getAllDayCheckbox().getValue()) { properties.put(Event.EVENT_TYPE, "DF"); } else { - properties.put(Event.EVENT_TYPE, "D"); + properties.put(Event.EVENT_TYPE, ("D" + (daysInterval > 1 ? "H" : ""))); + //properties.put(Event.EVENT_TYPE, "D"); } properties.put(Event.DATE_END, new Date(calBeginNextEventDateLong + milisPerDay * (lengthDailyEvent - 1))); addPersonalEventDaily(properties, count, lengthDailyEvent, calBeginNextEventDateLong, milisPerDay, startDate, endDate, eventSummary, eventDescription); @@ -937,7 +954,8 @@ private void addDailySeriesEvent(Integer ids, long daysInterval, long lengthDail if (view.getAllDayCheckbox().getValue()) { dailyProperties.put(Event.EVENT_TYPE, "DF"); } else { - dailyProperties.put(Event.EVENT_TYPE, "D"); + dailyProperties.put(Event.EVENT_TYPE, ("D" + (daysInterval > 1 ? "H" : ""))); + // dailyProperties.put(Event.EVENT_TYPE, "D"); } dailyProperties.put(Event.DATE_END, new Date(calEndNextEventDateLong)); setFullDayEvent(startDate, endDate, new Date(calBeginNextEventDateLong), dailyProperties); @@ -967,6 +985,7 @@ private void addDailySeriesEvent(Integer ids, long daysInterval, long lengthDail * @param eventDescription the value of eventDescription */ private void processWeeklyEvents(final Date beginEventIntervalDate, final Date endEventIntervalDate, final Date endEventIntervalDateRadio, final Date startDate, final Date endDate, final Map properties, String eventSummary, String eventDescription) { + // Window.alert("processWeeklyEvents"); long milisPerDay = 86400000; long weekDiff = ((endEventIntervalDateRadio.getTime() - beginEventIntervalDate.getTime() + milisPerDay) / (milisPerDay * 7)); int weeksInterval = (int) weekDiff; @@ -987,10 +1006,13 @@ private void processWeeklyEvents(final Date beginEventIntervalDate, final Date e properties.put(Event.SUMMARY, (String) properties.get(Event.SUMMARY)); properties.put(Event.DESCRIPTION, (String) properties.get(Event.DESCRIPTION));// + " (Weekly event 1 of " + weeksInterval + ")"); +// Window.alert("#5 processWeeklyEvents event.getEventType() = " + (event!=null?event.getEventType():"NULL") +// + " daysInterval=" + daysInterval); if (view.getAllDayCheckbox().getValue()) { properties.put(Event.EVENT_TYPE, "WF"); } else { - properties.put(Event.EVENT_TYPE, "W"); + properties.put(Event.EVENT_TYPE, ("W" + (daysInterval > 1 ? "H" : ""))); + //properties.put(Event.EVENT_TYPE, "W"); } addPersonalEventWeekly(properties, weeksInterval, calBeginNextEventDateLong, calEndNextEventDateLong, daysInterval, startDate, endDate, eventSummary, eventDescription); @@ -1040,13 +1062,15 @@ private void addDailySeriesEventNew2(Integer ids, int daysInterval, long calBegi String newSummary = eventSummary; String newDescription = eventDescription; - // newDescription += " (Weekly event " + (i + 1) + " of " + daysInterval + ")"; + // newDescription += " (Weekly event " + (i + 1) + " of " + daysInterval + ")"; dailyProperties.put(Event.SUMMARY, newSummary); dailyProperties.put(Event.DESCRIPTION, newDescription); if (view.getAllDayCheckbox().getValue()) { dailyProperties.put(Event.EVENT_TYPE, "WF"); } else { - dailyProperties.put(Event.EVENT_TYPE, "W"); +// Window.alert("#1 addDailySeriesEventNew2 event.getEventType() = " + (event!=null?event.getEventType():"null") +// + " daysInterval=" + daysInterval); + dailyProperties.put(Event.EVENT_TYPE, ("W" + (daysInterval > 1 ? "H" : ""))); } dailyProperties.put(Event.REFERENCE_ID, ids); @@ -1094,11 +1118,14 @@ private void setFullDayEvent(final Date startDate, final Date endDate, Date calB * @param eventDescription the value of eventDescription */ private void processMonthlyEvents(final Date beginEventIntervalDate, Date endEventIntervalDate, final Date endEventIntervalDateRadio, final Map properties, Boolean isMonthlySameDayOfWeek, final Date startDate, final Date endDate, String eventSummary, String eventDescription) { + long milisPerDay = 86400000; //24 * 60 * 60 * 1000) + long daysInterval = ((endEventIntervalDate.getTime() - beginEventIntervalDate.getTime()) / milisPerDay) + 1; if (view.getAllDayCheckbox().getValue()) { properties.put(Event.EVENT_TYPE, "MF"); } else { - properties.put(Event.EVENT_TYPE, "M"); + properties.put(Event.EVENT_TYPE, ("M" + (daysInterval > 1 ? "H" : ""))); + // properties.put(Event.EVENT_TYPE, "M"); } properties.put(Event.DATE_END, endEventIntervalDate); Date endEventIntervalDate1 = endEventIntervalDate; @@ -1156,6 +1183,9 @@ public void onCommandSuccess(final CreateResult result) { private void addMonthlySeriesEvent(Date endEventIntervalDate, String ids, int monthInterval, Date beginEventIntervalDate, final Date startDate, final Date endDate, String eventSummary, String eventDescription, final boolean isMonthlySameDayOfWeek) { Date calBeginNextEventDate = beginEventIntervalDate; long diff = endEventIntervalDate.getTime() - beginEventIntervalDate.getTime(); + long milisPerDay = 86400000; //24 * 60 * 60 * 1000) + long daysInterval = ((endEventIntervalDate.getTime() - beginEventIntervalDate.getTime()) / milisPerDay) + 1; + for (int i = 1; i < monthInterval; i++) { calBeginNextEventDate = getMonthlySameDayOfWeek2(beginEventIntervalDate, calBeginNextEventDate, i, isMonthlySameDayOfWeek); @@ -1164,19 +1194,22 @@ private void addMonthlySeriesEvent(Date endEventIntervalDate, String ids, int mo monthlyProperties.put(Event.SUMMARY, view.getEventSummaryField().getValue()); monthlyProperties.put(Event.DATE, calBeginNextEventDate); - monthlyProperties.put(Event.EVENT_TYPE, "M"); +// monthlyProperties.put(Event.EVENT_TYPE, "M"); monthlyProperties.put(Event.DATE_END, new Date(calBeginNextEventDate.getTime() + diff)); if (view.getAllDayCheckbox().getValue()) { monthlyProperties.put(Event.EVENT_TYPE, "MF"); + } else { + monthlyProperties.put(Event.EVENT_TYPE, ("M" + (daysInterval > 1 ? "H" : ""))); + //monthlyProperties.put(Event.EVENT_TYPE, "M"); } setFullDayEvent(startDate, endDate, calBeginNextEventDate, monthlyProperties); String newSummary = eventSummary; String newDescription = eventDescription; - // newSummary += " (Monthly event " + (i + 1) + " of " + monthInterval + ")"; - // newDescription += " (Monthly " + (isMonthlySameDayOfWeek ? "same Day of a week " : "same Date ") + "event " + (i + 1) + " of " + monthInterval + ")"; + // newSummary += " (Monthly event " + (i + 1) + " of " + monthInterval + ")"; + // newDescription += " (Monthly " + (isMonthlySameDayOfWeek ? "same Day of a week " : "same Date ") + "event " + (i + 1) + " of " + monthInterval + ")"; monthlyProperties.put(Event.SUMMARY, newSummary); monthlyProperties.put(Event.DESCRIPTION, newDescription); @@ -1198,12 +1231,12 @@ private void addMonthlySeriesEvent(Date endEventIntervalDate, String ids, int mo * @param eventDescription the value of eventDescription */ private void processYearEvents(final Date beginEventIntervalDate, Date endEventIntervalDate, final Date endEventIntervalDateRadio, final Map properties, Boolean isYearlySameDayOfWeek, final Date startDate, final Date endDate, String eventSummary, String eventDescription) { - properties.put(Event.EVENT_TYPE, "Y"); - if (view.getAllDayCheckbox().getValue()) { - properties.put(Event.EVENT_TYPE, "YF"); - } + properties.put(Event.DATE_END, endEventIntervalDate); long milisDiff = endEventIntervalDate.getTime() - beginEventIntervalDate.getTime(); + long milisPerDay = 86400000; //24 * 60 * 60 * 1000) + long daysInterval = ((endEventIntervalDate.getTime() - beginEventIntervalDate.getTime()) / milisPerDay) + 1; + endEventIntervalDate = endEventIntervalDateRadio; int yearStart = beginEventIntervalDate.getYear(); int yearEnd = endEventIntervalDate.getYear(); @@ -1213,6 +1246,13 @@ private void processYearEvents(final Date beginEventIntervalDate, Date endEventI } if (yearInterval <= 0) { yearInterval = 1; + } + // properties.put(Event.EVENT_TYPE, "Y"); + if (view.getAllDayCheckbox().getValue()) { + properties.put(Event.EVENT_TYPE, "YF"); + } else { + properties.put(Event.EVENT_TYPE, ("Y" + (daysInterval > 1 ? "H" : ""))); + // properties.put(Event.EVENT_TYPE, "Y"); } properties.put(Event.SUMMARY, (String) properties.get(Event.SUMMARY));// + " (Yearly event 1 of " + yearInterval + ")"); properties.put(Event.DESCRIPTION, (String) properties.get(Event.DESCRIPTION));// + " (Yearly " + (isYearlySameDayOfWeek ? "same Day of a week " : "same Date ") + "event 1 of " + yearInterval + ")"); @@ -1248,6 +1288,10 @@ public void onCommandSuccess(final CreateResult result) { } private void addYearlySeriesEvent(final long milisDiff, String ids, int yearInterval, Date beginEventIntervalDate, Date endEventIntervalDate, final Date startDate, final Date endDate, String eventSummary, String eventDescription, final boolean isYearlySameDayOfWeek) { + long milisPerDay = 86400000; //24 * 60 * 60 * 1000) + long daysInterval = ((endEventIntervalDate.getTime() - beginEventIntervalDate.getTime()) / milisPerDay) + 1; + + Date calBeginNextEventDate = beginEventIntervalDate; for (int i = 1; i < yearInterval; i++) { calBeginNextEventDate = getYearlySameDayOfWeek(beginEventIntervalDate, calBeginNextEventDate, i, isYearlySameDayOfWeek); @@ -1257,10 +1301,12 @@ private void addYearlySeriesEvent(final long milisDiff, String ids, int yearInte yearlyProperties.put(Event.SUMMARY, view.getEventSummaryField().getValue()); yearlyProperties.put(Event.DATE, calBeginNextEventDate); - yearlyProperties.put(Event.EVENT_TYPE, "Y"); if (view.getAllDayCheckbox().getValue()) { yearlyProperties.put(Event.EVENT_TYPE, "YF"); + } else { + yearlyProperties.put(Event.EVENT_TYPE, ("Y" + (daysInterval > 1 ? "H" : ""))); + //yearlyProperties.put(Event.EVENT_TYPE, "Y"); } yearlyProperties.put(Event.DATE_END, new Date(calBeginNextEventDate.getTime() + milisDiff)); @@ -1269,8 +1315,8 @@ private void addYearlySeriesEvent(final long milisDiff, String ids, int yearInte String newSummary = eventSummary; String newDescription = eventDescription; - // newSummary += " (Yearly event " + (i + 1) + " of " + yearInterval + ")"; - // newDescription += " (Yearly " + (isYearlySameDayOfWeek ? "same Day of a week " : "same Date ") + "event " + (i + 1) + " of " + yearInterval + ")"; + // newSummary += " (Yearly event " + (i + 1) + " of " + yearInterval + ")"; + // newDescription += " (Yearly " + (isYearlySameDayOfWeek ? "same Day of a week " : "same Date ") + "event " + (i + 1) + " of " + yearInterval + ")"; yearlyProperties.put(Event.SUMMARY, newSummary); yearlyProperties.put(Event.DESCRIPTION, newDescription); @@ -1329,8 +1375,13 @@ public void onCommandSuccess(final VoidResult result) { final Calendar calendar = event.getParent(); final List oldEventList = calendar.getEvents().get(event.getKey()); - oldEventList.remove(event); - + if (oldEventList != null && oldEventList.contains(event)) { + oldEventList.remove(event); + } + final List oldFullDayEventList = calendar.getFullDayEvents().get(event.getKey()); + if (oldFullDayEventList != null && oldFullDayEventList.contains(event)) { + oldFullDayEventList.remove(event); + } updateEvent(event, properties); } }, view.getCancelButton(), view.getSaveButton()); @@ -1604,4 +1655,11 @@ private int getDaysInMonth(int year, int month) { private boolean isLeapYear(int year) { return (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)); } + + private static int calculateEventDurationInDays(final Date startDateTime, Date endDateTime) { + long diff = endDateTime.getTime() - startDateTime.getTime(); + long diffDays = diff / (24 * 60 * 60 * 1000) + 1; + int daysdiff = (int) diffDays; + return daysdiff; + } } diff --git a/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarPresenter.java b/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarPresenter.java index e2c7c6237..dec10ab84 100644 --- a/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarPresenter.java +++ b/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarPresenter.java @@ -180,7 +180,7 @@ public void onCommandSuccess(final VoidResult result) { oldEventList.remove(event); } //ak - Window.alert("12 refresh CalPres delete onCommandSuccess"); + // Window.alert("12 refresh CalPres delete onCommandSuccess"); calendar.refresh(); } }); @@ -197,7 +197,7 @@ public void onCommandFailure(final Throwable caught) { @Override public void onCommandSuccess(final VoidResult result) { eventMap.get(key).remove(next); - Window.alert("11 refresh deleteEventFunction1 onCommandSuccess"); + // Window.alert("11 refresh deleteEventFunction1 onCommandSuccess"); calendar.refresh(); } }); @@ -214,7 +214,7 @@ public void onCommandFailure(final Throwable caught) { @Override public void onCommandSuccess(final VoidResult result) { eventMap.get(key).remove(next); - Window.alert("10 refresh deleteEventFunction2 onCommandSuccess"); + // Window.alert("10 refresh deleteEventFunction2 onCommandSuccess"); calendar.refresh(); } }); @@ -296,7 +296,7 @@ public void onCommandSuccess(final VoidResult result) { oldEventList.remove(event); } //ak - Window.alert("9 refresh CalPres deleteChain onCommandSuccess"); + // Window.alert("9 refresh CalPres deleteChain onCommandSuccess"); calendar.refresh(); } }); @@ -422,14 +422,14 @@ public void componentSelected(final ButtonEvent event) { @Override public void onUpdate(final UpdateEvent event) { if (event.concern(UpdateEvent.CALENDAR_EVENT_UPDATE)) { - Window.alert("7 refresh CalPres Update event handler. "); + //Window.alert("7 refresh CalPres Update event handler. "); calendar.refresh(); } if (event.concern(UpdateEvent.REMINDER_UPDATED)) { // TODO appel reloadEventsOfReminderType((ReminderType) event.getParam(0)); - Window.alert("6 refresh CalPres Update event handler. "); + //Window.alert("6 refresh CalPres Update event handler. "); calendar.refresh(); } } @@ -443,7 +443,7 @@ public void onUpdate(final UpdateEvent event) { */ public void reload(final Map calendars, boolean editable) { Profiler.INSTANCE.markCheckpoint(Scenario.AGENDA, "Before refresh."); - Window.alert("5 refresh CalPres reload. "); + //Window.alert("5 refresh CalPres reload. "); calendar.refresh(); Profiler.INSTANCE.markCheckpoint(Scenario.AGENDA, "calendar.refresh ended."); @@ -460,7 +460,7 @@ public void reload(final Map calendars, boolean editable) */ @Override public void onViewRevealed() { - Window.alert("4 refresh onViewRevealed. "); + // Window.alert("4 refresh onViewRevealed. "); calendar.refresh(); } @@ -491,7 +491,7 @@ private void reloadEvents(final Map calendars) { view.getCalendarsStore().removeAll(); if (ClientUtils.isEmpty(calendars)) { - Window.alert("3 refresh reloadEvents. "); + // Window.alert("3 refresh reloadEvents. "); calendar.refresh(); Profiler.INSTANCE.endScenario(Scenario.AGENDA); return; @@ -501,7 +501,7 @@ private void reloadEvents(final Map calendars) { @Override protected void onComplete() { - Window.alert("2 refresh onComplete. "); + // Window.alert("2 refresh onComplete. "); calendar.refresh(); Profiler.INSTANCE.endScenario(Scenario.AGENDA); } @@ -568,7 +568,7 @@ protected void onCommandSuccess(Calendar result) { result.setStyle(calendarType.getColorCode()); result.setType(calendarType); calendars.set(location, result); - Window.alert("1 refresh reloadEventsOfReminderType. "); + // Window.alert("1 refresh reloadEventsOfReminderType. "); calendar.refresh(); } } diff --git a/src/main/java/org/sigmah/client/ui/widget/CalendarWidget.java b/src/main/java/org/sigmah/client/ui/widget/CalendarWidget.java index 043eea785..98e08e633 100644 --- a/src/main/java/org/sigmah/client/ui/widget/CalendarWidget.java +++ b/src/main/java/org/sigmah/client/ui/widget/CalendarWidget.java @@ -67,8 +67,8 @@ public class CalendarWidget extends Composite { public static final int CELL_DEFAULT_WIDTH = 150; public static final int CELL_DEFAULT_HEIGHT = 80; - - /** + + /** * Multiple calculated ("cached") values reused during laying out * the month view elements. */ @@ -85,7 +85,6 @@ public class CalendarWidget extends Composite { */ private float calculatedCellHeight; - public interface CalendarListener { void afterRefresh(); @@ -289,19 +288,19 @@ public void setListener(CalendarListener listener) { public void next() { displayMode.nextDate(startDate); - Window.alert("displayMode.nextDate(startDate);. "); + // Window.alert("displayMode.nextDate(startDate);. "); refresh(); } public void previous() { displayMode.previousDate(startDate); - Window.alert("refresh previous"); + // Window.alert("refresh previous"); refresh(); } public final void today() { displayMode.firstDay(startDate, today, firstDayOfWeek); - Window.alert("refresh today"); + // Window.alert("refresh today"); refresh(); } @@ -316,7 +315,7 @@ public Date getStartDate() { public void addCalendar(Calendar calendar) { calendars.add(calendar); - Window.alert("refresh addCalendar"); + // Window.alert("refresh addCalendar"); refresh(); } @@ -325,7 +324,7 @@ public List getCalendars() { } public void setCalendars(List calendars) { - // this.calendars = calendars; + // this.calendars = calendars; // Window.alert("SET setCalendars"); // for (Calendar calendar : calendars) { // if (!(calendar.getIdentifier() instanceof ActivityCalendarIdentifier)) { @@ -336,8 +335,8 @@ public void setCalendars(List calendars) { // } // } // } - this.calendars = calendars; - Window.alert("refresh setCalendars"); + this.calendars = calendars; + // Window.alert("refresh setCalendars"); refresh(); } @@ -352,7 +351,7 @@ public void setCalendars(List calendars) { */ public void setTitleFormatter(DateTimeFormat titleFormatter) { this.titleFormatter = titleFormatter; - Window.alert("refresh setTitleFormatter"); + // Window.alert("refresh setTitleFormatter"); refresh(); } @@ -366,7 +365,7 @@ public void setTitleFormatter(DateTimeFormat titleFormatter) { */ public void setHeaderFormatter(DateTimeFormat headerFormatter) { this.headerFormatter = headerFormatter; - Window.alert("refresh setHeaderFormatter"); + // Window.alert("refresh setHeaderFormatter"); refresh(); } @@ -380,7 +379,7 @@ public void setHeaderFormatter(DateTimeFormat headerFormatter) { */ public void setDayFormatter(DateTimeFormat dayFormatter) { this.dayFormatter = dayFormatter; - Window.alert("refresh setDayFormatter"); + // Window.alert("refresh setDayFormatter"); refresh(); } @@ -402,7 +401,7 @@ public void setDisplayMode(DisplayMode displayMode) { // Applying the CSS style associated with the new display mode grid.addStyleName(displayMode.getStyleName()); -Window.alert("refresh setDisplayMode"); + // Window.alert("refresh setDisplayMode"); refresh(); } @@ -414,7 +413,7 @@ public void setDisplayMode(DisplayMode displayMode) { */ public void setFirstDayOfWeek(int firstDayOfWeek) { this.firstDayOfWeek = firstDayOfWeek; - Window.alert("refresh setFirstDayOfWeek"); + // Window.alert("refresh setFirstDayOfWeek"); refresh(); } @@ -425,7 +424,7 @@ public int getDisplayHeaders() { public void setDisplayHeaders(int displayHeaders) { clear(); this.displayHeaders = displayHeaders; - Window.alert("refresh setDisplayHeaders"); + // Window.alert("refresh setDisplayHeaders"); refresh(); } @@ -436,7 +435,7 @@ public boolean isDisplayWeekNumber() { public void setDisplayWeekNumber(boolean displayWeekNumber) { clear(); this.displayWeekNumber = displayWeekNumber; - Window.alert("refresh setDisplayWeekNumber"); + // Window.alert("refresh setDisplayWeekNumber"); refresh(); } @@ -499,14 +498,14 @@ public static Map> normalize(final Map> even } public static Map> normalizeHourEvents(final Map> eventMap) { -Window.alert("normalizeHourEvents"); + // Window.alert("normalizeHourEvents"); final Map> hourEventMapNormalized = new HashMap>(); for (final Date key : eventMap.keySet()) { for (final Event event : eventMap.get(key)) { Date normalizedKeyDate = new Date(key.getYear(), key.getMonth(), key.getDate()); if (!isSameDay(event.getDtstart(), event.getDtend())) { - Window.alert("! isSameDay" + event.getSummary()); + // Window.alert("! isSameDay" + event.getSummary()); // if (event.getDtstart() != event.getDtend()) { //1 int daysdiff = calculateEventDurationInDays(event); @@ -555,7 +554,7 @@ public static Map> normalizeHourEvents(final Map0) { //SSS final Map> eventMap = normalize(calendar.getEvents()); //ss Map> eventMap = normalizeHourEvents(calendar.getEvents()); - // final Map> eventMap = normalize(eventMap2); + // final Map> eventMap = normalize(eventMap2); //final Map> eventMap = calendar.getEvents(); final List events = eventMap.get(date); @@ -853,9 +853,9 @@ private void drawEvents(int row, int column, final Date date, int startDrawPosit } final Iterator iterator = sortedHourEvents.iterator(); - if (startDrawPosition==-1){ + if (startDrawPosition == -1) { eventLimit = 1; - }else{ + } else { eventLimit = 99; } for (int i = 0; iterator.hasNext() && i < eventLimit; i++) { @@ -885,9 +885,9 @@ private void drawEvents(int row, int column, final Date date, int startDrawPosit dateLabel.addStyleName("calendar-event-date"); //final InlineLabel eventLabel = new InlineLabel(event.getReferenceId()==null?event.getSummary():"--->>"); - // final InlineLabel eventLabel = new InlineLabel(row + "; " + (!(event.getReferenceId() != null && event.getReferenceId().intValue() > 0)? event.getSummary() : event.getSummary() + "->>serial")); + // final InlineLabel eventLabel = new InlineLabel(row + "; " + (!(event.getReferenceId() != null && event.getReferenceId().intValue() > 0)? event.getSummary() : event.getSummary() + "->>serial")); final InlineLabel eventLabel = new InlineLabel(event.getSummary()); - eventLabel.addStyleName("calendar-event-label"); + eventLabel.addStyleName("calendar-event-label"); if (fullDayEvent) { flowPanel.addStyleName("calendar-fullday-event-" + event.getParent().getStyle()); @@ -897,13 +897,16 @@ private void drawEvents(int row, int column, final Date date, int startDrawPosit if (!fullDayEvent) { flowPanel.add(dateLabel); - + int daysdiff = calculateEventDurationInDays(event); - + flowPanel.setTitle(createTitleForHourEvent(daysdiff, event)); } flowPanel.add(eventLabel); - + if (event.getEventType().contains("H")) { + // DOM.setStyleAttribute(flowPanel.getElement(), "background-color", "rgba(28,97,217,0.3)"); + DOM.setStyleAttribute(flowPanel.getElement(), "background", "linear-gradient(-90deg, #1c61d9, #0000)"); + } final DecoratedPopupPanel detailPopup = new DecoratedPopupPanel(true); final Grid popupContent = new Grid(event.getParent().isEditable() ? 6 : 3, 1); @@ -953,7 +956,7 @@ public void onClick(ClickEvent clickEvent) { @Override public void onClick(ClickEvent clickEvent) { delegate.deleteChain(event, CalendarWidget.this); - Window.alert("refresh deleteChainAnchor onClick"); + // Window.alert("refresh deleteChainAnchor onClick"); refresh(); detailPopup.hide(); @@ -962,8 +965,7 @@ public void onClick(ClickEvent clickEvent) { popupContent.setWidget(3, 0, editAnchor); popupContent.setWidget(4, 0, deleteAnchor); - if (event.getEventType().equals("O") || event.getEventType().equals("OF")) { - } else { + if (!event.getEventType().contains("O")) { popupContent.setWidget(5, 0, deleteChainAnchor); } } @@ -1052,7 +1054,6 @@ public void onClick(ClickEvent event) { } } - private static int calculateEventDurationInDays(final Event event) { long diff = event.getDtend().getTime() - event.getDtstart().getTime(); long diffDays = diff / (24 * 60 * 60 * 1000) + 1; @@ -1181,7 +1182,7 @@ private void drawFullDayEvents(int row, int column, final Date date) { private static String createTitleForFullDayEvent(int daysdiff, final Event event) { return "Event: " + event.getSummary() + "\nDescr: " + event.getDescription() - + "\nDuration: " + daysdiff + " full day" + (daysdiff > 1 ? "s." : ".") + + "\nDuration: " + daysdiff + " full day" + (daysdiff > 1 ? "s." : ".") + (event.getDtstart().equals(event.getDtend()) ? (DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.YEAR_MONTH_WEEKDAY_DAY).format(event.getDtstart())) : ("\nFrom " + DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.YEAR_MONTH_WEEKDAY_DAY).format(event.getDtstart()) @@ -1195,15 +1196,15 @@ private static String createTitleForFullDayEvent(int daysdiff, final Event event * @return the java.lang.String */ private String createTitleForHourEvent(int daysdiff, final Event event) { - String duration = hourFormatter.format(new Date(event.getDtend().getTime()- event.getDtstart().getTime())); - long millis = event.getDtend().getTime()- event.getDtstart().getTime(); + String duration = hourFormatter.format(new Date(event.getDtend().getTime() - event.getDtstart().getTime())); + long millis = event.getDtend().getTime() - event.getDtstart().getTime(); long minute = (millis / (1000 * 60)) % 60; long hour = (millis / (1000 * 60 * 60)) % 24; return "Event: " + event.getSummary() + "\nDescr: " + event.getDescription() + "\nDuration: from " + hourFormatter.format(event.getDtstart()) + " to " + hourFormatter.format(event.getDtend()) - // + " (" + duration + " hours" + (daysdiff > 0 ? " every day)" : ")") + // + " (" + duration + " hours" + (daysdiff > 0 ? " every day)" : ")") + " (" + (hour > 0 ? (hour + " hours ") : "") + (minute > 0 ? (minute + " minutes") : "") + (daysdiff > 1 ? " every day)" : ") ") + (daysdiff > 1 ? (daysdiff + " days in row. ") : " ") @@ -1212,6 +1213,7 @@ private String createTitleForHourEvent(int daysdiff, final Event event) { : ("\nFrom " + DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.YEAR_MONTH_WEEKDAY_DAY).format(event.getDtstart()) + " to " + DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.YEAR_MONTH_WEEKDAY_DAY).format(event.getDtend()))); } + /** * @param event * @return @@ -1289,7 +1291,7 @@ public void onClick(ClickEvent clickEvent) { @Override public void onClick(ClickEvent clickEvent) { delegate.delete(event, CalendarWidget.this); - Window.alert("refresh deleteAnchor onClick "); + // Window.alert("refresh deleteAnchor onClick "); refresh(); detailPopup.hide(); } @@ -1301,7 +1303,7 @@ public void onClick(ClickEvent clickEvent) { @Override public void onClick(ClickEvent clickEvent) { delegate.deleteChain(event, CalendarWidget.this); - Window.alert("refresh deleteChainAnchor onClick"); + // Window.alert("refresh deleteChainAnchor onClick"); refresh(); detailPopup.hide(); @@ -1310,10 +1312,7 @@ public void onClick(ClickEvent clickEvent) { popupContent.setWidget(3, 0, editAnchor); popupContent.setWidget(4, 0, deleteAnchor); - // Window.alert(event.getEventType()); - if (event.getEventType().equals("O") || event.getEventType().equals("OF")) { - } else { - //Window.alert(event.getEventType()); + if (!event.getEventType().contains("O")) { popupContent.setWidget(5, 0, deleteChainAnchor); } } From 02972c4853618f013720bb64595dde7658bd0bd9 Mon Sep 17 00:00:00 2001 From: Seal98 Date: Wed, 23 Aug 2017 15:34:41 +0300 Subject: [PATCH 36/39] (issue#852) minor improvements 1)autofill the enddate with the startdate after the first time the start date field is filled 2)renamed "Start"/"End" "hour" into "Start"/"End" "time" 3)renamed "Delete chain" into "Delete all recurrences" 4)renamed "Daily"/"Weekly"/"Monthly"/"Yearly" "repeats details" into "Daily"/"Weekly"/"Monthly"/"Yearly" "repetition details" --- .../calendar/CalendarEventPresenter.java | 97 +++++++++++++++++-- .../ui/view/calendar/CalendarEventView.java | 8 +- .../client/ui/widget/CalendarWidget.java | 4 +- .../sigmah/client/i18n/UIConstants.properties | 8 +- 4 files changed, 101 insertions(+), 16 deletions(-) diff --git a/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java b/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java index 223925977..dc679f1ef 100644 --- a/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java +++ b/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java @@ -52,6 +52,9 @@ import org.sigmah.shared.dto.calendar.PersonalEventDTO; import com.allen_sauer.gwt.log.client.Log; import com.extjs.gxt.ui.client.event.ButtonEvent; +import com.extjs.gxt.ui.client.event.DatePickerEvent; +import com.extjs.gxt.ui.client.event.Events; +import com.extjs.gxt.ui.client.event.Listener; import com.extjs.gxt.ui.client.event.SelectionListener; import com.extjs.gxt.ui.client.widget.form.CheckBox; import com.extjs.gxt.ui.client.widget.form.DateField; @@ -62,6 +65,9 @@ import com.extjs.gxt.ui.client.widget.form.TextField; import com.extjs.gxt.ui.client.widget.form.Time; import com.extjs.gxt.ui.client.widget.form.TimeField; +import com.google.gwt.event.logical.shared.ValueChangeEvent; +import com.google.gwt.event.logical.shared.ValueChangeHandler; +import com.google.gwt.i18n.client.DateTimeFormat; import com.google.gwt.user.client.Window; import com.google.inject.ImplementedBy; import com.google.inject.Inject; @@ -461,6 +467,42 @@ private void prepareEditView() { view.getEventSummaryField().setValue(event.getSummary()); view.getEventDateStartField().setValue(event.getKey()); view.getEventDateEndField().setValue(event.getDtend()); + view.getEventDateStartField().getDatePicker().addListener(Events.Select, new Listener() { + + @Override + public void handleEvent(DatePickerEvent be) { + if (view.getEventDateEndField().getValue() == null) { + view.getEventDateEndField().setValue(view.getEventDateStartField().getValue()); + } + } + }); + view.getEventDateEndField().getDatePicker().addListener(Events.Select, new Listener() { + + @Override + public void handleEvent(DatePickerEvent be) { + if (view.getEventDateStartField().getValue() == null) { + view.getEventDateStartField().setValue(view.getEventDateEndField().getValue()); + } + } + }); + /* view.getEventStartTimeField().addListener(Events.Select, new Listener() { + + @Override + public void handleEvent(DatePickerEvent be) { + if (view.getEventEndTimeField().getValue() == null) { + view.getEventEndTimeField().setValue(view.getEventStartTimeField().getValue()); + } + } + }); + view.getEventEndTimeField().addListener(Events.Select, new Listener() { + + @Override + public void handleEvent(DatePickerEvent be) { + if (view.getEventStartTimeField().getValue() == null) { + view.getEventStartTimeField().setValue(view.getEventEndTimeField().getValue()); + } + } + });*/ if (view.getRepeatEventPeriodRG() != null) { view.getRepeatEventPeriodRG().clear(); view.getRepeatEventPeriodRG().clearInvalid(); @@ -572,6 +614,50 @@ private void prepareAddView() { view.getNumberOfRepetitions().show(); view.getRepetitionEndDate().show(); + /* view.getEventDateStartField().getDatePicker().addValueChangeHandler(new ValueChangeHandler() { + @Override + public void onValueChange(ValueChangeEvent event) { + Window.alert("123"); + } + });*/ + view.getEventDateStartField().getDatePicker().addListener(Events.Select, new Listener() { + + @Override + public void handleEvent(DatePickerEvent be) { + if (view.getEventDateEndField().getValue() == null) { + view.getEventDateEndField().setValue(view.getEventDateStartField().getValue()); + } + } + }); + view.getEventDateEndField().getDatePicker().addListener(Events.Select, new Listener() { + + @Override + public void handleEvent(DatePickerEvent be) { + if (view.getEventDateStartField().getValue() == null) { + view.getEventDateStartField().setValue(view.getEventDateEndField().getValue()); + } + } + }); + + /* view.getEventStartTimeField().addListener(Events.Select, new Listener() { + + @Override + public void handleEvent(DatePickerEvent be) { + if (view.getEventEndTimeField().getValue() == null) { + view.getEventEndTimeField().setValue(view.getEventStartTimeField().getValue()); + } + } + }); + view.getEventEndTimeField().addListener(Events.Select, new Listener() { + + @Override + public void handleEvent(DatePickerEvent be) { + if (view.getEventStartTimeField().getValue() == null) { + view.getEventStartTimeField().setValue(view.getEventEndTimeField().getValue()); + } + } + }); */ + view.getYearlyVariantRG().show(); view.getMontlyVariantRG().show(); view.getRepeatEventPeriodRG().show(); @@ -620,7 +706,7 @@ private void prepareAddView() { */ @SuppressWarnings("deprecation") private void onSaveAction() { - // Window.alert("onSaveAction"); + // Window.alert("onSaveAction"); if (!view.getForm().isValid()) { return; } @@ -985,7 +1071,7 @@ private void addDailySeriesEvent(Integer ids, long daysInterval, long lengthDail * @param eventDescription the value of eventDescription */ private void processWeeklyEvents(final Date beginEventIntervalDate, final Date endEventIntervalDate, final Date endEventIntervalDateRadio, final Date startDate, final Date endDate, final Map properties, String eventSummary, String eventDescription) { - // Window.alert("processWeeklyEvents"); + // Window.alert("processWeeklyEvents"); long milisPerDay = 86400000; long weekDiff = ((endEventIntervalDateRadio.getTime() - beginEventIntervalDate.getTime() + milisPerDay) / (milisPerDay * 7)); int weeksInterval = (int) weekDiff; @@ -1236,7 +1322,7 @@ private void processYearEvents(final Date beginEventIntervalDate, Date endEventI long milisDiff = endEventIntervalDate.getTime() - beginEventIntervalDate.getTime(); long milisPerDay = 86400000; //24 * 60 * 60 * 1000) long daysInterval = ((endEventIntervalDate.getTime() - beginEventIntervalDate.getTime()) / milisPerDay) + 1; - + endEventIntervalDate = endEventIntervalDateRadio; int yearStart = beginEventIntervalDate.getYear(); int yearEnd = endEventIntervalDate.getYear(); @@ -1247,12 +1333,12 @@ private void processYearEvents(final Date beginEventIntervalDate, Date endEventI if (yearInterval <= 0) { yearInterval = 1; } - // properties.put(Event.EVENT_TYPE, "Y"); + // properties.put(Event.EVENT_TYPE, "Y"); if (view.getAllDayCheckbox().getValue()) { properties.put(Event.EVENT_TYPE, "YF"); } else { properties.put(Event.EVENT_TYPE, ("Y" + (daysInterval > 1 ? "H" : ""))); - // properties.put(Event.EVENT_TYPE, "Y"); + // properties.put(Event.EVENT_TYPE, "Y"); } properties.put(Event.SUMMARY, (String) properties.get(Event.SUMMARY));// + " (Yearly event 1 of " + yearInterval + ")"); properties.put(Event.DESCRIPTION, (String) properties.get(Event.DESCRIPTION));// + " (Yearly " + (isYearlySameDayOfWeek ? "same Day of a week " : "same Date ") + "event 1 of " + yearInterval + ")"); @@ -1291,7 +1377,6 @@ private void addYearlySeriesEvent(final long milisDiff, String ids, int yearInte long milisPerDay = 86400000; //24 * 60 * 60 * 1000) long daysInterval = ((endEventIntervalDate.getTime() - beginEventIntervalDate.getTime()) / milisPerDay) + 1; - Date calBeginNextEventDate = beginEventIntervalDate; for (int i = 1; i < yearInterval; i++) { calBeginNextEventDate = getYearlySameDayOfWeek(beginEventIntervalDate, calBeginNextEventDate, i, isYearlySameDayOfWeek); diff --git a/src/main/java/org/sigmah/client/ui/view/calendar/CalendarEventView.java b/src/main/java/org/sigmah/client/ui/view/calendar/CalendarEventView.java index 700e13af0..491edec10 100644 --- a/src/main/java/org/sigmah/client/ui/view/calendar/CalendarEventView.java +++ b/src/main/java/org/sigmah/client/ui/view/calendar/CalendarEventView.java @@ -159,7 +159,7 @@ public void initialize() { eventDateEndField = Forms.date(I18N.CONSTANTS.calendar_addEvent_dateEnd_label(), false); eventDateEndField.setName(Event.DATE + "888end"); - + eventDescriptionField = Forms.textarea(I18N.CONSTANTS.calendarEventDescription(), false); eventDescriptionField.setName(Event.DESCRIPTION); eventDescriptionField.setId(Event.DESCRIPTION); @@ -320,7 +320,7 @@ private void createDailyPanel() { panelDaily = new FieldSet(); panelDaily.setExpanded(true); panelDaily.setBorders(true); - panelDaily.setHeadingHtml("Daily repeats settings"); + panelDaily.setHeadingHtml("Daily repetition details"); panelDaily.setAutoHeight(true); panelDaily.setVisible(false); @@ -388,7 +388,7 @@ private void createWeeklyPanel() { panelWeekly = new FieldSet(); panelWeekly.setExpanded(true); panelWeekly.setBorders(true); - panelWeekly.setHeadingHtml("Weekly repeats settings"); + panelWeekly.setHeadingHtml("Weekly repetition details"); panelWeekly.setAutoHeight(true); panelWeekly.setVisible(false); @@ -528,7 +528,7 @@ public void handleEvent(FieldEvent event) { numberOfRepetitions.disable(); } }); - + /* monthlyRepSettings = new FieldSet(); monthlyRepSettings.setExpanded(true); monthlyRepSettings.setBorders(true); diff --git a/src/main/java/org/sigmah/client/ui/widget/CalendarWidget.java b/src/main/java/org/sigmah/client/ui/widget/CalendarWidget.java index 98e08e633..3d4efc5d1 100644 --- a/src/main/java/org/sigmah/client/ui/widget/CalendarWidget.java +++ b/src/main/java/org/sigmah/client/ui/widget/CalendarWidget.java @@ -950,7 +950,7 @@ public void onClick(ClickEvent clickEvent) { } }); - final Anchor deleteChainAnchor = new Anchor("Delete chain"); + final Anchor deleteChainAnchor = new Anchor("Delete all recurrences"); deleteChainAnchor.addClickHandler(new ClickHandler() { @Override @@ -1297,7 +1297,7 @@ public void onClick(ClickEvent clickEvent) { } }); - final Anchor deleteChainAnchor = new Anchor("Delete chain"); + final Anchor deleteChainAnchor = new Anchor("Delete all recurrences"); deleteChainAnchor.addClickHandler(new ClickHandler() { @Override diff --git a/src/main/resources/org/sigmah/client/i18n/UIConstants.properties b/src/main/resources/org/sigmah/client/i18n/UIConstants.properties index 98dd7fa00..d1abd6572 100644 --- a/src/main/resources/org/sigmah/client/i18n/UIConstants.properties +++ b/src/main/resources/org/sigmah/client/i18n/UIConstants.properties @@ -475,9 +475,9 @@ calendarEditEvent=Edit event calendarEmptyChoice=Select a calendar... calendarEventDate=Date calendarEventDescription=Description -calendarEventEndHour=End hour +calendarEventEndHour=End time calendarEventObject=Object -calendarEventStartHour=Start hour +calendarEventStartHour=Start time calendarNoCalendarSelected=No calendar selected calendar.addEvent.noCalendar.ko=You cannot add an event without a calendar. # New Calnedar Event View @@ -2006,7 +2006,7 @@ calendar.addEvent.description.textArea.daily=\ The Daily event. calendar.addEvent.repeatOnceRB.label=once calendar.addEvent.repeatOnceRB.name=onceRepeatRBname calendar.addEvent.description.textArea.once=\ The Once event. -calendar.addEvent.repeatsSettings.headingHtml.monthly=Monthly repeats settings +calendar.addEvent.repeatsSettings.headingHtml.monthly=Monthly repetition details calendar.addEvent.repeatsSettings.SameDayOfWeekRB.label=Same day of week calendar.addEvent.repeatsSettings.SameDayOfWeekRB.monthly.name=radioMonthlySameDayOfWeek calendar.addEvent.repeatsSettings.SameDayOfWeekRB.monthly.toolTip=Every next month at the same day of week. (with autochange to ...h) @@ -2014,7 +2014,7 @@ calendar.addEvent.repeatsSettings.SameDateRB.label=Same date calendar.addEvent.repeatsSettings.SameDateRB.monthly.name=radioMonthlySameDate calendar.addEvent.repeatsSettings.SameDateRB.monthly.toolTip=Every next month at the same date. (with autochange to last day of month) calendar.addEvent.repeatsSettings.radioGroup.monthly.settings=Montly settings 999 -calendar.addEvent.repeatsSettings.headingHtml.yearly=Yearly repeats settings +calendar.addEvent.repeatsSettings.headingHtml.yearly=Yearly repetition details calendar.addEvent.repeatsSettings.SameDayOfWeekRB.yearly.toolTip=Repeat Calendar event at the same DAY of week annually calendar.addEvent.repeatsSettings.SameDayOfWeekRB.yearly.name=radioYearlySameDayOfWeek calendar.addEvent.repeatsSettings.SameDateRB.yearly.name=radioYearlySameDate From b84a3b5883fa2b4814acdf8b97b8decadb7366ec Mon Sep 17 00:00:00 2001 From: Seal98 Date: Fri, 25 Aug 2017 13:22:35 +0300 Subject: [PATCH 37/39] (issue#852) minor improvements #2 removed the fade to white on the presentation of fullday and non-fullday events --- .../client/ui/widget/CalendarWidget.java | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/sigmah/client/ui/widget/CalendarWidget.java b/src/main/java/org/sigmah/client/ui/widget/CalendarWidget.java index 3d4efc5d1..2c2cde156 100644 --- a/src/main/java/org/sigmah/client/ui/widget/CalendarWidget.java +++ b/src/main/java/org/sigmah/client/ui/widget/CalendarWidget.java @@ -858,6 +858,9 @@ private void drawEvents(int row, int column, final Date date, int startDrawPosit } else { eventLimit = 99; } + final FlexTable gridH = (FlexTable) getWidget(); + // FlowPanel cell = (FlowPanel) grid.getWidget(1, 1); + //FlowPanel cellH = (FlowPanel) grid.getWidget(row, 3); for (int i = 0; iterator.hasNext() && i < eventLimit; i++) { final Event event = iterator.next(); @@ -877,6 +880,7 @@ private void drawEvents(int row, int column, final Date date, int startDrawPosit // || event.getDtstart().getYear() != event.getDtend().getYear()) { if (event.getEventType().contains("F")) { fullDayEvent = true; + Window.alert("1"); flowPanel.addStyleName("calendar-fullday-event"); } } @@ -904,8 +908,14 @@ private void drawEvents(int row, int column, final Date date, int startDrawPosit } flowPanel.add(eventLabel); if (event.getEventType().contains("H")) { - // DOM.setStyleAttribute(flowPanel.getElement(), "background-color", "rgba(28,97,217,0.3)"); - DOM.setStyleAttribute(flowPanel.getElement(), "background", "linear-gradient(-90deg, #1c61d9, #0000)"); + DOM.setStyleAttribute(flowPanel.getElement(), "background-color", "rgba(28,97,217)"); + // DOM.setStyleAttribute(flowPanel.getElement(), "background", "linear-gradient(-90deg, #1c61d9, #0000)"); + + // cellH.add(flowPanel); + // DOM.setStyleAttribute(cellH.getElement(), "border-radius", "20px 20px 20px 20px"); + // DOM.setStyleAttribute(cellH.getElement(), "border-color", "green"); + // DOM.setStyleAttribute(cellH.getElement(), "border-style", "solid"); + // DOM.setStyleAttribute(cellH.getElement(), "border-width", "1px"); } final DecoratedPopupPanel detailPopup = new DecoratedPopupPanel(true); @@ -1004,6 +1014,7 @@ public void setPosition(int offsetWidth, int offsetHeight) { cell.add(flowPanel); } + // if (eventLimit != UNDEFINED && (fullDayEventCounter + sortedHourEvents.size()) > eventLimit) { if (startDrawPosition == -1 && eventLimit != UNDEFINED && (fullDayEventCounter + sortedHourEvents.size()) > 1) { //final Anchor eventLabel = new Anchor("\u25BC +" + (sortedHourEvents.size()-eventLimit) + " st:" + fullDayEventCounter +" fd events"); @@ -1539,7 +1550,7 @@ private void setFullDayEventStyle(Widget panel, float top, float width, int heig DOM.setStyleAttribute(panel.getElement(), "border-color", "#1c61d9"); DOM.setStyleAttribute(panel.getElement(), "border-style", "solid"); DOM.setStyleAttribute(panel.getElement(), "border-width", "1px"); - DOM.setStyleAttribute(panel.getElement(), "background-color", "rgba(28,97,217,0.3)"); - DOM.setStyleAttribute(panel.getElement(), "background", "linear-gradient(-90deg, #0000, #1c61d9)"); + DOM.setStyleAttribute(panel.getElement(), "background-color", "rgba(28,97,217)"); + // DOM.setStyleAttribute(panel.getElement(), "background", "linear-gradient(-90deg, #0000, #1c61d9)"); } } From 43a4c973a1ea4574ad287ecff352ccc67068d5ad Mon Sep 17 00:00:00 2001 From: Seal98 Date: Sat, 26 Aug 2017 12:16:43 +0300 Subject: [PATCH 38/39] (issue#852) Code refactoring #3. Applied refactoring to: -avoid unused method parameters -avoid duplicated code blocks - moved to methods -removed old debug alert messages -avoid unused imports -renamed some methods, variables, method parameters --- .../calendar/CalendarEventPresenter.java | 30 +----- .../presenter/calendar/CalendarPresenter.java | 93 ++++++------------- .../client/ui/widget/CalendarWidget.java | 41 ++------ 3 files changed, 36 insertions(+), 128 deletions(-) diff --git a/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java b/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java index dc679f1ef..0e5648f65 100644 --- a/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java +++ b/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java @@ -65,10 +65,6 @@ import com.extjs.gxt.ui.client.widget.form.TextField; import com.extjs.gxt.ui.client.widget.form.Time; import com.extjs.gxt.ui.client.widget.form.TimeField; -import com.google.gwt.event.logical.shared.ValueChangeEvent; -import com.google.gwt.event.logical.shared.ValueChangeHandler; -import com.google.gwt.i18n.client.DateTimeFormat; -import com.google.gwt.user.client.Window; import com.google.inject.ImplementedBy; import com.google.inject.Inject; import com.google.inject.Singleton; @@ -614,12 +610,6 @@ private void prepareAddView() { view.getNumberOfRepetitions().show(); view.getRepetitionEndDate().show(); - /* view.getEventDateStartField().getDatePicker().addValueChangeHandler(new ValueChangeHandler() { - @Override - public void onValueChange(ValueChangeEvent event) { - Window.alert("123"); - } - });*/ view.getEventDateStartField().getDatePicker().addListener(Events.Select, new Listener() { @Override @@ -772,19 +762,14 @@ private void onSaveAction() { if (event.getEventType() != null) { if ("OF".equals(event.getEventType())) { properties.put(Event.EVENT_TYPE, ("O" + (daysdiff > 1 ? "H" : ""))); - //properties.put(Event.EVENT_TYPE, "O"); } else if ("DF".equals(event.getEventType())) { properties.put(Event.EVENT_TYPE, ("D" + (daysdiff > 1 ? "H" : ""))); - //properties.put(Event.EVENT_TYPE, "D"); } else if ("WF".equals(event.getEventType())) { properties.put(Event.EVENT_TYPE, ("W" + (daysdiff > 1 ? "H" : ""))); - //properties.put(Event.EVENT_TYPE, "W" ); } else if ("MF".equals(event.getEventType())) { properties.put(Event.EVENT_TYPE, ("M" + (daysdiff > 1 ? "H" : ""))); - //properties.put(Event.EVENT_TYPE, "M"); } else if ("YF".equals(event.getEventType())) { properties.put(Event.EVENT_TYPE, ("Y" + (daysdiff > 1 ? "H" : ""))); - //properties.put(Event.EVENT_TYPE, "Y"); } } } @@ -920,7 +905,6 @@ private void processOnceEvent(final Date beginEventIntervalDate1, long diffInMil properties.put(Event.EVENT_TYPE, "OF"); } else { properties.put(Event.EVENT_TYPE, ("O" + (daysDiff > 1 ? "H" : ""))); - //properties.put(Event.EVENT_TYPE, "O"); } if (daysDiff == 1) { addPersonalEvent(properties); @@ -982,7 +966,6 @@ private void processDailyEvents(long count, long lengthDailyEvent, long milisPer properties.put(Event.EVENT_TYPE, "DF"); } else { properties.put(Event.EVENT_TYPE, ("D" + (daysInterval > 1 ? "H" : ""))); - //properties.put(Event.EVENT_TYPE, "D"); } properties.put(Event.DATE_END, new Date(calBeginNextEventDateLong + milisPerDay * (lengthDailyEvent - 1))); addPersonalEventDaily(properties, count, lengthDailyEvent, calBeginNextEventDateLong, milisPerDay, startDate, endDate, eventSummary, eventDescription); @@ -1041,7 +1024,6 @@ private void addDailySeriesEvent(Integer ids, long daysInterval, long lengthDail dailyProperties.put(Event.EVENT_TYPE, "DF"); } else { dailyProperties.put(Event.EVENT_TYPE, ("D" + (daysInterval > 1 ? "H" : ""))); - // dailyProperties.put(Event.EVENT_TYPE, "D"); } dailyProperties.put(Event.DATE_END, new Date(calEndNextEventDateLong)); setFullDayEvent(startDate, endDate, new Date(calBeginNextEventDateLong), dailyProperties); @@ -1098,8 +1080,7 @@ private void processWeeklyEvents(final Date beginEventIntervalDate, final Date e properties.put(Event.EVENT_TYPE, "WF"); } else { properties.put(Event.EVENT_TYPE, ("W" + (daysInterval > 1 ? "H" : ""))); - //properties.put(Event.EVENT_TYPE, "W"); - } + } addPersonalEventWeekly(properties, weeksInterval, calBeginNextEventDateLong, calEndNextEventDateLong, daysInterval, startDate, endDate, eventSummary, eventDescription); } @@ -1154,8 +1135,6 @@ private void addDailySeriesEventNew2(Integer ids, int daysInterval, long calBegi if (view.getAllDayCheckbox().getValue()) { dailyProperties.put(Event.EVENT_TYPE, "WF"); } else { -// Window.alert("#1 addDailySeriesEventNew2 event.getEventType() = " + (event!=null?event.getEventType():"null") -// + " daysInterval=" + daysInterval); dailyProperties.put(Event.EVENT_TYPE, ("W" + (daysInterval > 1 ? "H" : ""))); } dailyProperties.put(Event.REFERENCE_ID, ids); @@ -1211,7 +1190,6 @@ private void processMonthlyEvents(final Date beginEventIntervalDate, Date endEve properties.put(Event.EVENT_TYPE, "MF"); } else { properties.put(Event.EVENT_TYPE, ("M" + (daysInterval > 1 ? "H" : ""))); - // properties.put(Event.EVENT_TYPE, "M"); } properties.put(Event.DATE_END, endEventIntervalDate); Date endEventIntervalDate1 = endEventIntervalDate; @@ -1280,14 +1258,12 @@ private void addMonthlySeriesEvent(Date endEventIntervalDate, String ids, int mo monthlyProperties.put(Event.SUMMARY, view.getEventSummaryField().getValue()); monthlyProperties.put(Event.DATE, calBeginNextEventDate); -// monthlyProperties.put(Event.EVENT_TYPE, "M"); monthlyProperties.put(Event.DATE_END, new Date(calBeginNextEventDate.getTime() + diff)); if (view.getAllDayCheckbox().getValue()) { monthlyProperties.put(Event.EVENT_TYPE, "MF"); } else { monthlyProperties.put(Event.EVENT_TYPE, ("M" + (daysInterval > 1 ? "H" : ""))); - //monthlyProperties.put(Event.EVENT_TYPE, "M"); } setFullDayEvent(startDate, endDate, calBeginNextEventDate, monthlyProperties); @@ -1333,12 +1309,11 @@ private void processYearEvents(final Date beginEventIntervalDate, Date endEventI if (yearInterval <= 0) { yearInterval = 1; } - // properties.put(Event.EVENT_TYPE, "Y"); + if (view.getAllDayCheckbox().getValue()) { properties.put(Event.EVENT_TYPE, "YF"); } else { properties.put(Event.EVENT_TYPE, ("Y" + (daysInterval > 1 ? "H" : ""))); - // properties.put(Event.EVENT_TYPE, "Y"); } properties.put(Event.SUMMARY, (String) properties.get(Event.SUMMARY));// + " (Yearly event 1 of " + yearInterval + ")"); properties.put(Event.DESCRIPTION, (String) properties.get(Event.DESCRIPTION));// + " (Yearly " + (isYearlySameDayOfWeek ? "same Day of a week " : "same Date ") + "event 1 of " + yearInterval + ")"); @@ -1391,7 +1366,6 @@ private void addYearlySeriesEvent(final long milisDiff, String ids, int yearInte yearlyProperties.put(Event.EVENT_TYPE, "YF"); } else { yearlyProperties.put(Event.EVENT_TYPE, ("Y" + (daysInterval > 1 ? "H" : ""))); - //yearlyProperties.put(Event.EVENT_TYPE, "Y"); } yearlyProperties.put(Event.DATE_END, new Date(calBeginNextEventDate.getTime() + milisDiff)); diff --git a/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarPresenter.java b/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarPresenter.java index dec10ab84..0432ce303 100644 --- a/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarPresenter.java +++ b/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarPresenter.java @@ -55,7 +55,6 @@ import com.extjs.gxt.ui.client.event.SelectionListener; import com.extjs.gxt.ui.client.store.ListStore; import com.extjs.gxt.ui.client.widget.selection.AbstractStoreSelectionModel; -import com.google.gwt.user.client.Window; import com.google.inject.ImplementedBy; import com.google.inject.Inject; import java.util.Date; @@ -166,10 +165,6 @@ public void onCommandFailure(final Throwable caught) { @Override public void onCommandSuccess(final VoidResult result) { -// final List oldEventList -// = event.getParent().getEvents().get(event.getKey()); -// oldEventList.remove(event); - //ak if (event.getEventType().contains("F")) { final List oldFullDayEventList = event.getParent().getFullDayEvents().get(event.getKey()); @@ -179,14 +174,12 @@ public void onCommandSuccess(final VoidResult result) { = event.getParent().getEvents().get(event.getKey()); oldEventList.remove(event); } - //ak - // Window.alert("12 refresh CalPres delete onCommandSuccess"); calendar.refresh(); } }); } - public void deleteEventFunction1(final Event next, Integer parentId, final Map> eventMap, final Date key) { + public void deleteChildEvent(final Event next, Integer parentId, final Map> eventMap, final Date key) { dispatch.execute(new Delete(PersonalEventDTO.ENTITY_NAME, next.getIdentifier(), parentId), new CommandResultHandler() { @Override @@ -197,13 +190,12 @@ public void onCommandFailure(final Throwable caught) { @Override public void onCommandSuccess(final VoidResult result) { eventMap.get(key).remove(next); - // Window.alert("11 refresh deleteEventFunction1 onCommandSuccess"); calendar.refresh(); } }); } - public void deleteEventFunction2(final Event next, Integer parentId, final Map> eventMap, final Date key, int mainId) { + public void deleteParentEvent(final Event next, Integer parentId, final Map> eventMap, final Date key, int mainId) { dispatch.execute(new Delete(PersonalEventDTO.ENTITY_NAME, mainId, parentId), new CommandResultHandler() { @Override @@ -214,7 +206,6 @@ public void onCommandFailure(final Throwable caught) { @Override public void onCommandSuccess(final VoidResult result) { eventMap.get(key).remove(next); - // Window.alert("10 refresh deleteEventFunction2 onCommandSuccess"); calendar.refresh(); } }); @@ -229,51 +220,17 @@ public void deleteChain(final Event event, final CalendarWidget calendarWidget) final Map> eventMap = event.getParent().getEvents(); final Map> fullDayEventMap = event.getParent().getFullDayEvents(); - int mainId = event.getIdentifier(); - int refId = 0; + int eventId = event.getIdentifier(); + int eventRefId = 0; if (event.getReferenceId() != null) { - refId = event.getReferenceId().intValue(); + eventRefId = event.getReferenceId().intValue(); } String typeStr = (String) event.getEventType(); if (typeStr != null) { - for (final Date key : eventMap.keySet()) { - for (final Event next : eventMap.get(key)) { - if (refId != 0) { - if (next.getReferenceId() != null && (next.getReferenceId().intValue() == refId)) { - deleteEventFunction1(next, parentId, eventMap, key); - } else if ((next.getReferenceId() == null) && (next.getIdentifier().intValue() == refId)) { - deleteEventFunction1(next, parentId, eventMap, key); - } - } else { - if (next.getReferenceId() != null && (next.getReferenceId().intValue() == mainId)) { - deleteEventFunction1(next, parentId, eventMap, key); - } else if (next.getReferenceId() == null && next.getIdentifier().intValue() == mainId) { - deleteEventFunction2(next, parentId, eventMap, key, mainId); - } - } - } - } - //ak - for (final Date key : fullDayEventMap.keySet()) { - for (final Event next : fullDayEventMap.get(key)) { - if (refId != 0) { - if (next.getReferenceId() != null && (next.getReferenceId().intValue() == refId)) { - deleteEventFunction1(next, parentId, fullDayEventMap, key); - } else if ((next.getReferenceId() == null) && (next.getIdentifier().intValue() == refId)) { - deleteEventFunction1(next, parentId, fullDayEventMap, key); - } - } else { - if (next.getReferenceId() != null && (next.getReferenceId().intValue() == mainId)) { - deleteEventFunction1(next, parentId, fullDayEventMap, key); - } else if (next.getReferenceId() == null && next.getIdentifier().intValue() == mainId) { - deleteEventFunction2(next, parentId, fullDayEventMap, key, mainId); - } - } - } - } - //ak + deleteEventFromEventMap(eventMap, eventRefId, parentId, eventId); + deleteEventFromEventMap(fullDayEventMap, eventRefId, parentId, eventId); } else { - dispatch.execute(new Delete(PersonalEventDTO.ENTITY_NAME, mainId, parentId), new CommandResultHandler() { + dispatch.execute(new Delete(PersonalEventDTO.ENTITY_NAME, eventId, parentId), new CommandResultHandler() { @Override public void onCommandFailure(final Throwable caught) { @@ -282,10 +239,7 @@ public void onCommandFailure(final Throwable caught) { @Override public void onCommandSuccess(final VoidResult result) { -// final List oldEventList -// = event.getParent().getEvents().get(event.getKey()); -// oldEventList.remove(event); - //ak + if (event.getEventType().contains("F")) { final List oldFullDayEventList = event.getParent().getFullDayEvents().get(event.getKey()); @@ -295,14 +249,29 @@ public void onCommandSuccess(final VoidResult result) { = event.getParent().getEvents().get(event.getKey()); oldEventList.remove(event); } - //ak - // Window.alert("9 refresh CalPres deleteChain onCommandSuccess"); calendar.refresh(); } }); } } -// } + + private void deleteEventFromEventMap(final Map> theEventMap, int eventRefId, final Integer parentId, int eventId) { + for (final Date key : theEventMap.keySet()) { + for (final Event nextFullDayEvent : theEventMap.get(key)) { + if (eventRefId != 0) { + if (nextFullDayEvent.getReferenceId().intValue() == eventRefId) { + deleteChildEvent(nextFullDayEvent, parentId, theEventMap, key); + } + } else { + if (nextFullDayEvent.getReferenceId() != null && (nextFullDayEvent.getReferenceId().intValue() == eventId)) { + deleteChildEvent(nextFullDayEvent, parentId, theEventMap, key); + } else if (nextFullDayEvent.getReferenceId() == null && nextFullDayEvent.getIdentifier().intValue() == eventId) { + deleteParentEvent(nextFullDayEvent, parentId, theEventMap, key, eventId); + } + } + } + } + } }); // -- @@ -422,14 +391,12 @@ public void componentSelected(final ButtonEvent event) { @Override public void onUpdate(final UpdateEvent event) { if (event.concern(UpdateEvent.CALENDAR_EVENT_UPDATE)) { - //Window.alert("7 refresh CalPres Update event handler. "); calendar.refresh(); } if (event.concern(UpdateEvent.REMINDER_UPDATED)) { // TODO appel reloadEventsOfReminderType((ReminderType) event.getParam(0)); - //Window.alert("6 refresh CalPres Update event handler. "); calendar.refresh(); } } @@ -443,7 +410,6 @@ public void onUpdate(final UpdateEvent event) { */ public void reload(final Map calendars, boolean editable) { Profiler.INSTANCE.markCheckpoint(Scenario.AGENDA, "Before refresh."); - //Window.alert("5 refresh CalPres reload. "); calendar.refresh(); Profiler.INSTANCE.markCheckpoint(Scenario.AGENDA, "calendar.refresh ended."); @@ -460,7 +426,6 @@ public void reload(final Map calendars, boolean editable) */ @Override public void onViewRevealed() { - // Window.alert("4 refresh onViewRevealed. "); calendar.refresh(); } @@ -491,7 +456,6 @@ private void reloadEvents(final Map calendars) { view.getCalendarsStore().removeAll(); if (ClientUtils.isEmpty(calendars)) { - // Window.alert("3 refresh reloadEvents. "); calendar.refresh(); Profiler.INSTANCE.endScenario(Scenario.AGENDA); return; @@ -501,7 +465,6 @@ private void reloadEvents(final Map calendars) { @Override protected void onComplete() { - // Window.alert("2 refresh onComplete. "); calendar.refresh(); Profiler.INSTANCE.endScenario(Scenario.AGENDA); } @@ -568,11 +531,9 @@ protected void onCommandSuccess(Calendar result) { result.setStyle(calendarType.getColorCode()); result.setType(calendarType); calendars.set(location, result); - // Window.alert("1 refresh reloadEventsOfReminderType. "); calendar.refresh(); } } - }); return; } diff --git a/src/main/java/org/sigmah/client/ui/widget/CalendarWidget.java b/src/main/java/org/sigmah/client/ui/widget/CalendarWidget.java index 2c2cde156..fc50bd1c9 100644 --- a/src/main/java/org/sigmah/client/ui/widget/CalendarWidget.java +++ b/src/main/java/org/sigmah/client/ui/widget/CalendarWidget.java @@ -288,19 +288,16 @@ public void setListener(CalendarListener listener) { public void next() { displayMode.nextDate(startDate); - // Window.alert("displayMode.nextDate(startDate);. "); refresh(); } public void previous() { displayMode.previousDate(startDate); - // Window.alert("refresh previous"); refresh(); } public final void today() { displayMode.firstDay(startDate, today, firstDayOfWeek); - // Window.alert("refresh today"); refresh(); } @@ -315,7 +312,6 @@ public Date getStartDate() { public void addCalendar(Calendar calendar) { calendars.add(calendar); - // Window.alert("refresh addCalendar"); refresh(); } @@ -336,7 +332,6 @@ public void setCalendars(List calendars) { // } // } this.calendars = calendars; - // Window.alert("refresh setCalendars"); refresh(); } @@ -351,7 +346,6 @@ public void setCalendars(List calendars) { */ public void setTitleFormatter(DateTimeFormat titleFormatter) { this.titleFormatter = titleFormatter; - // Window.alert("refresh setTitleFormatter"); refresh(); } @@ -365,7 +359,6 @@ public void setTitleFormatter(DateTimeFormat titleFormatter) { */ public void setHeaderFormatter(DateTimeFormat headerFormatter) { this.headerFormatter = headerFormatter; - // Window.alert("refresh setHeaderFormatter"); refresh(); } @@ -379,7 +372,6 @@ public void setHeaderFormatter(DateTimeFormat headerFormatter) { */ public void setDayFormatter(DateTimeFormat dayFormatter) { this.dayFormatter = dayFormatter; - // Window.alert("refresh setDayFormatter"); refresh(); } @@ -401,7 +393,6 @@ public void setDisplayMode(DisplayMode displayMode) { // Applying the CSS style associated with the new display mode grid.addStyleName(displayMode.getStyleName()); - // Window.alert("refresh setDisplayMode"); refresh(); } @@ -413,7 +404,6 @@ public void setDisplayMode(DisplayMode displayMode) { */ public void setFirstDayOfWeek(int firstDayOfWeek) { this.firstDayOfWeek = firstDayOfWeek; - // Window.alert("refresh setFirstDayOfWeek"); refresh(); } @@ -424,7 +414,6 @@ public int getDisplayHeaders() { public void setDisplayHeaders(int displayHeaders) { clear(); this.displayHeaders = displayHeaders; - // Window.alert("refresh setDisplayHeaders"); refresh(); } @@ -435,7 +424,6 @@ public boolean isDisplayWeekNumber() { public void setDisplayWeekNumber(boolean displayWeekNumber) { clear(); this.displayWeekNumber = displayWeekNumber; - // Window.alert("refresh setDisplayWeekNumber"); refresh(); } @@ -498,7 +486,7 @@ public static Map> normalize(final Map> even } public static Map> normalizeHourEvents(final Map> eventMap) { - // Window.alert("normalizeHourEvents"); + final Map> hourEventMapNormalized = new HashMap>(); for (final Date key : eventMap.keySet()) { @@ -763,12 +751,10 @@ private void drawCell(int row, int column, Date date, int currentMonth) { FlowPanel cell = (FlowPanel) grid.getWidget(row, column); if (cell == null) { - // New cell cell = new FlowPanel(); cell.setWidth("100%"); grid.setWidget(row, column, cell); - } else { // Reusing an existing cell cell.clear(); @@ -797,8 +783,6 @@ private void drawEvents(int row, int column, final Date date, int startDrawPosit final FlexTable grid = (FlexTable) getWidget(); int fullDayEventCounter = 0; - // final VerticalPanel cell = (VerticalPanel) grid.getWidget(row, - // column); final FlowPanel cell = (FlowPanel) grid.getWidget(row, column); if (cell == null) { @@ -858,9 +842,7 @@ private void drawEvents(int row, int column, final Date date, int startDrawPosit } else { eventLimit = 99; } - final FlexTable gridH = (FlexTable) getWidget(); - // FlowPanel cell = (FlowPanel) grid.getWidget(1, 1); - //FlowPanel cellH = (FlowPanel) grid.getWidget(row, 3); + for (int i = 0; iterator.hasNext() && i < eventLimit; i++) { final Event event = iterator.next(); @@ -880,7 +862,6 @@ private void drawEvents(int row, int column, final Date date, int startDrawPosit // || event.getDtstart().getYear() != event.getDtend().getYear()) { if (event.getEventType().contains("F")) { fullDayEvent = true; - Window.alert("1"); flowPanel.addStyleName("calendar-fullday-event"); } } @@ -910,12 +891,6 @@ private void drawEvents(int row, int column, final Date date, int startDrawPosit if (event.getEventType().contains("H")) { DOM.setStyleAttribute(flowPanel.getElement(), "background-color", "rgba(28,97,217)"); // DOM.setStyleAttribute(flowPanel.getElement(), "background", "linear-gradient(-90deg, #1c61d9, #0000)"); - - // cellH.add(flowPanel); - // DOM.setStyleAttribute(cellH.getElement(), "border-radius", "20px 20px 20px 20px"); - // DOM.setStyleAttribute(cellH.getElement(), "border-color", "green"); - // DOM.setStyleAttribute(cellH.getElement(), "border-style", "solid"); - // DOM.setStyleAttribute(cellH.getElement(), "border-width", "1px"); } final DecoratedPopupPanel detailPopup = new DecoratedPopupPanel(true); @@ -966,7 +941,6 @@ public void onClick(ClickEvent clickEvent) { @Override public void onClick(ClickEvent clickEvent) { delegate.deleteChain(event, CalendarWidget.this); - // Window.alert("refresh deleteChainAnchor onClick"); refresh(); detailPopup.hide(); @@ -1052,11 +1026,12 @@ public void onClick(ClickEvent event) { // " cell.getElement() AbsoluteBottom=" + cell.getElement().getAbsoluteBottom()+ // " cell.getElement() ClientHeight =" + cell.getElement().getClientHeight() // ) ; - int chiled = grid.getCellFormatter().getElement(row, column).getChildCount(); +/* int chiled = grid.getCellFormatter().getElement(row, column).getChildCount(); int gridHeight = grid.getOffsetHeight(); int weekdayRowHeight = grid.getRowFormatter() .getElement(0).getOffsetHeight(); + */ // Window.alert("chiled=" + chiled + " gridHeight =" + gridHeight // + " weekdayRowHeight =" + weekdayRowHeight // ); @@ -1119,7 +1094,7 @@ private void placeItemInGridMonth(Widget panel, int colStart, int colEnd, final FlexTable grid = (FlexTable) getWidget(); // FlowPanel cell = (FlowPanel) grid.getWidget(1, 1); FlowPanel cell = (FlowPanel) grid.getWidget(row, colStart); - cell.add(panel);//sssss + cell.add(panel); calculatedCellOffsetHeight = cell.getElement().getClientHeight();//OffsetHeight(); int height = appointmentHeight(); @@ -1166,7 +1141,7 @@ private void drawFullDayEvents(int row, int column, final Date date) { } final Iterator iterator = sortedFullDayEvents.iterator(); - //ak + eventLimit = 1;//999 for (int i = 0; iterator.hasNext() && i < eventLimit; i++) { final Event event = iterator.next(); @@ -1302,7 +1277,6 @@ public void onClick(ClickEvent clickEvent) { @Override public void onClick(ClickEvent clickEvent) { delegate.delete(event, CalendarWidget.this); - // Window.alert("refresh deleteAnchor onClick "); refresh(); detailPopup.hide(); } @@ -1314,7 +1288,6 @@ public void onClick(ClickEvent clickEvent) { @Override public void onClick(ClickEvent clickEvent) { delegate.deleteChain(event, CalendarWidget.this); - // Window.alert("refresh deleteChainAnchor onClick"); refresh(); detailPopup.hide(); @@ -1467,7 +1440,7 @@ private void drawFullDayEventsForWeek(int row, int column, final Date date, } final Iterator iterator = sortedFullDayEvents.iterator(); - //ak + int eventLimit = 100;//999 int counterIvent = 0; boolean foundRowToPlace = false; From 4226c631b3b88d54e76056c6b17cb0074e29adda Mon Sep 17 00:00:00 2001 From: Seal98 Date: Sun, 27 Aug 2017 18:55:50 +0300 Subject: [PATCH 39/39] (issue#852) Hours multi day events in style similar to full day events. Implemented: -show "Hours multi day events" in style similar to "full day" events in monthly and weekly views -removed adding default descriptions to repetition events -performed some code refactoring: renamed some methods, variables, method parameters etc --- .../calendar/CalendarEventPresenter.java | 49 ++- .../presenter/calendar/CalendarPresenter.java | 30 +- .../ui/view/calendar/CalendarEventView.java | 238 ++++++----- .../client/ui/widget/CalendarWidget.java | 368 ++++++++++++++++-- .../calendar/PersonalCalendarHandler.java | 19 +- .../shared/command/result/Calendar.java | 207 +++++----- 6 files changed, 626 insertions(+), 285 deletions(-) diff --git a/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java b/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java index 0e5648f65..0f49298d9 100644 --- a/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java +++ b/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java @@ -481,7 +481,7 @@ public void handleEvent(DatePickerEvent be) { } } }); - /* view.getEventStartTimeField().addListener(Events.Select, new Listener() { + /* view.getEventStartTimeField().addListener(Events.Select, new Listener() { @Override public void handleEvent(DatePickerEvent be) { @@ -498,7 +498,7 @@ public void handleEvent(DatePickerEvent be) { view.getEventStartTimeField().setValue(view.getEventEndTimeField().getValue()); } } - });*/ + });*/ if (view.getRepeatEventPeriodRG() != null) { view.getRepeatEventPeriodRG().clear(); view.getRepeatEventPeriodRG().clearInvalid(); @@ -629,7 +629,7 @@ public void handleEvent(DatePickerEvent be) { } }); - /* view.getEventStartTimeField().addListener(Events.Select, new Listener() { + /* view.getEventStartTimeField().addListener(Events.Select, new Listener() { @Override public void handleEvent(DatePickerEvent be) { @@ -647,7 +647,6 @@ public void handleEvent(DatePickerEvent be) { } } }); */ - view.getYearlyVariantRG().show(); view.getMontlyVariantRG().show(); view.getRepeatEventPeriodRG().show(); @@ -760,6 +759,7 @@ private void onSaveAction() { // Window.alert("#4 not full day event.getEventType() = " + event.getEventType() // + " daysdiff=" + daysdiff); if (event.getEventType() != null) { + //Window.alert("111 event.getEventType()=" + event.getEventType() + " daysdiff=" + daysdiff); if ("OF".equals(event.getEventType())) { properties.put(Event.EVENT_TYPE, ("O" + (daysdiff > 1 ? "H" : ""))); } else if ("DF".equals(event.getEventType())) { @@ -1079,8 +1079,9 @@ private void processWeeklyEvents(final Date beginEventIntervalDate, final Date e if (view.getAllDayCheckbox().getValue()) { properties.put(Event.EVENT_TYPE, "WF"); } else { + //Window.alert("W +daysInterval" + daysInterval); properties.put(Event.EVENT_TYPE, ("W" + (daysInterval > 1 ? "H" : ""))); - } + } addPersonalEventWeekly(properties, weeksInterval, calBeginNextEventDateLong, calEndNextEventDateLong, daysInterval, startDate, endDate, eventSummary, eventDescription); } @@ -1111,12 +1112,15 @@ public void onCommandSuccess(final CreateResult result) { } private void addDailySeriesEventNew2(Integer ids, int daysInterval, long calBeginNextEventDateLong, long calEndNextEventDateLong, long milisPerWeek, final Date startDate, final Date endDate, String eventSummary, String eventDescription) { + long milisPerDay = 86400000; //24 * 60 * 60 * 1000) for (int i = 1; i < daysInterval; i++) { calBeginNextEventDateLong += milisPerWeek; calEndNextEventDateLong += milisPerWeek; + long daysLength = ((calEndNextEventDateLong - calBeginNextEventDateLong) / milisPerDay) + 1; + Map dailyProperties = new HashMap(); dailyProperties.put(Event.CALENDAR_ID, calendarWrapper); dailyProperties.put(Event.SUMMARY, view.getEventSummaryField().getValue()); @@ -1135,7 +1139,8 @@ private void addDailySeriesEventNew2(Integer ids, int daysInterval, long calBegi if (view.getAllDayCheckbox().getValue()) { dailyProperties.put(Event.EVENT_TYPE, "WF"); } else { - dailyProperties.put(Event.EVENT_TYPE, ("W" + (daysInterval > 1 ? "H" : ""))); + //Window.alert("W2 +daysLength" + daysLength); + dailyProperties.put(Event.EVENT_TYPE, ("W" + (daysLength > 1 ? "H" : ""))); } dailyProperties.put(Event.REFERENCE_ID, ids); @@ -1189,6 +1194,7 @@ private void processMonthlyEvents(final Date beginEventIntervalDate, Date endEve if (view.getAllDayCheckbox().getValue()) { properties.put(Event.EVENT_TYPE, "MF"); } else { + //Window.alert("M +daysInterval" + daysInterval); properties.put(Event.EVENT_TYPE, ("M" + (daysInterval > 1 ? "H" : ""))); } properties.put(Event.DATE_END, endEventIntervalDate); @@ -1263,6 +1269,7 @@ private void addMonthlySeriesEvent(Date endEventIntervalDate, String ids, int mo if (view.getAllDayCheckbox().getValue()) { monthlyProperties.put(Event.EVENT_TYPE, "MF"); } else { + //Window.alert("M2 +daysInterval" + daysInterval); monthlyProperties.put(Event.EVENT_TYPE, ("M" + (daysInterval > 1 ? "H" : ""))); } @@ -1313,6 +1320,7 @@ private void processYearEvents(final Date beginEventIntervalDate, Date endEventI if (view.getAllDayCheckbox().getValue()) { properties.put(Event.EVENT_TYPE, "YF"); } else { + //Window.alert("Y +daysInterval" + daysInterval); properties.put(Event.EVENT_TYPE, ("Y" + (daysInterval > 1 ? "H" : ""))); } properties.put(Event.SUMMARY, (String) properties.get(Event.SUMMARY));// + " (Yearly event 1 of " + yearInterval + ")"); @@ -1365,6 +1373,7 @@ private void addYearlySeriesEvent(final long milisDiff, String ids, int yearInte if (view.getAllDayCheckbox().getValue()) { yearlyProperties.put(Event.EVENT_TYPE, "YF"); } else { + //Window.alert("Y2 +daysInterval" + daysInterval); yearlyProperties.put(Event.EVENT_TYPE, ("Y" + (daysInterval > 1 ? "H" : ""))); } @@ -1441,6 +1450,10 @@ public void onCommandSuccess(final VoidResult result) { if (oldFullDayEventList != null && oldFullDayEventList.contains(event)) { oldFullDayEventList.remove(event); } + final List oldHourMultidayEventList = calendar.getHourMultiDayEvents().get(event.getKey()); + if (oldHourMultidayEventList != null && oldHourMultidayEventList.contains(event)) { + oldHourMultidayEventList.remove(event); + } updateEvent(event, properties); } }, view.getCancelButton(), view.getSaveButton()); @@ -1490,8 +1503,10 @@ private void updateEvent(final Event event, final Map properties) { final Calendar calendar = wrapper.getCalendar(); event.setParent(calendar); -//ak - if (calendar.getEvents() != null && !event.getEventType().contains("F")) { + + if (calendar.getEvents() != null + && !event.getEventType().contains("F") + && !event.getEventType().contains("H")) { List events = calendar.getEvents().get(day); if (events == null) { events = new ArrayList(); @@ -1499,9 +1514,21 @@ private void updateEvent(final Event event, final Map properties) { } events.add(event); } - if (calendar.getFullDayEvents() != null && (event.getEventType().contains("F") - || (event.getDtstart().getHours() == event.getDtend().getHours() - && event.getDtstart().getMinutes() == event.getDtend().getMinutes()))) { + if (calendar.getHourMultiDayEvents() != null + && event.getEventType().contains("H")) { + List hourMultiDayEvents = calendar.getHourMultiDayEvents().get(day); + if (hourMultiDayEvents == null) { + hourMultiDayEvents = new ArrayList(); + calendar.getHourMultiDayEvents().put(day, hourMultiDayEvents); + } + hourMultiDayEvents.add(event); + } +// if (calendar.getFullDayEvents() != null && (event.getEventType().contains("F") +// && !event.getEventType().contains("H") +// || (event.getDtstart().getHours() == event.getDtend().getHours() +// && event.getDtstart().getMinutes() == event.getDtend().getMinutes()))) { + if (calendar.getFullDayEvents() != null + && event.getEventType().contains("F")) { List fullDayEvents = calendar.getFullDayEvents().get(day); if (fullDayEvents == null) { fullDayEvents = new ArrayList(); diff --git a/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarPresenter.java b/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarPresenter.java index 0432ce303..19050eaff 100644 --- a/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarPresenter.java +++ b/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarPresenter.java @@ -169,6 +169,10 @@ public void onCommandSuccess(final VoidResult result) { final List oldFullDayEventList = event.getParent().getFullDayEvents().get(event.getKey()); oldFullDayEventList.remove(event); + } else if (event.getEventType().contains("H")) { + final List oldHourMultidayEventList + = event.getParent().getHourMultiDayEvents().get(event.getKey()); + oldHourMultidayEventList.remove(event); } else { final List oldEventList = event.getParent().getEvents().get(event.getKey()); @@ -219,6 +223,7 @@ public void deleteChain(final Event event, final CalendarWidget calendarWidget) final Map> eventMap = event.getParent().getEvents(); final Map> fullDayEventMap = event.getParent().getFullDayEvents(); + final Map> hourMultiDayEventMap = event.getParent().getHourMultiDayEvents(); int eventId = event.getIdentifier(); int eventRefId = 0; @@ -229,6 +234,7 @@ public void deleteChain(final Event event, final CalendarWidget calendarWidget) if (typeStr != null) { deleteEventFromEventMap(eventMap, eventRefId, parentId, eventId); deleteEventFromEventMap(fullDayEventMap, eventRefId, parentId, eventId); + deleteEventFromEventMap(hourMultiDayEventMap, eventRefId, parentId, eventId); } else { dispatch.execute(new Delete(PersonalEventDTO.ENTITY_NAME, eventId, parentId), new CommandResultHandler() { @@ -244,6 +250,10 @@ public void onCommandSuccess(final VoidResult result) { final List oldFullDayEventList = event.getParent().getFullDayEvents().get(event.getKey()); oldFullDayEventList.remove(event); + } else if (event.getEventType().contains("H")) { + final List oldHourMultidayEventList + = event.getParent().getHourMultiDayEvents().get(event.getKey()); + oldHourMultidayEventList.remove(event); } else { final List oldEventList = event.getParent().getEvents().get(event.getKey()); @@ -257,16 +267,20 @@ public void onCommandSuccess(final VoidResult result) { private void deleteEventFromEventMap(final Map> theEventMap, int eventRefId, final Integer parentId, int eventId) { for (final Date key : theEventMap.keySet()) { - for (final Event nextFullDayEvent : theEventMap.get(key)) { + for (final Event nextEvent : theEventMap.get(key)) { if (eventRefId != 0) { - if (nextFullDayEvent.getReferenceId().intValue() == eventRefId) { - deleteChildEvent(nextFullDayEvent, parentId, theEventMap, key); - } +// if (nextEvent.getReferenceId().intValue() == eventRefId) { +// deleteChildEvent(nextEvent, parentId, theEventMap, key); +// } + if ((nextEvent.getReferenceId() != null && (nextEvent.getReferenceId().intValue() == eventRefId)) + || ((nextEvent.getReferenceId() == null) && (nextEvent.getIdentifier().intValue() == eventRefId))) { + deleteChildEvent(nextEvent, parentId, theEventMap, key); + } } else { - if (nextFullDayEvent.getReferenceId() != null && (nextFullDayEvent.getReferenceId().intValue() == eventId)) { - deleteChildEvent(nextFullDayEvent, parentId, theEventMap, key); - } else if (nextFullDayEvent.getReferenceId() == null && nextFullDayEvent.getIdentifier().intValue() == eventId) { - deleteParentEvent(nextFullDayEvent, parentId, theEventMap, key, eventId); + if (nextEvent.getReferenceId() != null && (nextEvent.getReferenceId().intValue() == eventId)) { + deleteChildEvent(nextEvent, parentId, theEventMap, key); + } else if (nextEvent.getReferenceId() == null && nextEvent.getIdentifier().intValue() == eventId) { + deleteParentEvent(nextEvent, parentId, theEventMap, key, eventId); } } } diff --git a/src/main/java/org/sigmah/client/ui/view/calendar/CalendarEventView.java b/src/main/java/org/sigmah/client/ui/view/calendar/CalendarEventView.java index 491edec10..dc7d1ca5c 100644 --- a/src/main/java/org/sigmah/client/ui/view/calendar/CalendarEventView.java +++ b/src/main/java/org/sigmah/client/ui/view/calendar/CalendarEventView.java @@ -49,6 +49,7 @@ import com.extjs.gxt.ui.client.widget.form.ComboBox.TriggerAction; import com.google.gwt.user.client.ui.HTML; import java.util.Date; + /* import com.gwtext.client.data.Record; import com.gwtext.client.data.SimpleStore; @@ -57,7 +58,7 @@ import com.gwtext.client.widgets.form.ComboBox; import com.gwtext.client.widgets.form.FormPanel; import com.gwtext.client.widgets.form.event.ComboBoxListenerAdapter; -*/ + */ /** * Calendar event edit frame view used to create/edit a calendar event. * @@ -86,7 +87,7 @@ public class CalendarEventView extends AbstractPopupView implements private FieldSet panelDaily; private FieldSet monthlyRepSettings; private FieldSet yearlyRepSettings; - + private Radio yearlySameDayOfWeekRB; private Radio yearlySameDateRB; @@ -99,18 +100,18 @@ public class CalendarEventView extends AbstractPopupView implements private Radio radioMonthlySameDayOfWeek; private Radio radioNumberOfRepetitions; private Radio radioRepetitionEndDate; - + private Radio radioWeeklyNumberOfRepetitions; private Radio radioWeeklyRepetitionEndDate; private Radio radioYearlyNumberOfRepetitions; private Radio radioYearlyRepetitionEndDate; private Radio radioDailyNumberOfRepetitions; private Radio radioDailyRepetitionEndDate; - + private DateField repetitionEndDate; private TextArea numberOfRepetitions; private DateField dailyRepetitionEndDate; - private TextArea dailyNumberOfRepetitions; + private TextArea dailyNumberOfRepetitions; private DateField weeklyRepetitionEndDate; private TextArea weeklyNumberOfRepetitions; private DateField yearlyRepetitionEndDate; @@ -119,9 +120,10 @@ public class CalendarEventView extends AbstractPopupView implements private RadioGroup RepeatEventPeriodRG; private RadioGroup RepeatMultiEventPeriodRG; - private RadioGroup RepeatYearlyMultiEventPeriodRG; + private RadioGroup RepeatYearlyMultiEventPeriodRG; private RadioGroup RepeatWeeklyMultiEventPeriodRG; - private RadioGroup RepeatDailyMultiEventPeriodRG; + private RadioGroup RepeatDailyMultiEventPeriodRG; + /** * Builds the view. */ @@ -142,7 +144,6 @@ public void initialize() { createDailyPanel(); createRepeatEventPeriodRadioGroup(); - eventSummaryField = Forms.text(I18N.CONSTANTS.calendarEventObject(), true); eventSummaryField.setName(Event.SUMMARY); @@ -159,7 +160,7 @@ public void initialize() { eventDateEndField = Forms.date(I18N.CONSTANTS.calendar_addEvent_dateEnd_label(), false); eventDateEndField.setName(Event.DATE + "888end"); - + eventDescriptionField = Forms.textarea(I18N.CONSTANTS.calendarEventDescription(), false); eventDescriptionField.setName(Event.DESCRIPTION); eventDescriptionField.setId(Event.DESCRIPTION); @@ -200,7 +201,7 @@ public void handleEvent(FieldEvent event) { eventEndTimeField.setVisible(!allDayCheckbox.getValue()); } }); - + return allDayCheckbox; } @@ -229,12 +230,13 @@ private void createYearlyRb() { yearlyRepeatRB.addListener(Events.OnChange, new Listener() { @Override public void handleEvent(FieldEvent event) { - ((TextArea) form.getItemByItemId(Event.DESCRIPTION)).setValue(I18N.CONSTANTS.calendar_addEvent_description_textArea_yearly()); + //add default description + //((TextArea) form.getItemByItemId(Event.DESCRIPTION)).setValue(I18N.CONSTANTS.calendar_addEvent_description_textArea_yearly()); getPanelYearly().setVisible(getYearlyRepeatRB().getValue()); getPanelWeekly().setVisible(!yearlyRepeatRB.getValue()); getPanelMonthly().setVisible(!yearlyRepeatRB.getValue()); getPanelDaily().setVisible(!yearlyRepeatRB.getValue()); - + getYearlySameDateRB().show(); getYearlySameDayOfWeekRB().show(); getYearlySameDateRB().setValue(true); @@ -249,10 +251,11 @@ private void createMonthlyRb() { monthlyRepeatRB.addListener(Events.OnChange, new Listener() { @Override public void handleEvent(FieldEvent event) { - ((TextArea) form.getItemByItemId(Event.DESCRIPTION)).setValue(I18N.CONSTANTS.calendar_addEvent_description_textArea_monthly()); + //add default description + //((TextArea) form.getItemByItemId(Event.DESCRIPTION)).setValue(I18N.CONSTANTS.calendar_addEvent_description_textArea_monthly()); getPanelWeekly().setVisible(!monthlyRepeatRB.getValue()); getPanelYearly().setVisible(!monthlyRepeatRB.getValue()); - getPanelDaily().setVisible(!monthlyRepeatRB.getValue()); + getPanelDaily().setVisible(!monthlyRepeatRB.getValue()); getPanelMonthly().setVisible(getMonthlyRepeatRB().getValue()); eventDateStartField.setAllowBlank(false); getRadioMonthlySameDate().show(); @@ -268,12 +271,13 @@ private void createWeeklyRb() { weeklyRepeatRB.addListener(Events.OnChange, new Listener() { @Override public void handleEvent(FieldEvent event) { - ((TextArea) form.getItemByItemId(Event.DESCRIPTION)).setValue(I18N.CONSTANTS.calendar_addEvent_description_textArea_weekly()); + //add default description + //((TextArea) form.getItemByItemId(Event.DESCRIPTION)).setValue(I18N.CONSTANTS.calendar_addEvent_description_textArea_weekly()); getPanelYearly().setVisible(!weeklyRepeatRB.getValue()); getPanelMonthly().setVisible(!weeklyRepeatRB.getValue()); - getPanelDaily().setVisible(!weeklyRepeatRB.getValue()); + getPanelDaily().setVisible(!weeklyRepeatRB.getValue()); getPanelWeekly().setVisible(getWeeklyRepeatRB().getValue()); - // Window.alert("Test"); + // Window.alert("Test"); eventDateStartField.setAllowBlank(false); } }); @@ -287,11 +291,12 @@ private void createDailyRb() { dailyRepeatRB.addListener(Events.OnChange, new Listener() { @Override public void handleEvent(FieldEvent event) { - ((TextArea) form.getItemByItemId(Event.DESCRIPTION)).setValue(I18N.CONSTANTS.calendar_addEvent_description_textArea_daily()); + //add default description + //((TextArea) form.getItemByItemId(Event.DESCRIPTION)).setValue(I18N.CONSTANTS.calendar_addEvent_description_textArea_daily()); getPanelYearly().setVisible(!dailyRepeatRB.getValue()); getPanelMonthly().setVisible(!dailyRepeatRB.getValue()); getPanelWeekly().setVisible(!dailyRepeatRB.getValue()); - getPanelDaily().setVisible(getDailyRepeatRB().getValue()); + getPanelDaily().setVisible(getDailyRepeatRB().getValue()); } }); } @@ -308,14 +313,13 @@ public void handleEvent(FieldEvent event) { getPanelYearly().setVisible(!onceRepeatRB.getValue()); getPanelMonthly().setVisible(!onceRepeatRB.getValue()); getPanelWeekly().setVisible(!onceRepeatRB.getValue()); - getPanelDaily().setVisible(!onceRepeatRB.getValue()); - ((TextArea) form.getItemByItemId(Event.DESCRIPTION)).setValue(I18N.CONSTANTS.calendar_addEvent_description_textArea_once()); + getPanelDaily().setVisible(!onceRepeatRB.getValue()); + //add default description + //((TextArea) form.getItemByItemId(Event.DESCRIPTION)).setValue(I18N.CONSTANTS.calendar_addEvent_description_textArea_once()); } }); } - - private void createDailyPanel() { panelDaily = new FieldSet(); panelDaily.setExpanded(true); @@ -323,48 +327,47 @@ private void createDailyPanel() { panelDaily.setHeadingHtml("Daily repetition details"); panelDaily.setAutoHeight(true); panelDaily.setVisible(false); - + radioDailyNumberOfRepetitions = Forms.radio("Number of repetitions"); radioDailyNumberOfRepetitions.setName("Number of repetitonsYearly"); radioDailyNumberOfRepetitions.setValue(Boolean.FALSE); radioDailyNumberOfRepetitions.setOriginalValue(Boolean.FALSE); radioDailyNumberOfRepetitions.setToolTip("Set a number of repetitons (Yearly)"); - + dailyNumberOfRepetitions = Forms.textarea("", false); dailyNumberOfRepetitions.setName("numberOfRepetitionsyearly"); dailyNumberOfRepetitions.setId("numberOfRepetitionsyearly"); dailyNumberOfRepetitions.setMaxLength(255); dailyNumberOfRepetitions.setHeight(19); - + radioDailyRepetitionEndDate = Forms.radio("Repetition end date"); radioDailyRepetitionEndDate.setBoxLabel("Repetition end date"); radioDailyRepetitionEndDate.setName("Repetition end dateyearly"); radioDailyRepetitionEndDate.setValue(Boolean.FALSE); radioDailyRepetitionEndDate.setToolTip("Set a repetition end date"); - + dailyRepetitionEndDate = Forms.date("", true); - dailyRepetitionEndDate.setName("RepetitionEndDateFieldyearly"); + dailyRepetitionEndDate.setName("RepetitionEndDateFieldyearly"); dailyNumberOfRepetitions.disable(); dailyRepetitionEndDate.disable(); - + radioDailyNumberOfRepetitions.addListener(Events.OnChange, new Listener() { @Override public void handleEvent(FieldEvent event) { - dailyNumberOfRepetitions.enable(); - dailyRepetitionEndDate.disable(); + dailyNumberOfRepetitions.enable(); + dailyRepetitionEndDate.disable(); } - }); + }); - radioDailyRepetitionEndDate.addListener(Events.OnChange, new Listener() { @Override public void handleEvent(FieldEvent event) { - dailyRepetitionEndDate.enable(); - dailyNumberOfRepetitions.disable(); + dailyRepetitionEndDate.enable(); + dailyNumberOfRepetitions.disable(); } - }); - + }); + RepeatDailyMultiEventPeriodRG = Forms.radioGroup("Multi-event periodRGyearly", "Multi-event periodRGyearly", Style.Orientation.VERTICAL, @@ -372,7 +375,7 @@ public void handleEvent(FieldEvent event) { radioDailyRepetitionEndDate); RepeatDailyMultiEventPeriodRG.setSelectionRequired(Boolean.TRUE); RepeatDailyMultiEventPeriodRG.enable(); - + //panelMonthly.add(RepeatMultiEventPeriodRG); VerticalPanel verticalPanel = new VerticalPanel(); verticalPanel.add(dailyNumberOfRepetitions); @@ -380,10 +383,10 @@ public void handleEvent(FieldEvent event) { HorizontalPanel horizontalPanel = new HorizontalPanel(); horizontalPanel.add(RepeatDailyMultiEventPeriodRG); horizontalPanel.add(verticalPanel); - - panelDaily.add(horizontalPanel); + + panelDaily.add(horizontalPanel); } - + private void createWeeklyPanel() { panelWeekly = new FieldSet(); panelWeekly.setExpanded(true); @@ -391,48 +394,47 @@ private void createWeeklyPanel() { panelWeekly.setHeadingHtml("Weekly repetition details"); panelWeekly.setAutoHeight(true); panelWeekly.setVisible(false); - + radioWeeklyNumberOfRepetitions = Forms.radio("Number of repetitions"); radioWeeklyNumberOfRepetitions.setName("Number of repetitonsYearly"); radioWeeklyNumberOfRepetitions.setValue(Boolean.FALSE); radioWeeklyNumberOfRepetitions.setOriginalValue(Boolean.FALSE); radioWeeklyNumberOfRepetitions.setToolTip("Set a number of repetitons"); - + weeklyNumberOfRepetitions = Forms.textarea("", false); weeklyNumberOfRepetitions.setName("numberOfRepetitionsyearly"); weeklyNumberOfRepetitions.setId("numberOfRepetitionsyearly"); weeklyNumberOfRepetitions.setMaxLength(255); weeklyNumberOfRepetitions.setHeight(19); - + radioWeeklyRepetitionEndDate = Forms.radio("Repetition end date"); radioWeeklyRepetitionEndDate.setBoxLabel("Repetition end date"); radioWeeklyRepetitionEndDate.setName("Repetition end dateyearly"); radioWeeklyRepetitionEndDate.setValue(Boolean.FALSE); radioWeeklyRepetitionEndDate.setToolTip("Set a repetition end date"); - + weeklyRepetitionEndDate = Forms.date("", true); - weeklyRepetitionEndDate.setName("RepetitionEndDateFieldyearly"); + weeklyRepetitionEndDate.setName("RepetitionEndDateFieldyearly"); weeklyNumberOfRepetitions.disable(); weeklyRepetitionEndDate.disable(); - + radioWeeklyNumberOfRepetitions.addListener(Events.OnChange, new Listener() { @Override public void handleEvent(FieldEvent event) { - weeklyNumberOfRepetitions.enable(); - weeklyRepetitionEndDate.disable(); + weeklyNumberOfRepetitions.enable(); + weeklyRepetitionEndDate.disable(); } - }); + }); - radioWeeklyRepetitionEndDate.addListener(Events.OnChange, new Listener() { @Override public void handleEvent(FieldEvent event) { - weeklyRepetitionEndDate.enable(); - weeklyNumberOfRepetitions.disable(); + weeklyRepetitionEndDate.enable(); + weeklyNumberOfRepetitions.disable(); } - }); - + }); + RepeatWeeklyMultiEventPeriodRG = Forms.radioGroup("Multi-event periodRGyearly", "Multi-event periodRGyearly", Style.Orientation.VERTICAL, @@ -440,7 +442,7 @@ public void handleEvent(FieldEvent event) { radioWeeklyRepetitionEndDate); RepeatWeeklyMultiEventPeriodRG.setSelectionRequired(Boolean.TRUE); RepeatWeeklyMultiEventPeriodRG.enable(); - + //panelMonthly.add(RepeatMultiEventPeriodRG); VerticalPanel verticalPanel = new VerticalPanel(); verticalPanel.add(weeklyNumberOfRepetitions); @@ -448,10 +450,10 @@ public void handleEvent(FieldEvent event) { HorizontalPanel horizontalPanel = new HorizontalPanel(); horizontalPanel.add(RepeatWeeklyMultiEventPeriodRG); horizontalPanel.add(verticalPanel); - + panelWeekly.add(horizontalPanel); } - + private void createMonthlyPanel() { panelMonthly = new FieldSet(); panelMonthly.setExpanded(true); @@ -478,65 +480,59 @@ private void createMonthlyPanel() { montlyVariantRG.add(radioMonthlySameDayOfWeek); montlyVariantRG.add(radioMonthlySameDate); panelMonthly.add(montlyVariantRG); - - radioNumberOfRepetitions = Forms.radio("Number of repetitions"); radioNumberOfRepetitions.setName("Number of repetitons"); radioNumberOfRepetitions.setValue(Boolean.FALSE); radioNumberOfRepetitions.setOriginalValue(Boolean.FALSE); radioNumberOfRepetitions.setToolTip("Set a number of repetitions"); - + radioRepetitionEndDate = Forms.radio("Repetition end date"); radioRepetitionEndDate.setBoxLabel("Repetition end date"); radioRepetitionEndDate.setName("Repetition end date"); radioRepetitionEndDate.setValue(Boolean.FALSE); radioRepetitionEndDate.setToolTip("Set a repetition end date"); - - + RepeatMultiEventPeriodRG = Forms.radioGroup("Multi-event periodRG"); RepeatMultiEventPeriodRG.setSelectionRequired(Boolean.FALSE); RepeatMultiEventPeriodRG.setOrientation(Style.Orientation.VERTICAL); RepeatMultiEventPeriodRG.add(radioNumberOfRepetitions); - RepeatMultiEventPeriodRG.add(radioRepetitionEndDate); + RepeatMultiEventPeriodRG.add(radioRepetitionEndDate); panelMonthly.add(RepeatMultiEventPeriodRG); - + numberOfRepetitions = Forms.textarea("", false); numberOfRepetitions.setName("numberOfRepetitions"); numberOfRepetitions.setId("numberOfRepetitions"); numberOfRepetitions.setMaxLength(255); numberOfRepetitions.setHeight(19); - + repetitionEndDate = Forms.date("", true); - repetitionEndDate.setName("RepetitionEndDateField"); + repetitionEndDate.setName("RepetitionEndDateField"); repetitionEndDate.setData("", new Date()); - + radioNumberOfRepetitions.addListener(Events.OnChange, new Listener() { @Override public void handleEvent(FieldEvent event) { - numberOfRepetitions.enable(); - repetitionEndDate.disable(); + numberOfRepetitions.enable(); + repetitionEndDate.disable(); } - }); + }); - radioRepetitionEndDate.addListener(Events.OnChange, new Listener() { @Override public void handleEvent(FieldEvent event) { - repetitionEndDate.enable(); - numberOfRepetitions.disable(); + repetitionEndDate.enable(); + numberOfRepetitions.disable(); } - }); + }); - /* monthlyRepSettings = new FieldSet(); + /* monthlyRepSettings = new FieldSet(); monthlyRepSettings.setExpanded(true); monthlyRepSettings.setBorders(true); monthlyRepSettings.setHeadingHtml("End of monthly repetition event"); monthlyRepSettings.setAutoHeight(true); monthlyRepSettings.setVisible(true);*/ - - VerticalPanel verticalPanel = new VerticalPanel(); VerticalPanel verticalPanel1 = new VerticalPanel(); VerticalPanel verticalPanel2 = new VerticalPanel(); @@ -545,7 +541,6 @@ public void handleEvent(FieldEvent event) { verticalPanel1.add(numberOfRepetitions); verticalPanel2.add(repetitionEndDate); - verticalPanel.add(verticalPanel1); verticalPanel.add(verticalPanel3); verticalPanel.add(verticalPanel2); @@ -555,7 +550,7 @@ public void handleEvent(FieldEvent event) { horizontalPanel.add(verticalPanel); panelMonthly.add(new HTML("
")); panelMonthly.add(horizontalPanel); - // verticalPanel1.setHeight(verticalPanel.getHeight()/2); + // verticalPanel1.setHeight(verticalPanel.getHeight()/2); //verticalPanel2.setHeight(verticalPanel.getHeight()/2); } @@ -575,56 +570,54 @@ private void createYearlyPanel() { yearlySameDateRB = Forms.radio(I18N.CONSTANTS.calendar_addEvent_repeatsSettings_SameDateRB_label(), Boolean.FALSE); yearlySameDateRB.setName(I18N.CONSTANTS.calendar_addEvent_repeatsSettings_SameDateRB_yearly_name()); - yearlyVariantRG = Forms.radioGroup(I18N.CONSTANTS.calendar_addEvent_repeatsSettings_radioGroup_yearly_settings(), + yearlyVariantRG = Forms.radioGroup(I18N.CONSTANTS.calendar_addEvent_repeatsSettings_radioGroup_yearly_settings(), I18N.CONSTANTS.calendar_addEvent_repeatsSettings_radioGroup_yearly_settings_name(), Style.Orientation.HORIZONTAL, yearlySameDayOfWeekRB, yearlySameDateRB); yearlyVariantRG.setSelectionRequired(Boolean.FALSE); panelYearly.add(yearlyVariantRG); - - + radioYearlyNumberOfRepetitions = Forms.radio("Number of repetitions"); radioYearlyNumberOfRepetitions.setName("Number of repetitionsYearly"); radioYearlyNumberOfRepetitions.setValue(Boolean.FALSE); radioYearlyNumberOfRepetitions.setOriginalValue(Boolean.FALSE); radioYearlyNumberOfRepetitions.setToolTip("Set a number of repetitons"); - + yearlyNumberOfRepetitions = Forms.textarea("", false); yearlyNumberOfRepetitions.setName("numberOfRepetitionsyearly"); yearlyNumberOfRepetitions.setId("numberOfRepetitionsyearly"); yearlyNumberOfRepetitions.setMaxLength(255); yearlyNumberOfRepetitions.setHeight(19); - + radioYearlyRepetitionEndDate = Forms.radio("Repetition end date"); radioYearlyRepetitionEndDate.setBoxLabel("Repetition end date"); radioYearlyRepetitionEndDate.setName("Repetition end dateyearly"); radioYearlyRepetitionEndDate.setValue(Boolean.FALSE); radioYearlyRepetitionEndDate.setToolTip("Set a repetition end date"); - + yearlyRepetitionEndDate = Forms.date("", true); - yearlyRepetitionEndDate.setName("RepetitionEndDateFieldyearly"); + yearlyRepetitionEndDate.setName("RepetitionEndDateFieldyearly"); yearlyNumberOfRepetitions.disable(); yearlyRepetitionEndDate.disable(); - + radioYearlyNumberOfRepetitions.addListener(Events.OnChange, new Listener() { @Override public void handleEvent(FieldEvent event) { - yearlyNumberOfRepetitions.enable(); - yearlyRepetitionEndDate.disable(); + yearlyNumberOfRepetitions.enable(); + yearlyRepetitionEndDate.disable(); } - }); + }); - radioYearlyRepetitionEndDate.addListener(Events.OnChange, new Listener() { @Override public void handleEvent(FieldEvent event) { - yearlyRepetitionEndDate.enable(); - yearlyNumberOfRepetitions.disable(); + yearlyRepetitionEndDate.enable(); + yearlyNumberOfRepetitions.disable(); } - }); - + }); + RepeatYearlyMultiEventPeriodRG = Forms.radioGroup("Multi-event periodRGyearly", "Multi-event periodRGyearly", Style.Orientation.VERTICAL, @@ -632,11 +625,10 @@ public void handleEvent(FieldEvent event) { radioYearlyRepetitionEndDate); RepeatYearlyMultiEventPeriodRG.setSelectionRequired(Boolean.TRUE); RepeatYearlyMultiEventPeriodRG.enable(); - - + //panelMonthly.add(RepeatMultiEventPeriodRG); VerticalPanel verticalPanel = new VerticalPanel(); - + VerticalPanel verticalPanel1 = new VerticalPanel(); VerticalPanel verticalPanel2 = new VerticalPanel(); verticalPanel1.setHeight(23); @@ -647,7 +639,7 @@ public void handleEvent(FieldEvent event) { verticalPanel2.add(yearlyRepetitionEndDate); VerticalPanel verticalPanel3 = new VerticalPanel(); verticalPanel3.setHeight(5); - + verticalPanel.add(verticalPanel1); verticalPanel.add(verticalPanel3); verticalPanel.add(verticalPanel2); @@ -751,7 +743,7 @@ public FieldSet getMonthlyRepSettings() { public FieldSet getYearlyRepSettings() { return yearlyRepSettings; } - + @Override public FieldSet getPanelMonthly() { return panelMonthly; @@ -760,12 +752,13 @@ public FieldSet getPanelMonthly() { @Override public FieldSet getPanelWeekly() { return panelWeekly; - } - + } + @Override public FieldSet getPanelDaily() { return panelDaily; - } + } + /** * * @return @@ -804,12 +797,12 @@ public RadioGroup getYearlyVariantRG() { public RadioGroup getRepeatMultiEventPeriodRG() { return RepeatMultiEventPeriodRG; } - + @Override public RadioGroup getMontlyVariantRG() { return montlyVariantRG; - } - + } + @Override public Radio getYearlySameDayOfWeekRB() { return yearlySameDayOfWeekRB; @@ -824,10 +817,12 @@ public Radio getYearlySameDateRB() { public RadioGroup getRepeatEventPeriodRG() { return RepeatEventPeriodRG; } + @Override public Radio getRadioMonthlySameDate() { return radioMonthlySameDate; } + @Override public Radio getRadioMonthlySameDayOfWeek() { return radioMonthlySameDayOfWeek; @@ -837,7 +832,7 @@ public Radio getRadioMonthlySameDayOfWeek() { public Radio getRadioNumberOfRepetitions() { return radioNumberOfRepetitions; } - + @Override public Radio getRadioRepetitionEndDate() { return radioRepetitionEndDate; @@ -847,7 +842,7 @@ public Radio getRadioRepetitionEndDate() { public Radio getYearlyRadioNumberOfRepetitions() { return radioYearlyNumberOfRepetitions; } - + @Override public Radio getYearlyRadioRepetitionEndDate() { return radioYearlyRepetitionEndDate; @@ -857,7 +852,7 @@ public Radio getYearlyRadioRepetitionEndDate() { public Radio getDailyRadioNumberOfRepetitions() { return radioDailyNumberOfRepetitions; } - + @Override public Radio getDailyRadioRepetitionEndDate() { return radioDailyRepetitionEndDate; @@ -867,48 +862,49 @@ public Radio getDailyRadioRepetitionEndDate() { public Radio getWeeklyRadioNumberOfRepetitions() { return radioWeeklyNumberOfRepetitions; } - + @Override public Radio getWeeklyRadioRepetitionEndDate() { return radioWeeklyRepetitionEndDate; - } + } + @Override public TextArea getNumberOfRepetitions() { return numberOfRepetitions; } - + @Override public DateField getRepetitionEndDate() { return repetitionEndDate; } - + @Override public TextArea getWeeklyNumberOfRepetitions() { return weeklyNumberOfRepetitions; } - + @Override public DateField getWeeklyRepetitionEndDate() { return weeklyRepetitionEndDate; } - + @Override public TextArea getDailyNumberOfRepetitions() { return dailyNumberOfRepetitions; } - + @Override public DateField getDailyRepetitionEndDate() { return dailyRepetitionEndDate; } - + @Override public TextArea getYearlyNumberOfRepetitions() { return yearlyNumberOfRepetitions; } - + @Override public DateField getYearlyRepetitionEndDate() { return yearlyRepetitionEndDate; - } -} \ No newline at end of file + } +} diff --git a/src/main/java/org/sigmah/client/ui/widget/CalendarWidget.java b/src/main/java/org/sigmah/client/ui/widget/CalendarWidget.java index fc50bd1c9..c4761e9ce 100644 --- a/src/main/java/org/sigmah/client/ui/widget/CalendarWidget.java +++ b/src/main/java/org/sigmah/client/ui/widget/CalendarWidget.java @@ -493,7 +493,7 @@ public static Map> normalizeHourEvents(final Map> normalizeHourEvents(final Map sortedHourEvents = createSortedEventsSet(); + // Displaying multi day events + TreeSet sortedHourMultiDayEvents = createSortedEventsSet(); // Displaying full day events TreeSet sortedFullDayEvents = createSortedEventsSet(); for (final Calendar calendar : calendars) { if (!(calendar.getIdentifier() instanceof ActivityCalendarIdentifier)) { if (calendar.getEvents() != null) { - // && calendar.getEvents().size()>0) { + // && calendar.getEvents().size()>0) { //SSS final Map> eventMap = normalize(calendar.getEvents()); //ss Map> eventMap = normalizeHourEvents(calendar.getEvents()); @@ -809,31 +814,9 @@ private void drawEvents(int row, int column, final Date date, int startDrawPosit sortedHourEvents.addAll(events); } } - if (calendar.getFullDayEvents() != null) { - final Map> fullDayEventMap = normalize(calendar.getFullDayEvents()); - for (Map.Entry> entry : fullDayEventMap.entrySet()) { - Date key = entry.getKey(); - List value = entry.getValue(); - for (Iterator iterator = value.iterator(); iterator.hasNext();) { - Event next = iterator.next(); - Date theStartEventDate = next.getDtstart(); - Date theEndEventDate = next.getDtend(); - if (next.getEventType().contains("F") - && date.after(theStartEventDate) && date.before(theEndEventDate) - || date.equals(theStartEventDate) - || date.equals(theEndEventDate)) { - fullDayEventCounter++; - } - } - - } - final List fullDayEvents = fullDayEventMap.get(date); - if (fullDayEvents != null) { - sortedFullDayEvents.addAll(fullDayEvents); - } - } + hourMultiDayEventCounter = getHourMulriDayEventCounter(calendar, date, hourMultiDayEventCounter, sortedHourMultiDayEvents); + fullDayEventCounter = getFullDayEventCounter(calendar, date, fullDayEventCounter, sortedFullDayEvents); } - } final Iterator iterator = sortedHourEvents.iterator(); @@ -889,8 +872,8 @@ private void drawEvents(int row, int column, final Date date, int startDrawPosit } flowPanel.add(eventLabel); if (event.getEventType().contains("H")) { - DOM.setStyleAttribute(flowPanel.getElement(), "background-color", "rgba(28,97,217)"); - // DOM.setStyleAttribute(flowPanel.getElement(), "background", "linear-gradient(-90deg, #1c61d9, #0000)"); + DOM.setStyleAttribute(flowPanel.getElement(), "background-color", "rgba(28,97,217)"); + // DOM.setStyleAttribute(flowPanel.getElement(), "background", "linear-gradient(-90deg, #1c61d9, #0000)"); } final DecoratedPopupPanel detailPopup = new DecoratedPopupPanel(true); @@ -988,16 +971,16 @@ public void setPosition(int offsetWidth, int offsetHeight) { cell.add(flowPanel); } - // if (eventLimit != UNDEFINED && (fullDayEventCounter + sortedHourEvents.size()) > eventLimit) { - if (startDrawPosition == -1 && eventLimit != UNDEFINED && (fullDayEventCounter + sortedHourEvents.size()) > 1) { + if (startDrawPosition == -1 && eventLimit != UNDEFINED && (hourMultiDayEventCounter + fullDayEventCounter + sortedHourEvents.size()) > 1) { //final Anchor eventLabel = new Anchor("\u25BC +" + (sortedHourEvents.size()-eventLimit) + " st:" + fullDayEventCounter +" fd events"); - final Anchor eventLabel = new Anchor("\u25BC " + (sortedHourEvents.size() + fullDayEventCounter) + " events"); + final Anchor eventLabel = new Anchor("\u25BC " + (sortedHourEvents.size() + hourMultiDayEventCounter + fullDayEventCounter) + " events"); // eventLabel.setTitle("Click to view all events of the day."); final Date thisDate = new Date(date.getTime()); String theDateString = DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.YEAR_MONTH_WEEKDAY_DAY).format(thisDate); eventLabel.setTitle(theDateString + "\nClick to view all events of the day:" - + "\nShort time events: " + sortedHourEvents.size() + + "\nOne day events: " + sortedHourEvents.size() + + "\nMulti day events: " + hourMultiDayEventCounter + "\nFull day events: " + fullDayEventCounter); eventLabel.addClickHandler(new ClickHandler() { @@ -1031,15 +1014,84 @@ public void onClick(ClickEvent event) { int gridHeight = grid.getOffsetHeight(); int weekdayRowHeight = grid.getRowFormatter() .getElement(0).getOffsetHeight(); - */ + */ // Window.alert("chiled=" + chiled + " gridHeight =" + gridHeight // + " weekdayRowHeight =" + weekdayRowHeight // ); - cell.add(eventLabel); } } + private int getHourMulriDayEventCounter(final Calendar calendar, final Date date, int hourMultiDayEventCounter, TreeSet sortedHourMultiDayEvents) { + //hourMultiDayEventCounter + if (calendar.getHourMultiDayEvents() != null) { + final Map> hourMultiDayEventMap = normalize(calendar.getHourMultiDayEvents()); + for (Map.Entry> entry : hourMultiDayEventMap.entrySet()) { + Date key = entry.getKey(); + List value = entry.getValue(); + for (Iterator iterator = value.iterator(); iterator.hasNext();) { + Event next = iterator.next(); +// Date theStartEventDate = next.getDtstart(); +// Date theEndEventDate = next.getDtend(); + + Date theStartEventDateWithTime = next.getDtstart(); + Date theEndEventDateWithTime = next.getDtend(); + + Date theStartEventDate = new Date(date.getTime()); + Date theEndEventDate = new Date(date.getTime()); + + theStartEventDate.setYear(theStartEventDateWithTime.getYear()); + theStartEventDate.setMonth(theStartEventDateWithTime.getMonth()); + theStartEventDate.setDate(theStartEventDateWithTime.getDate()); + + theEndEventDate.setYear(theEndEventDateWithTime.getYear()); + theEndEventDate.setMonth(theEndEventDateWithTime.getMonth()); + theEndEventDate.setDate(theEndEventDateWithTime.getDate()); +//<---- + + if (next.getEventType().contains("H") + && date.after(theStartEventDate) && date.before(theEndEventDate) + || date.equals(theStartEventDate) + || date.equals(theEndEventDate)) { + hourMultiDayEventCounter++; + } + } + } + final List fullDayEvents = hourMultiDayEventMap.get(date); + if (fullDayEvents != null) { + sortedHourMultiDayEvents.addAll(fullDayEvents); + } + } + return hourMultiDayEventCounter; + } + + private int getFullDayEventCounter(final Calendar calendar, final Date date, int fullDayEventCounter, TreeSet sortedFullDayEvents) { + if (calendar.getFullDayEvents() != null) { + final Map> fullDayEventMap = normalize(calendar.getFullDayEvents()); + for (Map.Entry> entry : fullDayEventMap.entrySet()) { + Date key = entry.getKey(); + List value = entry.getValue(); + for (Iterator iterator = value.iterator(); iterator.hasNext();) { + Event next = iterator.next(); + Date theStartEventDate = next.getDtstart(); + Date theEndEventDate = next.getDtend(); + if (next.getEventType().contains("F") + && date.after(theStartEventDate) && date.before(theEndEventDate) + || date.equals(theStartEventDate) + || date.equals(theEndEventDate)) { + fullDayEventCounter++; + } + } + + } + final List fullDayEvents = fullDayEventMap.get(date); + if (fullDayEvents != null) { + sortedFullDayEvents.addAll(fullDayEvents); + } + } + return fullDayEventCounter; + } + private static int calculateEventDurationInDays(final Event event) { long diff = event.getDtend().getTime() - event.getDtstart().getTime(); long diffDays = diff / (24 * 60 * 60 * 1000) + 1; @@ -1165,14 +1217,76 @@ private void drawFullDayEvents(int row, int column, final Date date) { } } + /** + * Display full day events with started date + * + * @param row + * @param column + * @param date + */ + private void drawHourMultiDayEvents(int row, int column, final Date date) { + + TreeSet sortedFullDayEvents = createSortedEventsSet(); + + for (final Calendar calendar : calendars) { + if (!(calendar.getIdentifier() instanceof ActivityCalendarIdentifier) + && calendar.getFullDayEvents() != null) { + final Map> fullDayEventMap = normalize(calendar.getHourMultiDayEvents());//EE + final List fullDayEvents = fullDayEventMap.get(date); + if (fullDayEvents != null) { + sortedFullDayEvents.addAll(fullDayEvents); + } + } + } + + final Iterator iterator = sortedFullDayEvents.iterator(); + + eventLimit = 1;//999 + for (int i = 0; iterator.hasNext() && i < eventLimit; i++) { + final Event event = iterator.next(); + final ClickableFlowPanel flowPanelFullDayFirst = createFullDayPanel(event); + final ClickableFlowPanel flowPanelFullDayContinue = createFullDayPanel(event); + final FlexTable grid = (FlexTable) getWidget(); + int daysdiff = calculateEventDurationInDays(event); + + //String theDateString = DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.YEAR_MONTH_WEEKDAY_DAY).format(thisDate); + flowPanelFullDayFirst.setTitle(createTitleForHourMultiDayEvent(daysdiff, event));//EE3 + DOM.setStyleAttribute(flowPanelFullDayFirst.getElement(), "background-color", "rgba(28,97,217)"); + DOM.setStyleAttribute(flowPanelFullDayFirst.getElement(), "background", "linear-gradient(-90deg, #1c61d9, #0000)"); + if (column + daysdiff - 1 < 8) { + placeItemInGridMonth(flowPanelFullDayFirst, column, column + daysdiff, row, i); + } else { + placeItemInGridMonth(flowPanelFullDayFirst, column, 8, row, i); + if (row <= 5) { + flowPanelFullDayContinue.setTitle(createTitleForHourMultiDayEvent(daysdiff, event));//EE2 + DOM.setStyleAttribute(flowPanelFullDayContinue.getElement(), "background-color", "rgba(28,97,217)"); + DOM.setStyleAttribute(flowPanelFullDayContinue.getElement(), "background", "linear-gradient(-90deg, #1c61d9, #0000)"); + placeItemInGridMonth(flowPanelFullDayContinue, 1, 1 + daysdiff - (8 - column), row + 1, i); + } + } + } + } + private static String createTitleForFullDayEvent(int daysdiff, final Event event) { return "Event: " + event.getSummary() - + "\nDescr: " + event.getDescription() + + "\nDescr: " + (event.getDescription() != null ? event.getDescription() : "") + "\nDuration: " + daysdiff + " full day" + (daysdiff > 1 ? "s." : ".") + (event.getDtstart().equals(event.getDtend()) ? (DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.YEAR_MONTH_WEEKDAY_DAY).format(event.getDtstart())) : ("\nFrom " + DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.YEAR_MONTH_WEEKDAY_DAY).format(event.getDtstart()) - + " to " + DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.YEAR_MONTH_WEEKDAY_DAY).format(event.getDtend()))); + + " To " + DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.YEAR_MONTH_WEEKDAY_DAY).format(event.getDtend()))); + } + + private static String createTitleForHourMultiDayEvent(int daysdiff, final Event event) { + return "Event: " + event.getSummary() + + "\nDescr: " + (event.getDescription() != null ? event.getDescription() : "") + + "\nDuration: " + daysdiff + " day" + (daysdiff > 1 ? "s." : ".") + + (event.getDtstart().equals(event.getDtend()) + ? (DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.YEAR_MONTH_WEEKDAY_DAY).format(event.getDtstart())) + : ("\nFrom " + DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.YEAR_MONTH_WEEKDAY_DAY).format(event.getDtstart()) + + " " + DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.HOUR24_MINUTE).format(event.getDtstart()) + + " \nTo " + DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.YEAR_MONTH_WEEKDAY_DAY).format(event.getDtend()) + + " " + DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.HOUR24_MINUTE).format(event.getDtend()))); } /** @@ -1186,8 +1300,8 @@ private String createTitleForHourEvent(int daysdiff, final Event event) { long millis = event.getDtend().getTime() - event.getDtstart().getTime(); long minute = (millis / (1000 * 60)) % 60; long hour = (millis / (1000 * 60 * 60)) % 24; - return "Event: " + event.getSummary() - + "\nDescr: " + event.getDescription() + return "Hour Event: " + event.getSummary() + + "\nDescr: " + (event.getDescription() != null ? event.getDescription() : "") + "\nDuration: from " + hourFormatter.format(event.getDtstart()) + " to " + hourFormatter.format(event.getDtend()) // + " (" + duration + " hours" + (daysdiff > 0 ? " every day)" : ")") @@ -1222,7 +1336,7 @@ private ClickableFlowPanel createFullDayPanel(final Event event) { final InlineLabel dateLabel = new InlineLabel(eventDate.toString()); dateLabel.addStyleName("calendar-event-date"); - final InlineLabel eventLabel = new InlineLabel(event.getSummary()); + final InlineLabel eventLabel = new InlineLabel(event.getEventType().contains("H") ? (hourFormatter.format(event.getDtstart()) + " " + event.getSummary()) : event.getSummary()); //final InlineLabel eventLabel = new InlineLabel(event.getDtstart().getDate() + "; " + (event.getReferenceId()==null?event.getSummary():event.getSummary()) + "+>>"); eventLabel.addStyleName("calendar-event-label"); @@ -1460,7 +1574,8 @@ private void drawFullDayEventsForWeek(int row, int column, final Date date, long startDTForWeekleView = 0; long diff = event.getDtend().getTime() - event.getDtstart().getTime(); if (date.after(theStartEventDate)) { - diff = theStartEventDate.getTime() - event.getDtstart().getTime(); + //diff = theStartEventDate.getTime() - event.getDtstart().getTime(); + diff = event.getDtend().getTime() - date.getTime(); } long diffDays = diff / (24 * 60 * 60 * 1000) + 1; @@ -1488,6 +1603,175 @@ private void drawFullDayEventsForWeek(int row, int column, final Date date, } + /////////////// + /** + * Display full day events with started date + * + * @param row + * @param column + * @param date + */ + private void drawHourMultiDayEventsForWeek(int row, int column, final Date date, + List alreadyShownWeekViewEvents, + int[][] theShiftVecorOfFullDayEvents) { + + int theLastFDPanelInCellCounter = getLastFDPanelInCellCounter(theShiftVecorOfFullDayEvents, column); + // Window.alert("START column = " + column + "; theLastFullRaw =" + theLastFDPanelInCellCounter); + TreeSet sortedFullDayEvents = createSortedEventsSet(); + int eventCounter = 0; + int longFullDayEventShownCounter = 0; + + for (final Calendar calendar : calendars) { + if (!(calendar.getIdentifier() instanceof ActivityCalendarIdentifier)) { + if (calendar.getFullDayEvents() != null) { + //final Map> fullDayEventMap = normalize(calendar.getHourMultiDayEvents());//EEE + final Map> fullDayEventMap = normalizeHourEvents(calendar.getHourMultiDayEvents()); + for (Map.Entry> entry : fullDayEventMap.entrySet()) { + Date key = entry.getKey(); + List value = entry.getValue(); + for (Iterator iterator = value.iterator(); iterator.hasNext();) { + Event next = iterator.next(); + ///----> + Date theStartEventDateWithTime = next.getDtstart(); + Date theEndEventDateWithTime = next.getDtend(); + + Date theStartEventDate = new Date(date.getTime()); + Date theEndEventDate = new Date(date.getTime()); + + theStartEventDate.setYear(theStartEventDateWithTime.getYear()); + theStartEventDate.setMonth(theStartEventDateWithTime.getMonth()); + theStartEventDate.setDate(theStartEventDateWithTime.getDate()); + + theEndEventDate.setYear(theEndEventDateWithTime.getYear()); + theEndEventDate.setMonth(theEndEventDateWithTime.getMonth()); + theEndEventDate.setDate(theEndEventDateWithTime.getDate()); + //<---- + if (next.getEventType().contains("H")) { + if (!alreadyShownWeekViewEvents.contains(next)) { +// Date theStartEventDate = next.getDtstart(); +// Date theEndEventDate = next.getDtend(); + if (date.after(theStartEventDate) && date.before(theEndEventDate) + || date.equals(theStartEventDate) + || date.equals(theEndEventDate)) { + // In between + eventCounter++; + sortedFullDayEvents.add(next); + alreadyShownWeekViewEvents.add(next); + } + } else { +// Date theStartEventDate = next.getDtstart(); +// Date theEndEventDate = next.getDtend(); + if (date.after(theStartEventDate) && date.before(theEndEventDate) + || date.equals(theStartEventDate) + || date.equals(theEndEventDate)) { + + longFullDayEventShownCounter++; +// sortedEvents.add(next); +// alreadyShownWeekViewEvents.add(next); + } + } + } + } + } + } + } + } + + final Iterator iterator = sortedFullDayEvents.iterator(); + + int eventLimit = 100;//999 + int counterIvent = 0; + boolean foundRowToPlace = false; + int theRowToPlace = 0; + int last = theLastFDPanelInCellCounter; + for (int i = 0; iterator.hasNext() && i < eventLimit; i++) { + last = last + 1; + final Event event = iterator.next(); + + final ClickableFlowPanel fullDayFlowPanel = createFullDayPanel(event); + final FlexTable grid = (FlexTable) getWidget(); + ///ssss1 grid.setWidget(row, column, flowPanelFullDayFirst); + // RootPanel.get().add(flowPanelFullDayFirst); + // grid.add(flowPanelFullDayFirst); + + Date theStartEventDate = event.getDtstart(); + Date theEndEventDate = event.getDtend(); + + long startDTForWeekleView = 0; + Date newDateStart = new Date(date.getTime());//date.getTime() + Date newDateEnd = new Date(date.getTime()); + + newDateStart.setYear(theStartEventDate.getYear()); + newDateStart.setMonth(theStartEventDate.getMonth());//+1 + newDateStart.setDate(theStartEventDate.getDate()); + + newDateEnd.setYear(theEndEventDate.getYear()); + newDateEnd.setMonth(theEndEventDate.getMonth());//+1 + newDateEnd.setDate(theEndEventDate.getDate()); + + long diff = newDateEnd.getTime() - newDateStart.getTime(); + // Window.alert("! diff=" + diff); +// if (date.after(newDateStart)) { +// //-->> diff = newDateStart.getTime() - newDateEnd.getTime(); +// diff = 8 - diff; +// Window.alert("date.after(newDateStart) 2 diff=" + diff); +// } + + + /* + long diff = event.getDtend().getTime() - event.getDtstart().getTime(); + if (date.after(theStartEventDate)) { + diff = theStartEventDate.getTime() - event.getDtstart().getTime(); + } + */ + if (date.after(newDateStart)) { + //-->> diff = newDateStart.getTime() - newDateEnd.getTime(); + diff = newDateEnd.getTime() - date.getTime(); + //Window.alert("date.after(newDateStart)"); + } + long diffDays = diff / (24 * 60 * 60 * 1000) + 1; + int daysdiff = (int) diffDays; + //Window.alert("date.after(newDateStart) 2 daysdiff=" + daysdiff); + + // Window.alert("3 daysdiff=" + daysdiff); + //---->> + //-->> daysdiff = calculateEventDurationInDays(event); + //Window.alert("@@@333 daysdiff=" + daysdiff + " column=" + column); + + fullDayFlowPanel.setTitle(createTitleForHourMultiDayEvent(daysdiff, event)); + //to show full day long event if it longer then 1 week + while (column + daysdiff - 1 >= 8) { + // Window.alert("4 daysdiff=" + daysdiff); + daysdiff--; + } + //Window.alert("5 daysdiff=" + daysdiff); + if (column + daysdiff - 1 < 8) { + for (int day = column; day < column + daysdiff; day++) { + theShiftVecorOfFullDayEvents[day][last] += 1; + } + longFullDayEventShownCounter = theRowToPlace;// + counterIvent; + + int theLastFullDayLinePlace44 = getLastFDPanelInCellCounter(theShiftVecorOfFullDayEvents, column); + // Window.alert("6 column=" + column); + placeItemInGridWeek(fullDayFlowPanel, column, column + daysdiff, counterIvent, theLastFDPanelInCellCounter); + + } else { + for (int day = 1; day < 1 + daysdiff - (8 - column); day++) { + theShiftVecorOfFullDayEvents[day][last] += 1; + } + longFullDayEventShownCounter = theRowToPlace;// + counterIvent; + + int theLastFullDayLinePlace44 = getLastFDPanelInCellCounter(theShiftVecorOfFullDayEvents, 1); + // Window.alert("6 column=" + column); + placeItemInGridWeek(fullDayFlowPanel, 1, 1 + daysdiff - (8 - column), counterIvent, theLastFDPanelInCellCounter); + + } + counterIvent++; + } + + } + //////////// + private void placeItemInGridWeek(Widget panel, int colStart, int colEnd, int row, int cellPosition) { final FlexTable grid = (FlexTable) getWidget(); @@ -1524,6 +1808,6 @@ private void setFullDayEventStyle(Widget panel, float top, float width, int heig DOM.setStyleAttribute(panel.getElement(), "border-style", "solid"); DOM.setStyleAttribute(panel.getElement(), "border-width", "1px"); DOM.setStyleAttribute(panel.getElement(), "background-color", "rgba(28,97,217)"); - // DOM.setStyleAttribute(panel.getElement(), "background", "linear-gradient(-90deg, #0000, #1c61d9)"); + // DOM.setStyleAttribute(panel.getElement(), "background", "linear-gradient(-90deg, #0000, #1c61d9)"); } } diff --git a/src/main/java/org/sigmah/server/handler/calendar/PersonalCalendarHandler.java b/src/main/java/org/sigmah/server/handler/calendar/PersonalCalendarHandler.java index dbce64c42..8ce0a1ab2 100644 --- a/src/main/java/org/sigmah/server/handler/calendar/PersonalCalendarHandler.java +++ b/src/main/java/org/sigmah/server/handler/calendar/PersonalCalendarHandler.java @@ -85,7 +85,8 @@ public Calendar getCalendar(CalendarIdentifier identifier, EntityManager em) { if (events != null) { final HashMap> eventMap = new HashMap>(); final HashMap> fullDayEventMap = new HashMap>(); - + final HashMap> hourMultiDayEventMap = new HashMap>(); + for (final PersonalEvent event : events) { final Date key = normalize(event.getStartDate()); @@ -102,6 +103,14 @@ public Calendar getCalendar(CalendarIdentifier identifier, EntityManager em) { fullDayList = new ArrayList(); fullDayEventMap.put(key, fullDayList); } + + List hourMultiDayList = hourMultiDayEventMap.get(key); + + if (hourMultiDayList == null) { + hourMultiDayList = new ArrayList(); + hourMultiDayEventMap.put(key, hourMultiDayList); + } + final Event calendarEvent = new Event(); calendarEvent.setIdentifier(event.getId()); calendarEvent.setParent(calendar); @@ -115,15 +124,19 @@ public Calendar getCalendar(CalendarIdentifier identifier, EntityManager em) { } if(event.getEventType()!=null && event.getEventType().contains("F") - || (event.getStartDate().getHours()==event.getEndDate().getHours() - && event.getStartDate().getMinutes()==event.getEndDate().getMinutes())){ +// || (event.getStartDate().getHours()==event.getEndDate().getHours() +// && event.getStartDate().getMinutes()==event.getEndDate().getMinutes()) + ){ fullDayList.add(calendarEvent); + }else if (event.getEventType()!=null && event.getEventType().contains("H")){ + hourMultiDayList.add(calendarEvent); }else{ eventList.add(calendarEvent); } calendar.setEvents(eventMap); calendar.setFullDayEvents(fullDayEventMap); + calendar.setHourMultiDayEvents(hourMultiDayEventMap); } } return calendar; diff --git a/src/main/java/org/sigmah/shared/command/result/Calendar.java b/src/main/java/org/sigmah/shared/command/result/Calendar.java index 475771e8b..7be6ba5a6 100644 --- a/src/main/java/org/sigmah/shared/command/result/Calendar.java +++ b/src/main/java/org/sigmah/shared/command/result/Calendar.java @@ -21,7 +21,6 @@ * . * #L% */ - import java.util.Collection; import java.util.Date; import java.util.List; @@ -38,105 +37,113 @@ */ public class Calendar implements Result { - - private CalendarIdentifier identifier; - private CalendarType type; - private String name; - private Map> events; - private Map> fullDayEvents; - private Collection tasks; - private int style; - private boolean editable; - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(Object obj) { - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - final Calendar other = (Calendar) obj; - if (this.identifier != other.identifier && (this.identifier == null || !this.identifier.equals(other.identifier))) { - return false; - } - return true; - } - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - int hash = 7; - hash = 97 * hash + (this.identifier != null ? this.identifier.hashCode() : 0); - return hash; - } - - public CalendarIdentifier getIdentifier() { - return identifier; - } - - public void setIdentifier(CalendarIdentifier identifier) { - this.identifier = identifier; - } - - public CalendarType getType() { - return type; - } - - public void setType(CalendarType type) { - this.type = type; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public Map> getEvents() { - return events; - } - - public void setEvents(Map> events) { - this.events = events; - } - - public Collection getTasks() { - return tasks; - } - - public void setTasks(Collection tasks) { - this.tasks = tasks; - } - - public int getStyle() { - return style; - } - - public void setStyle(int style) { - this.style = style; - } - - public boolean isEditable() { - return editable; - } - - public void setEditable(boolean editable) { - this.editable = editable; - } - - public void setFullDayEvents(Map> fullDayEvents) { - this.fullDayEvents = fullDayEvents; + private CalendarIdentifier identifier; + private CalendarType type; + private String name; + private Map> events; + private Map> fullDayEvents; + private Map> hourMultiDayEvents; + private Collection tasks; + private int style; + private boolean editable; + + /** + * {@inheritDoc} + */ + @Override + public boolean equals(Object obj) { + if (obj == null) { + return false; } - - public Map> getFullDayEvents() { - return fullDayEvents; + if (getClass() != obj.getClass()) { + return false; + } + final Calendar other = (Calendar) obj; + if (this.identifier != other.identifier && (this.identifier == null || !this.identifier.equals(other.identifier))) { + return false; } + return true; + } + + /** + * {@inheritDoc} + */ + @Override + public int hashCode() { + int hash = 7; + hash = 97 * hash + (this.identifier != null ? this.identifier.hashCode() : 0); + return hash; + } + + public CalendarIdentifier getIdentifier() { + return identifier; + } + + public void setIdentifier(CalendarIdentifier identifier) { + this.identifier = identifier; + } + + public CalendarType getType() { + return type; + } + + public void setType(CalendarType type) { + this.type = type; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Map> getEvents() { + return events; + } + + public void setEvents(Map> events) { + this.events = events; + } + + public Collection getTasks() { + return tasks; + } + + public void setTasks(Collection tasks) { + this.tasks = tasks; + } + + public int getStyle() { + return style; + } + + public void setStyle(int style) { + this.style = style; + } + + public boolean isEditable() { + return editable; + } + + public void setEditable(boolean editable) { + this.editable = editable; + } + + public void setFullDayEvents(Map> fullDayEvents) { + this.fullDayEvents = fullDayEvents; + } + + public Map> getFullDayEvents() { + return fullDayEvents; + } + + public void setHourMultiDayEvents(Map> hourMultiDayEvents) { + this.hourMultiDayEvents = hourMultiDayEvents; + } + + public Map> getHourMultiDayEvents() { + return hourMultiDayEvents; + } }