@@ -157,7 +157,7 @@ function initLabelEdit() {
157157 } ) ;
158158}
159159
160- function updateIssuesMeta ( url , action , issueIds , elementId , isAdd ) {
160+ function updateIssuesMeta ( url , action , issueIds , elementId ) {
161161 return new Promise ( ( ( resolve ) => {
162162 $ . ajax ( {
163163 type : 'POST' ,
@@ -167,7 +167,6 @@ function updateIssuesMeta(url, action, issueIds, elementId, isAdd) {
167167 action,
168168 issue_ids : issueIds ,
169169 id : elementId ,
170- is_add : isAdd
171170 } ,
172171 success : resolve
173172 } ) ;
@@ -373,89 +372,70 @@ function initCommentForm() {
373372 const $list = $ ( `.ui.${ outerSelector } .list` ) ;
374373 const $noSelect = $list . find ( '.no-select' ) ;
375374 const $listMenu = $ ( `.${ selector } .menu` ) ;
376- let hasLabelUpdateAction = $listMenu . data ( 'action' ) === 'update' ;
377- const labels = { } ;
375+ let hasUpdateAction = $listMenu . data ( 'action' ) === 'update' ;
376+ const items = { } ;
378377
379378 $ ( `.${ 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 ) {
382381 const promises = [ ] ;
383- Object . keys ( labels ) . forEach ( ( elementId ) => {
384- const label = labels [ elementId ] ;
382+ Object . keys ( items ) . forEach ( ( elementId ) => {
383+ const item = items [ elementId ] ;
385384 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' ] ,
389388 elementId ,
390- label [ 'is-checked' ]
391389 ) ;
392390 promises . push ( promise ) ;
393391 } ) ;
394392 Promise . all ( promises ) . then ( reload ) ;
395393 }
396394 } ) ;
397395
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' ) ) {
426399 return false ;
427400 }
428401
402+ hasUpdateAction = $listMenu . data ( 'action' ) === 'update' ; // Update the var
429403 if ( $ ( this ) . hasClass ( 'checked' ) ) {
430404 $ ( this ) . removeClass ( 'checked' ) ;
431405 $ ( 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' ) ] = {
435409 'update-url' : $listMenu . data ( 'update-url' ) ,
436410 action : 'detach' ,
437411 'issue-id' : $listMenu . data ( 'issue-id' ) ,
438412 } ;
439413 } else {
440- delete labels [ $ ( this ) . data ( 'id' ) ] ;
414+ delete items [ $ ( this ) . data ( 'id' ) ] ;
441415 }
442416 }
443417 } else {
444418 $ ( this ) . addClass ( 'checked' ) ;
445419 $ ( 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' ) ] = {
449423 'update-url' : $listMenu . data ( 'update-url' ) ,
450424 action : 'attach' ,
451425 'issue-id' : $listMenu . data ( 'issue-id' ) ,
452426 } ;
453427 } else {
454- delete labels [ $ ( this ) . data ( 'id' ) ] ;
428+ delete items [ $ ( this ) . data ( 'id' ) ] ;
455429 }
456430 }
457431 }
458432
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+
459439 const listIds = [ ] ;
460440 $ ( this ) . parent ( ) . find ( '.item' ) . each ( function ( ) {
461441 if ( $ ( this ) . hasClass ( 'checked' ) ) {
@@ -473,23 +453,26 @@ function initCommentForm() {
473453 $ ( $ ( this ) . parent ( ) . data ( 'id' ) ) . val ( listIds . join ( ',' ) ) ;
474454 return false ;
475455 } ) ;
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 ) {
478459 updateIssuesMeta (
479460 $listMenu . data ( 'update-url' ) ,
480461 'clear' ,
481462 $listMenu . data ( 'issue-id' ) ,
482463 '' ,
483- ''
484464 ) . then ( reload ) ;
485465 }
486466
487467 $ ( this ) . parent ( ) . find ( '.item' ) . each ( function ( ) {
488468 $ ( this ) . removeClass ( 'checked' ) ;
489469 $ ( this ) . find ( '.octicon' ) . addClass ( 'invisible' ) ;
490- $ ( this ) . data ( 'is-checked' , 'remove' ) ;
491470 } ) ;
492471
472+ if ( selector === 'select-reviewers-modify' || selector === 'select-assignees-modify' ) {
473+ return false ;
474+ }
475+
493476 $list . find ( '.item' ) . each ( function ( ) {
494477 $ ( this ) . addClass ( 'hide' ) ;
495478 } ) ;
@@ -521,7 +504,6 @@ function initCommentForm() {
521504 '' ,
522505 $menu . data ( 'issue-id' ) ,
523506 $ ( this ) . data ( 'id' ) ,
524- $ ( this ) . data ( 'is-checked' )
525507 ) . then ( reload ) ;
526508 }
527509 switch ( input_id ) {
@@ -552,7 +534,6 @@ function initCommentForm() {
552534 '' ,
553535 $menu . data ( 'issue-id' ) ,
554536 $ ( this ) . data ( 'id' ) ,
555- $ ( this ) . data ( 'is-checked' )
556537 ) . then ( reload ) ;
557538 }
558539
@@ -672,10 +653,9 @@ function initIssueComments() {
672653 event . preventDefault ( ) ;
673654 updateIssuesMeta (
674655 url ,
675- ' ',
656+ isChecked === 'true' ? 'attach' : 'detach ',
676657 issueId ,
677658 id ,
678- isChecked
679659 ) . then ( reload ) ;
680660 } ) ;
681661
0 commit comments