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

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

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

    setDefaults: function () {
        this._super();
        this.props("id", "file/open");
        this.props("enabled", true);
        this.props("icon", PD.Path.to16x16("folder_plus.png"));
        this.props("canExecute", true);
    },

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

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

        var resource = _.first(this.getResources());

        if (this._canOpenResourceForEdit(resource.mimeType)) {
            window.location.hash = "#/module/resources-editor/" + resource.id;
        }
        else {
            PD.Web.Utilities.DownloadManager.download("~/Manage/Resources/DownloadFile/" + resource.id);
        }

    },

    _canOpenResourceForEdit: function (mimeType) {
    
        var supportedMime = null,
            supportedList = [
                "text/html",
                "text/javascript",
                "text/plain",
                "text/css",
                "text/xml",
                "text/json"
            ];

        supportedMime = _.find(supportedList, function (item) {
            return item === mimeType;
        });

        return supportedMime != null;

    }

});