Files
sprocket-ui/src/app/components/LedStripPatternSwitch.js
2018-05-10 22:23:58 +02:00

40 lines
1.3 KiB
JavaScript

import $ from 'jquery';
import Switch from './base/Switch/Switch';
import Store from '../core/store/RestStore';
export default class LedStripPatternSwitch extends Switch {
constructor(ctx, node) {
super(ctx, node);
this.store = new Store(this.config.endpoint);
this.modes = ["init", "Color", "Pattern", "octoPrint"];
this.patterns = [ "none", "Rainbow", "Scanner", "ColorWipe", "TheaterChase"];
}
onClick(evt) {
// FIXME separate mode from pattern
let payload = {
id: this.patterns.indexOf(this.config.name),
pattern: this.config.name.substring(0,1),
group: this.config.group,
mode: 'P',
state: this.state
};
this.ctx.mediator.trigger('/ledStripPreset/switched', payload);
}
subscribe() {
this.ctx.mediator.on('/ledStripPreset/switched', (payload) => {
this.store.save(payload);
if (payload.state
&& payload.id !== this.patterns.indexOf(this.config.name)
&& payload.group === this.config.group) {
if (this.state) {
this.state = false;
this.node.find('input').click();
}
}
});
}
}