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';
|
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 parsedCount = parseInt(count, 10);
|
|
|
|
const $todoPendingCount = $('.todos-count');
|
2017-10-10 03:47:42 -04:00
|
|
|
|
2017-10-30 14:59:16 -04:00
|
|
|
$todoPendingCount.text(highCountTrim(parsedCount));
|
|
|
|
$todoPendingCount.toggleClass('hidden', parsedCount === 0);
|
|
|
|
});
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
|
|
|
document.addEventListener('DOMContentLoaded', () => {
|
|
|
|
requestIdleCallback(initStatusTriggers);
|
2018-10-04 04:19:51 -04:00
|
|
|
});
|