/// class PD.Web.UI.Controls.Item

PD.Web.UI.Controls.Item =
Class.extend({

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

    _uid: null,
    _command: null,
    _context: null,

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

    init: function (options) {
        options = options || {};
        this._commandId = options.commandId;
        this._uid = uuid.v4();
        PD.Web.Structure.mixin(options, this);
        this.data().add("id", uuid.v4());
        this.onPreInit(options);
        this.onInit(options);
    },

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

    get_uid: function () {
        return this._uid;
    },

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

    onPreInit: function (e) {
        this._setDefaultValues(e);
    },

    onInit: function (e) {
        //overridable
    },

    onLoad: function (e) {
        //overridable
    },

    onComplete: function (e) {
        //overridable
    },

    onActivate: function (e) {
    },

    //===================================
    // PUBLIC METHODS
    //===================================

    refreshContext: function (e) {
        
        var args = {},
            refresh = this.data("refresh"),
            node = $(e.toolbar.element).find("[data-id=" + this.data("id") + "]");

        if (!PD.Type.isFunction(refresh)) {
            return;
        }

        args = new PD.Web.UI.Controls.ToolbarOnRefreshEventArgs($.extend({
            item: this,
            node: node
        }, e));

        refresh(args);

    },

    getNode: function () {
        return $("#" + this.data("id"));
    },

    getToolbar: function () {
        return this.getNode().closest(".k-toolbar").data("kendoToolBar");
    },

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

    executeCommand: function (args) {
        
        var info = this._commandInfo;

        if (info != null && info.command) {
            info.group.execute(this._commandId, args);
        }

    },

    onCommandChange: function (e) {
        // do nothing on purpose
    },

    _setDefaultValues: function (e) {
        //overridable
    }

});