           
           if not request.owners
             return false
-            
+
           for owner in request.owners
             ownerTrimmed = owner.split("@")[0]
             if deployUserTrimmed == ownerTrimmed
               return true
-          
+
           return false
         userRequestTotals =
             all: userRequests.length


class DashboardView extends View

    template: require '../templates/dashboard'

    events: ->
        _.extend super,
            'click [data-action="unstar"]': 'unstar'
            'click [data-action="change-user"]': 'changeUser'

    initialize: =>
        @listenTo app.user, 'change', @render

            deployUser: deployUser
            collectionSynced: @collection.synced
            userRequestTotals: userRequestTotals or { }
            haveStarredRequests: @collection.getStarredOnly().length

        @$el.html @templateBase context, partials
        @renderTable()

    renderTable: =>
        @sortCollection()
        requests = @currentRequests

        $contents = @templateRequestsTable
            starredRequests: requests
            requests: requests

        $table = @$ ".table-staged table"
        $tableBody = $table.find "tbody"
        $tableBody.html $contents

    sortCollection: =>
        requests = _.pluck @collection.getStarredOnly(), "attributes"

        # Sort the table if the user clicked on the table heading things
        if @sortAttribute?
            requests = _.sortBy requests, (request) =>

                # Traverse through the properties to find what we're after
                attributes = @sortAttribute.split '.'
                value = request
                for attribute in attributes
                    value = value[attribute]
                    value = '' if not value?
                return value

            if not @sortAscending
                requests = requests.reverse()
        else
            requests.reverse()

        @currentRequests = requests

    sortTable: (event) =>
        @isSorted = true

        $target = $ event.currentTarget
        newSortAttribute = $target.attr "data-sort-attribute"

        $currentlySortedHeading = @$ "[data-sorted=true]"
        $currentlySortedHeading.removeAttr "data-sorted"
        $currentlySortedHeading.find('span').remove()


        if newSortAttribute is @sortAttribute and @sortAscending?
            @sortAscending = not @sortAscending
        else
            # timestamp should be DESC by default
            @sortAscending = if newSortAttribute is "timestamp" then false else true

        @sortAttribute = newSortAttribute

        $target.attr "data-sorted", "true"
        $target.append "<span class='glyphicon glyphicon-chevron-#{ if @sortAscending then 'up' else 'down' }'></span>"

        @renderTable()

    unstar: (e) =>
        $target = $ e.currentTarget
