gitlab-org--gitlab-foss/app/assets/javascripts/blob_edit/blob_bundle.js

106 lines
3 KiB
JavaScript
Raw Normal View History

2018-06-16 09:20:30 -04:00
/* eslint-disable no-new */
import $ from 'jquery';
import initPopover from '~/blob/suggest_gitlab_ci_yml';
import createFlash from '~/flash';
import { disableButtonIfEmptyField, setCookie } from '~/lib/utils/common_utils';
import Tracking from '~/tracking';
import BlobFileDropzone from '../blob/blob_file_dropzone';
import NewCommitForm from '../new_commit_form';
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,
});
});
}
}
};
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 () => {
const editBlobForm = $('.js-edit-blob-form');
2017-08-01 04:50:59 -04:00
const deleteBlobForm = $('.js-delete-blob-form');
if (editBlobForm.length) {
2018-02-20 17:20:48 -05:00
const urlRoot = editBlobForm.data('relativeUrlRoot');
const assetsPath = editBlobForm.data('assetsPrefix');
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');
const isMarkdown = editBlobForm.data('is-markdown');
const previewMarkdownPath = editBlobForm.data('previewMarkdownPath');
const commitButton = $('.js-commit-button');
const cancelLink = $('#cancel-changes');
import('./edit_blob')
.then(({ default: EditBlob } = {}) => {
new EditBlob({
assetsPath: `${urlRoot}${assetsPath}`,
filePath,
currentAction,
projectId,
isMarkdown,
previewMarkdownPath,
});
initPopovers();
})
.catch((e) =>
createFlash({
message: e,
}),
);
cancelLink.on('click', () => {
window.onbeforeunload = null;
});
commitButton.on('click', () => {
window.onbeforeunload = null;
});
new NewCommitForm(editBlobForm);
// returning here blocks page navigation
window.onbeforeunload = () => '';
}
initUploadForm();
2017-08-01 04:50:59 -04:00
if (deleteBlobForm.length) {
new NewCommitForm(deleteBlobForm);
}
2018-02-21 15:22:56 -05:00
};