/// class ProspectDirector.Modules.Security.AclAdvancedDialog
/// using ProspectDirector.Types.Core.Dialog

ProspectDirector.Modules.Security.AclAdvancedDialog = (function (options) {

    var 

        PRIVATE = {

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

            init: function (options) {

                PRIVATE.options = $.extend({
                    selector: null,
                    data: {
                        hasChanges: false
                    }
                }, options);

                PRIVATE.init_dialog();

            },

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

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

            get_form: function () {
                return this.get_dialog().find("FORM");
            },

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

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

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

            init_dialog: function () {

                PRIVATE.get_buttonCancel().on("click", $.proxy(PRIVATE.cancelButton_onClick, PRIVATE));
                PRIVATE.get_buttonOk().on("click", $.proxy(PRIVATE.okButton_onClick, PRIVATE));

            },

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

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

            okButton_onClick: function (e) {

                if (PRIVATE.options.data.hasChanges) {

                    if (!confirm("There are unsaved changes to the ACL you about to cascade. Unsaved changes will not be included in the cascade.\n\nProceeed with the cascade ACL operation?")) {
                        return;
                    }

                }
                else {

                    if (!confirm("Continue with the cascade ACL operation?")) {
                        return;
                    }

                }

                PD.ajax({
                    type: "POST",
                    url: ProspectDirector.RUNTIME.resolveUrl("~/Security/AclAdvancedDialog"),
                    data: this.get_form().serialize(),
                    success: function () {

                        ProspectDirector.Types.Core.Notifications.success("ACL cascaded successfully.");

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

                    }
                });

            }

        },

        PUBLIC = {

        };

    PRIVATE.init(options);

    return PUBLIC;


});

ProspectDirector.Modules.Security.AclAdvancedDialog.Dialog =
new (ProspectDirector.Types.Core.Dialog.extend({

    init: function () {

        this._super("AclAdvancedDialog",
                    "Advanced Security",
                    ProspectDirector.RUNTIME.resolveUrl("~/Security/AclAdvancedDialog"));

    }

}));