/// class PD.Manage.Modules.ViewViewer

PD.Manage.Modules.ViewViewer =
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/ViewViewer"),
            data: {
                id: this.data("targetId")
            },
            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"),
            selectionMode: "none"
        });

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

    }

});