Orbital degeneracy, Jahn-Teller effect, and superconductivity in transition-metal chalcogenides