Skip to content

Commit 886789e

Browse files
committed
Merge commit '293eac1dbdf68cade7323fa424e9a2e231404908'
Bugfix for IE/Firefox; prep for ExtJS login screen
2 parents 09e3af3 + 293eac1 commit 886789e

File tree

5 files changed

+246
-9
lines changed

5 files changed

+246
-9
lines changed

Scalatron/webui/client/API.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
(function () {
22

3+
/* See webclient.html
34
function getUserName() {
45
return Ext.util.Cookies.get("scalatron-user");
56
}
7+
*/
68

79
Ext.define('API', {
810
singleton:true,

Scalatron/webui/client/Login.js

Lines changed: 219 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,219 @@
1+
/* 2012-05-04: merged this from chilicat to retain it for future use, but not yet activated in index.html. */
2+
Ext.require(['*']);
3+
4+
Ext.onReady(function () {
5+
6+
var lastUser;
7+
8+
function login() {
9+
var username = lastUser;
10+
var password = Ext.getCmp("password").getValue();
11+
loginFor(username, password);
12+
}
13+
14+
function loginFor(username, password, errorCallback) {
15+
lastUser = username;
16+
Ext.Ajax.request({
17+
url:"/api/users/" + username + "/session",
18+
method:"POST",
19+
headers:{
20+
"Accept":'application/json',
21+
"Content-Type":'application/json'
22+
},
23+
jsonData:{
24+
password:password
25+
},
26+
success:function () {
27+
if (username == "Administrator") {
28+
window.location = "/admin/list";
29+
} else {
30+
window.location = "/user/" + username + "/edit";
31+
}
32+
},
33+
failure:function (response) {
34+
if (errorCallback(response)) {
35+
Ext.MessageBox.alert('Login failed', response.statusText);
36+
}
37+
}
38+
})
39+
}
40+
41+
function enumUsers() {
42+
Ext.Ajax.request({
43+
scope:this,
44+
url:"/api/users/",
45+
method:'GET',
46+
headers:{
47+
"Accept":'application/json',
48+
"Content-Type":'application/json'
49+
},
50+
success:function (r) {
51+
var result = JSON.parse(r.responseText);
52+
var combo = Ext.getCmp("userName");
53+
combo.getStore().loadRawData(result.users);
54+
combo.setDisabled(false);
55+
}
56+
});
57+
}
58+
59+
function createStore() {
60+
return Ext.create('Ext.data.Store', {
61+
fields:['name']
62+
});
63+
}
64+
65+
function createUserGrid() {
66+
return {
67+
id:"userName",
68+
fieldLabel:'User Name',
69+
xtype:"grid",
70+
store:createStore(),
71+
margin:0,
72+
hideHeaders:true,
73+
border:0,
74+
height:100,
75+
columns:[
76+
{ header:'Name', dataIndex:'name', flex:1}
77+
],
78+
name:'user',
79+
displayField:'name',
80+
valueField:'name',
81+
queryMode:"local",
82+
83+
editable:false,
84+
autoSelect:false,
85+
forceSelection:false,
86+
87+
88+
allowBlank:false,
89+
listeners:{
90+
afterRender:function (c) {
91+
enumUsers();
92+
},
93+
itemclick:function (view, record) {
94+
var username = record.data.name;
95+
loginFor(username, "", function (response) {
96+
if (response.status == 401) {
97+
// user has password. Show password field.
98+
Ext.getCmp("box").getLayout().setActiveItem(1);
99+
Ext.getCmp("password").focus();
100+
// prevent default handling.
101+
return false;
102+
}
103+
104+
// allow default handling.
105+
return true;
106+
});
107+
}
108+
}
109+
}
110+
111+
}
112+
113+
function createPasswordPanel() {
114+
return Ext.create("Ext.form.Panel", {
115+
116+
layout: 'anchor',
117+
border: 0,
118+
119+
defaults: {
120+
anchor: '100%'
121+
},
122+
height:100,
123+
defaultType:'textfield',
124+
padding: "0 0 4 0",
125+
126+
items:[
127+
{
128+
inputType:"password",
129+
id:"password",
130+
fieldLabel:'Password',
131+
name:'password',
132+
margin: 6,
133+
134+
listeners:{
135+
scope:this,
136+
specialkey:function (f, e) {
137+
if (e.getKey() == e.ENTER) {
138+
login();
139+
} else if (e.getKey() == e.ESC) {
140+
Ext.getCmp("box").getLayout().setActiveItem(0);
141+
}
142+
}
143+
},
144+
145+
allowBlank:false
146+
}
147+
] ,
148+
149+
150+
buttons:[
151+
{
152+
text:'Back',
153+
id:"backButton",
154+
handler:function () {
155+
Ext.getCmp("box").getLayout().setActiveItem(0);
156+
}
157+
},
158+
{
159+
text:'Login',
160+
id:"loginButton",
161+
disabled:false,
162+
handler:function () {
163+
login();
164+
}
165+
}
166+
167+
]
168+
});
169+
}
170+
171+
172+
Ext.create('Ext.container.Viewport', {
173+
layout:{
174+
type:'vbox',
175+
align:'center'
176+
},
177+
id:'root',
178+
179+
items:[
180+
{
181+
xtype:"panel",
182+
margin:10,
183+
border:0,
184+
layout:{
185+
type:'vbox',
186+
align:'center'
187+
},
188+
items:[
189+
Ext.create('Ext.Img', {
190+
border:0,
191+
src:'/header.gif'
192+
})
193+
],
194+
flex:1,
195+
width:700
196+
},
197+
198+
{
199+
xtype:"panel",
200+
layout:"card",
201+
id:"box",
202+
203+
bodyPadding:0,
204+
width:300,
205+
title:"Welcome to Scalatron",
206+
207+
items:[
208+
createUserGrid(),
209+
createPasswordPanel()
210+
]
211+
},
212+
{
213+
flex:1,
214+
border:0
215+
}
216+
]
217+
});
218+
});
219+

Scalatron/webui/client/Tutorial.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Ext.define('TutorialPanel', {
2727
this.on('afterrender', function() {
2828
var hiddenFrame = this.el.createChild({
2929
id: 'tutorialIFrame',
30-
name: 'tutorialIFrame',
30+
name: 'tutorialIFrame', // Bugfix for firefox and IE
3131
tag: 'iframe',
3232
src: config.url,
3333
width: '0',
@@ -71,7 +71,7 @@ Ext.define('TutorialPanel', {
7171
var url = urls.getByKey(a.id);
7272
a.href = url;
7373

74-
var indexOfMarker = url.indexOf("/tutorial/tutorial")
74+
var indexOfMarker = url.indexOf("/tutorial/tutorial");
7575
if(indexOfMarker > 0) {
7676
// this URL points inside the tutorial
7777
a.target = 'tutorialIFrame';

Scalatron/webui/index.html

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
1-
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
2-
<html lang="en">
1+
<html>
32
<head>
43
<meta charset="UTF-8">
5-
<link rel="stylesheet" type="text/css" href="/format.css">
4+
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
5+
66
<title>Welcome to Scalatron</title>
7+
8+
<link rel="stylesheet" type="text/css" href="/format.css">
9+
10+
<!-- temporarily disabled until we're ready to include the new login screen
11+
<link rel="stylesheet" type="text/css" href="/ext-4.0.7/resources/css/ext-all-gray.css"/>
12+
<script type="text/javascript" src="/ext-4.0.7/bootstrap.js"></script>
13+
<script type="text/javascript" src="/ext-4.0.7/ext-all.js"></script>
14+
<script type="text/javascript" src="/client/Login.js"></script>
15+
-->
716
</head>
817

918
<body>
19+
1020
<div class="login">
1121
<table align="center">
1222
<tr>
@@ -20,4 +30,5 @@ <h1>Welcome to Scalatron</h1>
2030
</div>
2131

2232
</body>
33+
2334
</html>

Scalatron/webui/webclient.html

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,15 @@
1616
<link rel="stylesheet" type="text/css" href="/ext-4.0.7/resources/css/ext-all-gray.css"/>
1717

1818
<style type="text/css">
19-
/** Enable cell line wrap for build/error consol e **/
20-
.wrap .x-grid-cell-inner {
21-
white-space: normal;
22-
}
19+
/** Enable cell line wrap for build/error console **/
20+
.wrap .x-grid-cell-inner { white-space: normal; }
2321
</style>
2422

23+
<script type="text/javascript">
24+
// Hack to get the current user name. Cookie doesn't work
25+
function getUserName() { return '$BotName$'; }
26+
</script>
27+
2528
<!--<script type="text/javascript" src="/ext-4.0.7/bootstrap.js"></script>-->
2629
<script type="text/javascript" src="/ext-4.0.7/ext-all.js"></script>
2730

@@ -43,9 +46,11 @@
4346
</head>
4447

4548
<body>
49+
<!-- Note that this is an old hack: ideally, a script should use the API and REST to fetch the latest sources. -->
4650
<pre id="editor" style="color:white;visibility:hidden">$BotSourceCode$</pre>
4751

4852

53+
<!-- This UI element will later be recycled to provide the canvas for bot debugging. -->
4954
<div id=botviewContainer style="visibility:hidden">
5055
<center><canvas id="botview" width="217" height="217"></canvas></center>
5156
</div>

0 commit comments

Comments
 (0)