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

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

    //===================================
    // FIELDS
    //===================================

    _uploadInput: null,

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

    init: function (options) {

        this._super($.extend(true, {
            config: {
                resizable: false,
                height: "100px",
                width: "400px",
                title: "Apply License"
            }
        }, options));

    },

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

    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
    //===================================

    onInit: function () {
        this._init_uploadInput();
    },

    onActivate: function () {
        this.get_okButton().prop("disabled", true);
        this.get_okButton().on("click", _.bind(this.okButton_onClick, this));
        this.get_cancelButton().on("click", _.bind(this.cancelButton_onClick, this));
    },

    okButton_onClick: function () {
        
        this.close({
            command: "ok",
            data: {
                id: this._uploadInput.get_uploadUniqueName()
            }
        });

    },

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

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

    template: function (e) {

        return [
            "<div class='-pd-apply-license-dialog'>",
                "<div class='-pd-dialog-content'>",
                    "<div data-role='container'>",
                        "<div data-role='title'>Select License To Apply:</div>",
                        "<div data-role='upload'></div>",
                    "</div>",
                "</div>",
                "<div class='-pd-dialog-button-deck'>",
                    "<button class='-pd-button' data-id='ok'>OK</button>",
                    "<button class='-pd-button' data-id='cancel'>Cancel</button>",
                "</div>",
            "</div>"
        ];

    },

    _init_uploadInput: function () {

        var that = this;

        this._uploadInput = new PD.Web.UI.Controls.UploadInput({
            insertAt: "[data-role=upload]",
            uploadStart: function (e) {
                that.get_okButton().prop("disabled", true);
            },
            uploadComplete: function (e) {
                that.get_okButton().prop("disabled", false);
            }
        });

        this.get_children().add(this._uploadInput);

    }

});

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