Browse code

FEATBL-373 Feat: calendar, autocollect attendees

David Phan authored on 14/05/2018 08:05:33
Showing 1 changed files
... ...
@@ -183,6 +183,41 @@ net.bluemind.calendar.vevent.VEventActions.prototype.participation = function(e)
183 183
 
184 184
 };
185 185
 
186
+net.bluemind.calendar.vevent.VEventActions.prototype.collectAttendees_ = function(attendees) {
187
+  if (attendees == null || attendees.length == 0){
188
+    return;
189
+  }
190
+
191
+  var toCollect = goog.array.filter(attendees, function(a) {
192
+    return a.uri == null;
193
+  });
194
+
195
+  if (toCollect.length == 0) {
196
+    return;
197
+  }
198
+
199
+  goog.array.forEach(toCollect, function(c) {
200
+    var vcard = {
201
+      'container' : 'book:CollectedContacts_' + this.ctx_.user['uid'],
202
+      'uid' : net.bluemind.mvp.UID.generate(),
203
+      'value' : {
204
+        'identification' : {'name': {'familyNames' : c['commonName']}},
205
+        'organizational' : {},
206
+        'related' : {},
207
+        'explanatory' : {},
208
+        'communications' : {
209
+          'emails': [{'parameters' : [{'label' : 'TYPE', 'value' : 'work'}], 'value' : c['mailto']}]
210
+        }
211
+      }
212
+    };
213
+
214
+    this.ctx_.service('addressbook').create(vcard);
215
+
216
+  }, this);
217
+
218
+
219
+};
220
+
186 221
 /**
187 222
  * Save event actions
188 223
  * 
... ...
@@ -289,6 +324,7 @@ net.bluemind.calendar.vevent.VEventActions.prototype.create_ = function(e) {
289 289
     return this.showSendNotification_(model, e.type);
290 290
   } else {
291 291
     var vseries = this.adaptor_.fromVEventModelView(model);
292
+    this.collectAttendees_(model.attendees);
292 293
     return this.doCreate_(vseries, model.sendNotification).then(this.resolve_, this.reject_, this);
293 294
   }
294 295
 };
... ...
@@ -332,6 +368,7 @@ net.bluemind.calendar.vevent.VEventActions.prototype.update_ = function(e, vseri
332 332
       }
333 333
 
334 334
     }
335
+    this.collectAttendees_(model.attendees);
335 336
     return this.doUpdate_(vseries, model.sendNotification).then(this.resolve_, this.reject_, this);
336 337
   }
337 338