﻿/*
* Ext JS Library 2.0 RC 1
* Copyright(c) 2006-2007, Ext JS, LLC.
* licensing@extjs.com
* 
* http://extjs.com/license
*/
Ext.namespace('FinnKodeWeb');

FinnKodeWeb.PortletPanel = Ext.extend(Ext.Panel, {
    anchor: '100%',
    frame: true,
    collapsible: true,
    draggable: false,
    cls: 'x-portlet'
});
Ext.reg('portletpanel', FinnKodeWeb.PortletPanel);


FinnKodeWeb.PortletInheritancePanel = function(config) {
    // call superclass constructor
    FinnKodeWeb.PortletInheritancePanel.superclass.constructor.call(this, config);

    this.bookSectionId = 0;
    this.objectId = 0;
    this.inheritType = '' || config.inheritType;

    var tpl = new Ext.XTemplate(
      '<table>',
      '<tpl for="InheritedContentObjects">',
        '<tpl for="' + config.inheritType + '">',
            '<tpl if="xindex==1">',
                '<tr><td colspan="2">{parent.Number} {parent.Term}</td></tr>',
            '</tpl>',
            '<tr><td style="width:20px"></td><td>{.}</td></tr>',
        '</tpl>',
      '</tpl>',
      '</table>'
    );
    tpl.compile();

    this.loadObjectList = function(contentObject) {
        tpl.overwrite(this.body, contentObject);
        var count = 0;
        if (this.inheritType !== '') {
            for (var i = 0; i < contentObject.InheritedContentObjects.length; i++) {
                var inheritList = eval("contentObject.InheritedContentObjects[" + i + "]." + this.inheritType);
                if (inheritList) {
                    count += inheritList.length;
                }
            }
        }
        count == 0 ? this.hide() : this.show();
    };
}

Ext.extend(FinnKodeWeb.PortletInheritancePanel, FinnKodeWeb.PortletPanel, {
});
Ext.reg('portletinheritancepanel', FinnKodeWeb.PortletInheritancePanel);
