/// class ProspectDirector.Modules.Processes.ProcessStatusDialog
/// using ProspectDirector.Types.Core.Dialog

ProspectDirector.Modules.Processes.ProcessStatusDialog = (function (options) {

    var 

        PRIVATE = {

            init: function (options) {

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

                PRIVATE.init_dialog();

            },

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

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

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

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

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

            get_icon: function () {
                return PRIVATE.get_dialog().find("INPUT[data-id=icon]");
            },

            get_name: function () {
                return PRIVATE.get_dialog().find("INPUT[data-id=name]");
            },

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

            init_dialog: function () {

                this.get_cancelButton().on("click", $.proxy(this.cancelButton_onClick, this));
                this.get_saveButton().on("click", $.proxy(this.saveButton_onClick, this));
                this.get_icon().iconBrowserBox();
                this.get_name().focus();
                this.get_name().select();

                this.get_dialog().on("keypress", "INPUT[type=text]", $.proxy(function (e) {
                    if (e.keyCode === 13) {
                        this.saveButton_onClick();
                    }
                }, this));

            },

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

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

            saveButton_onClick: function () {

                PRIVATE.get_saveButton().disable();

                PD.ajax({

                    type: this.get_form().attr('method'),

                    url: this.get_form().attr('action'),

                    data: this.get_form().serialize(),

                    contextData: {
                        container: PRIVATE.get_form(),
                        control: PRIVATE.get_saveButton()
                    },

                    success: $.proxy(this.save_onSuccess, this)

                });

            },

            save_onSuccess: function (a, b, c) {

                this.get_dialog().data("dialog").hide({
                    command: "ok",
                    data: a
                });

            }

        },

        PUBLIC = {

        };

    PRIVATE.init(options);

    return PUBLIC;

});

ProspectDirector.Modules.Processes.ProcessStatusDialog.Dialog =
new (ProspectDirector.Types.Core.Dialog.extend({
    
    init: function () {
        this._super("processstatus",
                "Process Status",
                ProspectDirector.RUNTIME.resolveUrl("~/Process/StatusDialog"), true);
    }

}));