/// class ProspectDirector.Modules.Views.ViewBoundsSearchablesDialog
/// using ProspectDirector.Types.Core.Dialog

ProspectDirector.Modules.Views.ViewBoundsSearchablesDialog = (function (options) {

    var 

    PRIVATE = {

        //---------------------------
        //--- CONSTRUCTOR
        //---------------------------

        init: function () {

            options = $.extend({
                selector: null,
                viewStateId: null
            }, options);

            PRIVATE.init_dialog();

        },

        //---------------------------
        //--- PROPERTIES
        //---------------------------

        get_dialog: function () {
            return $(options.selector);
        },

        get_okButton: function () {
            return PRIVATE.get_dialog().find("INPUT[type=button][data-command=ok]");
        },

        get_cancelButton: function () {
            return PRIVATE.get_dialog().find("INPUT[type=button][data-command=cancel]");
        },

        //---------------------------
        //--- INITIALIZERS
        //---------------------------

        init_dialog: function () {

            PRIVATE.get_dialog().data("configuration", new ProspectDirector.Modules.Views.ViewSearchConfiguration({
                selector: PRIVATE.get_dialog().selector,
                viewStateId: options.viewStateId,
                data: options.data
            }));

            PRIVATE.get_okButton().on("click", $.proxy(PRIVATE.okButton_onClick, PRIVATE));
            PRIVATE.get_cancelButton().on("click", $.proxy(PRIVATE.cancelButton_onClick, PRIVATE));

        },

        //---------------------------
        //--- EVENT HANDLERS
        //---------------------------

        okButton_onClick: function () {

            var configuration = PRIVATE.get_dialog().data("configuration");

            this.get_okButton().disable();

            PD.ajax({
                type: "POST",
                url: ProspectDirector.RUNTIME.resolveUrl("~/ViewBounds/SearchablesDialog"),
                data: {
                    viewStateId: options.viewStateId,
                    data: JSON.stringify(configuration.getData())
                },
                success: $.proxy(PRIVATE.submit_onSuccess, PRIVATE)
            });

        },

        cancelButton_onClick: function () {
            PRIVATE.get_dialog().data("dialog").hide({
                command: "cancel"
            });
        },

        submit_onSuccess: function () {

            PRIVATE.get_dialog().data("dialog").hide({
                command: "ok"
            });

        }

        //---------------------------
        //--- METHODS
        //---------------------------

    },

    PUBLIC = {

    };

    PRIVATE.init();

    return PUBLIC;

});

ProspectDirector.Modules.Views.ViewBoundsSearchablesDialog.Dialog =
new (ProspectDirector.Types.Core.Dialog.extend({

    init: function () {

        this._super("ViewBoundsSearchables",
                    "Set \"Find in Results\" Columns",
                    ProspectDirector.RUNTIME.resolveUrl("~/ViewBounds/SearchablesDialog"));

    }

}));