snappymail/dev/Component/SaveTrigger.js

39 lines
1,021 B
JavaScript
Raw Normal View History

2019-07-05 03:19:24 +08:00
import { SaveSettingsStep } from 'Common/Enums';
import { AbstractComponent } from 'Component/Abstract';
2015-11-15 08:23:16 +08:00
export class SaveTriggerComponent extends AbstractComponent {
2015-11-15 08:23:16 +08:00
/**
* @param {Object} params
*/
constructor(params) {
super();
const el = params.element;
this.element = el || null;
2015-11-15 08:23:16 +08:00
this.value = params.value && params.value.subscribe ? params.value : null;
if (el) {
2019-07-05 03:19:24 +08:00
if (this.value) {
el.style.display = 'inline-block';
2015-11-15 08:23:16 +08:00
2019-07-05 03:19:24 +08:00
if (params.verticalAlign) {
el.style.verticalAlign = params.verticalAlign;
2015-11-15 08:23:16 +08:00
}
this.setState(this.value());
2019-07-05 03:19:24 +08:00
this.disposable.push(this.value.subscribe(this.setState, this));
} else {
el.style.display = 'none';
2015-11-15 08:23:16 +08:00
}
}
}
setState(value) {
value = parseInt(value,10);
this.element.querySelector('.icon-spinner').hidden = value !== SaveSettingsStep.Animate;
this.element.querySelector('.success').hidden = value !== SaveSettingsStep.TrueResult;
this.element.querySelector('.error').hidden = value !== SaveSettingsStep.FalseResult;
2016-04-21 01:12:51 +08:00
}
2015-11-15 08:23:16 +08:00
}