/// class PD.Manage.Modules.ViewCopyCommand

PD.Manage.Modules.ViewCopyCommand =
PD.Commands.Command.extend({

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

    setDefaults: function () {
        this.props("id", "view/copy");
        this.props("enabled", true);
        this.props("icon", PD.Path.to16x16("copy.png"));
        this.props("label", "Copy View");
        this.props("tooltip", "Create a copy of the selected View.");
        this.state("view", null);
    },

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

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

        var service = new PD.Manage.Services.ViewService(),
            view = this.state("view");

        this._showConfirmationDialog(view.name, function (e) {

            e.close();

            service.copyView(view.id, function (e) {

                PD.context.get_default().get_events().publish("view/copy", {
                    id: e.id
                });

            });

        });

    },

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

    _isEnabled: function () {
        return this.state("view") != null;
    },

    _showConfirmationDialog: function (name, callback) {

        PD.Web.UI.MessageDialog.info({
            width: 400,
            title: "Copy View",
            message: "Make a copy of the \"" + name + "\" view?",
            ok: callback
        });

    }

});
