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

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

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

    _definitions: null,
    _editors: null,

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

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

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

    get_definitions: function () {
        return this._definitions;
    },

    get_editors: function () {
        return this._editors;
    },

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

    resize: function () {
        this.DOM().resize();
    },

    render: function () {
        return this.DOM().render();
    },

    activate: function () {
        this._super();

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

        this.DOM().activate();
    },

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

        var that = this,
            editors = this.get_featureSet().get_editors().getByGroupId(this.get_groupId());

        editors.each(function (index, editor) {
            editor.setValidationErrors(validationErrors);
        });

    },

    DOM: function () {

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

        return this._DOM;

    },
    
    //==============================
    // PRIVATE METHODS
    //==============================

    _getDefinitionsData: function () {

        var result = this.get_definitions().transform(function (item) {
            return item.get_data();
        });

        return result.toArray();

    }

});