/// class PD.Manage.Modules.Resources.DownloadZipCommand
/// using PD.Manage.Modules.Resources.ResourceCommand

PD.Manage.Modules.Resources.DownloadZipCommand =
PD.Manage.Modules.Resources.ResourceCommand.extend({

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

    setDefaults: function () {
        this._super();
        this.props("id", this.inits("id") || "zip/download");
        this.props("enabled", false);
        this.props("label", "Download Zip");
        this.props("icon", PD.Path.to16x16("folder_zip_down.png"));
        this.props("tooltip", "");
        this.props("canExecute", true);
    },

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

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

        var resourceCount = this.getResources().length;

        if (resourceCount > 40) {
            PD.Web.UI.MessageDialog.warn({
                title: "Maximum Download Exceeded",
                message: "You have selected to download " + resourceCount + " resources. No more than 40 individual resources may be downloaded at one time."
            });
            return;
        }

        PD.Web.UI.MessageDialog.warn({
            title: "Download Zip?",
            message: "Download the selected " + (this.getResources().length) + " resources into a zip file?",
            ok: $.proxy(this._executeZip, this)
        });

    },

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

    _executeZip: function (e) {
        
        var resourceIds = _.map(this.getResources(), "id");

        e.close();
        
        PD.Web.MonitoredDownloadManager.download("~/Manage/Resources/GetPackage", {
            resourceIds: JSON.stringify(resourceIds)
        }, {
            dialogTitle: "Download Zip",
            dialogMessage: "Please wait while your zip is being created.",
        });
        
    }

});
