To avoid making a server request every time the dropdown opens, the whole list of groups are cached (from the last request): Whenever the user types in a search term it will still send server requests.
Added explicit escaping. Now internally using a pipe symbol as separator for select2, to make it possible to use group names containing commas.
Moved setupGroupsSelect() from admin.js to a common settings.js as OC.Settings.setupGoupsSelect(). Now using select2 as well on the apps page.