@ -157,7 +157,7 @@ function initLabelEdit() {
} ) ;
} ) ;
}
}
function updateIssuesMeta ( url , action , issueIds , elementId , isAdd ) {
function updateIssuesMeta ( url , action , issueIds , elementId ) {
return new Promise ( ( ( resolve ) => {
return new Promise ( ( ( resolve ) => {
$ . ajax ( {
$ . ajax ( {
type : 'POST' ,
type : 'POST' ,
@ -167,7 +167,6 @@ function updateIssuesMeta(url, action, issueIds, elementId, isAdd) {
action ,
action ,
issue _ids : issueIds ,
issue _ids : issueIds ,
id : elementId ,
id : elementId ,
is _add : isAdd
} ,
} ,
success : resolve
success : resolve
} ) ;
} ) ;
@ -373,21 +372,20 @@ function initCommentForm() {
const $list = $ ( ` .ui. ${ outerSelector } .list ` ) ;
const $list = $ ( ` .ui. ${ outerSelector } .list ` ) ;
const $noSelect = $list . find ( '.no-select' ) ;
const $noSelect = $list . find ( '.no-select' ) ;
const $listMenu = $ ( ` . ${ selector } .menu ` ) ;
const $listMenu = $ ( ` . ${ selector } .menu ` ) ;
let hasLabel UpdateAction = $listMenu . data ( 'action' ) === 'update' ;
let hasUpdateAction = $listMenu . data ( 'action' ) === 'update' ;
const label s = { } ;
const item s = { } ;
$ ( ` . ${ selector } ` ) . dropdown ( 'setting' , 'onHide' , ( ) => {
$ ( ` . ${ selector } ` ) . dropdown ( 'setting' , 'onHide' , ( ) => {
hasLabel UpdateAction = $listMenu . data ( 'action' ) === 'update' ; // Update the var
hasUpdateAction = $listMenu . data ( 'action' ) === 'update' ; // Update the var
if ( hasLabel UpdateAction ) {
if ( hasUpdateAction ) {
const promises = [ ] ;
const promises = [ ] ;
Object . keys ( label s) . forEach ( ( elementId ) => {
Object . keys ( item s) . forEach ( ( elementId ) => {
const label = label s[ elementId ] ;
const item = item s[ elementId ] ;
const promise = updateIssuesMeta (
const promise = updateIssuesMeta (
label [ 'update-url' ] ,
item [ 'update-url' ] ,
label . action ,
item . action ,
label [ 'issue-id' ] ,
item [ 'issue-id' ] ,
elementId ,
elementId ,
label [ 'is-checked' ]
) ;
) ;
promises . push ( promise ) ;
promises . push ( promise ) ;
} ) ;
} ) ;
@ -395,67 +393,49 @@ function initCommentForm() {
}
}
} ) ;
} ) ;
$listMenu . find ( '.item:not(.no-select)' ) . on ( 'click' , function ( ) {
$listMenu . find ( '.item:not(.no-select)' ) . on ( 'click' , function ( e ) {
// we don't need the action attribute when updating assignees
e . preventDefault ( ) ;
if ( selector === 'select-assignees-modify' || selector === 'select-reviewers-modify' ) {
if ( $ ( this ) . hasClass ( 'ban-change' ) ) {
// 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
return false ;
return false ;
}
}
hasUpdateAction = $listMenu . data ( 'action' ) === 'update' ; // Update the var
if ( $ ( this ) . hasClass ( 'checked' ) ) {
if ( $ ( this ) . hasClass ( 'checked' ) ) {
$ ( this ) . removeClass ( 'checked' ) ;
$ ( this ) . removeClass ( 'checked' ) ;
$ ( this ) . find ( '.octicon-check' ) . addClass ( 'invisible' ) ;
$ ( this ) . find ( '.octicon-check' ) . addClass ( 'invisible' ) ;
if ( hasLabel UpdateAction ) {
if ( hasUpdateAction ) {
if ( ! ( $ ( this ) . data ( 'id' ) in label s) ) {
if ( ! ( $ ( this ) . data ( 'id' ) in items ) ) {
label s[ $ ( this ) . data ( 'id' ) ] = {
items [ $ ( this ) . data ( 'id' ) ] = {
'update-url' : $listMenu . data ( 'update-url' ) ,
'update-url' : $listMenu . data ( 'update-url' ) ,
action : 'detach' ,
action : 'detach' ,
'issue-id' : $listMenu . data ( 'issue-id' ) ,
'issue-id' : $listMenu . data ( 'issue-id' ) ,
} ;
} ;
} else {
} else {
delete label s[ $ ( this ) . data ( 'id' ) ] ;
delete items [ $ ( this ) . data ( 'id' ) ] ;
}
}
}
}
} else {
} else {
$ ( this ) . addClass ( 'checked' ) ;
$ ( this ) . addClass ( 'checked' ) ;
$ ( this ) . find ( '.octicon-check' ) . removeClass ( 'invisible' ) ;
$ ( this ) . find ( '.octicon-check' ) . removeClass ( 'invisible' ) ;
if ( hasLabel UpdateAction ) {
if ( hasUpdateAction ) {
if ( ! ( $ ( this ) . data ( 'id' ) in label s) ) {
if ( ! ( $ ( this ) . data ( 'id' ) in items ) ) {
label s[ $ ( this ) . data ( 'id' ) ] = {
items [ $ ( this ) . data ( 'id' ) ] = {
'update-url' : $listMenu . data ( 'update-url' ) ,
'update-url' : $listMenu . data ( 'update-url' ) ,
action : 'attach' ,
action : 'attach' ,
'issue-id' : $listMenu . data ( 'issue-id' ) ,
'issue-id' : $listMenu . data ( 'issue-id' ) ,
} ;
} ;
} else {
} 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 = [ ] ;
const listIds = [ ] ;
$ ( this ) . parent ( ) . find ( '.item' ) . each ( function ( ) {
$ ( this ) . parent ( ) . find ( '.item' ) . each ( function ( ) {
if ( $ ( this ) . hasClass ( 'checked' ) ) {
if ( $ ( this ) . hasClass ( 'checked' ) ) {
@ -473,23 +453,26 @@ function initCommentForm() {
$ ( $ ( this ) . parent ( ) . data ( 'id' ) ) . val ( listIds . join ( ',' ) ) ;
$ ( $ ( this ) . parent ( ) . data ( 'id' ) ) . val ( listIds . join ( ',' ) ) ;
return false ;
return false ;
} ) ;
} ) ;
$listMenu . find ( '.no-select.item' ) . on ( 'click' , function ( ) {
$listMenu . find ( '.no-select.item' ) . on ( 'click' , function ( e ) {
if ( hasLabelUpdateAction || selector === 'select-assignees-modify' ) {
e . preventDefault ( ) ;
if ( hasUpdateAction ) {
updateIssuesMeta (
updateIssuesMeta (
$listMenu . data ( 'update-url' ) ,
$listMenu . data ( 'update-url' ) ,
'clear' ,
'clear' ,
$listMenu . data ( 'issue-id' ) ,
$listMenu . data ( 'issue-id' ) ,
'' ,
'' ,
''
) . then ( reload ) ;
) . then ( reload ) ;
}
}
$ ( this ) . parent ( ) . find ( '.item' ) . each ( function ( ) {
$ ( this ) . parent ( ) . find ( '.item' ) . each ( function ( ) {
$ ( this ) . removeClass ( 'checked' ) ;
$ ( this ) . removeClass ( 'checked' ) ;
$ ( this ) . find ( '.octicon' ) . addClass ( 'invisible' ) ;
$ ( 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 ( ) {
$list . find ( '.item' ) . each ( function ( ) {
$ ( this ) . addClass ( 'hide' ) ;
$ ( this ) . addClass ( 'hide' ) ;
} ) ;
} ) ;
@ -521,7 +504,6 @@ function initCommentForm() {
'' ,
'' ,
$menu . data ( 'issue-id' ) ,
$menu . data ( 'issue-id' ) ,
$ ( this ) . data ( 'id' ) ,
$ ( this ) . data ( 'id' ) ,
$ ( this ) . data ( 'is-checked' )
) . then ( reload ) ;
) . then ( reload ) ;
}
}
switch ( input _id ) {
switch ( input _id ) {
@ -552,7 +534,6 @@ function initCommentForm() {
'' ,
'' ,
$menu . data ( 'issue-id' ) ,
$menu . data ( 'issue-id' ) ,
$ ( this ) . data ( 'id' ) ,
$ ( this ) . data ( 'id' ) ,
$ ( this ) . data ( 'is-checked' )
) . then ( reload ) ;
) . then ( reload ) ;
}
}
@ -672,10 +653,9 @@ function initIssueComments() {
event . preventDefault ( ) ;
event . preventDefault ( ) ;
updateIssuesMeta (
updateIssuesMeta (
url ,
url ,
'',
isChecked === 'true' ? 'attach' : 'detach ',
issueId ,
issueId ,
id ,
id ,
isChecked
) . then ( reload ) ;
) . then ( reload ) ;
} ) ;
} ) ;