summaryrefslogtreecommitdiffstats
path: root/public/js
diff options
context:
space:
mode:
authorkolaente <konrad@kola-entertainments.de>2018-05-09 18:29:04 +0200
committerLauris BH <lauris@nix.lv>2018-05-09 19:29:04 +0300
commit95f2e2b57beedcdeb2b9623dc86e26f252fdd7bd (patch)
treeebfeb5b898f72fc57ac1fe9680374fdb4bc91aeb /public/js
parent238a997ec0b5d3e3bed0e55edcacebb44f86d373 (diff)
downloadgitea-95f2e2b57beedcdeb2b9623dc86e26f252fdd7bd.tar.gz
gitea-95f2e2b57beedcdeb2b9623dc86e26f252fdd7bd.zip
Multiple assignees (#3705)
Diffstat (limited to 'public/js')
-rw-r--r--public/js/index.js154
1 files changed, 94 insertions, 60 deletions
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');