FIX: When faq_url is custom, track the FAQ clicks

This commit is contained in:
Robin Ward 2016-08-11 13:43:42 -04:00
parent 35922bf692
commit cd371fa20e
2 changed files with 27 additions and 10 deletions

View file

@ -2,7 +2,6 @@ import { ajax } from 'discourse/lib/ajax';
import computed from 'ember-addons/ember-computed-decorators';
export default Ember.Controller.extend({
needs: ['application'],
showLoginButton: Em.computed.equal("model.path", "login"),

View file

@ -1,17 +1,33 @@
import { createWidget, applyDecorators } from 'discourse/widgets/widget';
import { h } from 'virtual-dom';
import DiscourseURL from 'discourse/lib/url';
import { ajax } from 'discourse/lib/ajax';
createWidget('priority-faq-link', {
tagName: 'a.faq-priority',
buildAttributes(attrs) {
return { href: attrs.href };
},
html() {
return [ I18n.t('faq'), ' ', h('span.badge.badge-notification', I18n.t('new_item')) ];
},
click(e) {
if (this.siteSettings.faq_url === this.attrs.href) {
e.preventDefault();
ajax("/users/read-faq", { method: "POST" }).then(() => {
this.currentUser.set('read_faq', true);
return DiscourseURL.routeToTag($(e.target).closest('a')[0]);
});
}
}
});
export default createWidget('hamburger-menu', {
tagName: 'div.hamburger-panel',
faqLink(href) {
return h('a.faq-priority', { attributes: { href } }, [
I18n.t('faq'),
' ',
h('span.badge.badge-notification', I18n.t('new_item'))
]);
},
adminLinks() {
const { currentUser } = this;
@ -139,7 +155,9 @@ export default createWidget('hamburger-menu', {
const prioritizeFaq = this.currentUser && !this.currentUser.read_faq;
if (prioritizeFaq) {
results.push(this.attach('menu-links', { heading: true, contents: () => this.faqLink(faqUrl) }));
results.push(this.attach('menu-links', { heading: true, contents: () => {
return this.attach('priority-faq-link', { href: faqUrl });
}}));
}
if (currentUser && currentUser.staff) {