Categories: Refactor for sorting

* Simplifies and abstracts out generation of category ids.
  Pads ids for proper sorting.
  Ids now have the more compact format of "###".
  Id generation logic put in separate function.

* Puts sorting of adapted categories into deferred.then callback

Bug: 66666
Change-Id: I5f42305d85bd5c8e4bdf4d5b2c67b215a6c145ff