     cache = {}
     values.reduce (acc, {module, role, permission})->
       storageKey = module+':'+role
+
+      console.log {storageKey}
       cached = cache[storageKey]
       if cached?
         cached.permissions.push permission

            @buttons["Save"].hideLoader()
            # TODO: do something with this callback

    options.fields or= optionizePermissions permissionSet
    super options,data
    @setClass 'permissions-form col-'+roles.length

  #   @bindEvent 'scroll'
  #   @on 'scroll', (event={})=>
  #     @applyScrollShadow event

  # applyScrollShadow:(event)->
  #   isAtTop = @$().scrollTop() is 0
  #   isAtBottom = @$().scrollTop()+@getHeight() is @$()[0].scrollHeight

  #   unless isAtTop
  #     @$('.permissions-header').addClass 'scrolling'
  #   else
  #     @$('.permissions-header').remove 'scrolling'

  #   unless isAtBottom
  #     @$('.formline.button-field').addClass 'scrolling'
  #   else
  #     @$('.formline.button-field').removeClass 'scrolling'


  createTree =(values)->
    values.reduce (acc, {module, role, permission})->

class PermissionsModal extends KDFormViewWithFields

  # TODO: this class is a bit of a mess.  I did some light refactoring, but
  # I decided that at least some of the concerns I have with this file are
  # dependent upon a cleaner intermediate data structure in the form api.

  constructor:(options,data)->

    group                   = data # @getData()
    {privacy,permissionSet} = options #@getOptions()

    roles = (role.title for role in options.roles when role.title isnt 'owner')

    options.buttons or=
      "Add Role"          :
