/// class PD.Web.UI.ErrorDialog
/// using PD.Web.UI.MessageDialog

/**
@class ErrorDialog
@constructor
@namespace Web.UI
@extends Web.UI.Dialog
**/
PD.Web.UI.ErrorDialog =
PD.Web.UI.MessageDialog.extend({

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

    onInit: function (e) {
        this._super(e);
    },

    onActivate: function (e) {
        this._super(e);

        var data = [],
            errors = this.get_options()["errors"];

        _.each(errors, function (err) {
            
            var item = {
                text: err.message,
                items: [],
                expanded: true,
                type: "error"
            };
            
            for (key in err.tags) {
                item.items[item.items.length] = {
                    text: key,
                    value: err.tags[key],
                    type: "tag"
                };
            }
            
            data[data.length] = item;

        });

        this.get_node().find("[data-id=tree]").kendoTreeView({
            dataSource: {
                data: data
            },
            encoded: false,
            select: function (e) {
                e.preventDefault();
            },
            template: function (e) {
                var item = e.item;
                if (item.type === "tag") {
                    return "<span style='font-weight:bold;display:inline-block;font-size:11px;padding-right:10px;'>" + s.humanize(item.text) + ":</span><span style='font-size:11px;'>" + (item.value != null ? item.value : "") + "</span>";
                }
                else {
                    return item.text;
                }
            }
        });

    },

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

    _setText: function () {
        this.get_textNode().append(this.get_message());
        this.get_textNode().append("<div class='-pd-error-dialog-content'><div data-id='tree' class='-pd-treeview no-k-state-hover'></div></div>");
    }

});

//================================
// STATIC METHODS
//================================

PD.Web.UI.ErrorDialog.show = function (options) {
    return PD.Web.UI.MessageDialog.warn(options, PD.Web.UI.ErrorDialog);
};
