2022-01-29 00:00:11 +03:00
import $ from 'jquery' ;
2021-10-16 20:28:04 +03:00
import { updateIssuesMeta } from './repo-issue.js' ;
export function initCommonIssue ( ) {
$ ( '.issue-checkbox' ) . on ( 'click' , ( ) => {
const numChecked = $ ( '.issue-checkbox' ) . children ( 'input:checked' ) . length ;
if ( numChecked > 0 ) {
$ ( '#issue-filters' ) . addClass ( 'hide' ) ;
$ ( '#issue-actions' ) . removeClass ( 'hide' ) ;
} else {
$ ( '#issue-filters' ) . removeClass ( 'hide' ) ;
$ ( '#issue-actions' ) . addClass ( 'hide' ) ;
}
} ) ;
2021-11-22 11:19:01 +03:00
$ ( '.issue-action' ) . on ( 'click' , async function ( ) {
let action = this . getAttribute ( 'data-action' ) ;
let elementId = this . getAttribute ( 'data-element-id' ) ;
const url = this . getAttribute ( 'data-url' ) ;
2021-10-16 20:28:04 +03:00
const issueIDs = $ ( '.issue-checkbox' ) . children ( 'input:checked' ) . map ( ( _ , el ) => {
2021-11-22 11:19:01 +03:00
return el . getAttribute ( 'data-issue-id' ) ;
2021-10-16 20:28:04 +03:00
} ) . get ( ) . join ( ',' ) ;
2022-02-18 09:50:36 +03:00
if ( elementId === '0' && url . slice ( - 9 ) === '/assignee' ) {
2021-10-16 20:28:04 +03:00
elementId = '' ;
action = 'clear' ;
}
2021-11-22 11:19:01 +03:00
updateIssuesMeta (
url ,
action ,
issueIDs ,
elementId
2021-12-04 09:43:14 +03:00
) . then ( ( ) => {
2021-11-22 11:19:01 +03:00
// NOTICE: This reset of checkbox state targets Firefox caching behaviour, as the
// checkboxes stay checked after reload
2021-10-16 20:28:04 +03:00
if ( action === 'close' || action === 'open' ) {
// uncheck all checkboxes
$ ( '.issue-checkbox input[type="checkbox"]' ) . each ( ( _ , e ) => { e . checked = false } ) ;
}
window . location . reload ( ) ;
} ) ;
} ) ;
2021-11-22 11:19:01 +03:00
// NOTICE: This event trigger targets Firefox caching behaviour, as the checkboxes stay
// checked after reload trigger ckecked event, if checkboxes are checked on load
2021-10-16 20:28:04 +03:00
$ ( '.issue-checkbox input[type="checkbox"]:checked' ) . first ( ) . each ( ( _ , e ) => {
e . checked = false ;
$ ( e ) . trigger ( 'click' ) ;
} ) ;
}