Browse code

FEATBL-725 Feat: default calendar alert setting

David Phan authored on 12/03/2019 09:45:12
Showing 5 changed files
... ...
@@ -73,4 +73,16 @@ public interface CalendarMessages extends Messages {
73 73
 
74 74
 	String allDay();
75 75
 
76
+	String defaultEventAlert();
77
+
78
+	String defaultAlldayEventAlert();
79
+
80
+	String seconds();
81
+
82
+	String minutes();
83
+
84
+	String hours();
85
+
86
+	String days();
87
+
76 88
 }
... ...
@@ -32,4 +32,12 @@ workingDays=Working days
32 32
 showDeclinedEvents=Show declined events
33 33
 
34 34
 tabFolders=My calendars
35
-allDay=All day
36 35
\ No newline at end of file
36
+allDay=All day
37
+
38
+defaultEventAlert=Default event alert
39
+defaultAlldayEventAlert=Default all-day event alert
40
+
41
+seconds=Seconds
42
+minutes=Minutes
43
+hours=Hours
44
+days=Days
37 45
\ No newline at end of file
... ...
@@ -26,4 +26,12 @@ dayEndsAt=La journée se termine à
26 26
 workingDays=Jours ouvrés
27 27
 showDeclinedEvents=Afficher les événements refusés
28 28
 tabFolders=Mes calendriers
