/// class PD.Manage.Modules.EventLog.ClearEventLogDialog
// using PD.Web.UI.Dialog

PD.Manage.Modules.EventLog.ClearEventLogDialog =
PD.Web.UI.Dialog.extend({

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

    init: function (options) {

        this._super($.extend(true, {
            config: {
                resizable: false,
                height: "125px",
                width: "300px",
                title: "Clear Event Log"
            }
        }, options));

    },

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

    get_timeRange: function () {
        return this.get_node().find("SELECT[data-id=time-range]");
    },
    
    get_okButton: function () {
        return this.get_node().find("BUTTON[data-id=ok]");
    },

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

    //===================================
    // EVENT HANDLERS
    //===================================

    onActivate: function () {

        this.get_okButton().on("click", _.bind(this.okButton_onClick, this));
        this.get_cancelButton().on("click", _.bind(this.cancelButton_onClick, this));

    },

    okButton_onClick: function () {

        var that = this;

        PD.ajax({
            type: "POST",
            url: PD.Path.resolve("~/Manage/EventLog/Clear"),
            data: {
                hours: parseInt(this.get_timeRange().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-clear-event-log-dialog'>",
                "<div style='font-size:12px;'>",
                    "<div>",
                        "Clear all event log entires that fall within the time range below.",
                    "</div>",
                    "Time Range: ",
                    "<select data-id='time-range'>",
                        "<option value='1'>Older Than 1 Hour</option>",
                        "<option value='24'>Older Than 24 Hours</option>",
                        "<option value='168'>Older Than 7 Days</option>",
                        "<option value='672'>Older Than 4 Weeks</option>",
                        "<option value='0'>All Time</option>",
                    "</select>",
                "</div>",
                "<div data-id='button-deck'>",
                    "<button class='-pdjs-dialog-button' data-id='ok'>OK</button>",
                    "<button class='-pdjs-dialog-button' data-id='cancel'>Cancel</button>",
                "</div>",
            "</div>"
        ];

    },

    //===================================
    // PRIVATE METHODS
    //===================================

});

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