mirror of
https://github.com/discourse/discourse.git
synced 2025-02-06 04:34:59 +08:00
50 lines
1.5 KiB
JavaScript
50 lines
1.5 KiB
JavaScript
import DropdownButton from 'discourse/components/dropdown-button';
|
|
import { allLevels, buttonDetails } from 'discourse/lib/notification-levels';
|
|
import { iconHTML } from 'discourse-common/helpers/fa-icon';
|
|
import computed from 'ember-addons/ember-computed-decorators';
|
|
|
|
export default DropdownButton.extend({
|
|
classNames: ['notification-options'],
|
|
title: '',
|
|
buttonIncludesText: true,
|
|
activeItem: Em.computed.alias('notificationLevel'),
|
|
i18nPrefix: '',
|
|
i18nPostfix: '',
|
|
|
|
@computed
|
|
dropDownContent() {
|
|
const prefix = this.get('i18nPrefix');
|
|
const postfix = this.get('i18nPostfix');
|
|
|
|
return allLevels.map(l => {
|
|
const start = `${prefix}.${l.key}${postfix}`;
|
|
return {
|
|
id: l.id,
|
|
title: I18n.t(`${start}.title`),
|
|
description: I18n.t(`${start}.description`),
|
|
styleClasses: `${l.key} fa fa-${l.icon}`
|
|
};
|
|
});
|
|
},
|
|
|
|
@computed('notificationLevel')
|
|
text(notificationLevel) {
|
|
const details = buttonDetails(notificationLevel);
|
|
const { key } = details;
|
|
const icon = iconHTML(details.icon, { class: key });
|
|
|
|
if (this.get('buttonIncludesText')) {
|
|
const prefix = this.get('i18nPrefix');
|
|
const postfix = this.get('i18nPostfix');
|
|
const text = I18n.t(`${prefix}.${key}${postfix}.title`);
|
|
return `${icon} ${text}<span class='caret'></span>`;
|
|
} else {
|
|
return `${icon} <span class='caret'></span>`;
|
|
}
|
|
},
|
|
|
|
clicked(/* id */) {
|
|
// sub-class needs to implement this
|
|
}
|
|
});
|