/// class PD.Manage.Modules.Entities.EntityCreateDialogCommand

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

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

    setDefaults: function () {

        this.props("id", "entity/create-dialog");
        this.props("enabled", true);
        this.props("icon", PD.Path.to16x16("plus.png"));
        this.props("label", "New");
        this.props("tooltip", "Create a new Entity of the selected Type.");

        this.state("entityType", null);

    },

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

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

        var entityTypeId = this.state("entityType").id;

        this._showDialog(entityTypeId);


    },

    isEnabled: function () {
        return this.state("entityType") != null &&
            this.state("entityType").id != null;
    },

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

    _showDialog: function (entityTypeId) {

        PDJS.Entities.EntityDialogs.showCreate({
            entityTypeId: entityTypeId,
            promptToOpen: false,
            onCreate: function (sender, e) {
                PD.context.get_default().get_events().publish("entity/create", {
                    id: e.id
                });
            }
        });

    }

});