@@ -147,19 +147,27 @@ class ClassHelper extends HTMLElement {
147147 }
148148
149149 const handleClickEvent = ( event ) => {
150- if ( this . popupRef != null ) {
150+ if ( this . popupRef == null ) {
151+ this . openPopUp ( initialRequestURL , this . helpurlProps )
152+ . catch ( error => {
153+ // Top level error handling for openPopUp method.
154+ cleanUpClosure ( ) ;
155+ } ) ;
156+ } else {
151157 // this.popupRef.focus();
152- // const form = this.popupRef.document.getElementById("popup-search");
153- // const formData = new FormData(form);
154- // const accumulatedValues = this.popupRef.document.getElementById("popup-preview").value;
158+ const form = this . popupRef . document . getElementById ( "popup-search" ) ;
159+ const formData = new FormData ( form ) ;
160+ const accumulatedValues = this . popupRef . document . getElementById ( "popup-preview" ) . value ;
155161 this . popupRef . close ( ) ;
156- }
157162
158- this . openPopUp ( initialRequestURL , this . helpurlProps )
159- . catch ( error => {
160- // Top level error handling for openPopUp method.
161- cleanUpClosure ( ) ;
162- } ) ;
163+ const requestURL = ClassHelper . getSearchURL ( this . trackerBaseURL , this . helpurlProps , formData ) ;
164+
165+ this . openPopUp ( requestURL , this . helpurlProps , accumulatedValues . split ( "," ) , formData )
166+ . catch ( error => {
167+ // Top level error handling for openPopUp method.
168+ cleanUpClosure ( ) ;
169+ } ) ;
170+ }
163171 } ;
164172
165173 const handleNextPageEvent = ( event ) => {
@@ -433,7 +441,7 @@ class ClassHelper extends HTMLElement {
433441 return url ;
434442 }
435443
436- getSearchFragment ( ) {
444+ getSearchFragment ( formData ) {
437445 const fragment = document . createDocumentFragment ( ) ;
438446 const form = document . createElement ( "form" ) ;
439447 form . setAttribute ( "id" , "popup-search" ) ;
@@ -469,11 +477,24 @@ class ClassHelper extends HTMLElement {
469477 let option = document . createElement ( "option" ) ;
470478 option . value = key ;
471479 option . textContent = this . dropdowns [ param ] . get ( key ) ;
480+ if ( formData ) {
481+ let value = formData . get ( param ) ;
482+ if ( value && value == key ) {
483+ option . selected = "selected" ;
484+ }
485+ }
472486 input . appendChild ( option ) ;
473487 }
474488 } else {
475489 input = document . createElement ( "input" ) ;
476490 input . setAttribute ( "type" , "text" ) ;
491+
492+ if ( formData ) {
493+ let value = formData . get ( param ) ;
494+ if ( value ) {
495+ input . value = value ;
496+ }
497+ }
477498 }
478499
479500 input . setAttribute ( "name" , param ) ;
@@ -738,14 +759,17 @@ class ClassHelper extends HTMLElement {
738759 * main method called when classhelper is clicked
739760 * @param {URL | string } apiURL
740761 * @param {HelpUrlProps } props
762+ * @param {string[] } preSelectedValues
763+ * @param {FormData } formData
741764 * @throws {Error } when fetching or parsing data from roundup rest api fails
742765 */
743- async openPopUp ( apiURL , props ) {
744- // Find preselected values
745- const input = document . getElementsByName ( props . formProperty ) . item ( 0 ) ;
746- let preSelectedValues = [ ] ;
747- if ( input . value ) {
748- preSelectedValues = input . value . split ( ',' ) ;
766+ async openPopUp ( apiURL , props , preSelectedValues , formData ) {
767+ if ( ! preSelectedValues ) {
768+ // Find preselected values
769+ const input = document . getElementsByName ( props . formProperty ) . item ( 0 ) ;
770+ if ( input . value ) {
771+ preSelectedValues = input . value . split ( ',' ) ;
772+ }
749773 }
750774
751775 const popupFeatures = `popup=yes,width=${ props . width } ,height=${ props . height } ` ;
@@ -793,7 +817,7 @@ class ClassHelper extends HTMLElement {
793817 popupBody . classList . add ( "flex-container" ) ;
794818
795819 if ( this . getAttribute ( "searchWith" ) ) {
796- const searchFrag = this . getSearchFragment ( ) ;
820+ const searchFrag = this . getSearchFragment ( formData ) ;
797821 popupBody . appendChild ( searchFrag ) ;
798822 }
799823
0 commit comments