/// class PD.Manage.Modules.OverviewPanelModule
// using PD.Web.UI.Controls.Control

PD.Manage.Modules.OverviewPanelModule =
PD.Web.UI.Controls.Control.extend({

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

    _data: null,

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

    init: function (options) {
        this._data = options;
        this._super(options);
    },

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

    get_tileId: function () {
        return this._data.moduleScripts.length > 0 ? this._data.moduleScripts[0].id : "--ERROR--";
    },

    get_label: function () {
        return this._data.label;
    },

    get_icon: function () {
        return this._data.icon;
    },

    get_notificaton: function () {
        return this._data.attributes.notify;
    },

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

    onFrame: function () {
        this.setFrame(this._data);
    },

    onActivate: function (e) {
        var that = this;
        this.get_node().data("module", this._data);
        this.get_node().on("click", ".-pd-corner-notify", _.bind(function (e) {
            e.stopPropagation();
            e.preventDefault();
            that._showNotifyMessageDialog();
            return false;
        }, this));
    },

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

    template: function (e) {
        
        var iconPath = PD.Path.to48x48(this.get_icon() || "folders.png");
        
        return [
            "<a data-id='" + this.get_tileId() + "' href='#/module/" + this.get_tileId() + "' class='-pd-overview-module-box'>",
                iconPath ? "<img src='" + iconPath + "' />" : "",
                "<label>",
                    this.get_label(),
                "</label>",
                this.get_notificaton() != null ? "<div class='-pd-corner-notify'>&nbsp;</div>" : "",
            "</div>"
        ];

    },

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

    _showNotifyMessageDialog: function () {

        PD.Web.UI.MessageDialog.warn({
            title: this.get_label() + " Notification",
            message: this.get_notificaton()
        });

    }

});