Skip to content
Snippets Groups Projects
Verified Commit 1ffff63f authored by Antoine R. Dumont's avatar Antoine R. Dumont
Browse files

save-code-now: Extract the checkbox filtering into a js template

This will allow to reuse that part inside the add-forge-now form as well.

Related to T4011
parent 8d5f258e
No related branches found
No related tags found
No related merge requests found
......@@ -9,6 +9,7 @@ import {csrfPost, handleFetchError, isGitRepoUrl, htmlAlert, removeUrlFragment,
getCanonicalOriginURL, getHumanReadableDate} from 'utils/functions';
import {swhSpinnerSrc} from 'utils/constants';
import artifactFormRowTemplate from './artifact-form-row.ejs';
import userRequestsFilterCheckboxFn from 'utils/requests-filter-checkbox.ejs';
let saveRequestsTable;
......@@ -103,15 +104,11 @@ export function deleteArtifactFormRow(event) {
$(event.target).closest('.swh-save-origin-artifact-form').remove();
}
const userRequestsFilterCheckbox = `
<div class="custom-control custom-checkbox swhid-option">
<input class="custom-control-input" value="option-user-requests-filter" type="checkbox"
id="swh-save-requests-user-filter">
<label class="custom-control-label font-weight-normal" for="swh-save-requests-user-filter">
show only your own requests
</label>
</div>
`;
const saveRequestCheckboxId = 'swh-save-requests-user-filter';
const userRequestsFilterCheckbox = userRequestsFilterCheckboxFn({
'inputId': saveRequestCheckboxId,
'checked': false // no filtering by default on that view
});
export function initOriginSave() {
......@@ -136,7 +133,7 @@ export function initOriginSave() {
ajax: {
url: Urls.origin_save_requests_list('all'),
data: (d) => {
if (swh.webapp.isUserLoggedIn() && $('#swh-save-requests-user-filter').prop('checked')) {
if (swh.webapp.isUserLoggedIn() && $(`#${saveRequestCheckboxId}`).prop('checked')) {
d.user_requests_only = '1';
}
}
......@@ -151,7 +148,7 @@ export function initOriginSave() {
fnInitComplete: function() {
if (swh.webapp.isUserLoggedIn()) {
$('div.user-requests-filter').html(userRequestsFilterCheckbox);
$('#swh-save-requests-user-filter').on('change', () => {
$(`#${saveRequestCheckboxId}`).on('change', () => {
saveRequestsTable.draw();
});
}
......
<%#
Copyright (C) 2022 The Software Heritage developers
See the AUTHORS file at the top-level directory of this distribution
License: GNU Affero General Public License version 3, or any later version
See top-level LICENSE file for more information
%>
<div class="custom-control custom-checkbox swhid-option">
<input class="custom-control-input" value="option-user-requests-filter"
type="checkbox"
<% if (checked) { %>
checked="checked"
<% } %>
id="<%= inputId %>">
<label class="custom-control-label font-weight-normal" for="<%= inputId %>">
show only your own requests
</label>
</div>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment