summaryrefslogtreecommitdiffstats
path: root/comm/calendar/base/content/dialogs/calendar-occurrence-prompt.js
blob: cb66e24ff923824e136f8a548a1bd3717c098ddb (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
/* 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/. */

var { cal } = ChromeUtils.import("resource:///modules/calendar/calUtils.jsm");

window.addEventListener("DOMContentLoaded", onLoad);

document.addEventListener("dialogaccept", () => exitOccurrenceDialog(1));
document.addEventListener("dialogcancel", () => exitOccurrenceDialog(0));

function exitOccurrenceDialog(aReturnValue) {
  window.arguments[0].value = aReturnValue;
  window.close();
}

function getDString(aKey) {
  return cal.l10n.getString("calendar-occurrence-prompt", aKey);
}

function onLoad() {
  let action = window.arguments[0].action || "edit";
  // the calling code prevents sending no items
  let multiple = window.arguments[0].items.length == 1 ? "single" : "multiple";
  let itemType;
  for (let item of window.arguments[0].items) {
    let type = item.isEvent() ? "event" : "task";
    if (itemType != type) {
      itemType = itemType ? "mixed" : type;
    }
  }

  // Set up title and type label
  document.title = getDString(`windowtitle.${itemType}.${action}`);
  let title = document.getElementById("title-label");
  if (multiple == "multiple") {
    title.value = getDString("windowtitle.multipleitems");
    document.getElementById("isrepeating-label").value = getDString(
      `header.containsrepeating.${itemType}.label`
    );
  } else {
    title.value = window.arguments[0].items[0].title;
    document.getElementById("isrepeating-label").value = getDString(
      `header.isrepeating.${itemType}.label`
    );
  }

  // Set up buttons
  document.getElementById("accept-buttons-box").setAttribute("action", action);
  document.getElementById("accept-buttons-box").setAttribute("type", itemType);

  document.getElementById("accept-occurrence-button").label = getDString(
    `buttons.${multiple}.occurrence.${action}.label`
  );

  document.getElementById("accept-allfollowing-button").label = getDString(
    `buttons.${multiple}.allfollowing.${action}.label`
  );
  document.getElementById("accept-parent-button").label = getDString(
    `buttons.${multiple}.parent.${action}.label`
  );
}