### codetube
    Copyright (C) 2011 payload payload@lavabit.com
    Copyright (C) 2011 dodo dodo.the.last@gmail.com

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.

    You should have received a copy of the GNU Affero General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>
###

{ DiffView } = require './diff'
{ Backbone } = require '../Backbone'

class DiffsView extends Backbone.View

    initialize: ({@el}) ->
        @views = []
        @model.bind 'add', @add_diff
        @one 'hide:progressbar', @hide_progressbar
        do @render
        super

    hide_progressbar: =>
        @$(".progressbar").css 'visibility', 'hidden'
        @one 'show:progressbar', @show_progressbar

    show_progressbar: =>
        @$(".progressbar").css 'visibility', 'visible'
        @one 'hide:progressbar', @hide_progressbar


    render: () =>
        for view in @views
            view.render()
        this

    add_diff: (commit) =>
        view = new DiffView model:commit
        _.extend view, { @owner, @project, @sha }
        @views.push view
        do view.render

        @$('.files').append view.el



module.exports = { DiffsView }
