Changeset 4656


Ignore:
Timestamp:
4 Jan 2010, 21:42:14 (15 years ago)
Author:
uli
Message:

Add viewlet manager and viewlets for primary navigation tab in the
upper left corner of the standard layout.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • waeup/branches/ulif-layout/src/waeup/browser/viewlets.py

    r4651 r4656  
    1515
    1616grok.templatedir('templates')
     17grok.context(IWAeUPObject) # Make IWAeUPObject the default context
    1718
    1819#grok.context(zope.interface.Interface)
     
    7879        return u'<div class="portlet"><a href="datacenter">Data Center</a></div>'
    7980
     81#
     82# Manage ("Edit settings") actions...
     83#   
    8084class ManageUniversityAction(grok.Viewlet):
    8185    grok.viewletmanager(ActionBar)
     
    174178    addlink_text = 'Add faculty'
    175179
     180
     181#
     182# Primary navigation tabs (in upper left navigation bar)...
     183#
     184class PrimaryNavManager(grok.ViewletManager):
     185    """Viewlet manager for the primary navigation tab.
     186    """
     187    grok.name('primary_nav')
     188
     189class PrimaryNavTab(grok.Viewlet):
     190    """Base for primary nav tabs.
     191    """
     192    grok.baseclass()
     193    grok.viewletmanager(PrimaryNavManager)
     194    grok.order(1)
     195    grok.require('waeup.manageUniversity')
     196
     197    pnav = 0 # This is a kind of id of a tab. If some page provides
     198             # also a 'pnav' attribute with the same value (here: 0),
     199             # then the tab will be rendered as 'active' when the page
     200             # gets rendered.
     201             #
     202             # This way you can assign certain pages to certain
     203             # primary nav tabs. Each primary tab should therefore set
     204             # the 'pnav' attribute to a different value (or several
     205             # tabs might be rendered as active simultanously when the
     206             # page gets rendered.
     207    tab_title = u'Some Text'
     208   
     209    @property
     210    def link_target(self):
     211        return self.view.application_url()
     212
     213    @property
     214    def active(self):
     215        view_pnav = getattr(self.view, 'pnav', 0)
     216        if view_pnav == self.pnav:
     217            return 'active'
     218        return ''
     219
     220class HomeTab(PrimaryNavTab):
     221    """Home-tab in primary navigation.
     222    """
     223    grok.order(1)
     224    grok.require('waeup.Public')
     225    grok.template('primarynavtab')
     226
     227    pnav = 0
     228    tab_title = u'Home'
     229
     230class FacultiesTab(PrimaryNavTab):
     231    """Faculties-tab in primary navigation.
     232    """
     233    grok.order(2)
     234    grok.require('waeup.manageUniversity')
     235    grok.template('primarynavtab')
     236
     237    pnav = 1
     238    tab_title = u'Faculties'
     239
     240    @property
     241    def link_target(self):
     242        return self.view.application_url('faculties')
     243
     244class SearchTab(PrimaryNavTab):
     245    """Search tab in primary navigation.
     246    """
     247    grok.order(3)
     248    grok.require('waeup.manageUniversity')
     249    grok.template('primarynavtab')
     250
     251    pnav = 2
     252    tab_title = u'Search'
     253
     254    @property
     255    def link_target(self):
     256        return self.view.application_url('@@search')
Note: See TracChangeset for help on using the changeset viewer.