       return error err  if err?
 
       unless bundle?
-        @createBundleView = new GroupsBundleCreateView {}, group
+        @createBundleView = new GroupsBundleCreateView {}, { group }
         @createBundleView.once 'BundleCreated', @bound 'resetBundleView'
         @addSubView @createBundleView
       else
-        @editBundleView = new GroupsBundleEditView {}, group
+        @editBundleView = new GroupsBundleEditView {}, { group, bundle }
         @editBundleView.once 'BundleDestroyed', @bound 'resetBundleView'
         @addSubView @editBundleView


class GroupsBundleEditView extends JView

  constructor: (options, data) ->
    super

    group = @getData()

    @destroyButton = new KDButtonView
      style     : "clean-gray"
      title     : "Destroy bundle"
      callback  : =>
        group.destroyBundle (err, bundle) =>


          @emit 'BundleDestroyed', bundle

    @saveButton = new KDButtonView
      style     : "modal-clean-green"
      title     : "Save bundle"
      callback  : =>
        overagePolicy = @overagePolicy.getValue()
        group.updateBundle { overagePolicy }

    @overageLabel = new KDLabelView
      title     : 'Overage policy'

    @overagePolicy = new KDSelectBox
      label       : @overageLabel
      name        : "overagePolicy"
      defaultValue: bundle.overagePolicy ? "not allowed"
      selectOptions : [
        { value : "not allowed",    title : "Not allowed" }
        { value : "by permission",  title : "Allowed only with admin approval" }
        { value : "allowed",        title : "Allowed for all members" }
      ]

  renderLimits: (limits) ->
    @limits.destroySubViews()
    @limitsData = {}
    for limit in limits
      @limitsData[limit.title] = limit
      cssClass = 'group-bundle-limit'
      cssClass += ' hidden'  unless computeUnitVisibility[limit.title]
      limitView = new GroupsBundleLimitView {cssClass}, limit
      @addSubView limitView

  pistachio: ->
    """
    <h3>Bundle details</h3>
    <p>There will be some cool details here.</p>
    <div class="group-bundle-plan-sliders clearfix">
      <div>{{> @usersLabel}} {{> @usersSlider}}</div>
      <div>{{> @computeLabel}}  {{> @computeSlider}}</div>
      <div>{{> @overageLabel}} {div#overage{> @overagePolicy}}</div>
    </div>
    {{> @limits}}
    <div>{{> @saveButton}} {{> @destroyButton}}</div>
    """

# class GroupsBundleLimitWrapper extends KDObject
#   constructor: (@limit, @usersLimit)->
#     super()
#     @calculate()
#     @limit.on 'update', @bound 'calculate'
#     @usersLimit.on 'update', @bound 'calculate'

#   calculate:->
#     {@unit, @title, @quota, @usage} = @limit
#     @perUserQuota = @quota / @usersLimit.quota
#     console.log this
#     @emit 'update'

class GroupsBundleLimitPerUserView extends JView

  pistachio: ->
    """
    {h2{#(title)}}
    {h3{#(usage)}}
    <h3>/</h3>
    <h3>{.per-user{#(perUserQuota)}} - {.total{#(quota)}}</h3>
    {h4{#(unit)}}
    """

class GroupsBundleLimitView extends JView

  pistachio: ->
    """
    {h2{#(title)}}
    {h3{#(usage)}}
    <h3>/</h3>
    {h3{#(quota)}}
    {h4{#(unit)}}
    """

class GroupsBundleView extends KDView

