2015-11-15 08:23:16 +08:00
|
|
|
|
2016-06-07 05:57:52 +08:00
|
|
|
import {pInt} from 'Common/Utils';
|
2015-11-15 08:23:16 +08:00
|
|
|
import {SaveSettingsStep} from 'Common/Enums';
|
|
|
|
import {AbstractComponent, componentExportHelper} from 'Component/Abstract';
|
|
|
|
|
|
|
|
class SaveTriggerComponent extends AbstractComponent
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @param {Object} params
|
|
|
|
*/
|
|
|
|
constructor(params) {
|
|
|
|
|
|
|
|
super();
|
|
|
|
|
|
|
|
this.element = params.element || null;
|
|
|
|
this.value = params.value && params.value.subscribe ? params.value : null;
|
|
|
|
|
|
|
|
if (this.element)
|
|
|
|
{
|
|
|
|
if (this.value)
|
|
|
|
{
|
|
|
|
this.element.css('display', 'inline-block');
|
|
|
|
|
|
|
|
if (params.verticalAlign)
|
|
|
|
{
|
|
|
|
this.element.css('vertical-align', params.verticalAlign);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.setState(this.value());
|
|
|
|
|
|
|
|
this.disposable.push(
|
|
|
|
this.value.subscribe(this.setState, this)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.element.hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
setState(value) {
|
|
|
|
|
2016-06-07 05:57:52 +08:00
|
|
|
switch (pInt(value))
|
2015-11-15 08:23:16 +08:00
|
|
|
{
|
|
|
|
case SaveSettingsStep.TrueResult:
|
|
|
|
this.element
|
|
|
|
.find('.animated,.error').hide().removeClass('visible')
|
|
|
|
.end()
|
2016-06-30 08:02:45 +08:00
|
|
|
.find('.success').show().addClass('visible');
|
2015-11-15 08:23:16 +08:00
|
|
|
break;
|
|
|
|
case SaveSettingsStep.FalseResult:
|
|
|
|
this.element
|
|
|
|
.find('.animated,.success').hide().removeClass('visible')
|
|
|
|
.end()
|
2016-06-30 08:02:45 +08:00
|
|
|
.find('.error').show().addClass('visible');
|
2015-11-15 08:23:16 +08:00
|
|
|
break;
|
|
|
|
case SaveSettingsStep.Animate:
|
|
|
|
this.element
|
|
|
|
.find('.error,.success').hide().removeClass('visible')
|
|
|
|
.end()
|
2016-06-30 08:02:45 +08:00
|
|
|
.find('.animated').show().addClass('visible');
|
2015-11-15 08:23:16 +08:00
|
|
|
break;
|
|
|
|
case SaveSettingsStep.Idle:
|
2016-06-30 08:02:45 +08:00
|
|
|
default:
|
2015-11-15 08:23:16 +08:00
|
|
|
this.element
|
|
|
|
.find('.animated').hide()
|
|
|
|
.end()
|
2016-06-30 08:02:45 +08:00
|
|
|
.find('.error,.success').removeClass('visible');
|
2015-11-15 08:23:16 +08:00
|
|
|
break;
|
|
|
|
}
|
2016-04-21 01:12:51 +08:00
|
|
|
}
|
2015-11-15 08:23:16 +08:00
|
|
|
}
|
|
|
|
|
2017-03-01 02:44:13 +08:00
|
|
|
export default componentExportHelper(SaveTriggerComponent, 'SaveTriggerComponent');
|