/*global define*/

define([
    'jquery',
    'underscore',
    'backbone',
    'collections/<%=collectionName.toString().toLowerCase() %>',
    'templates'
], function ($, _, Backbone, <%= collectionName %>, JST) {
    'use strict';
    var <%= className %>View = Backbone.View.extend({
        template: JST['<%= jst_path %>'],
        collectionFun:<%= collectionName %>,
        tagName: 'div',
        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();
        }
    });
    return <%= className %>View;
});