29
-allDay=Journée entière
30 29
\ No newline at end of file
30
+allDay=Journée entière
31
+
32
+defaultEventAlert=Rappel événement par défaut
33
+defaultAlldayEventAlert=Rappel événement journalier par défaut
34
+
35
+seconds=Secondes
36
+minutes=Minutes
37
+hours=Heures
38
+days=Jours
31 39
\ No newline at end of file
32 40
new file mode 100644
... ...
@@ -0,0 +1,82 @@
1
+package net.bluemind.ui.settings.calendar;
2
+
3
+import com.google.gwt.core.client.GWT;
4
+import com.google.gwt.user.client.ui.Composite;
5
+import com.google.gwt.user.client.ui.HasEnabled;
6
+import com.google.gwt.user.client.ui.HorizontalPanel;
7
+import com.google.gwt.user.client.ui.IntegerBox;
8
+import com.google.gwt.user.client.ui.ListBox;
9
+
10
+public class DurationValue extends Composite implements HasEnabled {
11
+
12
+	private boolean enabled;
13
+	private IntegerBox duration;
14
+	private ListBox unit;
15
+
16
+	private final CalendarMessages messages = GWT.create(CalendarMessages.class);
17
+
18
+	public DurationValue() {
19
+		HorizontalPanel panel = new HorizontalPanel();
20
+
21
+		duration = new IntegerBox();
22
+		duration.setWidth("70px");
23
+		duration.setMaxLength(8);
24
+		panel.add(duration);
25
+
26
+		unit = new ListBox();
27
+		unit.addItem(messages.seconds(), "seconds");
28
+		unit.addItem(messages.minutes(), "minutes");
29
+		unit.addItem(messages.hours(), "hours");
30
+		unit.addItem(messages.days(), "days");
31
+		panel.add(unit);
32
+
33
+		initWidget(panel);
34
+	}
35
+
36
+	@Override
37
+	public boolean isEnabled() {
38
+		return enabled;
39
+	}
40
+
41
+	public Integer getValue() {
42
+
43
+		int idx = unit.getSelectedIndex();
44
+
45
+		if (idx == 1) {
46
+			return duration.getValue() * 60;
47
+		} else if (idx == 2) {
48
+			return duration.getValue() * 3600;
49
+		} else if (idx == 3) {
50
+			return duration.getValue() * 86400;
51
+		}
52
+
53
+		return duration.getValue();
54
+	}
55
+
56
+	public void setValue(Integer value) {
57
+
58
+		int val = value;
59
+		int idx = 0;
60
+		if (value % 86400 == 0) {
61
+			val = value / 86400;
62
+			idx = 3;
63
+		} else if (value % 3600 == 0) {
64
+			val = value / 3600;
65
+			idx = 2;
66
+		} else if (value % 60 == 0) {
67
+			val = value / 60;
68
+			idx = 1;
69
+		}
70
+
71
+		duration.setValue(val);
72
+		unit.setSelectedIndex(idx);
73
+	}
74
+
75
+	@Override
76
+	public void setEnabled(boolean enabled) {
77
+		this.enabled = enabled;
78
+		duration.setEnabled(enabled);
79
+		duration.setEnabled(enabled);
80
+	}
81
+
82
+}
... ...
@@ -65,6 +65,10 @@ public class GeneralPartWidget extends CompositeGwtWidgetElement {
65 65
 
66 66
 	private YesNoPanel showDeclinedEvents;
67 67
 
68
+	private DurationValue defaultEventAlert;
69
+
70
+	private DurationValue defaultAlldayEventAlert;
71
+
68 72
 	public GeneralPartWidget(WidgetElement instance) {
69 73
 		table = new FlexTable();
70 74
 		table.setStyleName("formContainer");
... ...
@@ -129,6 +133,13 @@ public class GeneralPartWidget extends CompositeGwtWidgetElement {
129 133
 		showDeclinedEvents = new YesNoPanel("showDeclinedEvents");
130 134
 		ct(i++, messages.showDeclinedEvents(), showDeclinedEvents);
131 135
 
136
+		// default alert
137
+		defaultEventAlert = new DurationValue();
138
+		ct(i++, messages.defaultEventAlert(), defaultEventAlert);
139
+
140
+		defaultAlldayEventAlert = new DurationValue();
141
+		ct(i++, messages.defaultAlldayEventAlert(), defaultAlldayEventAlert);
142
+
132 143
 		if (instance.isReadOnly()) {
133 144
 			workingDays.setEnabled(false);
134 145
 			dayStartsAt.setEnabled(false);
... ...
@@ -138,6 +149,8 @@ public class GeneralPartWidget extends CompositeGwtWidgetElement {
138 149
 			defaultView.setEnabled(false);
139 150
 			showWeekends.setEnabled(false);
140 151
 			showDeclinedEvents.setEnabled(false);
152
+			defaultEventAlert.setEnabled(false);
153
+			defaultAlldayEventAlert.setEnabled(false);
141 154
 		}
142 155
 	}
143 156
 
... ...
@@ -155,6 +168,8 @@ public class GeneralPartWidget extends CompositeGwtWidgetElement {
155 168
 		listboxGetValue(dayEndsAt, model, "work_hours_end");
156 169
 		listboxGetValues(workingDays, model, "working_days");
157 170
 		model.put("show_declined_events", new JSONString("" + showDeclinedEvents.getValue()));
171
+		model.put("default_event_alert", new JSONString("" + defaultEventAlert.getValue()));
172
+		model.put("default_allday_event_alert", new JSONString("" + defaultAlldayEventAlert.getValue()));
158 173
 	}
159 174
 
160 175
 	@Override
... ...
@@ -171,9 +186,19 @@ public class GeneralPartWidget extends CompositeGwtWidgetElement {
171 186
 		listboxSetValues(workingDays, value(model, "working_days"));
172 187
 		yesNoSetValue(showDeclinedEvents, value(model, "show_declined_events"));
173 188
 
189
+		setDuration(defaultEventAlert, value(model, "default_event_alert"));
190
+		setDuration(defaultAlldayEventAlert, value(model, "default_allday_event_alert"));
191
+
174 192
 		validateAllDay(whStart, whEnd);
175 193
 	}
176 194
 
195
+	private void setDuration(DurationValue dv, String value) {
196
+		if (value != null) {
197
+			dv.setValue(Integer.parseInt(value));
198
+		}
199
+
200
+	}
201
+
177 202
 	private void validateAllDay(String whStart, String whEnd) {
178 203
 		if (whStart.equals("0") && whEnd.equals("0")) {
179 204
 			dayStartsAt.setEnabled(false);