summaryrefslogtreecommitdiffstats
path: root/comm/mail/components/preferences/syncDialog.js
blob: 6920a8aa59b1009d13cbfed799fd5514429d3c46 (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
/* 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/. */

const engineItems = {
  configSyncAccount: "services.sync.engine.accounts",
  configSyncAddress: "services.sync.engine.addressbooks",
  configSyncCalendar: "services.sync.engine.calendars",
  configSyncIdentity: "services.sync.engine.identities",
  configSyncPasswords: "services.sync.engine.passwords",
};

window.addEventListener("load", function () {
  for (let [id, prefName] of Object.entries(engineItems)) {
    let element = document.getElementById(id);
    element.checked = Services.prefs.getBoolPref(prefName, false);
  }

  let options = window.arguments[0];
  if (options.disconnectFun) {
    window.addEventListener("dialogextra2", function () {
      options.disconnectFun().then(disconnected => {
        if (disconnected) {
          window.close();
        }
      });
    });
  } else {
    document.querySelector("dialog").getButton("extra2").hidden = true;
  }
});

window.addEventListener("dialogaccept", function () {
  for (let [id, prefName] of Object.entries(engineItems)) {
    let element = document.getElementById(id);
    Services.prefs.setBoolPref(prefName, element.checked);
  }
});