if !isReview && !existsReview {
// Submit the review we've just created so the comment shows up in the issue view
- if _, _, err = SubmitReview(doer, gitRepo, issue, models.ReviewTypeComment, "", latestCommitID); err != nil {
+ if _, _, err = SubmitReview(doer, gitRepo, issue, models.ReviewTypeComment, "", latestCommitID, nil); err != nil {
return nil, err
}
}
}
// SubmitReview creates a review out of the existing pending review or creates a new one if no pending review exist
-func SubmitReview(doer *models.User, gitRepo *git.Repository, issue *models.Issue, reviewType models.ReviewType, content, commitID string) (*models.Review, *models.Comment, error) {
+func SubmitReview(doer *models.User, gitRepo *git.Repository, issue *models.Issue, reviewType models.ReviewType, content, commitID string, attachmentUUIDs []string) (*models.Review, *models.Comment, error) {
pr, err := issue.GetPullRequest()
if err != nil {
return nil, nil, err
}
}
- review, comm, err := models.SubmitReview(doer, issue, reviewType, content, commitID, stale)
+ review, comm, err := models.SubmitReview(doer, issue, reviewType, content, commitID, stale, attachmentUUIDs)
if err != nil {
return nil, nil, err
}
return files;
}
-async function uploadFile(file) {
+async function uploadFile(file, uploadUrl) {
const formData = new FormData();
formData.append('file', file, file.name);
- const res = await fetch($('#dropzone').data('upload-url'), {
+ const res = await fetch(uploadUrl, {
method: 'POST',
headers: {'X-Csrf-Token': csrf},
body: formData,
function initImagePaste(target) {
target.each(function () {
- this.addEventListener('paste', async (e) => {
- for (const img of getPastedImages(e)) {
- const name = img.name.substr(0, img.name.lastIndexOf('.'));
- insertAtCursor(this, `![${name}]()`);
- const data = await uploadFile(img);
- replaceAndKeepCursor(this, `![${name}]()`, `![${name}](${AppSubUrl}/attachments/${data.uuid})`);
- const input = $(`<input id="${data.uuid}" name="files" type="hidden">`).val(data.uuid);
- $('.files').append(input);
- }
- }, false);
+ const dropzone = this.querySelector('.dropzone');
+ if (!dropzone) {
+ return;
+ }
+ const uploadUrl = dropzone.dataset.uploadUrl;
+ const dropzoneFiles = dropzone.querySelector('.files');
+ for (const textarea of this.querySelectorAll('textarea')) {
+ textarea.addEventListener('paste', async (e) => {
+ for (const img of getPastedImages(e)) {
+ const name = img.name.substr(0, img.name.lastIndexOf('.'));
+ insertAtCursor(textarea, `![${name}]()`);
+ const data = await uploadFile(img, uploadUrl);
+ replaceAndKeepCursor(textarea, `![${name}]()`, `![${name}](${AppSubUrl}/attachments/${data.uuid})`);
+ const input = $(`<input id="${data.uuid}" name="files" type="hidden">`).val(data.uuid);
+ dropzoneFiles.appendChild(input[0]);
+ }
+ }, false);
+ }
});
}
-function initSimpleMDEImagePaste(simplemde, files) {
+function initSimpleMDEImagePaste(simplemde, dropzone, files) {
+ const uploadUrl = dropzone.dataset.uploadUrl;
simplemde.codemirror.on('paste', async (_, e) => {
for (const img of getPastedImages(e)) {
const name = img.name.substr(0, img.name.lastIndexOf('.'));
- const data = await uploadFile(img);
+ const data = await uploadFile(img, uploadUrl);
const pos = simplemde.codemirror.getCursor();
simplemde.codemirror.replaceRange(`![${name}](${AppSubUrl}/attachments/${data.uuid})`, pos);
const input = $(`<input id="${data.uuid}" name="files" type="hidden">`).val(data.uuid);
autoSimpleMDE = setCommentSimpleMDE($('.comment.form textarea:not(.review-textarea)'));
initBranchSelector();
initCommentPreviewTab($('.comment.form'));
- initImagePaste($('.comment.form textarea'));
+ initImagePaste($('.comment.form'));
// Listsubmit
function initListSubmits(selector, outerSelector) {
let dz;
const $dropzone = $editContentZone.find('.dropzone');
- const $files = $editContentZone.find('.comment-files');
- if ($dropzone.length > 0) {
+ if ($dropzone.length === 1) {
$dropzone.data('saved', false);
const filenameDict = {};
submitted: false
};
const input = $(`<input id="${data.uuid}" name="files" type="hidden">`).val(data.uuid);
- $files.append(input);
+ $dropzone.find('.files').append(input);
});
this.on('removedfile', (file) => {
if (!(file.name in filenameDict)) {
this.on('reload', () => {
$.getJSON($editContentZone.data('attachment-url'), (data) => {
dz.removeAllFiles(true);
- $files.empty();
+ $dropzone.find('.files').empty();
$.each(data, function () {
const imgSrc = `${$dropzone.data('link-url')}/${this.uuid}`;
dz.emit('addedfile', this);
};
$dropzone.find(`img[src='${imgSrc}']`).css('max-width', '100%');
const input = $(`<input id="${this.uuid}" name="files" type="hidden">`).val(this.uuid);
- $files.append(input);
+ $dropzone.find('.files').append(input);
});
});
});
$simplemde = setCommentSimpleMDE($textarea);
commentMDEditors[$editContentZone.data('write')] = $simplemde;
initCommentPreviewTab($editContentForm);
- initSimpleMDEImagePaste($simplemde, $files);
+ if ($dropzone.length === 1) {
+ initSimpleMDEImagePaste($simplemde, $dropzone[0], $dropzone.find('.files'));
+ }
$editContentZone.find('.cancel.button').on('click', () => {
$renderContent.show();
$editContentZone.find('.save.button').on('click', () => {
$renderContent.show();
$editContentZone.hide();
- const $attachments = $files.find('[name=files]').map(function () {
+ const $attachments = $dropzone.find('.files').find('[name=files]').map(function () {
return $(this).val();
}).get();
$.post($editContentZone.data('update-url'), {
$simplemde.codemirror.focus();
assingMenuAttributes(form.find('.menu'));
});
+
+ const $reviewBox = $('.review-box');
+ if ($reviewBox.length === 1) {
+ setCommentSimpleMDE($reviewBox.find('textarea'));
+ initImagePaste($reviewBox);
+ }
+
// The following part is only for diff views
if ($('.repository.pull.diff').length === 0) {
return;
};
function setCommentSimpleMDE($editArea) {
+ if ($editArea.length === 0) {
+ return null;
+ }
+
const simplemde = new SimpleMDE({
autoDownloadFontAwesome: false,
element: $editArea[0],
const $files = $editor.parent().find('.files');
const $simplemde = setCommentSimpleMDE($textarea);
initCommentPreviewTab($editor);
- initSimpleMDEImagePaste($simplemde, $files);
+ const dropzone = $editor.parent().find('.dropzone')[0];
+ initSimpleMDEImagePaste($simplemde, dropzone, $files);
}
function initOrganization() {
initLinkAccountView();
// Dropzone
- const $dropzone = $('#dropzone');
- if ($dropzone.length > 0) {
+ for (const el of document.querySelectorAll('.dropzone')) {
const filenameDict = {};
-
- await createDropzone('#dropzone', {
+ const $dropzone = $(el);
+ await createDropzone(el, {
url: $dropzone.data('upload-url'),
headers: {'X-Csrf-Token': csrf},
maxFiles: $dropzone.data('max-file'),
this.on('success', (file, data) => {
filenameDict[file.name] = data.uuid;
const input = $(`<input id="${data.uuid}" name="files" type="hidden">`).val(data.uuid);
- $('.files').append(input);
+ $dropzone.find('.files').append(input);
});
this.on('removedfile', (file) => {
if (file.name in filenameDict) {