Browse code

FEATBL-726 Feat: calendar ui default reminder

David Phan authored on 11/03/2019 07:29:28
Showing 4 changed files
... ...
@@ -1136,6 +1136,10 @@ net.bluemind.calendar.day.DayView.prototype.handleInDayMouseDown_ = function(e)
1136 1136
         start: date.getTimeZone(),
1137 1137
         end: date.getTimeZone()
1138 1138
       },
1139
+      alarm : [{
1140
+        trigger : this.ctx.settings.get('default_event_alert'),
1141
+        action : 'Email'
1142
+      }],
1139 1143
       states : {
1140 1144
         allday : false,
1141 1145
         pending : false,
... ...
@@ -1267,6 +1271,10 @@ net.bluemind.calendar.day.DayView.prototype.createAlldayEvent_ = function(start,
1267 1271
       start: null,
1268 1272
       end: null
1269 1273
     },
1274
+    alarm : [{
1275
+      trigger : this.ctx.settings.get('default_allday_event_alert'),
1276
+      action : 'Email'
1277
+    }],
1270 1278
     states : {
1271 1279
       allday : true,
1272 1280
       pending : false,
... ...
@@ -469,6 +469,10 @@ net.bluemind.calendar.month.MonthView.prototype.createEvent_ = function(start, r
469 469
       start: null,
470 470
       end: null
471 471
     },
472
+    alarm : [{
473
+      trigger : this.ctx.settings.get('default_allday_event_alert'),
474
+      action : 'Email'
475
+    }],
472 476
     states : {
473 477
       allday : true,
474 478
       pending : false,
... ...
@@ -347,6 +347,7 @@ net.bluemind.calendar.vevent.VEventPresenter.prototype.newVEvent_ = function() {
347 347
   dtstart.setMilliseconds(0);
348 348
   var dtend = dtstart.clone();
349 349
   dtend.add(new goog.date.Interval(goog.date.Interval.HOURS, 1));
350
+
350 351
   return {
351 352
     'dtstart' : {
352 353
       'precision' : 'DateTime',
... ...
@@ -364,7 +365,10 @@ net.bluemind.calendar.vevent.VEventPresenter.prototype.newVEvent_ = function() {
364 365
     'description' : '',
365 366
     'location' : '',
366 367
     'priority' : 5,
367
-    'alarm' : [],
368
+    'alarm' : [{
369
+      'trigger' : -1 * this.ctx.settings.get('default_event_alert'),
370
+      'action' : 'Email'
371
+    }],
368 372
     'status' : 'Tentative',
369 373
     'exdate' : null,
370 374
     'categories' : [],
... ...
@@ -107,6 +107,17 @@ net.bluemind.calendar.vevent.ui.Form = function(ctx, opt_domHelper) {
107 107
   this.warnings_.set('dates', new Array());
108 108
   this.warnings_.set('master', new Array());
109 109
 
110
+  this.alarm_ = new goog.structs.Map();
111
+  this.alarm_.set('allday', [{
112
+    trigger : this.ctx.settings.get('default_allday_event_alert'),
113
+    action : 'Email'
114
+  }]);
115
+  this.alarm_.set('inday', [{
116
+    trigger : this.ctx.settings.get('default_event_alert'),
117
+    action : 'Email'
118
+  }]);
119
+
120
+
110 121
   var child = new goog.ui.Toolbar();
111 122
   var renderer = goog.ui.style.app.ButtonRenderer.getInstance();
112 123
   child.setId('toolbar');
... ...
@@ -290,6 +301,14 @@ net.bluemind.calendar.vevent.ui.Form.prototype.calendars;
290 301
 net.bluemind.calendar.vevent.ui.Form.prototype.tags;
291 302
 
292 303
 /**
304
+ * Alarms
305
+ * 
306
+ * @type {Array.<Object>}
307
+ * @private
308
+ */
309
+net.bluemind.calendar.vevent.ui.Form.prototype.alarm_;
310
+
311
+/**
293 312
  * Generate a date field
294 313
  * 
295 314
  * @return {goog.ui.InputDatePicker} picker.
... ...
@@ -427,10 +446,15 @@ net.bluemind.calendar.vevent.ui.Form.prototype.enterDocument = function() {
427 446
   handler.listen(el, goog.events.InputHandler.EventType.INPUT, function(e) {
428 447
     this.getModel().summary = goog.dom.forms.getValue(e.target);
429 448
   });
449
+
430 450
   // REMINDER
431 451
   handler.listen(dom.getElement('bm-ui-form-add-reminder'), goog.events.EventType.CLICK, function() {
452
+    var defaultAlert = this.ctx.settings.get('default_event_alert');
453
+    if(this.getModel().states.allday){
454
+      defaultAlert = this.ctx.settings.get('default_allday_event_alert');
455
+    }
432 456
     this.addReminder_({
433
-      trigger : 600,
457
+      trigger : defaultAlert,
434 458
       action : 'Email'
435 459
     });
436 460
   });
... ...
@@ -463,7 +487,7 @@ net.bluemind.calendar.vevent.ui.Form.prototype.enterDocument = function() {
463 487
   });
464 488
 
465 489
   // ALLDAY
466
-  handler.listen(dom.getElement('bm-ui-form-allday'), goog.events.EventType.CHANGE, this.onAllDayChange_);
490
+  handler.listen(dom.getElement('bm-ui-form-allday'), goog.events.EventType.CHANGE, this.onAllDayChangeAndReminderUpdate_);
467 491
   // OPACITY
468 492
   handler.listen(dom.getElement('bm-ui-form-opacity-busy'), goog.events.EventType.CHANGE, function(e) {
469 493
     this.getModel().transp = 'Opaque';
... ...
@@ -676,11 +700,13 @@ net.bluemind.calendar.vevent.ui.Form.prototype.setModelValues_ = function() {
676 700
         this.addAttendee_(attendee);
677 701
       }, this);
678 702
     }
703
+
679 704
     this.getChild('reminder').forEachChild(function(child) {
680 705
       if (this.getChildCount() > 1) {
681 706
         this.removeFormField(child);
682 707
       }
683 708
     }, this);
709
+
684 710
     model.alarm = model.alarm || [];
685 711
     goog.array.forEach(model.alarm, function(value) {
686 712
       this.addReminder_(value);
... ...
@@ -1186,6 +1212,30 @@ net.bluemind.calendar.vevent.ui.Form.prototype.onRepeatChange_ = function(e) {
1186 1212
   }
1187 1213
 };
1188 1214
 
1215
+
1216
+/**
1217
+ * Apply check and modification when the all day status change
1218
+ *   and set reminders
1219
+ * 
1220
+ * @private
1221
+ */
1222
+net.bluemind.calendar.vevent.ui.Form.prototype.onAllDayChangeAndReminderUpdate_ = function() {
1223
+  this.onAllDayChange_();
1224
+
1225
+  var model = this.getModel();
1226
+  var allday = model.states.allday;
1227
+  this.alarm_.set(!allday ? 'allday' : 'inday', model.alarm);
1228
+
1229
+
1230
+  this.getChild('reminder').forEachChild(function(child) {
1231
+    child.dispose();
1232
+  }, this);
1233
+  goog.array.forEach(this.alarm_.get(allday ? 'allday' : 'inday'), function(value) {
1234
+    this.addReminder_(value);
1235
+  }, this);
1236
+
1237
+};
1238
+
1189 1239
 /**
1190 1240
  * Apply check and modification when the all day status change
1191 1241
  * 
... ...
@@ -1222,7 +1272,6 @@ net.bluemind.calendar.vevent.ui.Form.prototype.onAllDayChange_ = function() {
1222 1272
       model.dtend.add(new goog.date.Interval(goog.date.Interval.DAYS, 1));
1223 1273
       this.getChild('dend').setDate(e);
1224 1274
     }
1225
-
1226 1275
   } else {
1227 1276
     if (!(model.dtstart instanceof goog.date.DateTime)) {
1228 1277
       model.dtstart = new net.bluemind.date.DateTime(model.dtstart);
... ...
@@ -1243,6 +1292,7 @@ net.bluemind.calendar.vevent.ui.Form.prototype.onAllDayChange_ = function() {
1243 1292
     }
1244 1293
     this.getChild('tstart').setValue(this.formatter.time.format(model.dtstart));
1245 1294
     this.getChild('tend').setValue(this.formatter.time.format(model.dtend));
1295
+
1246 1296
   }
1247 1297
   this.getChild('freebusy').updateDummyEventOnFormUpdate(model.dtstart, model.dtend, true);
1248 1298