/// class PD.Manage.Modules.Entities.EntityOpenCommand

PD.Manage.Modules.Entities.EntityOpenCommand =
PD.Commands.Command.extend({

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

    setDefaults: function () {

        this.props("id", "entity/open");
        this.props("icon", PD.Path.to16x16("FOLDER_OPEN.PNG"));
        this.props("label", "Open");
        this.props("tooltip", "Open the selected Entity.");

        this.state("entities", null);

    },

    setState: function (state) {
        this._super(state);
        this.props("enabled", this._isEnabled())
    },

    execute: function (e) {
        this._super(e);

        var entity = this._getEntity();

        if (entity != null) {
            window.open(PD.Path.resolve("~/Explore/" + entity.id));
        }

    },

    //===================================
    // PRIVATE METHODS
    //===================================

    _isEnabled: function () {
        return this._getEntity() != null;
    },

    _getEntity: function () {

        var result = null,
            entities = this.state("entities");

        if (_.isArray(entities) && entities.length === 1) {
            result = _.first(entities);
        }

        return result;

    }

});