/// class PD.Web.UI.Controls.SearchInResultsWidget
/// using PD.Web.UI.Controls.GridWidget

PD.Web.UI.Controls.SearchInResultsGridWidget =
PD.Web.UI.Controls.GridWidget.extend({

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

    _searchBox: null,

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

    onActivate: function () {
        this._initSearchBox();
        this.get_grid().get_dataSource().bind(
            "dataSourceRead",
            $.proxy(this._onGridDataSourceRead, this));
    },

    _onGridDataSourceRead: function (e) {
        if (this._searchBox) {
            e.searchTerm = this._searchBox.value();
        }
    },

    template: function () {
        return "<div class='-pd-widget' style='padding-top:5px;width:210px;'></div>";
    },

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

    _initSearchBox: function () {

        var that = this;

        this._searchBox = new PD.Web.UI.Controls.SearchBox({
            watermark: "Find In Results...",
            search: function (value) {
                that.get_grid().get_dataSource().read();
            }
        });

        this.get_children().add(this._searchBox);

    }

});