This example shows how to use a CapabilitiesGrid to let the user choose layers, as well as add new layer sources from WMS services. Adding new layer sources requires that a proxy be configured.
The js is not minified so it is readable. See capabilitiesgrid.js.