     , (d)-> d.valueOf()
     f(@date)
 
+  findResaOn: (day)->
+    Bookings.find {
+        date: day.toDate()
+      }, {
+        fields: {'_id':1, date: 1, color: 1, owner: 1}
+      }
   hazBooking: (day)->
     return [] if @reservations.length is 0
-    f = lodash.memoize (d)=>
-      return @reservations.filter (r)->
-        moment.utc(r.date).format('DDMMYY') is d.format('DDMMYY')
-      .map (r)=>
-        { color: @owners["#{r.owner}"], owner: r.owner, id: r._id }
-    , (d)-> d.valueOf()
-    f(day)
+    @findResaOn(day)
+    .map (r)=>
+      { owner: lodash.find(@owners, (u)-> u._id is r.owner), id: r._id }
 
   cancelEdition: ->
     @editing = false

    @bookings.forEach (b)=>
      return unless b.canBook
      return if b.booked is b.original
      @reservations.save( {
        date: b.toISOString()
        owner: @ownerId
        #'_id': b.id
      }).then (data)=>
        b.id = data[0]._id
        b.owners.push {owner: @ownerId, color: @owners[@ownerId], id: b.id }
        @initDay b
        @updateDay b
      .catch (err)=>
        console.error err
        @Notification.error "Une erreur est survenue"
    @cancelations.forEach (c)=>
      id = _.find(c.owners, (o)=> o.owner is @ownerId)?.id
      return unless id
      @reservations.remove(id).then (data)=>
        lodash.remove c.owners, (o)-> o.id is id
        @initDay c
        @updateDay c
      .catch (err)->
        console.error err
    @bookings = []
    @cancelations = []
    @selections = []

  o

class Calendar
  constructor: ($scope, $reactive, $meteor, @$q, @Notification)->
    $reactive(@).attach $scope

    console.group "Calendar Controller"

    @ownerId = Meteor.user()?._id
    @weeks = []
    @_weeks = []
    @selections = []
    @removables = []
    @cancelations = []
    @bookings = []

    @subscribe 'users'
    @subscribe 'bookings'

    @date = moment.utc().startOf('d')
    @helpers(
      date : moment.utc().startOf('d')
      owners: -> Meteor.users.find {}
      reservations: =>
        start = moment.utc(@date).startOf('month').add(-1,'w')
        end = moment.utc(@date).endOf('month').add(1,'w')
        Bookings.find {
          date: {
            $lte: end.toDate()
            $gte:start.toDate()
          }
        }, {
          fields: {'_id':1, date: 1, color: 1, owner: 1}
        }
    )
    @autorun( =>
      if @reservations[0]
        @display()
        $scope.$apply()
    )
    #Meteor.call 'booking_on', moment(), (err, res)=>
      #return console.error err if err
      #console.group "BOOKING ON"
      #console.log res
      #console.groupEnd()

    labels = moment.weekdays()
    dim = labels.shift()
