@@ -147,44 +147,49 @@ class ClassHelper extends HTMLElement {
147147 }
148148
149149 const handleClickEvent = ( event ) => {
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 {
157- // this.popupRef.focus();
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 ;
161- this . popupRef . close ( ) ;
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- } ) ;
150+ if ( this . popupRef != null && ! this . popupRef . closed ) {
151+ this . popupRef . focus ( ) ;
152+ return ;
170153 }
154+
155+ this . openPopUp ( initialRequestURL , this . helpurlProps )
156+ . catch ( error => {
157+ // Top level error handling for openPopUp method.
158+ cleanUpClosure ( ) ;
159+
160+ if ( this . popupRef != null ) {
161+ const fragment = this . getErrorFragment ( "An error occurred while opening the popup window" ) ;
162+ this . popupRef . document . body . innerHTML = ""
163+ this . popupRef . document . body . appendChild ( fragment ) ;
164+ }
165+
166+ console . error ( error ) ;
167+ } ) ;
171168 } ;
172169
173170 const handleNextPageEvent = ( event ) => {
174171 this . pageChange ( event . detail . value , this . helpurlProps )
175172 . catch ( error => {
176173 // Top level error handling for nextPage method.
177- this . removeEventListener ( "nextPage" , handleNextPageEvent ) ;
178174 cleanUpClosure ( ) ;
175+ const fragment = this . getErrorFragment ( "An error occurred while fetching the next page of table" ) ;
176+ this . popupRef . document . body . innerHTML = ""
177+ this . popupRef . document . body . appendChild ( fragment ) ;
178+
179+ console . error ( error , `request data url: ${ event . detail . value } ` ) ;
179180 } ) ;
180181 }
181182
182183 const handlePrevPageEvent = ( event ) => {
183184 this . pageChange ( event . detail . value , this . helpurlProps )
184185 . catch ( error => {
185186 // Top level error handling for prevPage method.
186- this . removeEventListener ( "prevPage" , handlePrevPageEvent ) ;
187187 cleanUpClosure ( ) ;
188+ const fragment = this . getErrorFragment ( "An error occurred while fetching the previous page of table" ) ;
189+ this . popupRef . document . body . innerHTML = ""
190+ this . popupRef . document . body . appendChild ( fragment ) ;
191+
192+ console . error ( error , `request data url: ${ event . detail . value } ` ) ;
188193 } ) ;
189194 }
190195
@@ -199,8 +204,12 @@ class ClassHelper extends HTMLElement {
199204 this . searchEvent ( searchURL , this . helpurlProps )
200205 . catch ( error => {
201206 // Top level error handling for searchEvent method.
202- this . removeEventListener ( "search" , handleSearchEvent ) ;
203207 cleanUpClosure ( ) ;
208+ const fragment = this . getErrorFragment ( "An error occurred while fetching the search results" ) ;
209+ this . popupRef . document . body . innerHTML = ""
210+ this . popupRef . document . body . appendChild ( fragment ) ;
211+
212+ console . error ( error , `request data url: ${ event . detail . value } ` ) ;
204213 } ) ;
205214 }
206215
@@ -441,6 +450,32 @@ class ClassHelper extends HTMLElement {
441450 return url ;
442451 }
443452
453+ getErrorFragment ( message ) {
454+ const fragment = document . createDocumentFragment ( ) ;
455+ const div = document . createElement ( "div" ) ;
456+ div . classList . add ( "error-div" ) ;
457+ const h3_1 = document . createElement ( "h3" ) ;
458+ h3_1 . textContent = message ;
459+ const h3_2 = document . createElement ( "h3" ) ;
460+ h3_2 . textContent = "Classhelper will not intercept helpurl link." ;
461+ const h3_3 = document . createElement ( "h3" ) ;
462+ h3_3 . textContent = "Using fallback helpurl instead." ;
463+ const h3_4 = document . createElement ( "h3" ) ;
464+ h3_4 . textContent = "Please check the console for more details." ;
465+
466+ const button = document . createElement ( "button" ) ;
467+ button . textContent = "Close Popup" ;
468+
469+ button . addEventListener ( "click" , ( ) => {
470+ this . popupRef . close ( ) ;
471+ } ) ;
472+
473+ div . append ( h3_1 , h3_2 , h3_3 , h3_4 , button ) ;
474+ fragment . appendChild ( div ) ;
475+
476+ return fragment ;
477+ }
478+
444479 getSearchFragment ( formData ) {
445480 const fragment = document . createDocumentFragment ( ) ;
446481 const form = document . createElement ( "form" ) ;
@@ -769,6 +804,8 @@ class ClassHelper extends HTMLElement {
769804 const input = document . getElementsByName ( props . formProperty ) . item ( 0 ) ;
770805 if ( input . value ) {
771806 preSelectedValues = input . value . split ( ',' ) ;
807+ } else {
808+ preSelectedValues = [ ] ;
772809 }
773810 }
774811
@@ -834,10 +871,6 @@ class ClassHelper extends HTMLElement {
834871 const accumulatorFrag = this . getAccumulatorFragment ( preSelectedValues ) ;
835872 popupBody . appendChild ( accumulatorFrag ) ;
836873
837- this . popupRef . addEventListener ( "beforeunload" , ( ) => {
838- this . popupRef = null ;
839- } ) ;
840-
841874 this . popupRef . document . addEventListener ( "keydown" , ( e ) => {
842875 if ( e . target . tagName == "TR" ) {
843876 if ( e . key === "ArrowDown" ) {
0 commit comments