﻿// -------- basic tab settings helper class --------- //
Ext.ux.BasicDesktopTabSettingsHelper = Ext.extend(Object, {

    // internal fields


    // standard constructor
    constructor: function(currentAction) {

        // store current action for hover handler
        this.m_currentAction = currentAction;

        Ext.ux.BasicDesktopTabSettingsHelper.superclass.constructor.call(this);
    },

    // standard initializer
    initComponent: function() {
        Ext.ux.BasicDesktopTabSettingsHelper.superclass.initComponent.apply(this, arguments);

        // extra args have to go here as base class initComponent doesn't get called for some reason
        var config = {};

        Ext.apply(this, config);
        Ext.apply(this.initialConfig, config);
    },


    // initialize main tabs
    initialize: function(tabs) {
        this.initializeInt(tabs);
    },

    // initialize tabs
    initializeInt: function(items) {
        for (var i = 0; i < items.length; i++) {
            if (!items[i].isDisabled) {
                $.preloadImages(items[i].activeImagePath, items[i].hoverImagePath, items[i].inactiveImagePath);

                // bind hover images
                $.bindHoverImages(
                    items[i].imageId,
                    items[i].hoverImagePath,
                    items[i].inactiveImagePath,
                    items[i].actionName,
                    delegate(this, this.checkIsActive),
                    null, null, null, null, null);
            }
        }
    },

    // return true if the specified controller is the controller of the current action
    checkIsActive: function(action) {

        var isCurrentAction = false;

        if ((this.m_currentAction !== null) && (action.toLowerCase() == this.m_currentAction.toLowerCase())) {
            isCurrentAction = true;
        }

        return isCurrentAction;
    }
});