initial import
[vuplus_webkit] / Tools / BuildSlaveSupport / build.webkit.org-config / public_html / TestFailures / scripts / ui.js
1 /*
2  * Copyright (C) 2011 Google Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23  * THE POSSIBILITY OF SUCH DAMAGE.
24  */
25
26 var ui = ui || {};
27
28 (function () {
29
30 ui.displayURLForBuilder = function(builderName)
31 {
32     return 'http://build.chromium.org/p/chromium.webkit/waterfall?' + $.param({
33         'builder': builderName
34     });
35 }
36
37 ui.displayNameForBuilder = function(builderName)
38 {
39     return builderName.replace(/Webkit /, '');
40 }
41
42 ui.urlForTest = function(testName)
43 {
44     return 'http://trac.webkit.org/browser/trunk/LayoutTests/' + testName;
45 }
46
47 ui.rolloutReasonForTestNameList = function(testNameList)
48 {
49     return 'Broke:\n' + testNameList.map(function(testName) {
50         return '* ' + testName;
51     }).join('\n');
52 }
53
54 ui.onebar = base.extends('div', {
55     init: function()
56     {
57         this.id = 'onebar';
58         this.innerHTML =
59             '<ul>' +
60                 '<li><a href="#summary">Summary</a></li>' +
61                 '<li><a href="#results">Results</a></li>' +
62                 '<li><a href="#commits">Commits</a></li>' +
63                 '<li><a href="#failures">Failures</a></li>' +
64             '</ul>' +
65             '<div id="summary"></div>' +
66             '<div id="results"></div>' +
67             '<div id="commits">Coming soon...</div>' +
68             '<div id="failures"></div>';
69         this._tabNames = [
70             'summary',
71             'results',
72             'commits',
73             'failures',
74         ]
75         this._tabs = $(this).tabs({
76             disabled: [1, 2],
77         });
78     },
79     attach: function()
80     {
81         document.body.insertBefore(this, document.body.firstChild);
82     },
83     tabNamed: function(tabName)
84     {
85         return $('#' + tabName, this)[0];
86     },
87     summary: function()
88     {
89         return this.tabNamed('summary');
90     },
91     results: function()
92     {
93         return this.tabNamed('results');
94     },
95     failures: function()
96     {
97         return this.tabNamed('failures');
98     },
99     select: function(tabName)
100     {
101         var tabIndex = this._tabNames.indexOf(tabName);
102         this._tabs.tabs('enable', tabIndex);
103         this._tabs.tabs('select', tabIndex);
104     }
105 });
106
107 // FIXME: Loading a module shouldn't set off a timer.  The controller should kick this off.
108 setInterval(function() {
109     Array.prototype.forEach.call(document.querySelectorAll("time.relative"), function(time) {
110         time.update && time.update();
111     });
112 }, config.kRelativeTimeUpdateFrequency);
113
114 ui.RelativeTime = base.extends('time', {
115     init: function()
116     {
117         this.setDate(new Date());
118         this.className = 'relative';
119     },
120     date: function()
121     {
122         return this._date;
123     },
124     update: function()
125     {
126         this.textContent = base.relativizeTime(this._date);
127     },
128     setDate: function(date)
129     {
130         this._date = date;
131         this.textContent = base.relativizeTime(date);
132     }
133 });
134
135 ui.MessageBox = base.extends('div',  {
136     init: function(title, message)
137     {
138         this._content = document.createElement('div');
139         this.appendChild(this._content);
140         this.addMessage(message);
141         document.body.appendChild(this);
142         $(this).dialog({
143             resizable: false,
144             title: title,
145             width: $(window).width() * 0.80,  // FIXME: We should have CSS do this work for us.
146         });
147         $(this).bind('dialogclose', function() {
148             $(this).detach();
149         }.bind(this));
150     },
151     close: function()
152     {
153         $(this).dialog('close');
154     },
155     addMessage: function(message)
156     {
157         var element = document.createElement('div');
158         $(element).addClass('message').text(message);
159         this._content.appendChild(element);
160     },
161     // FIXME: It's unclear whether this code could live here or in a controller.
162     addFinalMessage: function(message)
163     {
164         this.addMessage(message);
165         this.appendChild(new ui.actions.List([new ui.actions.Close()]));
166         $(statusView).bind('close', statusView.close.bind(statusView));
167     }
168 });
169
170 })();