/// class PD.Manage.Modules.TestMailSettingsDialog
// using PD.Web.UI.Dialog

PD.Manage.Modules.TestMailSettingsDialog =
PD.Web.UI.Dialog.extend({

    //===================================
    // CONSTRUCTOR
    //===================================

    init: function (options) {

        this._super($.extend(true, {
            config: {
                resizable: false,
                height: "140px",
                width: "350px",
                title: "Test Mail Settings"
            }
        }, options));

    },

    //===================================
    // PROPERTIES
    //===================================

    get_to: function () {
        return this.get_node().find("INPUT[data-id=to]");
    },
    
    get_sendButton: function () {
        return this.get_node().find("BUTTON[data-id=send]");
    },

    get_cancelButton: function () {
        return this.get_node().find("BUTTON[data-id=cancel]");
    },
    
    //===================================
    // EVENT HANDLERS
    //===================================

    onActivate: function () {

        this.get_sendButton().on("click", _.bind(this.sendButton_onClick, this));
        this.get_cancelButton().on("click", _.bind(this.cancelButton_onClick, this));
        
    },

    sendButton_onClick: function () {

        var that = this;
        
        PD.ajax({
            type: "POST",
            url: PD.Path.resolve("~/Manage/MailQueue/TestMailSettings"),
            data: {
                sendTo: this.get_to().val()
            },
            contextData: {
                container: this.get_node()
            },
            success: function (e) {
                that.close({
                    command: "ok",
                    data: e
                });
            }
        });

    },

    cancelButton_onClick: function () {
        this.close();
    },

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

    template: function (e) {

        return [
            "<div class='-pd-test-email-settings-dialog'>",
                "<div>",
                    "<div>",
                        "Input one or more email addresses, separated by semicolons, into the 'Send To' field below ",
                        "and click 'Send' to send a test email to the specified recepients.",
                    "</div>",
                    "<label>Send To:</label><br/>",
                    "<input type='text' data-id='to' />",
                "</div>",
                "<div data-id='button-deck'>",
                    "<button class='-pd-button' data-id='send'>Send Test Mail</button>",
                    "<button class='-pd-button' data-id='cancel'>Cancel</button>",
                "</div>",
            "</div>"
        ];

    }

});

PD.Manage.Modules.TestMailSettingsDialog.open =
function (options) {
    return new PD.Manage.Modules.TestMailSettingsDialog(options);
};