2018-03-09 15:18:59 -05:00
|
|
|
import $ from 'jquery';
|
2018-10-04 04:19:51 -04:00
|
|
|
import Vue from 'vue';
|
|
|
|
import Translate from '~/vue_shared/translate';
|
2017-10-10 03:47:42 -04:00
|
|
|
import { highCountTrim } from '~/lib/utils/text_utility';
|
2018-10-04 04:19:51 -04:00
|
|
|
import SetStatusModalTrigger from './set_status_modal/set_status_modal_trigger.vue';
|
|
|
|
import SetStatusModalWrapper from './set_status_modal/set_status_modal_wrapper.vue';
|
2018-11-21 10:20:32 -05:00
|
|
|
import { parseBoolean } from '~/lib/utils/common_utils';
|
2020-04-09 11:09:29 -04:00
|
|
|
import Tracking from '~/tracking';
|
2017-03-11 02:30:44 -05:00
|
|
|
|
2017-10-10 03:47:42 -04:00
|
|
|
/**
|
|
|
|
* Updates todo counter when todos are toggled.
|
|
|
|
* When count is 0, we hide the badge.
|
|
|
|
*
|
|
|
|
* @param {jQuery.Event} e
|
|
|
|
* @param {String} count
|
|
|
|
*/
|
2017-10-30 14:59:16 -04:00
|
|
|
export default function initTodoToggle() {
|
|
|
|
$(document).on('todo:toggle', (e, count) => {
|
|
|
|
const $todoPendingCount = $('.todos-count');
|
2017-10-10 03:47:42 -04:00
|
|
|
|
2019-09-18 14:06:14 -04:00
|
|
|
$todoPendingCount.text(highCountTrim(count));
|
|
|
|
$todoPendingCount.toggleClass('hidden', count === 0);
|
2017-10-30 14:59:16 -04:00
|
|
|
});
|
|
|
|
}
|
2018-10-04 04:19:51 -04:00
|
|
|
|
2019-01-08 06:25:02 -05:00
|
|
|
function initStatusTriggers() {
|
2018-10-04 04:19:51 -04:00
|
|
|
const setStatusModalTriggerEl = document.querySelector('.js-set-status-modal-trigger');
|
|
|
|
const setStatusModalWrapperEl = document.querySelector('.js-set-status-modal-wrapper');
|
|
|
|
|
|
|
|
if (setStatusModalTriggerEl || setStatusModalWrapperEl) {
|
|
|
|
Vue.use(Translate);
|
|
|
|
|
|
|
|
// eslint-disable-next-line no-new
|
|
|
|
new Vue({
|
|
|
|
el: setStatusModalTriggerEl,
|
|
|
|
data() {
|
|
|
|
const { hasStatus } = this.$options.el.dataset;
|
|
|
|
|
|
|
|
return {
|
2018-11-21 10:20:32 -05:00
|
|
|
hasStatus: parseBoolean(hasStatus),
|
2018-10-04 04:19:51 -04:00
|
|
|
};
|
|
|
|
},
|
|
|
|
render(createElement) {
|
|
|
|
return createElement(SetStatusModalTrigger, {
|
|
|
|
props: {
|
|
|
|
hasStatus: this.hasStatus,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
// eslint-disable-next-line no-new
|
|
|
|
new Vue({
|
|
|
|
el: setStatusModalWrapperEl,
|
|
|
|
data() {
|
|
|
|
const { currentEmoji, currentMessage } = this.$options.el.dataset;
|
|
|
|
|
|
|
|
return {
|
|
|
|
currentEmoji,
|
|
|
|
currentMessage,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
render(createElement) {
|
|
|
|
const { currentEmoji, currentMessage } = this;
|
|
|
|
|
|
|
|
return createElement(SetStatusModalWrapper, {
|
|
|
|
props: {
|
|
|
|
currentEmoji,
|
|
|
|
currentMessage,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
2019-01-08 06:25:02 -05:00
|
|
|
}
|
|
|
|
|
2020-04-09 11:09:29 -04:00
|
|
|
export function initNavUserDropdownTracking() {
|
|
|
|
const el = document.querySelector('.js-nav-user-dropdown');
|
|
|
|
const buyEl = document.querySelector('.js-buy-ci-minutes-link');
|
|
|
|
|
|
|
|
if (el && buyEl) {
|
|
|
|
const { trackLabel, trackProperty } = buyEl.dataset;
|
|
|
|
const trackEvent = 'show_buy_ci_minutes';
|
|
|
|
|
|
|
|
$(el).on('shown.bs.dropdown', () => {
|
|
|
|
Tracking.event(undefined, trackEvent, {
|
|
|
|
label: trackLabel,
|
|
|
|
property: trackProperty,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-08 06:25:02 -05:00
|
|
|
document.addEventListener('DOMContentLoaded', () => {
|
|
|
|
requestIdleCallback(initStatusTriggers);
|
2020-04-09 11:09:29 -04:00
|
|
|
initNavUserDropdownTracking();
|
2018-10-04 04:19:51 -04:00
|
|
|
});
|