/// class PD.Manage.Modules.Plugins

PD.Manage.Modules.Plugins =
PD.Manage.Module.extend({

    //===================================
    // FIELDS
    //===================================

    _grid: null,

    //===================================
    // EVENT HANDLERS
    //===================================

    onActivate: function (e) {
        this.data("hasToolbar", false);
        this._grid_init();
    },

    prepare: function () {

        var that = this;

        PD.ajax({
            url: PD.Path.resolve("~/Manage/Plugins"),
            success: function (data) {
                that.data("viewStateId", data.viewStateId);
                that.ready();
            },
            error: function (e) {
                that.error();
                e.errorHandled = true;
            }
        });

    },

    //===================================
    // PROTECTED METHODS
    //===================================

    template: function (e) {
        return [
            "<div style='position:absolute;top:0;left:0;bottom:0;right:0;overflow:hidden;'>",
                "<div data-id='grid' style='position:absolute;top:10px;left:10px;bottom:10px;right:10px;border:1px solid #DDDDDD;'>",
                "</div>",
            "</div>"
        ];
    },

    focus: function () {
        this._super();
        this._grid.redraw();
    },

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

    _grid_init: function () {


        var that = this;

        this._grid = new PD.Web.UI.Controls.ViewGrid({
            insertAt: "DIV:first",
            viewStateId: this.data("viewStateId"),
            dblclick: function (e) {
                if (e.selection.Installed) {
                    window.location.hash = "#/plugin/" + e.selection.CustomID;
                }
                else {
                    ProspectDirector.Web.UI.MessageDialog.warn({
                        message: "The plugin is no longer installed."});
                }
            }
        });

        this.get_children().add(this._grid);

    }

});