/// class ProspectDirector.Web.UI.Queries.SelectAnchorDialogDOM
/// using ProspectDirector.Web.UI.SelectionDialogBaseDOM

/**
@constructor
@class SelectAnchorDialogDOM
@namespace Web.UI.Queries
@extends Web.UI.SelectionDialogBaseDOM
**/
ProspectDirector.Web.UI.Queries.SelectAnchorDialogDOM = ProspectDirector.Web.UI.SelectionDialogBaseDOM.extend({

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

    render: function () {

        var content = "" +
        "<div style=\"position:absolute;top:10px;left:10px;right:10px;bottom:10px;\">" +
        "<div data-id=\"search-box\" style=\"position:absolute;top:0px;right:0px;\"></div>" +
        "<div style=\"position:absolute;left:0px;right:0px;top:30px;bottom:35px;\">" +
        "<div data-id=\"grid\"></div>" +
        "</div>" +
        "<div style=\"position:absolute;height:25px;bottom:0px;left:0px;right:0px;text-align:right;\">" +
        "<button data-id=\"ok\" class=\"-pd-button\">OK</button>" +
        "&nbsp;" +
        "<button data-id=\"cancel\" class=\"-pd-button\">Cancel</button>" +
        "</div>" +
        "</div>";

        this.get_container().append(content);

    },

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

    setGridOptions: function () {

        return this._super({
            dataSource: {
                schema: {
                    data: "paths",
                    total: "totalCount",
                    model: {
                        id: "id"
                    }
                },
                transport: {
                    read: {
                        url: ProspectDirector.RUNTIME.resolveUrl("~/query/findanchor")
                    }
                }
            },
            columns: [
                {
                    title: "Target",
                    field: "0",
                    template: function (e) {
                        return e.types[0].name;
                    },
                    width: 150
                },
                {
                    title: "Path",
                    field: "1",
                    template: function (e) {
                        return e.name;
                    }, width: 600
                },
                {
                    title: "&nbsp;"
                }
            ]
        });

    },

    setGridSelectionOptions: function () {
        return this._super({
            primaryKey: "id"
        });
    },

    getGridSortOrder: function (arr) {

        var index = 0,
            result = [];

        if ($.isArray(arr)) {

            for (index = 0; index < arr.length; index++) {

                result[result.length] = {
                    ascending: arr[index].dir === "asc",
                    column: arr[index].field === "0" ? 0 : 1
                }

            }

        }

        return result;

    }

});