1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 /** Information about a particular status page. */
6 function StatusPageInfo(statusPageName
, statusPageUrl
) {
9 this.jsonUrl
= statusPageUrl
+ 'current?format=json';
11 this.name
= statusPageName
;
13 this.url
= statusPageUrl
;
16 /** Send and parse an asynchronous request to get a repo status JSON. */
17 StatusPageInfo
.prototype.requestJson = function() {
18 if (this.inFlight
) return;
21 gNumRequestsInFlight
++;
23 var statusPageInfo
= this;
24 var request
= new XMLHttpRequest();
25 request
.open('GET', this.jsonUrl
, true);
26 request
.onreadystatechange = function() {
27 if (request
.readyState
== 4 && request
.status
== 200) {
28 statusPageInfo
.inFlight
--;
29 gNumRequestsInFlight
--;
31 var statusPageJson
= JSON
.parse(request
.responseText
);
32 statusPageInfo
.date
= statusPageJson
.date
;
33 statusPageInfo
.message
= statusPageJson
.message
;
34 statusPageInfo
.state
= statusPageJson
.general_state
;
40 /** Creates HTML displaying the status. */
41 StatusPageInfo
.prototype.createHtml = function() {
42 var linkElement
= document
.createElement('a');
43 linkElement
.href
= this.url
;
44 linkElement
.innerHTML
= this.name
;
46 var statusElement
= document
.createElement('li');
47 statusElement
.appendChild(linkElement
);
49 var dateElement
= document
.createElement('li');
50 dateElement
.innerHTML
= this.date
;
52 var messageElement
= document
.createElement('li');
53 messageElement
.innerHTML
= this.message
;
55 var boxElement
= document
.createElement('ul');
56 boxElement
.className
= 'box ' + this.state
;
57 boxElement
.appendChild(statusElement
);
58 boxElement
.appendChild(dateElement
);
59 boxElement
.appendChild(messageElement
);