@@ -81,6 +81,14 @@ function applyAdvancedSearchPageHandlers() {
8181 }
8282 } ) ;
8383
84+ const account = $ ( this ) . closest ( 'li' ) . find ( '.adv_folder_link' ) ;
85+ const accountLabel = account . text ( ) ;
86+ const accountId = account . data ( 'target' ) ;
87+
88+ const isFolderSelected = ( folder ) => get_adv_sources ( ) . find ( source => source . label === getFolderLabel ( folder ) ) ;
89+
90+ const getFolderLabel = ( folder ) => accountLabel + ' > ' + folder ;
91+
8492 modal . setContent ( `
8593 <div class="d-flex gap-3 flex-wrap">
8694 <div class="form-check form-switch">
@@ -89,24 +97,20 @@ function applyAdvancedSearchPageHandlers() {
8997 </div>
9098 ${ specialFolders . map ( folder => `
9199 <div class="form-check form-switch">
92- <input class="form-check-input special_folder_checkbox" type="checkbox" data-folder-id="${ folder } ">
100+ <input class="form-check-input special_folder_checkbox" type="checkbox" data-folder-id="${ folder } " ${ isFolderSelected ( folder ) ? 'checked' : '' } >
93101 <label class="form-check-label" for="${ folder } ">${ folder } </label>
94102 </div>
95103 ` ) . join ( '' ) }
96104 </div>
97105 ` ) ;
98106
99- const account = $ ( this ) . closest ( 'li' ) . find ( '.adv_folder_link' ) ;
100- const accountLabel = account . text ( ) ;
101- const accountId = account . data ( 'target' ) ;
102-
103107 modal . addFooterBtn ( 'Pick' , 'btn-primary' , function ( ) {
104108 const selectedFolders = [ ] ;
105109 $ ( '.special_folder_checkbox:checked' ) . each ( function ( ) {
106110 selectedFolders . push ( $ ( this ) . data ( 'folder-id' ) ) ;
107111 } ) ;
108112 selectedFolders . forEach ( folder => {
109- add_source_to_list ( accountId + folder , accountLabel + ' > ' + folder , false ) ;
113+ add_source_to_list ( accountId + folder , getFolderLabel ( folder ) , false ) ;
110114 } ) ;
111115 modal . hide ( ) ;
112116 } ) ;
@@ -122,5 +126,13 @@ function applyAdvancedSearchPageHandlers() {
122126 const allChecked = $ ( '.special_folder_checkbox' ) . length === $ ( '.special_folder_checkbox:checked' ) . length ;
123127 $ ( '#all' ) . prop ( 'checked' , allChecked ) ;
124128 } ) ;
129+
130+ if ( specialFolders . every ( folder => isFolderSelected ( folder ) ) ) {
131+ $ ( '#all' ) . prop ( 'checked' , true ) ;
132+ }
125133 } ) ;
134+
135+ return ( ) => {
136+ $ ( 'body' ) . off ( "click" , ".pick_special_folders" ) ;
137+ }
126138}
0 commit comments