=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ouwt/ouwt.js' --- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ouwt/ouwt.js 2014-10-10 14:03:12 +0000 +++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ouwt/ouwt.js 2014-10-17 06:19:47 +0000 @@ -403,43 +403,51 @@ } else { selection.busy( true ); - $.ajax( { - url: organisationUnitTreePath + "clearselected.action", - type: 'POST' - }).done(function() { - var selected = selection.getSelected(); - - if( multipleSelectionAllowed ) { - var q = ''; - - $.each( selected, function( i, item ) { - q += "id=" + item; - - if( i < (selected.length - 1) ) { - q += '&'; - } - }); - - $.ajax({ - url: organisationUnitTreePath + "addorgunit.action", - data: q, - type: 'POST' - } ).complete( function() { - selection.busy( false ); - }); - } else { - selected = $.isArray( selected ) ? selected[0] : selected; - - $.post( organisationUnitTreePath + "setorgunit.action", { - id: selected - } ).complete( function() { - selection.busy( false ); - fn(); - } ); - } - }).always(function() { - selection.busy( false ); - }); + if( selection.getSelected() && selection.getSelected().length === 0 ) { + setTimeout(doSync, 1000); + } else { + doSync(); + } + + function doSync() { + $.ajax( { + url: organisationUnitTreePath + "clearselected.action", + type: 'POST' + }).done(function() { + var selected = selection.getSelected(); + + if( multipleSelectionAllowed ) { + var q = ''; + + $.each( selected, function( i, item ) { + q += "id=" + item; + + if( i < (selected.length - 1) ) { + q += '&'; + } + }); + + $.ajax({ + url: organisationUnitTreePath + "addorgunit.action", + data: q, + type: 'POST' + } ).complete( function() { + selection.busy( false ); + }); + } else { + selected = $.isArray( selected ) ? selected[0] : selected; + + $.post( organisationUnitTreePath + "setorgunit.action", { + id: selected + } ).complete( function() { + selection.busy( false ); + fn(); + } ); + } + }).always(function() { + selection.busy( false ); + }); + } } };