summaryrefslogtreecommitdiffstats
path: root/comm/calendar/base/content/widgets/calendar-item-summary.js
blob: 747c5e1d5d4ba6ac4439d5631c484f418134e07a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

"use strict";

/* global MozElements MozXULElement */

/* import-globals-from ../../src/calApplicationUtils.js */
/* import-globals-from ../dialogs/calendar-summary-dialog.js */

// Wrap in a block to prevent leaking to window scope.
{
  var { cal } = ChromeUtils.import("resource:///modules/calendar/calUtils.jsm");
  var { recurrenceStringFromItem } = ChromeUtils.import(
    "resource:///modules/calendar/calRecurrenceUtils.jsm"
  );

  /**
   * Represents a mostly read-only summary of a calendar item. Used in places
   * like the calendar summary dialog and calendar import dialog. All instances
   * should have an ID attribute.
   */
  class CalendarItemSummary extends MozXULElement {
    static get markup() {
      return `<vbox class="item-summary-box" flex="1">
        <!-- General -->
        <hbox class="calendar-caption" align="center">
          <label value="&read.only.general.label;" class="header"/>
          <separator class="groove" flex="1"/>
        </hbox>
        <html:table class="calendar-summary-table">
          <html:tr>
            <html:th>
              &read.only.title.label;
            </html:th>
            <html:td class="item-title">
            </html:td>
          </html:tr>
          <html:tr class="calendar-row" hidden="hidden">
            <html:th>
              &read.only.calendar.label;
            </html:th>
            <html:td class="item-calendar">
            </html:td>
          </html:tr>
          <html:tr class="item-date-row">
            <html:th class="item-start-row-label"
                     taskStartLabel="&read.only.task.start.label;"
                     eventStartLabel="&read.only.event.start.label;">
            </html:th>
            <html:td class="item-date-row-start-date">
            </html:td>
          </html:tr>
          <html:tr class="item-date-row">
            <html:th class="item-due-row-label"
                     taskDueLabel="&read.only.task.due.label;"
                     eventEndLabel="&read.only.event.end.label;">
            </html:th>
            <html:td class="item-date-row-end-date">
            </html:td>
          </html:tr>
          <html:tr class="repeat-row" hidden="hidden">
            <html:th>
              &read.only.repeat.label;
            </html:th>
            <html:td class="repeat-details">
            </html:td>
          </html:tr>
          <html:tr class="location-row" hidden="hidden">
            <html:th>
              &read.only.location.label;
            </html:th>
            <html:td class="item-location">
            </html:td>
          </html:tr>
          <html:tr class="category-row" hidden="hidden">
            <html:th>
              &read.only.category.label;
            </html:th>
            <html:td class="item-category">
            </html:td>
          </html:tr>
          <html:tr class="item-organizer-row" hidden="hidden">
            <html:th>
              &read.only.organizer.label;
            </html:th>
            <html:td class="item-organizer-cell">
            </html:td>
          </html:tr>
          <html:tr class="status-row" hidden="hidden">
            <html:th>
              &task.status.label;
            </html:th>
            <html:td class="status-row-td">
              <html:div hidden="true" status="TENTATIVE">&newevent.status.tentative.label;</html:div>
              <html:div hidden="true" status="CONFIRMED">&newevent.status.confirmed.label;</html:div>
              <html:div hidden="true" status="CANCELLED">&newevent.eventStatus.cancelled.label;</html:div>
              <html:div hidden="true" status="CANCELLED">&newevent.todoStatus.cancelled.label;</html:div>
              <html:div hidden="true" status="NEEDS-ACTION">&newevent.status.needsaction.label;</html:div>
              <html:div hidden="true" status="IN-PROCESS">&newevent.status.inprogress.label;</html:div>
              <html:div hidden="true" status="COMPLETED">&newevent.status.completed.label;</html:div>
            </html:td>
          </html:tr>
          <separator class="groove" flex="1" hidden="true"/>
          <html:tr class="reminder-row" hidden="hidden">
            <html:th class="reminder-label">
              &read.only.reminder.label;
            </html:th>
            <html:td class="reminder-details">
            </html:td>
          </html:tr>
          <html:tr class="attachments-row item-attachments-row" hidden="hidden" >
            <html:th class="attachments-label">
              &read.only.attachments.label;
            </html:th>
            <html:td>
              <vbox class="item-attachment-cell">
                <!-- attachment box template -->
                <hbox class="attachment-template"
                      hidden="true"
                      align="center"
                      disable-on-readonly="true">
                  <html:img class="attachment-icon invisible-on-broken"
                            alt="" />
                  <label class="text-link item-attachment-cell-label"
                         crop="end"
                         flex="1" />
                </hbox>
              </vbox>
            </html:td>
          </html:tr>
        </html:table>
        <!-- Attendees -->
        <box class="item-attendees-description">
          <box class="item-attendees" orient="vertical" hidden="true">
            <spacer class="default-spacer"/>
            <hbox class="calendar-caption" align="center">
              <label value="&read.only.attendees.label;"
                    class="header"/>
              <separator class="groove" flex="1"/>
            </hbox>
            <vbox class="item-attendees-list-container"
                  flex="1"
                  context="attendee-popup"
                  oncontextmenu="onAttendeeContextMenu(event)">
            </vbox>
          </box>

          <splitter id="attendeeDescriptionSplitter"
                    class="item-summary-splitter"
                    collapse="after"
                    orient="vertical"
                    state="open"/>

          <!-- Description -->
          <box class="item-description-box" hidden="true" orient="vertical">
            <hbox class="calendar-caption" align="center">
              <label value="&read.only.description.label;"
                    class="header"/>
              <separator class="groove" flex="1"/>
            </hbox>
            <iframe class="item-description"
                    type="content"
                    flex="1"
                    oncontextmenu="openDescriptionContextMenu(event);">
            </iframe>
          </box>
        </box>

        <!-- URL link -->
        <box class="event-grid-link-row" hidden="true" orient="vertical">
          <spacer class="default-spacer"/>
          <hbox class="calendar-caption" align="center">
            <label value="&read.only.link.label;"
                   class="header"/>
            <separator class="groove" flex="1"/>
          </hbox>
          <label class="url-link text-link default-indent"
                 crop="end"/>
        </box>
      </vbox>`;
    }

    static get entities() {
      return [
        "chrome://calendar/locale/global.dtd",
        "chrome://calendar/locale/calendar.dtd",
        "chrome://calendar/locale/calendar-event-dialog.dtd",
        "chrome://branding/locale/brand.dtd",
      ];
    }

    static get alarmMenulistFragment() {
      let frag = document.importNode(
        MozXULElement.parseXULToFragment(
          `<hbox align="center">
            <menulist class="item-alarm"
                      disable-on-readonly="true">
              <menupopup>
                <menuitem label="&event.reminder.none.label;"
                          selected="true"
                          value="none"/>
                <menuseparator/>
                <menuitem label="&event.reminder.0minutes.before.label;"
                          length="0"
                          origin="before"
                          relation="START"
                          unit="minutes"/>
                <menuitem label="&event.reminder.5minutes.before.label;"
                          length="5"
                          origin="before"
                          relation="START"
                          unit="minutes"/>
                <menuitem label="&event.reminder.15minutes.before.label;"
                          length="15"
                          origin="before"
                          relation="START"
                          unit="minutes"/>
                <menuitem label="&event.reminder.30minutes.before.label;"
                          length="30"
                          origin="before"
                          relation="START"
                          unit="minutes"/>
                <menuseparator/>
                <menuitem label="&event.reminder.1hour.before.label;"
                          length="1"
                          origin="before"
                          relation="START"
                          unit="hours"/>
                <menuitem label="&event.reminder.2hours.before.label;"
                          length="2"
                          origin="before"
                          relation="START"
                          unit="hours"/>
                <menuitem label="&event.reminder.12hours.before.label;"
                          length="12"
                          origin="before"
                          relation="START"
                          unit="hours"/>
                <menuseparator/>
                <menuitem label="&event.reminder.1day.before.label;"
                          length="1"
                          origin="before"
                          relation="START"
                          unit="days"/>
                <menuitem label="&event.reminder.2days.before.label;"
                          length="2"
                          origin="before"
                          relation="START"
                          unit="days"/>
                <menuitem label="&event.reminder.1week.before.label;"
                          length="7"
                          origin="before"
                          relation="START"
                          unit="days"/>
                <menuseparator/>
                <menuitem class="reminder-custom-menuitem"
                          label="&event.reminder.custom.label;"
                          value="custom"/>
              </menupopup>
            </menulist>
            <hbox class="reminder-details">
              <hbox class="alarm-icons-box" align="center"/>
              <!-- TODO oncommand? onkeypress? -->
              <label class="reminder-multiple-alarms-label text-link"
                     hidden="true"
                     value="&event.reminder.multiple.label;"
                     disable-on-readonly="true"
                     flex="1"
                     hyperlink="true"/>
              <label class="reminder-single-alarms-label text-link"
                     hidden="true"
                     disable-on-readonly="true"
                     flex="1"
                     hyperlink="true"/>
            </hbox>
          </hbox>`,
          CalendarItemSummary.entities
        ),
        true
      );
      Object.defineProperty(this, "alarmMenulistFragment", { value: frag });
      return frag;
    }

    connectedCallback() {
      if (this.delayConnectedCallback() || this.hasConnected) {
        return;
      }
      this.hasConnected = true;

      this.appendChild(this.constructor.fragment);

      this.mItem = null;
      this.mCalendar = null;
      this.mReadOnly = true;
      this.mIsInvitation = false;

      this.mIsToDoItem = null;

      let urlLink = this.querySelector(".url-link");
      urlLink.addEventListener("click", event => {
        launchBrowser(urlLink.getAttribute("href"), event);
      });
      urlLink.addEventListener("command", event => {
        launchBrowser(urlLink.getAttribute("href"), event);
      });
    }

    set item(item) {
      this.mItem = item;
      this.mIsToDoItem = item.isTodo();

      // When used in places like the import dialog, there is no calendar (yet).
      if (item.calendar) {
        this.mCalendar = item.calendar;

        this.mIsInvitation =
          item.calendar.supportsScheduling &&
          item.calendar.getSchedulingSupport()?.isInvitation(item);

        this.mReadOnly = !(
          cal.acl.isCalendarWritable(this.mCalendar) &&
          (cal.acl.userCanModifyItem(item) ||
            (this.mIsInvitation && cal.acl.userCanRespondToInvitation(item)))
        );
      }

      if (!item.descriptionHTML || !item.getAttendees().length) {
        // Hide the splitter when there is no description or attendees.
        document.getElementById("attendeeDescriptionSplitter").setAttribute("hidden", "true");
      }
    }

    get item() {
      return this.mItem;
    }

    get calendar() {
      return this.mCalendar;
    }

    get readOnly() {
      return this.mReadOnly;
    }

    get isInvitation() {
      return this.mIsInvitation;
    }

    /**
     * Update the item details in the UI. To be called when this element is
     * first rendered and when the item changes.
     */
    updateItemDetails() {
      if (!this.item) {
        // Setup not complete, do nothing for now.
        return;
      }
      let item = this.item;
      let isToDoItem = this.mIsToDoItem;

      this.querySelector(".item-title").textContent = item.title;

      if (this.calendar) {
        this.querySelector(".calendar-row").removeAttribute("hidden");
        this.querySelector(".item-calendar").textContent = this.calendar.name;
      }

      // Show start date.
      let itemStartDate = item[cal.dtz.startDateProp(item)];

      let itemStartRowLabel = this.querySelector(".item-start-row-label");
      let itemDateRowStartDate = this.querySelector(".item-date-row-start-date");

      itemStartRowLabel.style.visibility = itemStartDate ? "visible" : "collapse";
      itemDateRowStartDate.style.visibility = itemStartDate ? "visible" : "collapse";

      if (itemStartDate) {
        itemStartRowLabel.textContent = itemStartRowLabel.getAttribute(
          isToDoItem ? "taskStartLabel" : "eventStartLabel"
        );
        itemDateRowStartDate.textContent = cal.dtz.getStringForDateTime(itemStartDate);
      }

      // Show due date / end date.
      let itemDueDate = item[cal.dtz.endDateProp(item)];

      let itemDueRowLabel = this.querySelector(".item-due-row-label");
      let itemDateRowEndDate = this.querySelector(".item-date-row-end-date");

      itemDueRowLabel.style.visibility = itemDueDate ? "visible" : "collapse";
      itemDateRowEndDate.style.visibility = itemDueDate ? "visible" : "collapse";

      if (itemDueDate) {
        // For all-day events, display the last day, not the finish time.
        if (itemDueDate.isDate) {
          itemDueDate = itemDueDate.clone();
          itemDueDate.day--;
        }
        itemDueRowLabel.textContent = itemDueRowLabel.getAttribute(
          isToDoItem ? "taskDueLabel" : "eventEndLabel"
        );
        itemDateRowEndDate.textContent = cal.dtz.getStringForDateTime(itemDueDate);
      }

      let alarms = item.getAlarms();
      let hasAlarms = alarms && alarms.length;
      let canShowReadOnlyReminders = hasAlarms && item.calendar;
      let shouldShowReminderMenu =
        !this.readOnly &&
        this.isInvitation &&
        item.calendar &&
        item.calendar.getProperty("capabilities.alarms.oninvitations.supported") !== false;

      // For invitations where the reminders can be edited, show a menu to
      // allow setting the reminder, because you can't edit an invitation in
      // the edit item dialog. For all other cases, show a plain text
      // representation of the reminders but only if there are any.
      if (shouldShowReminderMenu) {
        if (!this.mAlarmsMenu) {
          // Attempt to vertically align the label. It's not perfect but it's the best we've got.
          let reminderLabel = this.querySelector(".reminder-label");
          reminderLabel.style.verticalAlign = "middle";
          let reminderCell = this.querySelector(".reminder-details");
          while (reminderCell.lastChild) {
            reminderCell.lastChild.remove();
          }

          // Add the menulist dynamically only if it's going to be used. This removes a
          // significant performance penalty in most use cases.
          reminderCell.append(this.constructor.alarmMenulistFragment.cloneNode(true));
          this.mAlarmsMenu = this.querySelector(".item-alarm");
          this.mLastAlarmSelection = 0;

          this.mAlarmsMenu.addEventListener("command", () => {
            this.updateReminder();
          });

          this.querySelector(".reminder-multiple-alarms-label").addEventListener("click", () => {
            this.updateReminder();
          });

          this.querySelector(".reminder-single-alarms-label").addEventListener("click", () => {
            this.updateReminder();
          });
        }

        if (hasAlarms) {
          this.mLastAlarmSelection = loadReminders(alarms, this.mAlarmsMenu, this.mItem.calendar);
        }
        this.updateReminder();
      } else if (canShowReadOnlyReminders) {
        this.updateReminderReadOnly(alarms);
      }

      if (shouldShowReminderMenu || canShowReadOnlyReminders) {
        this.querySelector(".reminder-row").removeAttribute("hidden");
      }

      let recurrenceDetails = recurrenceStringFromItem(
        item,
        "calendar-event-dialog",
        "ruleTooComplexSummary"
      );
      this.updateRecurrenceDetails(recurrenceDetails);
      this.updateAttendees(item);

      let url = item.getProperty("URL")?.trim() || "";

      let link = this.querySelector(".url-link");
      link.setAttribute("href", url);
      link.setAttribute("value", url);
      // Hide the row if there is no url.
      this.querySelector(".event-grid-link-row").hidden = !url;

      let location = item.getProperty("LOCATION");
      if (location) {
        this.updateLocation(location);
      }

      let categories = item.getCategories();
      if (categories.length > 0) {
        this.querySelector(".category-row").removeAttribute("hidden");
        // TODO: this join is unfriendly for l10n (categories.join(", ")).
        this.querySelector(".item-category").textContent = categories.join(", ");
      }

      if (item.organizer && item.organizer.id) {
        this.updateOrganizer(item);
      }

      let status = item.getProperty("STATUS");
      if (status && status.length) {
        this.updateStatus(status, isToDoItem);
      }

      let descriptionText = item.descriptionText?.trim();
      if (descriptionText) {
        this.updateDescription(descriptionText, item.descriptionHTML);
      }

      let attachments = item.getAttachments();
      if (attachments.length) {
        this.updateAttachments(attachments);
      }
    }

    /**
     * Updates the reminder, called when a reminder has been selected in the
     * menulist.
     */
    updateReminder() {
      this.mLastAlarmSelection = commonUpdateReminder(
        this.mAlarmsMenu,
        this.mItem,
        this.mLastAlarmSelection,
        this.mItem.calendar,
        this.querySelector(".reminder-details"),
        null,
        false
      );
    }

    /**
     * Updates the reminder to display the set reminders as read-only text.
     * Depends on updateReminder() to get the text to display.
     */
    updateReminderReadOnly(alarms) {
      let reminderLabel = this.querySelector(".reminder-label");
      reminderLabel.style.verticalAlign = null;
      let reminderCell = this.querySelector(".reminder-details");
      while (reminderCell.lastChild) {
        reminderCell.lastChild.remove();
      }
      delete this.mAlarmsMenu;

      switch (alarms.length) {
        case 0:
          reminderCell.textContent = "";
          break;
        case 1:
          reminderCell.textContent = alarms[0].toString(this.item);
          break;
        default:
          for (let a of alarms) {
            reminderCell.appendChild(document.createTextNode(a.toString(this.item)));
            reminderCell.appendChild(document.createElement("br"));
          }
          break;
      }
    }

    /**
     * Updates the item's recurrence details, i.e. shows text describing them,
     * or hides the recurrence row if the item does not recur.
     *
     * @param {string | null} details - Recurrence details as a string or null.
     *                                  Passing null hides the recurrence row.
     */
    updateRecurrenceDetails(details) {
      let repeatRow = this.querySelector(".repeat-row");
      let repeatDetails = repeatRow.querySelector(".repeat-details");

      repeatRow.toggleAttribute("hidden", !details);
      repeatDetails.textContent = details ? details.replace(/\n/g, " ") : "";
    }

    /**
     * Updates the attendee listbox, displaying all attendees invited to the item.
     */
    updateAttendees(item) {
      let attendees = item.getAttendees();
      if (attendees && attendees.length) {
        this.querySelector(".item-attendees").removeAttribute("hidden");
        this.querySelector(".item-attendees-list-container").appendChild(
          cal.invitation.createAttendeesList(document, attendees)
        );
      }
    }

    /**
     * Updates the location, creating a link if the value is a URL.
     *
     * @param {string} location - The value of the location property.
     */
    updateLocation(location) {
      this.querySelector(".location-row").removeAttribute("hidden");
      let urlMatch = location.match(/(https?:\/\/[^ ]*)/);
      let url = urlMatch && urlMatch[1];
      let itemLocation = this.querySelector(".item-location");
      if (url) {
        let link = document.createElementNS("http://www.w3.org/1999/xhtml", "a");
        link.setAttribute("class", "item-location-link text-link");
        link.setAttribute("href", url);
        link.title = url;
        link.setAttribute("onclick", "launchBrowser(this.getAttribute('href'), event)");
        link.setAttribute("oncommand", "launchBrowser(this.getAttribute('href'), event)");

        let label = document.createXULElement("label");
        label.setAttribute("context", "location-link-context-menu");
        label.textContent = location;
        link.appendChild(label);

        itemLocation.replaceChildren(link);
      } else {
        itemLocation.textContent = location;
      }
    }

    /**
     * Update the organizer part of the UI.
     *
     * @param {calIItemBase} item - The calendar item.
     */
    updateOrganizer(item) {
      this.querySelector(".item-organizer-row").removeAttribute("hidden");
      let organizerLabel = cal.invitation.createAttendeeLabel(
        document,
        item.organizer,
        item.getAttendees()
      );
      let organizerName = organizerLabel.querySelector(".attendee-name");
      organizerName.classList.add("text-link");
      organizerName.addEventListener("click", () => sendMailToOrganizer(this.mItem));
      this.querySelector(".item-organizer-cell").appendChild(organizerLabel);
    }

    /**
     * Update the status part of the UI.
     *
     * @param {string} status - The status of the calendar item.
     * @param {boolean} isToDoItem - True if the calendar item is a todo, false if an event.
     */
    updateStatus(status, isToDoItem) {
      let statusRow = this.querySelector(".status-row");
      let statusRowData = this.querySelector(".status-row-td");

      for (let i = 0; i < statusRowData.children.length; i++) {
        if (statusRowData.children[i].getAttribute("status") == status) {
          statusRow.removeAttribute("hidden");

          if (status == "CANCELLED" && isToDoItem) {
            // There are two status elements for CANCELLED, the second one is for
            // todo items. Increment the counter here.
            i++;
          }
          statusRowData.children[i].removeAttribute("hidden");
          break;
        }
      }
    }

    /**
     * Update the description part of the UI.
     *
     * @param {string} descriptionText - The value of the DESCRIPTION property.
     * @param {string} descriptionHTML - HTML description if available.
     */
    async updateDescription(descriptionText, descriptionHTML) {
      this.querySelector(".item-description-box").removeAttribute("hidden");
      let itemDescription = this.querySelector(".item-description");
      if (itemDescription.contentDocument.readyState != "complete") {
        // The iframe's document hasn't loaded yet. If we add to it now, what we add will be
        // overwritten. Wait for the initial document to load.
        await new Promise(resolve => {
          itemDescription._listener = {
            QueryInterface: ChromeUtils.generateQI([
              "nsIWebProgressListener",
              "nsISupportsWeakReference",
            ]),
            onStateChange(webProgress, request, stateFlags, status) {
              if (stateFlags & Ci.nsIWebProgressListener.STATE_STOP) {
                itemDescription.browsingContext.webProgress.removeProgressListener(this);
                delete itemDescription._listener;
                resolve();
              }
            },
          };
          itemDescription.browsingContext.webProgress.addProgressListener(
            itemDescription._listener,
            Ci.nsIWebProgress.NOTIFY_STATE_ALL
          );
        });
      }
      let docFragment = cal.view.textToHtmlDocumentFragment(
        descriptionText,
        itemDescription.contentDocument,
        descriptionHTML
      );

      // Make any links open in the user's default browser, not in Thunderbird.
      for (let anchor of docFragment.querySelectorAll("a")) {
        anchor.addEventListener("click", function (event) {
          event.preventDefault();
          if (event.isTrusted) {
            launchBrowser(anchor.getAttribute("href"), event);
          }
        });
      }

      itemDescription.contentDocument.body.appendChild(docFragment);

      const link = itemDescription.contentDocument.createElement("link");
      link.rel = "stylesheet";
      link.href = "chrome://messenger/skin/shared/editorContent.css";
      itemDescription.contentDocument.head.appendChild(link);
    }

    /**
     * Update the attachments part of the UI.
     *
     * @param {calIAttachment[]} attachments - Array of attachment objects.
     */
    updateAttachments(attachments) {
      // We only want to display URI type attachments and no ones received inline with the
      // invitation message (having a CID: prefix results in about:blank) here.
      let attCounter = 0;
      attachments.forEach(aAttachment => {
        if (aAttachment.uri && aAttachment.uri.spec != "about:blank") {
          let attachment = this.querySelector(".attachment-template").cloneNode(true);
          attachment.removeAttribute("id");
          attachment.removeAttribute("hidden");

          let label = attachment.querySelector("label");
          label.setAttribute("value", aAttachment.uri.spec);

          label.addEventListener("click", () => {
            openAttachmentFromItemSummary(aAttachment.hashId, this.mItem);
          });

          let icon = attachment.querySelector("img");
          let iconSrc = aAttachment.uri.spec.length ? aAttachment.uri.spec : "dummy.html";
          if (aAttachment.uri && !aAttachment.uri.schemeIs("file")) {
            // Using an uri directly, with e.g. a http scheme, wouldn't render any icon.
            if (aAttachment.formatType) {
              iconSrc = "goat?contentType=" + aAttachment.formatType;
            } else {
              // Let's try to auto-detect.
              let parts = iconSrc.substr(aAttachment.uri.scheme.length + 2).split("/");
              if (parts.length) {
                iconSrc = parts[parts.length - 1];
              }
            }
          }
          icon.setAttribute("src", "moz-icon://" + iconSrc);

          this.querySelector(".item-attachment-cell").appendChild(attachment);
          attCounter++;
        }
      });

      if (attCounter > 0) {
        this.querySelector(".attachments-row").removeAttribute("hidden");
      }
    }
  }

  customElements.define("calendar-item-summary", CalendarItemSummary);
}