/*global <%= appClassName %>, Backbone, JST*/

<%= appClassName %>.Views = <%= appClassName %>.Views || {};

(function () {
    'use strict';
    <%= appClassName %>.Views.<%= className %> = Backbone.View.extend({
        template: JST['<%= jst_path %>'],
        tagName: 'div',
        collection:new <%= appClassName %>.Collections.<%= collectionName %>(),
        className: '',
        events: {},
        initialize: function (collection) {
            if(collection instanceof this.collectionFun){
                this.collection=collection;
            }else{
                this.collection=new this.collectionFun();
                this.collection.fetch({beforeSend:function(xhr){},reset:true,data:{}});
            }
            this.listenTo(this.collection, 'reset', this.render);
        },
        render: function () {
            this.$el.html(this.template({<%=collectionName.toString().toLowerCase() %>:this.collection.toJSON()}));
            $('#body').html(this.$el.html());
            this.trigger("render", "render done!");
            return this;
        },
        remove: function(){
            this.undelegateEvents();
        }
    });
})();
