debian-mirror-gitlab/app/assets/javascripts/pages/shared/wikis/index.js

93 lines
2.3 KiB
JavaScript
Raw Normal View History

2020-06-23 00:09:42 +05:30
import $ from 'jquery';
import Vue from 'vue';
import ShortcutsWiki from '~/behaviors/shortcuts/shortcuts_wiki';
2021-04-29 21:17:54 +05:30
import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils';
2021-03-11 19:13:27 +05:30
import csrf from '~/lib/utils/csrf';
import Translate from '~/vue_shared/translate';
2020-06-23 00:09:42 +05:30
import GLForm from '../../../gl_form';
2021-03-11 19:13:27 +05:30
import ZenMode from '../../../zen_mode';
2020-06-23 00:09:42 +05:30
import deleteWikiModal from './components/delete_wiki_modal.vue';
2021-04-17 20:07:23 +05:30
import wikiAlert from './components/wiki_alert.vue';
2021-04-29 21:17:54 +05:30
import wikiForm from './components/wiki_form.vue';
2021-03-11 19:13:27 +05:30
import Wikis from './wikis';
2020-06-23 00:09:42 +05:30
2021-04-17 20:07:23 +05:30
const createModalVueApp = () => {
2020-06-23 00:09:42 +05:30
new Wikis(); // eslint-disable-line no-new
new ShortcutsWiki(); // eslint-disable-line no-new
new ZenMode(); // eslint-disable-line no-new
new GLForm($('.wiki-form')); // eslint-disable-line no-new
const deleteWikiModalWrapperEl = document.getElementById('delete-wiki-modal-wrapper');
if (deleteWikiModalWrapperEl) {
Vue.use(Translate);
const { deleteWikiUrl, pageTitle } = deleteWikiModalWrapperEl.dataset;
// eslint-disable-next-line no-new
new Vue({
el: deleteWikiModalWrapperEl,
2021-09-30 23:02:18 +05:30
data() {
return {
deleteWikiUrl: '',
};
2020-06-23 00:09:42 +05:30
},
render(createElement) {
return createElement(deleteWikiModal, {
props: {
pageTitle,
deleteWikiUrl,
csrfToken: csrf.token,
},
});
},
});
}
};
2021-04-17 20:07:23 +05:30
const createAlertVueApp = () => {
const el = document.getElementById('js-wiki-error');
if (el) {
const { error, wikiPagePath } = el.dataset;
// eslint-disable-next-line no-new
new Vue({
el,
render(createElement) {
return createElement(wikiAlert, {
props: {
error,
wikiPagePath,
},
});
},
});
}
};
2021-04-29 21:17:54 +05:30
const createWikiFormApp = () => {
const el = document.getElementById('js-wiki-form');
if (el) {
const { pageInfo, formatOptions } = el.dataset;
// eslint-disable-next-line no-new
new Vue({
el,
provide: {
formatOptions: JSON.parse(formatOptions),
pageInfo: convertObjectPropsToCamelCase(JSON.parse(pageInfo)),
},
render(createElement) {
return createElement(wikiForm);
},
});
}
};
2021-04-17 20:07:23 +05:30
export default () => {
createModalVueApp();
createAlertVueApp();
2021-04-29 21:17:54 +05:30
createWikiFormApp();
2021-04-17 20:07:23 +05:30
};