snappymail/dev/Component/Select.js

57 lines
1.4 KiB
JavaScript
Raw Normal View History

import { SaveSettingStatus } from 'Common/Enums';
import { dispose, koComputable } from 'External/ko';
import { defaultOptionsAfterRender } from 'Common/Utils';
2015-11-15 08:23:16 +08:00
export class SelectComponent {
2015-11-15 08:23:16 +08:00
/**
* @param {Object} params
*/
constructor(params) {
2022-10-10 19:52:56 +08:00
this.value = params.value;
this.label = params.label;
this.trigger = params.trigger?.subscribe ? params.trigger : null;
2022-10-10 19:52:56 +08:00
this.placeholder = params.placeholder;
this.options = params.options;
this.optionsText = params.optionsText;
this.optionsValue = params.optionsValue;
let size = 0 < params.size ? 'span' + params.size : '';
if (this.trigger) {
const
classForTrigger = ko.observable(''),
setTriggerState = value => {
2022-10-10 19:52:56 +08:00
switch (value) {
case SaveSettingStatus.Success:
classForTrigger('success');
break;
case SaveSettingStatus.Failed:
classForTrigger('error');
break;
default:
classForTrigger('');
break;
}
};
setTriggerState(this.trigger());
this.className = koComputable(() =>
(size + ' settings-save-trigger-input ' + classForTrigger()).trim()
);
this.disposables = [
this.trigger.subscribe(setTriggerState, this),
this.className
];
} else {
this.className = size;
}
2015-11-15 08:23:16 +08:00
this.defaultOptionsAfterRender = defaultOptionsAfterRender;
2015-11-15 08:23:16 +08:00
}
dispose() {
2022-10-10 19:52:56 +08:00
this.disposables?.forEach(dispose);
}
2015-11-15 08:23:16 +08:00
}