fix crazy races with javasacript by using global delegations
This commit is contained in:
		| @@ -3,9 +3,9 @@ | ||||
|   var path = 'admin'; | ||||
|  | ||||
|   // this is called by do_search to support local code | ||||
|   // here, when tab changes need to strike/unstrike the navbar search | ||||
|   // which might need to act on the newly inserted content | ||||
|   // but which cannot use jQuery delegation via .on() | ||||
|   function inner_view_processing(tab) { | ||||
|     var target = '#' + tab + '_pane'; | ||||
|  | ||||
|     // activate typeahead on the topo boxes | ||||
|     $('.nd_topo_dev').autocomplete({ | ||||
| @@ -14,10 +14,6 @@ | ||||
|       ,minLength: 0 | ||||
|     }); | ||||
|  | ||||
|     // get all devices on device input focus | ||||
|     $(".nd_topo_dev").on('focus', function(e) { $(this).autocomplete('search', '%') }); | ||||
|     $(".nd_topo_dev_caret").on('click', function(e) { $(this).siblings('.nd_topo_dev').autocomplete('search', '%') }); | ||||
|  | ||||
|     // activate typeahead on the topo boxes | ||||
|     $('.nd_topo_port.nd_topo_dev1').autocomplete({ | ||||
|       source: function (request, response)  { | ||||
| @@ -40,10 +36,25 @@ | ||||
|       ,delay: 150 | ||||
|       ,minLength: 0 | ||||
|     }); | ||||
|   } | ||||
|  | ||||
|   // on load, establish global delegations for now and future | ||||
|   $(document).ready(function() { | ||||
|     var tab = '[% task.tag %]' | ||||
|     var target = '#' + tab + '_pane'; | ||||
|  | ||||
|     // get all devices on device input focus | ||||
|     $(target).on('focus', '.nd_topo_dev', function(e) { | ||||
|       $(this).autocomplete('search', '%') }); | ||||
|     $(target).on('click', '.nd_topo_dev_caret', function(e) { | ||||
|       $(this).siblings('.nd_topo_dev').autocomplete('search', '%') }); | ||||
|  | ||||
|     // get all ports on port input focus | ||||
|     $(".nd_topo_port").on('focus', function(e) { $(this).autocomplete('search') }); | ||||
|     $(".nd_topo_port_caret").on('click', function(e) { $(this).siblings('.nd_topo_port').autocomplete('search') }); | ||||
|     $(target).on('focus', '.nd_topo_port', function(e) { | ||||
|       $(this).autocomplete('search') }); | ||||
|     $(target).on('click', '.nd_topo_port_caret', function(e) { | ||||
|       $(this).siblings('.nd_topo_port').autocomplete('search') }); | ||||
|  | ||||
|  | ||||
|     // activity for admin task tables | ||||
|     // dynamically bind to all forms in the table | ||||
| @@ -54,7 +65,7 @@ | ||||
|       // submit the query and put results into the tab pane | ||||
|       $.ajax({ | ||||
|         type: 'POST' | ||||
|         ,async: false | ||||
|         ,async: true | ||||
|         ,dataType: 'html' | ||||
|         ,url: uri_base + '/ajax/content/admin/' + tab + '/' + $(this).attr('name') | ||||
|         ,data: $(this).serializeArray() | ||||
| @@ -64,7 +75,7 @@ | ||||
|           ); | ||||
|         } | ||||
|         ,success: function(content) { | ||||
|           $(target).html(content); | ||||
|           $('#' + tab + '_form').trigger('submit'); | ||||
|         } | ||||
|         ,error: function() { | ||||
|           $(target).html( | ||||
| @@ -74,8 +85,4 @@ | ||||
|         } | ||||
|       }); | ||||
|     }); | ||||
|   } | ||||
|  | ||||
|   // on load, check initial Device Search Options form state, | ||||
|   // and on each change to the form fields | ||||
|   $(document).ready(function() { }); | ||||
|   }); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user