mirror of
https://github.com/the-djmaze/snappymail.git
synced 2024-11-15 20:24:51 +08:00
1423b88839
Added material design checkbox component Added lang changing animation
90 lines
1.9 KiB
JavaScript
90 lines
1.9 KiB
JavaScript
|
|
(function () {
|
|
|
|
'use strict';
|
|
|
|
var
|
|
_ = require('_'),
|
|
ko = require('ko'),
|
|
|
|
Enums = require('Common/Enums'),
|
|
Utils = require('Common/Utils'),
|
|
|
|
AbstractComponent = require('Component/Abstract')
|
|
;
|
|
|
|
/**
|
|
* @constructor
|
|
*
|
|
* @param {Object} oParams
|
|
*
|
|
* @extends AbstractComponent
|
|
*/
|
|
function AbstractInput(oParams) {
|
|
|
|
AbstractComponent.call(this);
|
|
|
|
this.value = oParams.value || '';
|
|
this.size = oParams.size || 0;
|
|
this.label = oParams.label || '';
|
|
this.enable = oParams.enable || true;
|
|
this.trigger = oParams.trigger && oParams.trigger.subscribe ? oParams.trigger : null;
|
|
this.placeholder = oParams.placeholder || '';
|
|
|
|
this.labeled = !Utils.isUnd(oParams.label);
|
|
this.triggered = !Utils.isUnd(oParams.trigger) && !!this.trigger;
|
|
|
|
this.classForTrigger = ko.observable('');
|
|
|
|
this.className = ko.computed(function () {
|
|
|
|
var
|
|
iSize = ko.unwrap(this.size),
|
|
sSuffixValue = this.trigger ?
|
|
' ' + Utils.trim('settings-saved-trigger-input ' + this.classForTrigger()) : ''
|
|
;
|
|
|
|
return (0 < iSize ? 'span' + iSize : '') + sSuffixValue;
|
|
|
|
}, this);
|
|
|
|
if (!Utils.isUnd(oParams.width) && oParams.element)
|
|
{
|
|
oParams.element.find('input,select,textarea').css('width', oParams.width);
|
|
}
|
|
|
|
this.disposable.push(this.className);
|
|
|
|
if (this.trigger)
|
|
{
|
|
this.setTriggerState(this.trigger());
|
|
|
|
this.disposable.push(
|
|
this.trigger.subscribe(this.setTriggerState, this)
|
|
);
|
|
}
|
|
};
|
|
|
|
AbstractInput.prototype.setTriggerState = function (nValue)
|
|
{
|
|
switch (Utils.pInt(nValue))
|
|
{
|
|
case Enums.SaveSettingsStep.TrueResult:
|
|
this.classForTrigger('success');
|
|
break;
|
|
case Enums.SaveSettingsStep.FalseResult:
|
|
this.classForTrigger('error');
|
|
break;
|
|
default:
|
|
this.classForTrigger('');
|
|
break;
|
|
}
|
|
};
|
|
|
|
_.extend(AbstractInput.prototype, AbstractComponent.prototype);
|
|
|
|
AbstractInput.componentExportHelper = AbstractComponent.componentExportHelper;
|
|
|
|
module.exports = AbstractInput;
|
|
|
|
}());
|