Add connect defaults readonly flag, closes #10

This commit is contained in:
Ken-Håvard Lieng 2018-04-15 01:02:28 +02:00
parent fcd204321a
commit 39641c315f
6 changed files with 96 additions and 72 deletions

File diff suppressed because one or more lines are too long

View File

@ -219,8 +219,18 @@ i[class*=' icon-']:before {
}
.connect-form h1 {
margin-bottom: 15px;
text-align: center;
margin-bottom: 15px;
}
.connect-details {
color: #999;
text-align: center;
margin-bottom: 15px;
}
.connect-details h2 {
color: #6bb758;
}
.connect-form input {

View File

@ -8,27 +8,32 @@ export default class Connect extends Component {
};
handleSubmit = e => {
const { connect, select, join } = this.props;
const { connect, select, join, defaults } = this.props;
e.preventDefault();
let address = e.target.address.value.trim();
const nick = e.target.nick.value.trim();
const channels = e.target.channels.value
.split(',')
.map(s => s.trim())
.filter(s => s);
let { address, channels } = defaults;
const opts = {
name: e.target.name.value.trim(),
tls: e.target.ssl.checked
name: defaults.name
};
if (this.state.showOptionals) {
opts.realname = e.target.realname.value.trim();
opts.username = e.target.username.value.trim();
if (!defaults.readonly) {
address = e.target.address.value.trim();
channels = e.target.channels.value
.split(',')
.map(s => s.trim())
.filter(s => s);
opts.name = e.target.name.value.trim();
opts.tls = e.target.ssl.checked;
if (this.state.passwordTouched) {
opts.password = e.target.password.value.trim();
if (this.state.showOptionals) {
opts.realname = e.target.realname.value.trim();
opts.username = e.target.username.value.trim();
if (this.state.passwordTouched) {
opts.password = e.target.password.value.trim();
}
}
}
@ -76,9 +81,24 @@ export default class Connect extends Component {
);
}
return (
<div className="connect">
<Navicon />
let form;
if (defaults.readonly) {
form = (
<form className="connect-form" onSubmit={this.handleSubmit}>
<h1>Connect</h1>
{defaults.showDetails && (
<div className="connect-details">
<h2>{defaults.address}</h2>
{defaults.channels.sort().map(channel => <p>{channel}</p>)}
</div>
)}
<input name="nick" type="text" placeholder="Nick" />
<input type="submit" value="Connect" />
</form>
);
} else {
form = (
<form className="connect-form" onSubmit={this.handleSubmit}>
<h1>Connect</h1>
<input
@ -111,6 +131,13 @@ export default class Connect extends Component {
</p>
<input type="submit" value="Connect" />
</form>
);
}
return (
<div className="connect">
<Navicon />
{form}
</div>
);
}

View File

@ -14,7 +14,9 @@ const ConnectDefaults = Record({
address: '',
channels: [],
ssl: false,
password: false
password: false,
readonly: false,
showDetails: false
});
const App = Record({

View File

@ -11,6 +11,10 @@ channels = [
]
password = ""
ssl = true
# Only allow a nick to be filled in
readonly = false
# Show server and channel info when readonly is enabled
show_details = false
[https]
enabled = false

View File

@ -11,11 +11,13 @@ import (
)
type connectDefaults struct {
Name string `json:"name"`
Address string `json:"address"`
Channels []string `json:"channels"`
Password bool `json:"password"`
SSL bool `json:"ssl"`
Name string `json:"name"`
Address string `json:"address"`
Channels []string `json:"channels"`
Password bool `json:"password,omitempty"`
SSL bool `json:"ssl,omitempty"`
ReadOnly bool `json:"readonly,omitempty"`
ShowDetails bool `json:"showDetails,omitempty"`
}
type indexData struct {
@ -78,11 +80,13 @@ func getIndexData(r *http.Request, session *Session) *indexData {
data.Channels = channels
data.Defaults = connectDefaults{
Name: viper.GetString("defaults.name"),
Address: viper.GetString("defaults.address"),
Channels: viper.GetStringSlice("defaults.channels"),
Password: viper.GetString("defaults.password") != "",
SSL: viper.GetBool("defaults.ssl"),
Name: viper.GetString("defaults.name"),
Address: viper.GetString("defaults.address"),
Channels: viper.GetStringSlice("defaults.channels"),
Password: viper.GetString("defaults.password") != "",
SSL: viper.GetBool("defaults.ssl"),
ReadOnly: viper.GetBool("defaults.readonly"),
ShowDetails: viper.GetBool("defaults.show_details"),
}
server, channel := getTabFromPath(r.URL.EscapedPath())