Skip to content

Commit 6fe842e

Browse files
committed
Add ErrorDialog class. Use it for VoIP/command errors.
1 parent bb06484 commit 6fe842e

8 files changed

Lines changed: 108 additions & 9 deletions

File tree

‎skins/base/css/common.css‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,5 +68,15 @@ html {
6868
max-width: 500px;
6969
z-index: -100;
7070
position: relative;
71-
top: 100px;
71+
top: 200px;
7272
}
73+
74+
.mx_ErrorDialogTitle {
75+
background-color: #d2322d;
76+
min-height: 16px;
77+
padding: 15px;
78+
border-bottom: 1px solid #e5e5e5;
79+
font-weight: bold;
80+
line-height: 1.4;
81+
color: #fff;
82+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
Copyright 2015 OpenMarket Ltd
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
'use strict';
18+
19+
/*
20+
* Usage:
21+
* Modal.createDialog(ErrorDialog, {
22+
* title: "some text", (default: "Error")
23+
* description: "some more text",
24+
* button: "Button Text",
25+
* onClose: someFunction,
26+
* focus: true|false (default: true)
27+
* });
28+
*/
29+
30+
var React = require('react');
31+
32+
module.exports = React.createClass({
33+
displayName: 'ErrorDialog',
34+
35+
// can't use getDefaultProps, see Modal.js
36+
componentWillMount: function() {
37+
if (!this.props.title) {
38+
this.props.title = "Error";
39+
}
40+
if (!this.props.description) {
41+
this.props.description = "An error has occurred.";
42+
}
43+
if (!this.props.button) {
44+
this.props.button = "OK";
45+
}
46+
if (this.props.focus === undefined) {
47+
this.props.focus = true;
48+
}
49+
if (!this.props.onClose) {
50+
var self = this;
51+
this.props.onClose = function() {
52+
self.props.onFinished();
53+
};
54+
}
55+
},
56+
57+
render: function() {
58+
return (
59+
<div className="mx_ErrorDialog">
60+
<div className="mx_ErrorDialogTitle">
61+
{this.props.title}
62+
</div>
63+
{this.props.description}<br />
64+
<button onClick={this.props.onClose} autoFocus={this.props.focus}>
65+
{this.props.button}
66+
</button>
67+
</div>
68+
);
69+
}
70+
});
71+

‎skins/base/views/organisms/UserSettings.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ var ChangePassword = ComponentBroker.get('molecules/ChangePassword');
2525
var LogoutPrompt = ComponentBroker.get('organisms/LogoutPrompt');
2626
var Loader = require("react-loader");
2727

28-
var Modal = require("../../../../src/Modal")
28+
var Modal = require("../../../../src/Modal");
2929

3030
module.exports = React.createClass({
3131
displayName: 'UserSettings',

‎src/CallHandler.js‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ limitations under the License.
5454
*/
5555

5656
var MatrixClientPeg = require("./MatrixClientPeg");
57+
var Modal = require("./Modal");
58+
var ComponentBroker = require('./ComponentBroker');
59+
var ErrorDialog = ComponentBroker.get("organisms/ErrorDialog");
5760
var Matrix = require("matrix-js-sdk");
5861
var dis = require("./dispatcher");
5962

@@ -154,7 +157,12 @@ dis.register(function(payload) {
154157
console.error("Room %s does not exist.", payload.room_id);
155158
return;
156159
}
157-
if (room.getJoinedMembers().length !== 2) {
160+
var members = room.getJoinedMembers();
161+
if (members.length !== 2) {
162+
var text = members.length === 1 ? "yourself." : "more than 2 people.";
163+
Modal.createDialog(ErrorDialog, {
164+
description: "You cannot place a call with " + text
165+
});
158166
console.error(
159167
"Fail: There are %s joined members in this room, not 2.",
160168
room.getJoinedMembers().length

‎src/ComponentBroker.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,5 @@ require('../skins/base/views/molecules/voip/MCallAnswerTile');
109109
require('../skins/base/views/molecules/voip/MCallHangupTile');
110110
require('../skins/base/views/molecules/EventAsTextTile');
111111
require('../skins/base/views/molecules/MemberInfo');
112+
require('../skins/base/views/organisms/ErrorDialog');
112113
}

‎src/Modal.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ module.exports = {
4444
if (props && props.onFinished) props.onFinished.apply(arguments);
4545
};
4646

47+
// FIXME: If a dialog uses getDefaultProps it clobbers the onFinished
48+
// property set here so you can't close the dialog from a button click!
4749
var dialog = (
4850
<div className="mx_Dialog_Wrapper">
4951
<div className="mx_Dialog">

‎src/SlashCommands.js‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,22 +100,18 @@ var commands = {
100100
else {
101101
// attempt to join this alias.
102102
return success(
103-
MatrixClientPeg.get().joinRoom(room_alias).done(
103+
MatrixClientPeg.get().joinRoom(room_alias).then(
104104
function(room) {
105105
dis.dispatch({
106106
action: 'view_room',
107107
room_id: room.roomId
108108
});
109-
}, function(err) {
110-
console.error(
111-
"Failed to join room: %s", JSON.stringify(err)
112-
);
113109
})
114110
);
115111
}
116112
}
117113
}
118-
return reject("Usage: /join <room_alias> [NOT IMPLEMENTED]");
114+
return reject("Usage: /join <room_alias>");
119115
},
120116

121117
// Kick a user from the room with an optional reason

‎src/controllers/molecules/MessageComposer.js‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ limitations under the License.
1818

1919
var MatrixClientPeg = require("../../MatrixClientPeg");
2020
var SlashCommands = require("../../SlashCommands");
21+
var Modal = require("../../Modal");
22+
var ComponentBroker = require('../../ComponentBroker');
23+
var ErrorDialog = ComponentBroker.get("organisms/ErrorDialog");
2124

2225
var dis = require("../../dispatcher");
2326
var KeyCode = {
@@ -196,10 +199,18 @@ module.exports = {
196199
console.log("Command success.");
197200
}, function(err) {
198201
console.error("Command failure: %s", err);
202+
Modal.createDialog(ErrorDialog, {
203+
title: "Server Error",
204+
description: err.message
205+
});
199206
});
200207
}
201208
else if (cmd.error) {
202209
console.error(cmd.error);
210+
Modal.createDialog(ErrorDialog, {
211+
title: "Command Error",
212+
description: cmd.error
213+
});
203214
}
204215
return;
205216
}

0 commit comments

Comments
 (0)