/// class PD.Manage.Modules.Entities.EntityPropertiesDialogCommand

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

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

    setDefaults: function () {

        this.props("id", "entity/properties-dialog");
        this.props("label", "Edit");
        this.props("icon", PD.Path.to16x16("clipboard_checks.png"));
        this.props("tooltip", "Edit the properties of 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 = _.first(this._getEntities());

        this._showDialog(entity.id);

    },

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

    _isEnabled: function () {
        return this._getEntities().length === 1;
    },

    _getEntities: function () {

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

        if (_.isArray(entities) && entities.length > 0) {
            result = entities;
        }

        return result;

    },

    _showDialog: function (entityId) {

        PDJS.Entities.EntityDialogs.showProperties({
            entityId: entityId,
            onSave: function (sender, e) {
                PD.context.get_default().get_events().publish("entity/update", {
                    id: entityId
                });
            }
        });

    }

});