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

ProspectDirector.Modules.Views.ViewDesignFiltersDialog = (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.ViewFilterConfiguration({
                selector: PRIVATE.get_dialog().selector,
                viewStateId: options.viewStateId,
                data: options.data,
                type: "design"
            }));
            
            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("~/ViewDesign/FiltersDialog"),
                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.ViewDesignFiltersDialog.Dialog =
new (ProspectDirector.Types.Core.Dialog.extend({

    init: function () {

        this._super("ViewDesignFilters",
                    "View Design Filters",
                    ProspectDirector.RUNTIME.resolveUrl("~/ViewDesign/FiltersDialog"));

    }

}));