fix / update for broken gallery sorting

adds two new functions, one to query the gallery on the admin side, and one to properly save it. also includes JS for sorting items and some general cleanup
old habit, honestly. do it to make sure it doesn't try to apply the sortable if the element doesn't exist. but probably not needed.