2018-06-16 09:20:30 -04:00
|
|
|
/* eslint-disable no-new */
|
2018-03-09 15:18:59 -05:00
|
|
|
|
|
|
|
import $ from 'jquery';
|
2020-03-09 14:07:59 -04:00
|
|
|
import initPopover from '~/blob/suggest_gitlab_ci_yml';
|
2021-06-04 14:10:08 -04:00
|
|
|
import createFlash from '~/flash';
|
2020-07-15 23:09:12 -04:00
|
|
|
import { disableButtonIfEmptyField, setCookie } from '~/lib/utils/common_utils';
|
2020-04-01 14:07:56 -04:00
|
|
|
import Tracking from '~/tracking';
|
2021-02-01 10:08:56 -05:00
|
|
|
import BlobFileDropzone from '../blob/blob_file_dropzone';
|
|
|
|
import NewCommitForm from '../new_commit_form';
|
2017-03-07 19:04:20 -05:00
|
|
|
|
2020-11-12 13:09:26 -05:00
|
|
|
const initPopovers = () => {
|
|
|
|
const suggestEl = document.querySelector('.js-suggest-gitlab-ci-yml');
|
|
|
|
|
|
|
|
if (suggestEl) {
|
|
|
|
const commitButton = document.querySelector('#commit-changes');
|
|
|
|
|
|
|
|
initPopover(suggestEl);
|
|
|
|
|
|
|
|
if (commitButton) {
|
|
|
|
const { dismissKey, humanAccess } = suggestEl.dataset;
|
|
|
|
const urlParams = new URLSearchParams(window.location.search);
|
|
|
|
const mergeRequestPath = urlParams.get('mr_path') || true;
|
|
|
|
|
|
|
|
const commitCookieName = `suggest_gitlab_ci_yml_commit_${dismissKey}`;
|
|
|
|
const commitTrackLabel = 'suggest_gitlab_ci_yml_commit_changes';
|
|
|
|
const commitTrackValue = '20';
|
|
|
|
|
|
|
|
commitButton.addEventListener('click', () => {
|
|
|
|
setCookie(commitCookieName, mergeRequestPath);
|
|
|
|
|
|
|
|
Tracking.event(undefined, 'click_button', {
|
|
|
|
label: commitTrackLabel,
|
|
|
|
property: humanAccess,
|
|
|
|
value: commitTrackValue,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-12-16 01:10:11 -05:00
|
|
|
export const initUploadForm = () => {
|
|
|
|
const uploadBlobForm = $('.js-upload-blob-form');
|
|
|
|
if (uploadBlobForm.length) {
|
|
|
|
const method = uploadBlobForm.data('method');
|
|
|
|
|
|
|
|
new BlobFileDropzone(uploadBlobForm, method);
|
|
|
|
new NewCommitForm(uploadBlobForm);
|
|
|
|
|
|
|
|
disableButtonIfEmptyField(uploadBlobForm.find('.js-commit-message'), '.btn-upload-file');
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-02-21 15:22:56 -05:00
|
|
|
export default () => {
|
2017-03-07 19:04:20 -05:00
|
|
|
const editBlobForm = $('.js-edit-blob-form');
|
2017-08-01 04:50:59 -04:00
|
|
|
const deleteBlobForm = $('.js-delete-blob-form');
|
2017-03-07 19:04:20 -05:00
|
|
|
|
|
|
|
if (editBlobForm.length) {
|
2018-02-20 17:20:48 -05:00
|
|
|
const urlRoot = editBlobForm.data('relativeUrlRoot');
|
|
|
|
const assetsPath = editBlobForm.data('assetsPrefix');
|
2019-03-07 07:35:07 -05:00
|
|
|
const filePath = `${editBlobForm.data('blobFilename')}`;
|
2018-02-20 17:20:48 -05:00
|
|
|
const currentAction = $('.js-file-title').data('currentAction');
|
2018-10-02 19:00:38 -04:00
|
|
|
const projectId = editBlobForm.data('project-id');
|
2018-12-14 12:56:25 -05:00
|
|
|
const isMarkdown = editBlobForm.data('is-markdown');
|
2021-08-24 11:10:36 -04:00
|
|
|
const previewMarkdownPath = editBlobForm.data('previewMarkdownPath');
|
2018-11-27 05:05:25 -05:00
|
|
|
const commitButton = $('.js-commit-button');
|
2022-03-05 01:19:08 -05:00
|
|
|
const cancelLink = $('#cancel-changes');
|
2018-12-13 16:27:23 -05:00
|
|
|
|
2020-10-16 11:08:46 -04:00
|
|
|
import('./edit_blob')
|
|
|
|
.then(({ default: EditBlob } = {}) => {
|
|
|
|
new EditBlob({
|
|
|
|
assetsPath: `${urlRoot}${assetsPath}`,
|
|
|
|
filePath,
|
|
|
|
currentAction,
|
|
|
|
projectId,
|
|
|
|
isMarkdown,
|
2021-08-24 11:10:36 -04:00
|
|
|
previewMarkdownPath,
|
2020-10-16 11:08:46 -04:00
|
|
|
});
|
2020-11-12 13:09:26 -05:00
|
|
|
initPopovers();
|
2020-10-16 11:08:46 -04:00
|
|
|
})
|
2021-06-04 14:10:08 -04:00
|
|
|
.catch((e) =>
|
|
|
|
createFlash({
|
|
|
|
message: e,
|
|
|
|
}),
|
|
|
|
);
|
2020-10-16 11:08:46 -04:00
|
|
|
|
2018-12-13 16:27:23 -05:00
|
|
|
cancelLink.on('click', () => {
|
|
|
|
window.onbeforeunload = null;
|
|
|
|
});
|
2018-11-27 05:05:25 -05:00
|
|
|
|
|
|
|
commitButton.on('click', () => {
|
|
|
|
window.onbeforeunload = null;
|
|
|
|
});
|
2017-03-07 19:04:20 -05:00
|
|
|
|
|
|
|
new NewCommitForm(editBlobForm);
|
2018-11-27 05:05:25 -05:00
|
|
|
|
|
|
|
// returning here blocks page navigation
|
|
|
|
window.onbeforeunload = () => '';
|
2017-03-07 19:04:20 -05:00
|
|
|
}
|
|
|
|
|
2020-12-16 01:10:11 -05:00
|
|
|
initUploadForm();
|
2017-08-01 04:50:59 -04:00
|
|
|
|
|
|
|
if (deleteBlobForm.length) {
|
|
|
|
new NewCommitForm(deleteBlobForm);
|
|
|
|
}
|
2018-02-21 15:22:56 -05:00
|
|
|
};
|