From 95f2e2b57beedcdeb2b9623dc86e26f252fdd7bd Mon Sep 17 00:00:00 2001 From: kolaente Date: Wed, 9 May 2018 18:29:04 +0200 Subject: Multiple assignees (#3705) --- public/js/index.js | 154 ++++++++++++++++++++++++++++++++--------------------- 1 file changed, 94 insertions(+), 60 deletions(-) (limited to 'public/js') diff --git a/public/js/index.js b/public/js/index.js index dc473b6f3b..000229dbc1 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -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'; - - $('.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'); + // 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'; + + $('.' + selector).dropdown('setting', 'onHide', function(){ + hasLabelUpdateAction = $listMenu.data('action') == 'update'; // Update the var if (hasLabelUpdateAction) { - updateIssuesMeta( - $labelMenu.data('update-url'), - "detach", - $labelMenu.data('issue-id'), - $(this).data('id') - ); + location.reload(); } - } else { - $(this).addClass('checked'); - $(this).find('.octicon').addClass('octicon-check'); - if (hasLabelUpdateAction) { + }); + + $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'), - "attach", - $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; } - } - 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).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 { - $($(this).data('id-selector')).addClass('hide'); + $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'); -- cgit v1.2.3