@@ -23,15 +23,29 @@ def wait_for_task
2323 end
2424 end
2525
26- def browser_refresh_task ( task_id , async_interval , should_flash : false )
26+ def browser_refresh_task ( task_id , async_interval , should_flash : false , response_type : nil )
27+ response_type ||= :script
28+
2729 async_interval = 1000 if async_interval . to_i < 1000 # if it is not an integer, assign to 1 second
2830 async_interval += 250 if async_interval . to_i < 5000 # Slowly move up to 5 second retries
29- render :update do |page |
30- page << javascript_prologue
31- ajax_call = remote_function ( :url => { :action => 'wait_for_task' , :task_id => task_id , :async_interval => async_interval } )
32- page << "setTimeout(\" #{ ajax_call } \" , #{ async_interval } );"
33- page . replace ( "flash_msg_div" , :partial => "layouts/flash_msg" ) if should_flash
34- page << "miqScrollTop();" if @flash_array . present?
31+
32+ case response_type
33+ when :script
34+ render :update do |page |
35+ page << javascript_prologue
36+ ajax_call = remote_function ( :url => { :action => 'wait_for_task' , :task_id => task_id , :async_interval => async_interval } )
37+ page << "setTimeout(\" #{ ajax_call } \" , #{ async_interval } );"
38+ page . replace ( "flash_msg_div" , :partial => "layouts/flash_msg" ) if should_flash
39+ page << "miqScrollTop();" if @flash_array . present?
40+ end
41+ when :json
42+ render :json => {
43+ :async_interval => async_interval ,
44+ :task_id => task_id ,
45+ :should_flash => should_flash
46+ }
47+ else
48+ raise "Invalid response type: #{ response_type } "
3549 end
3650 end
3751 private :browser_refresh_task
@@ -65,7 +79,7 @@ def initiate_wait_for_task(options = {})
6579 task . context_data = ( task . context_data || { } ) . merge ( :async_params => async_params )
6680 task . save!
6781
68- browser_refresh_task ( task_id , async_interval , :should_flash => !!options [ :flash ] )
82+ browser_refresh_task ( task_id , async_interval , :should_flash => !!options [ :flash ] , :response_type => options [ :response_type ] )
6983 end
7084 private :initiate_wait_for_task
7185
0 commit comments