2014-10-29 06:05:50 +08:00
|
|
|
|
|
|
|
(function () {
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var
|
|
|
|
_ = require('_'),
|
|
|
|
ko = require('ko'),
|
|
|
|
|
|
|
|
Enums = require('Common/Enums'),
|
|
|
|
Utils = require('Common/Utils'),
|
|
|
|
|
2014-10-30 05:08:53 +08:00
|
|
|
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 AbstractInput(oParams)
|
|
|
|
{
|
2014-10-29 06:05:50 +08:00
|
|
|
AbstractComponent.call(this);
|
|
|
|
|
|
|
|
this.value = oParams.value || '';
|
|
|
|
this.size = oParams.size || 0;
|
|
|
|
this.label = oParams.label || '';
|
2014-10-31 04:09:53 +08:00
|
|
|
this.enable = Utils.isUnd(oParams.enable) ? true : oParams.enable;
|
2014-10-29 06:05:50 +08:00
|
|
|
this.trigger = oParams.trigger && oParams.trigger.subscribe ? oParams.trigger : null;
|
2014-10-30 05:08:53 +08:00
|
|
|
this.placeholder = oParams.placeholder || '';
|
2014-10-29 06:05:50 +08:00
|
|
|
|
|
|
|
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)
|
|
|
|
);
|
|
|
|
}
|
2014-10-30 23:09:48 +08:00
|
|
|
}
|
2014-10-29 06:05:50 +08:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
}());
|