/// class PD.Manage.Modules.Resources.FileUploadDialogCommand

PD.Manage.Modules.Resources.FileUploadDialogCommand =
PD.Commands.Command.extend({

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

    setDefaults: function () {

        this.props("id", this.inits("id") || "file/upload-dialog");
        this.props("enabled", true);
        this.props("icon", PD.Path.to16x16("documents_empty_plus.png"));
        this.props("label", "Add Files");
        this.props("tooltip", "Upload and add new files.<br/><br/>The new files will be added<br/>to the currently selected folder.");
        this.props("canExecute", true);

        this.state("targetFolderId", null);

    },

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

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

        var that = this,
            targetFolderId = this.state("targetFolderId");

        PD.Manage.Modules.Resources.UploadFilesDialog.open({
            data: {
                currentFolderId: targetFolderId
            },
            callbacks: {
                ok: function (e) {

                    setTimeout(function () {

                        PD.context.get_default().get_events().publish("resources/add", {
                            folderId: targetFolderId
                        });

                        e.close();

                    }, 1000)

                }
            }
        });

    },

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

    _enabledAndCanExecute: function (value) {
        this.props("enabled", value);
        this.props("canExecute", value);
    }

});