1
0
mirror of https://github.com/home-assistant/frontend.git synced 2025-12-20 10:48:44 +00:00
Files
frontend/js/common/component/script/index.js
Paulus Schoutsen 28457747e7 Fix eslint import extension (#682)
* Fix eslint import extension

* Update eslint hound

* Enable no unresolved for normal usage
2017-11-25 11:14:44 -08:00

51 lines
1.0 KiB
JavaScript

import { h, Component } from 'preact';
import ActionRow from './action_row.js';
export default class Script extends Component {
constructor() {
super();
this.addAction = this.addAction.bind(this);
this.actionChanged = this.actionChanged.bind(this);
}
addAction() {
const script = this.props.script.concat({
service: '',
});
this.props.onChange(script);
}
actionChanged(index, newValue) {
const script = this.props.script.concat();
if (newValue === null) {
script.splice(index, 1);
} else {
script[index] = newValue;
}
this.props.onChange(script);
}
render({ script }) {
return (
<div class="script">
{script.map((act, idx) => (
<ActionRow
index={idx}
action={act}
onChange={this.actionChanged}
/>))}
<paper-card>
<div class='card-actions add-card'>
<paper-button onTap={this.addAction}>Add action</paper-button>
</div>
</paper-card>
</div>
);
}
}