@ -157,7 +157,7 @@ function initLabelEdit() {
} ) ;
}
function updateIssuesMeta ( url , action , issueIds , elementId , isAdd ) {
function updateIssuesMeta ( url , action , issueIds , elementId ) {
return new Promise ( ( ( resolve ) => {
$ . ajax ( {
type : 'POST' ,
@ -167,7 +167,6 @@ function updateIssuesMeta(url, action, issueIds, elementId, isAdd) {
action ,
issue_ids : issueIds ,
id : elementId ,
is_add : isAdd
} ,
success : resolve
} ) ;
@ -373,21 +372,20 @@ function initCommentForm() {
const $list = $ ( ` .ui. ${ outerSelector } .list ` ) ;
const $noSelect = $list . find ( '.no-select' ) ;
const $listMenu = $ ( ` . ${ selector } .menu ` ) ;
let hasLabel UpdateAction = $listMenu . data ( 'action' ) === 'update' ;
const label s = { } ;
let hasUpdateAction = $listMenu . data ( 'action' ) === 'update' ;
const item s = { } ;
$ ( ` . ${ selector } ` ) . dropdown ( 'setting' , 'onHide' , ( ) => {
hasLabel UpdateAction = $listMenu . data ( 'action' ) === 'update' ; // Update the var
if ( hasLabel UpdateAction ) {
hasUpdateAction = $listMenu . data ( 'action' ) === 'update' ; // Update the var
if ( hasUpdateAction ) {
const promises = [ ] ;
Object . keys ( label s) . forEach ( ( elementId ) => {
const label = label s[ elementId ] ;
Object . keys ( item s) . forEach ( ( elementId ) => {
const item = item s[ elementId ] ;
const promise = updateIssuesMeta (
label [ 'update-url' ] ,
label . action ,
label [ 'issue-id' ] ,
item [ 'update-url' ] ,
item . action ,
item [ 'issue-id' ] ,
elementId ,
label [ 'is-checked' ]
) ;
promises . push ( promise ) ;
} ) ;
@ -395,67 +393,49 @@ function initCommentForm() {
}
} ) ;
$listMenu . find ( '.item:not(.no-select)' ) . on ( 'click' , function ( ) {
// we don't need the action attribute when updating assignees
if ( selector === 'select-assignees-modify' || selector === 'select-reviewers-modify' ) {
// UI magic. We need to do this here, otherwise it would destroy the functionality of
// adding/removing labels
if ( $ ( this ) . data ( 'can-change' ) === 'block' ) {
return false ;
}
if ( $ ( this ) . hasClass ( 'checked' ) ) {
$ ( this ) . removeClass ( 'checked' ) ;
$ ( this ) . find ( '.octicon-check' ) . addClass ( 'invisible' ) ;
$ ( this ) . data ( 'is-checked' , 'remove' ) ;
} else {
$ ( this ) . addClass ( 'checked' ) ;
$ ( this ) . find ( '.octicon-check' ) . removeClass ( 'invisible' ) ;
$ ( this ) . data ( 'is-checked' , 'add' ) ;
}
updateIssuesMeta (
$listMenu . data ( 'update-url' ) ,
'' ,
$listMenu . data ( 'issue-id' ) ,
$ ( this ) . data ( 'id' ) ,
$ ( this ) . data ( 'is-checked' )
) ;
$listMenu . data ( 'action' , 'update' ) ; // Update to reload the page when we updated items
$listMenu . find ( '.item:not(.no-select)' ) . on ( 'click' , function ( e ) {
e . preventDefault ( ) ;
if ( $ ( this ) . hasClass ( 'ban-change' ) ) {
return false ;
}
hasUpdateAction = $listMenu . data ( 'action' ) === 'update' ; // Update the var
if ( $ ( this ) . hasClass ( 'checked' ) ) {
$ ( this ) . removeClass ( 'checked' ) ;
$ ( this ) . find ( '.octicon-check' ) . addClass ( 'invisible' ) ;
if ( hasLabel UpdateAction ) {
if ( ! ( $ ( this ) . data ( 'id' ) in label s) ) {
label s[ $ ( this ) . data ( 'id' ) ] = {
if ( hasUpdateAction ) {
if ( ! ( $ ( this ) . data ( 'id' ) in items ) ) {
items [ $ ( this ) . data ( 'id' ) ] = {
'update-url' : $listMenu . data ( 'update-url' ) ,
action : 'detach' ,
'issue-id' : $listMenu . data ( 'issue-id' ) ,
} ;
} else {
delete label s[ $ ( this ) . data ( 'id' ) ] ;
delete items [ $ ( this ) . data ( 'id' ) ] ;
}
}
} else {
$ ( this ) . addClass ( 'checked' ) ;
$ ( this ) . find ( '.octicon-check' ) . removeClass ( 'invisible' ) ;
if ( hasLabel UpdateAction ) {
if ( ! ( $ ( this ) . data ( 'id' ) in label s) ) {
label s[ $ ( this ) . data ( 'id' ) ] = {
if ( hasUpdateAction ) {
if ( ! ( $ ( this ) . data ( 'id' ) in items ) ) {
items [ $ ( this ) . data ( 'id' ) ] = {
'update-url' : $listMenu . data ( 'update-url' ) ,
action : 'attach' ,
'issue-id' : $listMenu . data ( 'issue-id' ) ,
} ;
} else {
delete label s[ $ ( this ) . data ( 'id' ) ] ;
delete item s[ $ ( this ) . data ( 'id' ) ] ;
}
}
}
// TODO: Which thing should be done for choosing review requests
// to make choosed items be shown on time here?
if ( selector === 'select-reviewers-modify' || selector === 'select-assignees-modify' ) {
return false ;
}
const listIds = [ ] ;
$ ( this ) . parent ( ) . find ( '.item' ) . each ( function ( ) {
if ( $ ( this ) . hasClass ( 'checked' ) ) {
@ -473,23 +453,26 @@ function initCommentForm() {
$ ( $ ( this ) . parent ( ) . data ( 'id' ) ) . val ( listIds . join ( ',' ) ) ;
return false ;
} ) ;
$listMenu . find ( '.no-select.item' ) . on ( 'click' , function ( ) {
if ( hasLabelUpdateAction || selector === 'select-assignees-modify' ) {
$listMenu . find ( '.no-select.item' ) . on ( 'click' , function ( e ) {
e . preventDefault ( ) ;
if ( hasUpdateAction ) {
updateIssuesMeta (
$listMenu . data ( 'update-url' ) ,
'clear' ,
$listMenu . data ( 'issue-id' ) ,
'' ,
''
) . then ( reload ) ;
}
$ ( this ) . parent ( ) . find ( '.item' ) . each ( function ( ) {
$ ( this ) . removeClass ( 'checked' ) ;
$ ( this ) . find ( '.octicon' ) . addClass ( 'invisible' ) ;
$ ( this ) . data ( 'is-checked' , 'remove' ) ;
} ) ;
if ( selector === 'select-reviewers-modify' || selector === 'select-assignees-modify' ) {
return false ;
}
$list . find ( '.item' ) . each ( function ( ) {
$ ( this ) . addClass ( 'hide' ) ;
} ) ;
@ -521,7 +504,6 @@ function initCommentForm() {
'' ,
$menu . data ( 'issue-id' ) ,
$ ( this ) . data ( 'id' ) ,
$ ( this ) . data ( 'is-checked' )
) . then ( reload ) ;
}
switch ( input_id ) {
@ -552,7 +534,6 @@ function initCommentForm() {
'' ,
$menu . data ( 'issue-id' ) ,
$ ( this ) . data ( 'id' ) ,
$ ( this ) . data ( 'is-checked' )
) . then ( reload ) ;
}
@ -672,10 +653,9 @@ function initIssueComments() {
event . preventDefault ( ) ;
updateIssuesMeta (
url ,
'' ,
isChecked === 'true' ? 'attach' : 'detach ' ,
issueId ,
id ,
isChecked
) . then ( reload ) ;
} ) ;