debian-mirror-gitlab/app/assets/javascripts/blob_edit/blob_bundle.js

87 lines
2.5 KiB
JavaScript
Raw Normal View History

2018-11-08 19:23:39 +05:30
/* eslint-disable no-new */
2018-05-09 12:01:36 +05:30
import $ from 'jquery';
2018-03-17 18:26:18 +05:30
import NewCommitForm from '../new_commit_form';
2017-08-17 22:00:37 +05:30
import EditBlob from './edit_blob';
import BlobFileDropzone from '../blob/blob_file_dropzone';
2020-04-08 14:13:33 +05:30
import initPopover from '~/blob/suggest_gitlab_ci_yml';
2020-04-22 19:07:51 +05:30
import { setCookie } from '~/lib/utils/common_utils';
import Tracking from '~/tracking';
2017-08-17 22:00:37 +05:30
2018-03-27 19:54:05 +05:30
export default () => {
2017-08-17 22:00:37 +05:30
const editBlobForm = $('.js-edit-blob-form');
const uploadBlobForm = $('.js-upload-blob-form');
2017-09-10 17:25:29 +05:30
const deleteBlobForm = $('.js-delete-blob-form');
2020-04-08 14:13:33 +05:30
const suggestEl = document.querySelector('.js-suggest-gitlab-ci-yml');
2017-08-17 22:00:37 +05:30
if (editBlobForm.length) {
2018-03-27 19:54:05 +05:30
const urlRoot = editBlobForm.data('relativeUrlRoot');
const assetsPath = editBlobForm.data('assetsPrefix');
2019-07-07 11:18:12 +05:30
const filePath = `${editBlobForm.data('blobFilename')}`;
2018-03-27 19:54:05 +05:30
const currentAction = $('.js-file-title').data('currentAction');
2018-12-05 23:21:45 +05:30
const projectId = editBlobForm.data('project-id');
2019-02-15 15:39:39 +05:30
const isMarkdown = editBlobForm.data('is-markdown');
const commitButton = $('.js-commit-button');
const cancelLink = $('.btn.btn-cancel');
cancelLink.on('click', () => {
window.onbeforeunload = null;
});
commitButton.on('click', () => {
window.onbeforeunload = null;
});
new EditBlob({
assetsPath: `${urlRoot}${assetsPath}`,
filePath,
currentAction,
projectId,
isMarkdown,
});
2017-08-17 22:00:37 +05:30
new NewCommitForm(editBlobForm);
2019-02-15 15:39:39 +05:30
// returning here blocks page navigation
window.onbeforeunload = () => '';
2017-08-17 22:00:37 +05:30
}
if (uploadBlobForm.length) {
const method = uploadBlobForm.data('method');
new BlobFileDropzone(uploadBlobForm, method);
new NewCommitForm(uploadBlobForm);
window.gl.utils.disableButtonIfEmptyField(
uploadBlobForm.find('.js-commit-message'),
'.btn-upload-file',
);
}
2017-09-10 17:25:29 +05:30
if (deleteBlobForm.length) {
new NewCommitForm(deleteBlobForm);
}
2020-04-08 14:13:33 +05:30
if (suggestEl) {
2020-04-22 19:07:51 +05:30
const commitButton = document.querySelector('#commit-changes');
2020-04-08 14:13:33 +05:30
initPopover(suggestEl);
2020-04-22 19:07:51 +05:30
if (commitButton) {
const { dismissKey, humanAccess } = suggestEl.dataset;
const commitCookieName = `suggest_gitlab_ci_yml_commit_${dismissKey}`;
const commitTrackLabel = 'suggest_gitlab_ci_yml_commit_changes';
const commitTrackValue = '20';
commitButton.addEventListener('click', () => {
setCookie(commitCookieName, true);
Tracking.event(undefined, 'click_button', {
label: commitTrackLabel,
property: humanAccess,
value: commitTrackValue,
});
});
}
2020-04-08 14:13:33 +05:30
}
2018-03-27 19:54:05 +05:30
};