Skip to content

Commit

Permalink
Merge branch 'main' into combomarkdowneditor-jquery-attr
Browse files Browse the repository at this point in the history
  • Loading branch information
GiteaBot authored Mar 24, 2024
2 parents 4c26417 + a7d0c5d commit c8d20d8
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 40 deletions.
26 changes: 13 additions & 13 deletions web_src/js/features/comp/LabelEdit.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@ function isExclusiveScopeName(name) {
}

function updateExclusiveLabelEdit(form) {
const $nameInput = $(`${form} .label-name-input`);
const $exclusiveField = $(`${form} .label-exclusive-input-field`);
const $exclusiveCheckbox = $(`${form} .label-exclusive-input`);
const $exclusiveWarning = $(`${form} .label-exclusive-warning`);
const nameInput = document.querySelector(`${form} .label-name-input`);
const exclusiveField = document.querySelector(`${form} .label-exclusive-input-field`);
const exclusiveCheckbox = document.querySelector(`${form} .label-exclusive-input`);
const exclusiveWarning = document.querySelector(`${form} .label-exclusive-warning`);

if (isExclusiveScopeName($nameInput.val())) {
$exclusiveField.removeClass('muted');
$exclusiveField.removeAttr('aria-disabled');
if ($exclusiveCheckbox[0].checked && $exclusiveCheckbox.data('exclusive-warn')) {
$exclusiveWarning.removeClass('tw-hidden');
if (isExclusiveScopeName(nameInput.value)) {
exclusiveField?.classList.remove('muted');
exclusiveField?.removeAttribute('aria-disabled');
if (exclusiveCheckbox.checked && exclusiveCheckbox.getAttribute('data-exclusive-warn')) {
exclusiveWarning?.classList.remove('tw-hidden');
} else {
$exclusiveWarning.addClass('tw-hidden');
exclusiveWarning?.classList.add('tw-hidden');
}
} else {
$exclusiveField.addClass('muted');
$exclusiveField.attr('aria-disabled', 'true');
$exclusiveWarning.addClass('tw-hidden');
exclusiveField?.classList.add('muted');
exclusiveField?.setAttribute('aria-disabled', 'true');
exclusiveWarning?.classList.add('tw-hidden');
}
}

Expand Down
56 changes: 29 additions & 27 deletions web_src/js/features/repo-home.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,55 +6,57 @@ import {POST} from '../modules/fetch.js';
const {appSubUrl} = window.config;

export function initRepoTopicBar() {
const $mgrBtn = $('#manage_topic');
if (!$mgrBtn.length) return;
const $editDiv = $('#topic_edit');
const $viewDiv = $('#repo-topics');
const $saveBtn = $('#save_topic');
const $topicDropdown = $('#topic_edit .dropdown');
const $topicForm = $editDiv; // the old logic, $editDiv is topicForm
const mgrBtn = document.getElementById('manage_topic');
if (!mgrBtn) return;
const editDiv = document.getElementById('topic_edit');
const viewDiv = document.getElementById('repo-topics');
const saveBtn = document.getElementById('save_topic');
const topicDropdown = editDiv.querySelector('.dropdown');
const $topicDropdown = $(topicDropdown);
const $topicForm = $(editDiv);
const $topicDropdownSearch = $topicDropdown.find('input.search');
const topicPrompts = {
countPrompt: $topicDropdown.attr('data-text-count-prompt'),
formatPrompt: $topicDropdown.attr('data-text-format-prompt'),
countPrompt: topicDropdown.getAttribute('data-text-count-prompt') ?? undefined,
formatPrompt: topicDropdown.getAttribute('data-text-format-prompt') ?? undefined,
};

$mgrBtn.on('click', () => {
hideElem($viewDiv);
showElem($editDiv);
mgrBtn.addEventListener('click', () => {
hideElem(viewDiv);
showElem(editDiv);
$topicDropdownSearch.trigger('focus');
});

$('#cancel_topic_edit').on('click', () => {
hideElem($editDiv);
showElem($viewDiv);
$mgrBtn.trigger('focus');
hideElem(editDiv);
showElem(viewDiv);
mgrBtn.focus();
});

$saveBtn.on('click', async () => {
saveBtn.addEventListener('click', async () => {
const topics = $('input[name=topics]').val();

const data = new FormData();
data.append('topics', topics);

const response = await POST($saveBtn.attr('data-link'), {data});
const response = await POST(saveBtn.getAttribute('data-link'), {data});

if (response.ok) {
const responseData = await response.json();
if (responseData.status === 'ok') {
$viewDiv.children('.topic').remove();
$(viewDiv).children('.topic').remove();
if (topics.length) {
const topicArray = topics.split(',');
topicArray.sort();
for (const topic of topicArray) {
const $link = $('<a class="ui repo-topic large label topic tw-m-0"></a>');
$link.attr('href', `${appSubUrl}/explore/repos?q=${encodeURIComponent(topic)}&topic=1`);
$link.text(topic);
$link.insertBefore($mgrBtn); // insert all new topics before manage button
const link = document.createElement('a');
link.classList.add('ui', 'repo-topic', 'large', 'label', 'topic', 'tw-m-0');
link.href = `${appSubUrl}/explore/repos?q=${encodeURIComponent(topic)}&topic=1`;
link.textContent = topic;
mgrBtn.parentNode.insertBefore(link, mgrBtn); // insert all new topics before manage button
}
}
hideElem($editDiv);
showElem($viewDiv);
hideElem(editDiv);
showElem(viewDiv);
}
} else if (response.status === 422) {
const responseData = await response.json();
Expand Down Expand Up @@ -144,14 +146,14 @@ export function initRepoTopicBar() {
},
onAdd(addedValue, _addedText, $addedChoice) {
addedValue = addedValue.toLowerCase().trim();
$($addedChoice).attr('data-value', addedValue);
$($addedChoice).attr('data-text', addedValue);
$($addedChoice)[0].setAttribute('data-value', addedValue);
$($addedChoice)[0].setAttribute('data-text', addedValue);
},
});

$.fn.form.settings.rules.validateTopic = function (_values, regExp) {
const $topics = $topicDropdown.children('a.ui.label');
const status = $topics.length === 0 || $topics.last().attr('data-value').match(regExp);
const status = $topics.length === 0 || $topics.last()[0].getAttribute('data-value').match(regExp);
if (!status) {
$topics.last().removeClass('green').addClass('red');
}
Expand Down

0 comments on commit c8d20d8

Please sign in to comment.