@@ -40,6 +40,8 @@ $(document).ready(function () {
4040 } ) ;
4141 //initializing UI combobox dropdown by overriding its methods.
4242 ajaxAutoCompleteDropDown ( ) ;
43+ //initializing events listener
44+ initializeEvents ( ) ;
4345 // bindObservers will add observer on passed html section when DOM is ready.
4446 bindObservers ( "body" ) ;
4547
@@ -92,22 +94,81 @@ $(document).ready(function () {
9294 }
9395} ) ;
9496
95- /* bindObservers function contains the code of adding observers and it can be called for specific section as well
96- when we need to add observer on section which is updated by Ajax.
97- Example: bindObservers("sectionSelector");
98- sectionSelector can be Id, Class and Element name.
99- */
100- function bindObservers ( bind_element ) {
97+ /* initializeEvents function contains the code of adding events at the loading of the page */
98+ function initializeEvents ( ) {
10199
102100 // Adding observer for checkboxes for select all action.
103- jQuery ( bind_element ) . on ( "click" , "[type=checkbox]" , function ( ) {
101+ $ ( "body" ) . on ( "click" , "[type=checkbox]" , function ( ) {
104102 var action_checkbox = jQuery ( this ) ,
105103 parent_action = action_checkbox . is ( ".selectAll" ) ? action_checkbox : action_checkbox . getForm ( ) . getFormFields ( ) . filter ( ".selectAll" ) ;
106104 if ( parent_action . length !== 0 ) {
107105 addSelectAllObserver ( action_checkbox ) ;
108106 }
109107 } ) ;
110108
109+ $ ( "body" ) . on ( "click" , "[data-dialog-url]" , function ( ) {
110+ var element = jQuery ( this ) ;
111+ var url = element . data ( "dialog-url" ) ;
112+ var title = element . data ( "dialog-title" ) ;
113+ var width = element . data ( "dialog-width" ) ;
114+ var height = element . data ( "dialog-height" ) ;
115+ var params = element . data ( "dialog-params" ) ;
116+ var dialogContainer = jQuery ( '<div/>' ) ;
117+ dialogContainer . dialog ( {
118+ autoOpen : false ,
119+ title : title ,
120+ height : height ,
121+ width : width ,
122+ modal : true ,
123+ closeOnEscape : true ,
124+ close : function ( ) {
125+ dialogContainer . dialog ( 'destroy' ) ;
126+ } ,
127+ open : function ( ) {
128+ jQuery . ajax ( {
129+ url : url ,
130+ type : "POST" ,
131+ data : params ,
132+ success : function ( data ) {
133+ dialogContainer . html ( data ) ;
134+ bindObservers ( dialogContainer ) ;
135+ } ,
136+ error : ( xhr ) => {
137+ // unauthorized user, reload page with the link id so we can reopen the modal
138+ if ( xhr . status === 401 ) {
139+ const url = new URL ( window . location . href ) ;
140+ url . searchParams . append ( SP_CLICK_ON , element . attr ( 'id' ) ) ;
141+ window . location . replace ( url . toString ( ) ) ;
142+ } else {
143+ // display some feedback in the modal body
144+ dialogContainer . text ( `An unexpected server error occurred (status : ${ xhr . status } ).` ) ;
145+ }
146+ }
147+ } ) ;
148+ }
149+ } ) ;
150+ dialogContainer . dialog ( "open" ) ;
151+ dialogContainer . on ( "closeCurrentModalAfterAjaxSubmitFormUpdateAreasInSuccess" , function ( ) {
152+ dialogContainer . dialog ( "destroy" ) ;
153+ } ) ;
154+ } ) ;
155+
156+ $ ( "body" ) . on ( "click" , "[data-confirm-message]" , function ( e ) {
157+ var element = jQuery ( this ) ;
158+ var confirmMessage = element . data ( "confirm-message" ) ;
159+ if ( ! confirm ( confirmMessage ) ) {
160+ e . preventDefault ( ) ;
161+ }
162+ } ) ;
163+ }
164+
165+ /* bindObservers function contains the code of adding observers and it can be called for specific section as well
166+ when we need to add observer on section which is updated by Ajax.
167+ Example: bindObservers("sectionSelector");
168+ sectionSelector can be Id, Class and Element name.
169+ */
170+ function bindObservers ( bind_element ) {
171+
111172 // If parent checkbox is already checked on DOM ready then check its child checkboxes also.
112173 if ( jQuery ( ".selectAll" ) . is ( ":checked" ) ) {
113174 jQuery ( ".selectAll" ) . removeAttr ( "checked" ) . trigger ( "click" ) ;
@@ -181,59 +242,7 @@ function bindObservers(bind_element) {
181242 var params = element . data ( "inplace-editor-params" ) ;
182243 ajaxInPlaceEditDisplayField ( id , url , ( new Function ( "return " + params + ";" ) ( ) ) ) ;
183244 } ) ;
184- jQuery ( bind_element ) . on ( "click" , "[data-dialog-url]" , function ( ) {
185- var element = jQuery ( this ) ;
186- var url = element . data ( "dialog-url" ) ;
187- var title = element . data ( "dialog-title" ) ;
188- var width = element . data ( "dialog-width" ) ;
189- var height = element . data ( "dialog-height" ) ;
190- var params = element . data ( "dialog-params" ) ;
191- var dialogContainer = jQuery ( '<div/>' ) ;
192- dialogContainer . dialog ( {
193- autoOpen : false ,
194- title : title ,
195- height : height ,
196- width : width ,
197- modal : true ,
198- closeOnEscape : true ,
199- close : function ( ) {
200- dialogContainer . dialog ( 'destroy' ) ;
201- } ,
202- open : function ( ) {
203- jQuery . ajax ( {
204- url : url ,
205- type : "POST" ,
206- data : params ,
207- success : function ( data ) {
208- dialogContainer . html ( data ) ;
209- bindObservers ( dialogContainer ) ;
210- } ,
211- error : ( xhr ) => {
212- // unauthorized user, reload page with the link id so we can reopen the modal
213- if ( xhr . status === 401 ) {
214- const url = new URL ( window . location . href ) ;
215- url . searchParams . append ( SP_CLICK_ON , element . attr ( 'id' ) ) ;
216- window . location . replace ( url . toString ( ) ) ;
217- } else {
218- // display some feedback in the modal body
219- dialogContainer . text ( `An unexpected server error occurred (status : ${ xhr . status } ).` ) ;
220- }
221- }
222- } ) ;
223- }
224- } ) ;
225- dialogContainer . dialog ( "open" ) ;
226- dialogContainer . on ( "closeCurrentModalAfterAjaxSubmitFormUpdateAreasInSuccess" , function ( ) {
227- dialogContainer . dialog ( "destroy" ) ;
228- } ) ;
229- } ) ;
230- jQuery ( bind_element ) . on ( "click" , "[data-confirm-message]" , function ( e ) {
231- var element = jQuery ( this ) ;
232- var confirmMessage = element . data ( "confirm-message" ) ;
233- if ( ! confirm ( confirmMessage ) ) {
234- e . preventDefault ( ) ;
235- }
236- } ) ;
245+
237246 jQuery ( bind_element ) . find ( "[data-lookup-presentation]" ) . each ( function ( ) {
238247 var element = jQuery ( this ) ;
239248 var form = element . _form ( ) ;
@@ -670,15 +679,11 @@ function ajaxUpdateArea(areaId, target, targetParams) {
670679
671680function updateArea ( areaId , data ) {
672681 // If the area is indicate as embedded why replace the area instead inject into
673- var bindObserversArea = "#" + areaId
674682 if ( / ^ e m b e d d e d / . test ( areaId ) ) {
675683 jQuery ( "#" + areaId ) . replaceWith ( data ) ;
676- const newContentId = $ ( data ) . filter ( '.embeddedScreen' ) . attr ( 'id' ) ;
677- bindObserversArea = "#" + newContentId ;
678684 } else {
679685 jQuery ( "#" + areaId ) . html ( data ) ;
680686 }
681- bindObservers ( bindObserversArea ) ;
682687}
683688
684689/** Update multiple areas (HTML container elements).
@@ -851,6 +856,12 @@ function ajaxSubmitFormUpdateAreas(formName, areaCsvString, close) {
851856 areaId = $form [ 0 ] . target
852857 }
853858 updateArea ( areaId , data )
859+ var bindObserversArea = "#" + areaId
860+ if ( / ^ e m b e d d e d / . test ( areaId ) ) {
861+ const newContentId = $ ( data ) . filter ( '.embeddedScreen' ) . attr ( 'id' ) ;
862+ bindObserversArea = "#" + newContentId ;
863+ }
864+ bindObservers ( bindObserversArea ) ;
854865 } else {
855866 if ( containsErrorMessages ( data ) ) {
856867 displayErrorMessages ( data )
0 commit comments