summaryrefslogtreecommitdiffstats
path: root/content/passwordPrompt/passwordPrompt.js
blob: 8af40d9ba7f6140a92f81b9e8a82627bd32680eb (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
/*
 * This file is part of TbSync.
 *
 * 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";

var tbSyncPassword = {
  
  onload: function () {
    let data = window.arguments[0];
    this.resolve = window.arguments[1];
    this.resolved = false;

    this.namefield =  document.getElementById("tbsync.account");
    this.passfield = document.getElementById("tbsync.password");
    this.userfield = document.getElementById("tbsync.user");

    this.namefield.value = data.accountname;
    this.userfield.value = data.username;
    this.userfield.disabled = data.usernameLocked;

    window.addEventListener("unload", tbSyncPassword.doCANCEL.bind(this));
    document.getElementById("tbsync.password").focus();
    document.getElementById("tbsync.password.ok").addEventListener("click", tbSyncPassword.doOK.bind(this));
    document.getElementById("tbsync.password.cancel").addEventListener("click", () => window.close());
  },

  doOK: function (event) {
    if (!this.resolved) {
      this.resolved = true
      this.resolve({username: this.userfield.value, password: this.passfield.value});
      window.close();
    }
  },
  
  doCANCEL: function (event) {
    if (!this.resolved) {
      this.resolved = true
      this.resolve(false);
    }
  },
  
};