/// class ProspectDirector.Web.UI.FeatureSets.Layouts.SimpleLayout

/**
@class SimpleLayout
@namespace Web.UI.FeatureSets.Layouts
@constructor
@extends Web.UI.FeatureSets.Layouts.Layout
**/
ProspectDirector.Web.UI.FeatureSets.Layouts.SimpleLayout =
ProspectDirector.Web.UI.FeatureSets.Layouts.Layout.extend({

    //================================
    // CONSTRUCTOR
    //================================

    init: function (options) {
        this._super(options);
        this.get_eventBus().subscribe("validationErrors", $.proxy(this._onValidationErrors, this));
    },

    //================================
    // EVENT HANDLERS
    //================================

    _onValidationErrors: function (e, data) {

        var errors = data.validationErrors;

        this.get_assemblers().each(function (index, assembler) {
            assembler.setValidationErrors(errors.getByGroupId(assembler.get_groupId()));
        });

    },

    //================================
    // PUBLIC METHODS
    //================================

    DOM: function () {

        if (!this._DOM) {
            this._DOM = new ProspectDirector.Web.UI.FeatureSets.Layouts.SimpleLayoutDOM({
                containerID: this.get_options().containerId
            });
        }

        return this._DOM;

    },

    //================================
    // PUBLIC OVERIDDEN METHODS
    //================================

    resize: function (e) {

        this.get_assemblers().each(function (index, assembler) {
            assembler.resize();
        });

    },

    render: function () {

        var that = this,
            groups = new ProspectDirector.Web.List();

        this.get_featureSet().get_groups().each(function (index, group) {

            var assembler = that.getAssemblerByGroupId(group.get_id());

            groups.add({
                id: group.get_id(),
                content: assembler.render()
            });

        });

        return this.DOM().render(groups);

    },

    activate: function () {

        this.get_assemblers().each(function (index, assembler) {
            assembler.activate();
        });

    },

    reload: function (featureSet) {
        this._super(featureSet);
        this.DOM().clear();
    }

});