Fixees #6496 by refactoring code in edit_contentlet.js