forked from forgejo/forgejo
Multiple assignees (#3705)
This commit is contained in:
parent
238a997ec0
commit
95f2e2b57b
36 changed files with 1012 additions and 451 deletions
|
@ -179,81 +179,115 @@ function initCommentForm() {
|
|||
initBranchSelector();
|
||||
initCommentPreviewTab($('.comment.form'));
|
||||
|
||||
// Labels
|
||||
var $list = $('.ui.labels.list');
|
||||
var $noSelect = $list.find('.no-select');
|
||||
var $labelMenu = $('.select-label .menu');
|
||||
var hasLabelUpdateAction = $labelMenu.data('action') == 'update';
|
||||
// Listsubmit
|
||||
function initListSubmits(selector, outerSelector) {
|
||||
var $list = $('.ui.' + outerSelector + '.list');
|
||||
var $noSelect = $list.find('.no-select');
|
||||
var $listMenu = $('.' + selector + ' .menu');
|
||||
var hasLabelUpdateAction = $listMenu.data('action') == 'update';
|
||||
|
||||
$('.select-label').dropdown('setting', 'onHide', function(){
|
||||
if (hasLabelUpdateAction) {
|
||||
location.reload();
|
||||
}
|
||||
});
|
||||
|
||||
$labelMenu.find('.item:not(.no-select)').click(function () {
|
||||
if ($(this).hasClass('checked')) {
|
||||
$(this).removeClass('checked');
|
||||
$(this).find('.octicon').removeClass('octicon-check');
|
||||
$('.' + selector).dropdown('setting', 'onHide', function(){
|
||||
hasLabelUpdateAction = $listMenu.data('action') == 'update'; // Update the var
|
||||
if (hasLabelUpdateAction) {
|
||||
location.reload();
|
||||
}
|
||||
});
|
||||
|
||||
$listMenu.find('.item:not(.no-select)').click(function () {
|
||||
|
||||
// we don't need the action attribute when updating assignees
|
||||
if (selector == 'select-assignees-modify') {
|
||||
|
||||
// UI magic. We need to do this here, otherwise it would destroy the functionality of
|
||||
// adding/removing labels
|
||||
if ($(this).hasClass('checked')) {
|
||||
$(this).removeClass('checked');
|
||||
$(this).find('.octicon').removeClass('octicon-check');
|
||||
} else {
|
||||
$(this).addClass('checked');
|
||||
$(this).find('.octicon').addClass('octicon-check');
|
||||
}
|
||||
|
||||
updateIssuesMeta(
|
||||
$labelMenu.data('update-url'),
|
||||
"detach",
|
||||
$labelMenu.data('issue-id'),
|
||||
$listMenu.data('update-url'),
|
||||
"",
|
||||
$listMenu.data('issue-id'),
|
||||
$(this).data('id')
|
||||
);
|
||||
$listMenu.data('action', 'update'); // Update to reload the page when we updated items
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
$(this).addClass('checked');
|
||||
$(this).find('.octicon').addClass('octicon-check');
|
||||
if (hasLabelUpdateAction) {
|
||||
updateIssuesMeta(
|
||||
$labelMenu.data('update-url'),
|
||||
"attach",
|
||||
$labelMenu.data('issue-id'),
|
||||
$(this).data('id')
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
var labelIds = [];
|
||||
$(this).parent().find('.item').each(function () {
|
||||
if ($(this).hasClass('checked')) {
|
||||
labelIds.push($(this).data('id'));
|
||||
$($(this).data('id-selector')).removeClass('hide');
|
||||
$(this).removeClass('checked');
|
||||
$(this).find('.octicon').removeClass('octicon-check');
|
||||
if (hasLabelUpdateAction) {
|
||||
updateIssuesMeta(
|
||||
$listMenu.data('update-url'),
|
||||
"detach",
|
||||
$listMenu.data('issue-id'),
|
||||
$(this).data('id')
|
||||
);
|
||||
}
|
||||
} else {
|
||||
$($(this).data('id-selector')).addClass('hide');
|
||||
$(this).addClass('checked');
|
||||
$(this).find('.octicon').addClass('octicon-check');
|
||||
if (hasLabelUpdateAction) {
|
||||
updateIssuesMeta(
|
||||
$listMenu.data('update-url'),
|
||||
"attach",
|
||||
$listMenu.data('issue-id'),
|
||||
$(this).data('id')
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
var listIds = [];
|
||||
$(this).parent().find('.item').each(function () {
|
||||
if ($(this).hasClass('checked')) {
|
||||
listIds.push($(this).data('id'));
|
||||
$($(this).data('id-selector')).removeClass('hide');
|
||||
} else {
|
||||
$($(this).data('id-selector')).addClass('hide');
|
||||
}
|
||||
});
|
||||
if (listIds.length == 0) {
|
||||
$noSelect.removeClass('hide');
|
||||
} else {
|
||||
$noSelect.addClass('hide');
|
||||
}
|
||||
$($(this).parent().data('id')).val(listIds.join(","));
|
||||
return false;
|
||||
});
|
||||
if (labelIds.length == 0) {
|
||||
$listMenu.find('.no-select.item').click(function () {
|
||||
if (hasLabelUpdateAction || selector == 'select-assignees-modify') {
|
||||
updateIssuesMeta(
|
||||
$listMenu.data('update-url'),
|
||||
"clear",
|
||||
$listMenu.data('issue-id'),
|
||||
""
|
||||
);
|
||||
$listMenu.data('action', 'update'); // Update to reload the page when we updated items
|
||||
}
|
||||
|
||||
$(this).parent().find('.item').each(function () {
|
||||
$(this).removeClass('checked');
|
||||
$(this).find('.octicon').removeClass('octicon-check');
|
||||
});
|
||||
|
||||
$list.find('.item').each(function () {
|
||||
$(this).addClass('hide');
|
||||
});
|
||||
$noSelect.removeClass('hide');
|
||||
} else {
|
||||
$noSelect.addClass('hide');
|
||||
}
|
||||
$($(this).parent().data('id')).val(labelIds.join(","));
|
||||
return false;
|
||||
});
|
||||
$labelMenu.find('.no-select.item').click(function () {
|
||||
if (hasLabelUpdateAction) {
|
||||
updateIssuesMeta(
|
||||
$labelMenu.data('update-url'),
|
||||
"clear",
|
||||
$labelMenu.data('issue-id'),
|
||||
""
|
||||
);
|
||||
}
|
||||
$($(this).parent().data('id')).val('');
|
||||
|
||||
$(this).parent().find('.item').each(function () {
|
||||
$(this).removeClass('checked');
|
||||
$(this).find('.octicon').removeClass('octicon-check');
|
||||
});
|
||||
}
|
||||
|
||||
$list.find('.item').each(function () {
|
||||
$(this).addClass('hide');
|
||||
});
|
||||
$noSelect.removeClass('hide');
|
||||
$($(this).parent().data('id')).val('');
|
||||
});
|
||||
// Init labels and assignees
|
||||
initListSubmits('select-label', 'labels');
|
||||
initListSubmits('select-assignees', 'assignees');
|
||||
initListSubmits('select-assignees-modify', 'assignees');
|
||||
|
||||
function selectItem(select_id, input_id) {
|
||||
var $menu = $(select_id + ' .menu');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue