toolkit/mozapps/update/content/history.js

branch
TOR_BUG_9701
changeset 15
b8a032363ba2
equal deleted inserted replaced
-1:000000000000 0:7d5f92cb8613
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6 const NS_XUL = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
7
8 var gUpdateHistory = {
9 _view: null,
10
11 /**
12 * Initialize the User Interface
13 */
14 onLoad: function() {
15 this._view = document.getElementById("historyItems");
16
17 var um =
18 Components.classes["@mozilla.org/updates/update-manager;1"].
19 getService(Components.interfaces.nsIUpdateManager);
20 var uc = um.updateCount;
21 if (uc) {
22 while (this._view.hasChildNodes())
23 this._view.removeChild(this._view.firstChild);
24
25 var bundle = document.getElementById("updateBundle");
26
27 for (var i = 0; i < uc; ++i) {
28 var update = um.getUpdateAt(i);
29 if (!update || !update.name)
30 continue;
31
32 // Don't display updates that are downloading since they don't have
33 // valid statusText for the UI (bug 485493).
34 if (!update.statusText)
35 continue;
36
37 var element = document.createElementNS(NS_XUL, "update");
38 this._view.appendChild(element);
39 element.name = bundle.getFormattedString("updateFullName",
40 [update.name, update.buildID]);
41 element.type = bundle.getString("updateType_" + update.type);
42 element.installDate = this._formatDate(update.installDate);
43 if (update.detailsURL)
44 element.detailsURL = update.detailsURL;
45 else
46 element.hideDetailsURL = true;
47 element.status = update.statusText;
48 }
49 }
50 var cancelbutton = document.documentElement.getButton("cancel");
51 cancelbutton.focus();
52 },
53
54 /**
55 * Formats a date into human readable form
56 * @param seconds
57 * A date in seconds since 1970 epoch
58 * @returns A human readable date string
59 */
60 _formatDate: function(seconds) {
61 var sdf =
62 Components.classes["@mozilla.org/intl/scriptabledateformat;1"].
63 getService(Components.interfaces.nsIScriptableDateFormat);
64 var date = new Date(seconds);
65 return sdf.FormatDateTime("", sdf.dateFormatLong,
66 sdf.timeFormatSeconds,
67 date.getFullYear(),
68 date.getMonth() + 1,
69 date.getDate(),
70 date.getHours(),
71 date.getMinutes(),
72 date.getSeconds());
73 }
74 };
75

mercurial