Index: branches/5.1.x/core/admin_templates/js/script.js =================================================================== diff -u -N -r13402 -r13461 --- branches/5.1.x/core/admin_templates/js/script.js (.../script.js) (revision 13402) +++ branches/5.1.x/core/admin_templates/js/script.js (.../script.js) (revision 13461) @@ -1795,4 +1795,34 @@ break; } } +} + +function disable_categories($category_dropdown_id, $allowed_categories) { + if ($allowed_categories === true) { + return ; + } + + var $selected_category = false; + var $categories = $( jq('#' + $category_dropdown_id) ).children('option'); + + $categories.each( + function () { + var $me = $(this); + var $category_id = parseInt( $me.attr('value') ); + + if (!in_array($category_id, $allowed_categories)) { + if ($me.attr('selected')) { + $selected_category = $me; + } + + $me.attr('disabled', 'disabled'); + } + } + ); + + if ($selected_category !== false && $allowed_categories.length > 0) { + // when selected category became disabled -> select 1st available category + $selected_category.attr('selected', ''); + $("option[value='" + $allowed_categories[0] + '"]', $categories).attr('selected', 'selected'); + } } \ No newline at end of file