2018-09-22 14:03:30 +10:00
|
|
|
import { createWidget } from 'discourse/widgets/widget';
|
|
|
|
|
import { h } from 'virtual-dom';
|
|
|
|
|
import { avatarFor } from 'discourse/widgets/post';
|
|
|
|
|
|
|
|
|
|
function donationDisplay(amount, type) {
|
|
|
|
|
return h(`div.donations-${type}`, [
|
|
|
|
|
h('span', I18n.t(`discourse_donations.cause.category.${type}`)),
|
|
|
|
|
h('span', `$${(amount/100).toFixed(2)}`)
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
createWidget('category-header-widget', {
|
|
|
|
|
tagName: 'span',
|
|
|
|
|
|
2018-09-23 08:36:28 +10:00
|
|
|
html(args) {
|
|
|
|
|
if (args.currentPath.toLowerCase().indexOf('category') === -1) return;
|
|
|
|
|
|
2018-09-23 08:44:50 +10:00
|
|
|
const controller = this.register.lookup('controller:navigation/category');
|
|
|
|
|
const category = controller.get("category");
|
2018-09-22 14:03:30 +10:00
|
|
|
|
2018-09-23 08:36:28 +10:00
|
|
|
if (category && category.donations_cause) {
|
2018-09-22 14:03:30 +10:00
|
|
|
$("body").addClass("donations-category");
|
|
|
|
|
|
|
|
|
|
let contents = [
|
|
|
|
|
h('div.donations-category-contents', [
|
|
|
|
|
h('h1', category.name),
|
|
|
|
|
h('div.category-title-description', h('p', category.description_text))
|
2018-09-23 08:44:50 +10:00
|
|
|
])
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
let metadata = [
|
|
|
|
|
donationDisplay(category.donations_total || 0, 'total'),
|
|
|
|
|
donationDisplay(category.donations_month || 0, 'month')
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
if (category.donations_github) {
|
|
|
|
|
metadata.push(
|
2018-09-22 14:03:30 +10:00
|
|
|
h('div.donations-github', this.attach('link', {
|
|
|
|
|
icon: 'github',
|
|
|
|
|
label: 'discourse_donations.cause.github.label',
|
|
|
|
|
href: category.donations_github
|
2018-09-23 08:44:50 +10:00
|
|
|
}))
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (category.donations_meta) {
|
|
|
|
|
metadata.push(
|
2018-09-22 17:48:38 +10:00
|
|
|
h('div.donations-meta', this.attach('link', {
|
|
|
|
|
href: category.donations_meta,
|
|
|
|
|
contents: () => {
|
|
|
|
|
return [
|
2018-09-23 08:44:50 +10:00
|
|
|
h('img.meta-icon', {
|
|
|
|
|
attributes: {
|
|
|
|
|
src: 'https://discourse-meta.s3.dualstack.us-west-1.amazonaws.com/original/3X/b/1/b19ba793155a785bbd9707bc0cabbd3a987fa126.png?v=6'
|
|
|
|
|
}
|
|
|
|
|
}),
|
2018-09-22 17:48:38 +10:00
|
|
|
h('span', I18n.t('discourse_donations.cause.meta.label'))
|
|
|
|
|
];
|
|
|
|
|
}
|
2018-09-22 14:03:30 +10:00
|
|
|
}))
|
2018-09-23 08:44:50 +10:00
|
|
|
);
|
|
|
|
|
}
|
2018-09-22 14:03:30 +10:00
|
|
|
|
2018-09-23 08:44:50 +10:00
|
|
|
contents.push(h('div.donations-category-metadata', metadata));
|
|
|
|
|
|
|
|
|
|
let users = [];
|
2018-09-22 14:03:30 +10:00
|
|
|
|
|
|
|
|
if (category.donations_backers.length) {
|
2018-09-23 08:44:50 +10:00
|
|
|
users.push(h('div.donations-backers', [
|
2018-09-22 14:03:30 +10:00
|
|
|
h('div.donations-backers-title', I18n.t('discourse_donations.cause.backers.label')),
|
|
|
|
|
category.donations_backers.map(user => {
|
|
|
|
|
return avatarFor('medium', {
|
|
|
|
|
template: user.avatar_template,
|
|
|
|
|
username: user.username,
|
|
|
|
|
name: user.name,
|
|
|
|
|
url: user.usernameUrl,
|
|
|
|
|
className: "backer-avatar"
|
|
|
|
|
});
|
|
|
|
|
})
|
|
|
|
|
]));
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (category.donations_maintainers.length) {
|
2018-09-23 08:44:50 +10:00
|
|
|
users.push(h('div.donations-maintainers', [
|
2018-09-22 14:03:30 +10:00
|
|
|
h('div.donations-maintainers-title', I18n.t('discourse_donations.cause.maintainers.label')),
|
|
|
|
|
category.donations_maintainers.map(user => {
|
|
|
|
|
if (user) {
|
|
|
|
|
return avatarFor('medium', {
|
|
|
|
|
template: user.avatar_template,
|
|
|
|
|
username: user.username,
|
|
|
|
|
name: user.name,
|
|
|
|
|
url: user.usernameUrl,
|
|
|
|
|
className: "maintainer-avatar"
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
]));
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-23 08:44:50 +10:00
|
|
|
if (users.length) {
|
|
|
|
|
contents.push(h('div.donations-category-users', users));
|
2018-09-22 14:03:30 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return h('div.donations-category-header', {
|
|
|
|
|
"attributes" : {
|
|
|
|
|
"style" : "background-color: #" + category.color + "; color: #" + category.text_color + ";"
|
|
|
|
|
}
|
|
|
|
|
}, contents);
|
|
|
|
|
} else {
|
|
|
|
|
$("body").removeClass("donations-category");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|