 
     @addSubView @listController.getView()
 
-    @listController.on 'LazyLoadThresholdReached', @bound 'fetchMembers'
+    @listController.on 'LazyLoadThresholdReached', =>
+      if @searchInput.getValue()
+        unless @isFetching
+          @isFetching = yes
+          @page++
+          @search()
+      else
+        @fetchMembers()
 
 
   fetchMembers: ->


  search: ->

    @skip  = 0
    @query = @searchInput.getValue()

    @refresh()


  refresh: ->

    @listController.removeAllItems()
    @listController.lazyLoader.show()
    @fetchMembers()


      return @handleError err  if err

      @fetchUserRoles members, (members) =>
        @listMembers members
        @isFetching = no


  fetchUserRoles: (members, callback) ->

    # collect account ids to fetch user roles
    ids = members.map (member) -> return member.getId()

    myAccountId = whoami().getId()
    ids.push myAccountId

    @getData().fetchUserRoles ids, (err, roles) =>
      return @handleError err  if err

      # create account id and roles map
      userRoles = {}

      # roles array is a flat array which means when you query for an account
      # the response would be 3 items array which contains different roles for
      # the same user. create an array by user and collect all roles belong
      # to that user.
      for role in roles
        list = userRoles[role.targetId] or= []
        list.push role.as

      # save user role array into jAccount as jAccount.role
      for member in members
        roles = userRoles[member.getId()]
        member.roles = roles  if roles

      @loggedInUserRoles = userRoles[myAccountId]

      callback members


  handleError: (err) ->
