/// class ProspectDirector.Web.UI.FeatureSets.MacroEditorAssembler
/// using ProspectDirector.Web.UI.FeatureSets.EditorAssemblerBase

/**
@class MacroEditorAssembler
@namespace Web.UI.FeatureSets
@extends Web.UI.FeatureSets.EditorAssemblerBase
@constructor
**/
ProspectDirector.Web.UI.FeatureSets.MacroEditorAssembler = ProspectDirector.Web.UI.FeatureSets.EditorAssemblerBase.extend({

    //==============================
    // FIELDS
    //==============================

    _editors: null,

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

    init: function (options) {
        this._super(options);
        this._editors = this.get_featureSet().get_editors().getByGroupId(this.get_groupId());
    },

    //==============================
    // PROPERTIES
    //==============================

    get_editors: function () {
        return this._editors;
    },
    
    //==============================
    // PUBLIC METHODS
    //==============================

    DOM: function () {

        if (!this._DOM) {
            this._DOM = new ProspectDirector.Web.UI.FeatureSets.MacroEditorAssemblerDOM({
                containerID: this.get_options().containerId,
                groupId: this.get_groupId(),
                id: this.get_id()
            });
        }

        return this._DOM;

    },

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

    resize: function () {

        var that = this,
            dimensions = this.DOM().getDimensions();

        this.get_editors().each(function (index, editor) {
            editor.focus();
        });

        this.get_editors().each(function (index, editor) {
            var size = editor.calculateDimensions(dimensions.height, dimensions.width);
            editor.size(size);
        });

    },

    render: function () {

        var content = "";

        this.get_editors().each(function (index, editor) {
            content += editor.render();
        });

        return this.DOM().render(null, content);

    },

    setValidationErrors: function (validationErrors) {
        this._super(validationErrors);

        var that = this;

        this.get_editors().each(function (index, editor) {
            var filteredValidationErrors = validationErrors.getByFeatureType(editor.get_feature().get_binding());
            editor.setValidationErrors(filteredValidationErrors);
        });

    },

    activate: function () {

        this._super();

        this.get_editors().each(function (index, editor) {
            editor.activate();
        });

        if (this.get_validationErrors()) {
            this.setValidationErrors(this.get_validationErrors());
        }

    },

    onValidationError: function (data) {
        // overridable
    }

});