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

          selectOptions   = [{title:'None',value:null}]
          selectOptions.push {title:readableText(role),value:role} for role in roles

          form.addSubView @inputCopyPermissions = inputCopyPermissions = new KDSelectBox
            cssClass      : 'copy-permissions'
            selectOptions : selectOptions
            defaultValue  : null

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

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

  readableText = (text)->
    dictionary =
      "JTag" : "Tags"
      "JGroup": 'Groups'
      "JReview": 'Reviews'
      "JPost":'Posts'
      "JVocabulary": 'Vocabularies'
      "JVM": "Compute"
    return dictionary[text] or text.charAt(0).toUpperCase()+text.slice(1)

  _getCheckboxName =(module, permission, role)->
    ['permission', module].join('-')+'|'+[role, permission].join('|')

  checkForPermission = (permissions,module,permission,role)->
    for perm in permissions
      if perm.module is module and perm.role is role
        for perm1 in perm.permissions
          if perm1? and perm1 is permission
            return yes
        return no

  cascadeFormElements = (set,roles,module,permission)->
    [current,remainder...] = roles
    cascadeData = {}

    isChecked = checkForPermission set.permissions, module, permission, current

    cssClass = 'permission-checkbox '+__utils.slugify(permission)+' '+current

    name = _getCheckboxName module, permission, current

    cascadeData[current]= {
      name
      cssClass
      itemClass: KDCheckBox
      defaultValue: isChecked ? no
    }

    if current in ['admin','owner']
      cascadeData[current].defaultValue = yes
      cascadeData[current].disabled = yes
    if current and remainder.length > 0
      cascadeData[current].nextElementFlat = cascadeFormElements set, remainder, module, permission
    return cascadeData

  cascadeHeaderElements = (roles)->
    [current,remainder...] = roles
    cascadeData = {}
    cascadeData[current]=
      itemClass     : KDView
      partial       : readableText current
      cssClass      : 'text header-item role-'+__utils.slugify(current)
      tooltip       :
        showOnlyWhenOverflowing : yes
        title       : readableText current
        placement   : 'top'
        direction   : 'center'
        offset      :
          top       : 5
          left      : 0
    if current and remainder.length > 0
      cascadeData[current].nextElementFlat = cascadeHeaderElements remainder
    return cascadeData

  optionizePermissions = (roles, set)->
    permissionOptions =
      head              :
        itemClass       : KDView
        cssClass        : 'permissions-header col-'+roles.length
        nextElementFlat :
          cascadeHeaderElements roles

    for module, permissions of set.permissionsByModule
      permissionOptions['header '+module.toLowerCase()] =
        itemClass       : KDView
        partial         : readableText module
        cssClass        : 'permissions-module text'

      for permission in permissions
        permissionOptions[module+'-'+__utils.slugify(permission)] =
          itemClass     : KDView
          partial       : readableText permission
          cssClass      : 'text'
          tooltip       :
            title       : readableText permission
            direction   : 'center'
            placement   : 'left'
            offset      :
              top       : 3
              left      : 0
            showOnlyWhenOverflowing : yes
          nextElementFlat :
            cascadeFormElements set, roles, module, permission
    permissionOptions

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