@@ -157,7 +157,7 @@ function initLabelEdit() {
157
157
} ) ;
158
158
}
159
159
160
- function updateIssuesMeta ( url , action , issueIds , elementId , isAdd ) {
160
+ function updateIssuesMeta ( url , action , issueIds , elementId ) {
161
161
return new Promise ( ( ( resolve ) => {
162
162
$ . ajax ( {
163
163
type : 'POST' ,
@@ -167,7 +167,6 @@ function updateIssuesMeta(url, action, issueIds, elementId, isAdd) {
167
167
action,
168
168
issue_ids : issueIds ,
169
169
id : elementId ,
170
- is_add : isAdd
171
170
} ,
172
171
success : resolve
173
172
} ) ;
@@ -373,89 +372,70 @@ function initCommentForm() {
373
372
const $list = $ ( `.ui.${ outerSelector } .list` ) ;
374
373
const $noSelect = $list . find ( '.no-select' ) ;
375
374
const $listMenu = $ ( `.${ selector } .menu` ) ;
376
- let hasLabelUpdateAction = $listMenu . data ( 'action' ) === 'update' ;
377
- const labels = { } ;
375
+ let hasUpdateAction = $listMenu . data ( 'action' ) === 'update' ;
376
+ const items = { } ;
378
377
379
378
$ ( `.${ selector } ` ) . dropdown ( 'setting' , 'onHide' , ( ) => {
380
- hasLabelUpdateAction = $listMenu . data ( 'action' ) === 'update' ; // Update the var
381
- if ( hasLabelUpdateAction ) {
379
+ hasUpdateAction = $listMenu . data ( 'action' ) === 'update' ; // Update the var
380
+ if ( hasUpdateAction ) {
382
381
const promises = [ ] ;
383
- Object . keys ( labels ) . forEach ( ( elementId ) => {
384
- const label = labels [ elementId ] ;
382
+ Object . keys ( items ) . forEach ( ( elementId ) => {
383
+ const item = items [ elementId ] ;
385
384
const promise = updateIssuesMeta (
386
- label [ 'update-url' ] ,
387
- label . action ,
388
- label [ 'issue-id' ] ,
385
+ item [ 'update-url' ] ,
386
+ item . action ,
387
+ item [ 'issue-id' ] ,
389
388
elementId ,
390
- label [ 'is-checked' ]
391
389
) ;
392
390
promises . push ( promise ) ;
393
391
} ) ;
394
392
Promise . all ( promises ) . then ( reload ) ;
395
393
}
396
394
} ) ;
397
395
398
- $listMenu . find ( '.item:not(.no-select)' ) . on ( 'click' , function ( ) {
399
- // we don't need the action attribute when updating assignees
400
- if ( selector === 'select-assignees-modify' || selector === 'select-reviewers-modify' ) {
401
- // UI magic. We need to do this here, otherwise it would destroy the functionality of
402
- // adding/removing labels
403
-
404
- if ( $ ( this ) . data ( 'can-change' ) === 'block' ) {
405
- return false ;
406
- }
407
-
408
- if ( $ ( this ) . hasClass ( 'checked' ) ) {
409
- $ ( this ) . removeClass ( 'checked' ) ;
410
- $ ( this ) . find ( '.octicon-check' ) . addClass ( 'invisible' ) ;
411
- $ ( this ) . data ( 'is-checked' , 'remove' ) ;
412
- } else {
413
- $ ( this ) . addClass ( 'checked' ) ;
414
- $ ( this ) . find ( '.octicon-check' ) . removeClass ( 'invisible' ) ;
415
- $ ( this ) . data ( 'is-checked' , 'add' ) ;
416
- }
417
-
418
- updateIssuesMeta (
419
- $listMenu . data ( 'update-url' ) ,
420
- '' ,
421
- $listMenu . data ( 'issue-id' ) ,
422
- $ ( this ) . data ( 'id' ) ,
423
- $ ( this ) . data ( 'is-checked' )
424
- ) ;
425
- $listMenu . data ( 'action' , 'update' ) ; // Update to reload the page when we updated items
396
+ $listMenu . find ( '.item:not(.no-select)' ) . on ( 'click' , function ( e ) {
397
+ e . preventDefault ( ) ;
398
+ if ( $ ( this ) . hasClass ( 'ban-change' ) ) {
426
399
return false ;
427
400
}
428
401
402
+ hasUpdateAction = $listMenu . data ( 'action' ) === 'update' ; // Update the var
429
403
if ( $ ( this ) . hasClass ( 'checked' ) ) {
430
404
$ ( this ) . removeClass ( 'checked' ) ;
431
405
$ ( this ) . find ( '.octicon-check' ) . addClass ( 'invisible' ) ;
432
- if ( hasLabelUpdateAction ) {
433
- if ( ! ( $ ( this ) . data ( 'id' ) in labels ) ) {
434
- labels [ $ ( this ) . data ( 'id' ) ] = {
406
+ if ( hasUpdateAction ) {
407
+ if ( ! ( $ ( this ) . data ( 'id' ) in items ) ) {
408
+ items [ $ ( this ) . data ( 'id' ) ] = {
435
409
'update-url' : $listMenu . data ( 'update-url' ) ,
436
410
action : 'detach' ,
437
411
'issue-id' : $listMenu . data ( 'issue-id' ) ,
438
412
} ;
439
413
} else {
440
- delete labels [ $ ( this ) . data ( 'id' ) ] ;
414
+ delete items [ $ ( this ) . data ( 'id' ) ] ;
441
415
}
442
416
}
443
417
} else {
444
418
$ ( this ) . addClass ( 'checked' ) ;
445
419
$ ( this ) . find ( '.octicon-check' ) . removeClass ( 'invisible' ) ;
446
- if ( hasLabelUpdateAction ) {
447
- if ( ! ( $ ( this ) . data ( 'id' ) in labels ) ) {
448
- labels [ $ ( this ) . data ( 'id' ) ] = {
420
+ if ( hasUpdateAction ) {
421
+ if ( ! ( $ ( this ) . data ( 'id' ) in items ) ) {
422
+ items [ $ ( this ) . data ( 'id' ) ] = {
449
423
'update-url' : $listMenu . data ( 'update-url' ) ,
450
424
action : 'attach' ,
451
425
'issue-id' : $listMenu . data ( 'issue-id' ) ,
452
426
} ;
453
427
} else {
454
- delete labels [ $ ( this ) . data ( 'id' ) ] ;
428
+ delete items [ $ ( this ) . data ( 'id' ) ] ;
455
429
}
456
430
}
457
431
}
458
432
433
+ // TODO: Which thing should be done for choosing review requests
434
+ // to make choosed items be shown on time here?
435
+ if ( selector === 'select-reviewers-modify' || selector === 'select-assignees-modify' ) {
436
+ return false ;
437
+ }
438
+
459
439
const listIds = [ ] ;
460
440
$ ( this ) . parent ( ) . find ( '.item' ) . each ( function ( ) {
461
441
if ( $ ( this ) . hasClass ( 'checked' ) ) {
@@ -473,23 +453,26 @@ function initCommentForm() {
473
453
$ ( $ ( this ) . parent ( ) . data ( 'id' ) ) . val ( listIds . join ( ',' ) ) ;
474
454
return false ;
475
455
} ) ;
476
- $listMenu . find ( '.no-select.item' ) . on ( 'click' , function ( ) {
477
- if ( hasLabelUpdateAction || selector === 'select-assignees-modify' ) {
456
+ $listMenu . find ( '.no-select.item' ) . on ( 'click' , function ( e ) {
457
+ e . preventDefault ( ) ;
458
+ if ( hasUpdateAction ) {
478
459
updateIssuesMeta (
479
460
$listMenu . data ( 'update-url' ) ,
480
461
'clear' ,
481
462
$listMenu . data ( 'issue-id' ) ,
482
463
'' ,
483
- ''
484
464
) . then ( reload ) ;
485
465
}
486
466
487
467
$ ( this ) . parent ( ) . find ( '.item' ) . each ( function ( ) {
488
468
$ ( this ) . removeClass ( 'checked' ) ;
489
469
$ ( this ) . find ( '.octicon' ) . addClass ( 'invisible' ) ;
490
- $ ( this ) . data ( 'is-checked' , 'remove' ) ;
491
470
} ) ;
492
471
472
+ if ( selector === 'select-reviewers-modify' || selector === 'select-assignees-modify' ) {
473
+ return false ;
474
+ }
475
+
493
476
$list . find ( '.item' ) . each ( function ( ) {
494
477
$ ( this ) . addClass ( 'hide' ) ;
495
478
} ) ;
@@ -521,7 +504,6 @@ function initCommentForm() {
521
504
'' ,
522
505
$menu . data ( 'issue-id' ) ,
523
506
$ ( this ) . data ( 'id' ) ,
524
- $ ( this ) . data ( 'is-checked' )
525
507
) . then ( reload ) ;
526
508
}
527
509
switch ( input_id ) {
@@ -552,7 +534,6 @@ function initCommentForm() {
552
534
'' ,
553
535
$menu . data ( 'issue-id' ) ,
554
536
$ ( this ) . data ( 'id' ) ,
555
- $ ( this ) . data ( 'is-checked' )
556
537
) . then ( reload ) ;
557
538
}
558
539
@@ -672,10 +653,9 @@ function initIssueComments() {
672
653
event . preventDefault ( ) ;
673
654
updateIssuesMeta (
674
655
url ,
675
- ' ',
656
+ isChecked === 'true' ? 'attach' : 'detach ',
676
657
issueId ,
677
658
id ,
678
- isChecked
679
659
) . then ( reload ) ;
680
660
} ) ;
681
661
0 commit comments