﻿// JScript File

Ext.namespace('FinnKodeWeb');

FinnKodeWeb.PanelObjectList = function(config) {
    config.listType = '' || config.listType;
    this.listType = config.listType;

    var _contentObject = null;
    var _bookId, _bookSectionId;
    var _reload = true;

    var _reloadFunction = function(tab) {
        if (_contentObject != null && _reload) {
            _reload = false;
            var tpl = new Ext.XTemplate(
                '<table style="font: normal 11px tahoma,arial,helvetica,sans-serif;">',
                '<tpl for="' + tab.listType + '">',
                    '<tr valign="top"><td nowrap><a href=javascript:NavigateTo("' + _bookId + '","' + _bookSectionId + '","{ObjectId}")>{Number}</a></td><td><a href=javascript:NavigateTo("' + _bookId + '","' + _bookSectionId + '","{ObjectId}")>{Term}</a></td></tr>',
                '</tpl>',
              '</table>'
            );
            tpl.compile();
            tpl.overwrite(tab.body, _contentObject);
            var count = 0;
            if (tab.listType != "") {
                count = eval("_contentObject." + tab.listType + ".length");
            }
            count == 0 ? tab.disable() : tab.enable();
        }
    };

    Ext.apply(config, {
        listeners: {
            'activate': function(tab) {
                _reloadFunction(tab);
            }
        }
    });
    // call superclass constructor
    FinnKodeWeb.PanelObjectList.superclass.constructor.call(this, config);

    this.loadObjectList = function(contentObject, bookId, bookSectionId) {
        _contentObject = contentObject;
        _bookId = bookId;
        _bookSectionId = bookSectionId;
        _reload = true;
        if (this.rendered) _reloadFunction(this);
    };
}

Ext.extend(FinnKodeWeb.PanelObjectList, Ext.Panel, {
    autoScroll: true
});

Ext.reg('objectlistpanel', FinnKodeWeb.PanelObjectList);
