Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show Pastebin Attachment if File/Input Already Uploaded #22813

Merged
merged 3 commits into from
Nov 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions static/js/zamboni/reviewers.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,19 +303,22 @@ function initExtraReviewActions() {
}),
);

$('#toggle_attachment_file').on('click', function (e) {
e.preventDefault();
$('#attachment-type-toggle').addClass('hidden');
$('#attachment_input_wrapper').addClass('hidden');
const showFileWrapper = (e) => {
e?.preventDefault();
$('#attachment-type-toggle, #attachment_input_wrapper').addClass('hidden');
$('#attachment_file_wrapper').removeClass('hidden');
});

$('#toggle_attachment_input').on('click', function (e) {
e.preventDefault();
$('#attachment-type-toggle').addClass('hidden');
$('#attachment_file_wrapper').addClass('hidden');
};
const showInputWrapper = (e) => {
e?.preventDefault();
$('#attachment-type-toggle, #attachment_file_wrapper').addClass('hidden');
$('#attachment_input_wrapper').removeClass('hidden');
});
};

$('#id_attachment_file').prop('files').length && showFileWrapper();
Copy link
Contributor

@KevinMind KevinMind Nov 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My jquery days are long gone but my understanding is this code will execute one time on page load, or when that element is in the dom? It's not totally clear since there is no explicit event trigger. Is it possible to do that somehow or maybe add a comment indicating when this code is/should be executed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once on page load, yeah -- initExtraReviewActions() is called on document ready.

I could add a comment, but it feels like something that would really be relevant to the entire function rather than a comment singling out this particular line within it?

$('#id_attachment_input').val() && showInputWrapper();

$('#toggle_attachment_file').on('click', showFileWrapper);
$('#toggle_attachment_input').on('click', showInputWrapper);

// One-off-style buttons.
$('.more-actions button.oneoff[data-api-url]').click(
Expand Down
Loading