This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/assets/javascripts/discourse/components/group-flair-inputs.js.es6
2018-06-15 17:03:24 +02:00

60 lines
1.5 KiB
JavaScript

import computed from "ember-addons/ember-computed-decorators";
import { escapeExpression } from "discourse/lib/utilities";
export default Ember.Component.extend({
classNames: ["group-flair-inputs"],
@computed
demoAvatarUrl() {
return Discourse.getURL("/images/avatar.png");
},
@computed("model.flair_url")
flairPreviewIcon(flairURL) {
return flairURL && flairURL.substr(0, 3) === "fa-";
},
@computed("model.flair_url", "flairPreviewIcon")
flairPreviewImage(flairURL, flairPreviewIcon) {
return flairURL && !flairPreviewIcon;
},
@computed(
"model.flair_url",
"flairPreviewImage",
"model.flairBackgroundHexColor",
"model.flairHexColor"
)
flairPreviewStyle(
flairURL,
flairPreviewImage,
flairBackgroundHexColor,
flairHexColor
) {
let style = "";
if (flairPreviewImage) {
style += `background-image: url(${escapeExpression(flairURL)});`;
}
if (flairBackgroundHexColor) {
style += `background-color: #${flairBackgroundHexColor};`;
}
if (flairHexColor) style += `color: #${flairHexColor};`;
return Ember.String.htmlSafe(style);
},
@computed("model.flairBackgroundHexColor")
flairPreviewClasses(flairBackgroundHexColor) {
if (flairBackgroundHexColor) return "rounded";
},
@computed("flairPreviewImage")
flairPreviewLabel(flairPreviewImage) {
const key = flairPreviewImage ? "image" : "icon";
return I18n.t(`groups.flair_preview_${key}`);
}
});