snappymail/dev/Component/SaveTrigger.js

95 lines
1.9 KiB
JavaScript
Raw Normal View History

2014-10-29 06:05:50 +08:00
(function () {
'use strict';
var
_ = require('_'),
Enums = require('Common/Enums'),
Utils = require('Common/Utils'),
AbstractComponent = require('Component/Abstract')
2014-10-29 06:05:50 +08:00
;
/**
* @constructor
*
* @param {Object} oParams
*
* @extends AbstractComponent
*/
2014-10-30 23:09:48 +08:00
function SaveTriggerComponent(oParams)
{
2014-10-29 06:05:50 +08:00
AbstractComponent.call(this);
this.element = oParams.element || null;
this.value = oParams.value && oParams.value.subscribe ? oParams.value : null;
if (this.element)
{
if (this.value)
{
this.element.css('display', 'inline-block');
if (oParams.verticalAlign)
{
this.element.css('vertical-align', oParams.verticalAlign);
}
2014-10-29 06:05:50 +08:00
this.setState(this.value());
this.disposable.push(
this.value.subscribe(this.setState, this)
);
}
else
{
this.element.hide();
}
}
2014-10-30 23:09:48 +08:00
}
2014-10-29 06:05:50 +08:00
SaveTriggerComponent.prototype.setState = function (nValue)
{
switch (Utils.pInt(nValue))
{
case Enums.SaveSettingsStep.TrueResult:
this.element
.find('.animated,.error').hide().removeClass('visible')
.end()
.find('.success').show().addClass('visible')
;
break;
case Enums.SaveSettingsStep.FalseResult:
this.element
.find('.animated,.success').hide().removeClass('visible')
.end()
.find('.error').show().addClass('visible')
;
break;
case Enums.SaveSettingsStep.Animate:
this.element
.find('.error,.success').hide().removeClass('visible')
.end()
.find('.animated').show().addClass('visible')
;
break;
default:
2014-10-30 23:09:48 +08:00
case Enums.SaveSettingsStep.Idle:
2014-10-29 06:05:50 +08:00
this.element
.find('.animated').hide()
.end()
.find('.error,.success').removeClass('visible')
;
break;
}
};
_.extend(SaveTriggerComponent.prototype, AbstractComponent.prototype);
module.exports = AbstractComponent.componentExportHelper(
SaveTriggerComponent, 'SaveTriggerComponent');
}());