summaryrefslogtreecommitdiffstats
path: root/toolkit/mozapps/update/content/history.js
blob: 51de669af39c8463fbc6316fff1a30bb0b8c64b9 (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
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* 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 gUpdateHistory = {
  _view: null,

  /**
   * Initialize the User Interface
   */
  onLoad() {
    this._view = document.getElementById("historyItems");

    var um = Cc["@mozilla.org/updates/update-manager;1"].getService(
      Ci.nsIUpdateManager
    );
    var uc = um.getUpdateCount();
    if (uc) {
      while (this._view.hasChildNodes()) {
        this._view.firstChild.remove();
      }

      for (var i = 0; i < uc; ++i) {
        var update = um.getUpdateAt(i);

        if (!update || !update.name) {
          continue;
        }

        // Don't display updates that are downloading since they don't have
        // valid statusText for the UI (bug 485493).
        if (!update.statusText) {
          continue;
        }

        var element = document.createXULElement("richlistitem");
        element.className = "update";

        const topLine = document.createXULElement("hbox");
        const nameLabel = document.createXULElement("label");
        nameLabel.className = "update-name";
        document.l10n.setAttributes(nameLabel, "update-full-build-name", {
          name: update.name,
          buildID: update.buildID,
        });
        topLine.appendChild(nameLabel);

        if (update.detailsURL) {
          const detailsLink = document.createXULElement("label", {
            is: "text-link",
          });
          detailsLink.href = update.detailsURL;
          document.l10n.setAttributes(detailsLink, "update-details");
          topLine.appendChild(detailsLink);
        }

        const installedOnLabel = document.createXULElement("label");
        installedOnLabel.className = "update-installedOn-label";
        document.l10n.setAttributes(installedOnLabel, "update-installed-on", {
          date: this._formatDate(update.installDate),
        });

        const statusLabel = document.createXULElement("label");
        statusLabel.className = "update-status-label";
        document.l10n.setAttributes(statusLabel, "update-status", {
          status: update.statusText,
        });

        element.append(topLine, installedOnLabel, statusLabel);
        this._view.appendChild(element);
      }
    }
    var cancelbutton = document.getElementById("history").getButton("cancel");
    cancelbutton.focus();
  },

  /**
   * Formats a date into human readable form
   * @param   seconds
   *          A date in seconds since 1970 epoch
   * @returns A human readable date string
   */
  _formatDate(seconds) {
    var date = new Date(seconds);
    const dtOptions = {
      year: "numeric",
      month: "long",
      day: "numeric",
      hour: "numeric",
      minute: "numeric",
      second: "numeric",
    };
    return date.toLocaleString(undefined, dtOptions);
  },
};