/// class PD.Manage.Modules.Resources.FileConflictDialog
// using PD.Shared.Dialogs.TaskAlertDialog

PD.Manage.Modules.Resources.FileConflictDialog =
PD.Shared.Dialogs.TaskAlertDialog.extend({

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

    init: function (options) {

        this._super($.extend(true, {
            config: {
                title: "File Conflict",
                actions: []
            }
        }, options));

    },

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

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

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

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

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

    onActivate: function (options) {
        this.get_replaceButton().on("click", _.bind(this._replaceButton_onClick, this));
        this.get_skipButton().on("click", _.bind(this._skipButton_onClick, this));
        this.get_canelButton().on("click", _.bind(this._cancelButton_onClick, this));
    },

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

    _replaceButton_onClick: function () {
        this.close({
            command: "ok",
            data: this._getResponse(2)
        });
    },

    _skipButton_onClick: function () {
        this.close({
            command: "ok",
            data: this._getResponse(1)
        });
    },

    _cancelButton_onClick: function () {
        this.close({
            command: "ok",
            data: this._getResponse(0)
        });
    },

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

    template: function (options) {
        return [
            "<div data-dialog-type='folder-conflict' class='task-alert-dialog'>",
                "<div class='-pd-task-alert-content'>",
                    "<div>",
                        "The destination already contains a file named <b>" + this.getTag("name") + "</b><br/><br/>",
                        "Do you want to replace the file<br/><br/>",
                        "<div class='-pd-file-in-conflict'><b>" + this.getTag("name") + "</b><br/>" + this.getTag("targetpath") + "</div>",
                        "<div style='padding:10px 0 10px 0;'>with this one</div>",
                        "<div class='-pd-file-in-conflict'><b>" + this.getTag("name") + "</b><br/>" + this.getTag("sourcepath") + "</div>",
                    "</div>",
                    "<div class='-pd-task-alert-repeat'>",
                        "<label>",
                            "<input type='checkbox' data-id='repeat' />&nbsp;Do this for all conflicts like this.",
                        "</label>",
                    "</div>",
                "</div>",
                "<div class='-pd-dialog-button-deck'>",
                    "<button class='-pd-button' data-id='replace'>Replace</button>",
                    "<button class='-pd-button' data-id='skip'>Skip</button>",
                    "<button class='-pd-button' data-id='cancel'>Cancel</button>",
                "</div>",
            "</div>"
        ];
    },

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

    _getResponse: function (action) {
        return {
            action: action,
            repeat: this.get_node().find("INPUT[data-id=repeat]").is(":checked")
        };
    }

});

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