Changeset 4787 for waeup


Ignore:
Timestamp:
11 Jan 2010, 16:26:30 (15 years ago)
Author:
uli
Message:

Introduce new bases for action buttons. All button viewlets are now
derived from these (configurable) bases.

File:
1 edited

Legend:

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

    r4778 r4787  
    3030
    3131#
     32# Baseclasses that give some defaults for really used viewlets.
     33#
     34class ActionButton(grok.Viewlet):
     35    """A base for action buttons.
     36
     37    An action button provides an icon, some text and links to a
     38    target.  If you want to set a different text, icon or target name
     39    for some active button below, just override the approriate
     40    attribute in the concerned viewlet.
     41
     42    Action buttons provide by default dynamic attributes
     43
     44     * ``alt``
     45          An alternative text for the icon. By default the same as
     46          the text.
     47
     48     * ``icon_url``
     49          The URL of the icon.
     50
     51     * ``target_url``
     52          The URL of the link target.
     53
     54    """
     55    grok.baseclass()
     56    grok.context(IWAeUPObject)
     57    grok.template('actionbutton')
     58    grok.viewletmanager(ActionBar)
     59    icon = 'actionicon_modify.png' # File must exist in static/
     60    target = '@@manage' # link to this viewname.
     61    text = 'Edit settings' # Text to display on the button
     62
     63    @property
     64    def alt(self):
     65        """Alternative text for icon.
     66        """
     67        return self.text
     68
     69    @property
     70    def icon_url(self):
     71        """Get the icon URL.
     72        """
     73        return self.view.static[self.icon]()
     74
     75    @property
     76    def target_url(self):
     77        """Get a URL to the target...
     78        """
     79        return self.view.url(self.view.context, self.target)
     80
     81   
     82class ManageActionButton(ActionButton):
     83    """A base for 'edit' buttons
     84    """
     85    grok.baseclass()
     86    grok.order(2)
     87    grok.require('waeup.manageUniversity')
     88    icon = 'actionicon_modify.png'
     89    target = '@@manage'
     90    text = 'Edit settings'
     91
     92class AddActionButton(ActionButton):
     93    """A base for 'add' buttons.
     94    """
     95    grok.baseclass()
     96    grok.order(4)
     97    grok.require('waeup.manageUniversity')
     98    icon = 'actionicon_addfavorite.png'
     99    target = 'add'
     100    text = 'Add'
     101
     102
     103#
    32104# General viewlets (for more than one page/context)
    33105#
     
    153225#
    154226# Manage ("Edit settings") actions...
    155 #   
    156 class ManageUniversityAction(grok.Viewlet):
    157     grok.viewletmanager(ActionBar)
    158     grok.context(IUniversity)
    159     grok.view(UniversityPage)
    160     grok.require('waeup.manageUniversity')
    161     grok.order(2)
    162     grok.template('manageaction')
    163 
    164 class GoToFacultiesAction(grok.Viewlet):
    165     grok.viewletmanager(ActionBar)
    166     grok.context(IUniversity)
    167     grok.view(UniversityPage)
    168     grok.require('waeup.manageUniversity')
    169     grok.order(3)
    170     grok.template('gotofacultiesaction')
    171 
    172 class ManageFacultiesAction(ManageUniversityAction):
     227#
     228class ManageUniversityActionButton(ManageActionButton):
     229    """ 'Edit settings' button for University instances.
     230    """
     231    grok.context(IUniversity)
     232    grok.view(UniversityPage)
     233   
     234class ManageFacultiesActionButton(ManageActionButton):
     235    """ 'Edit settings' button for faculty container.
     236    """
    173237    grok.context(IFacultyContainer)
    174238    grok.view(FacultyContainerPage)
    175     grok.template('manageaction')
    176 
    177 class ManageDataCenterAction(ManageUniversityAction):
     239
     240class ManageDataCenterActionButton(ManageActionButton):
     241    """ 'Edit settings' button for datacenter.
     242    """
    178243    grok.context(IDataCenter)
    179244    grok.view(DatacenterPage)
    180     grok.template('manageaction')
    181     grok.require('waeup.manageUniversity')
    182 
    183 class ManageFacultyAction(ManageUniversityAction):
     245   
     246class ManageFacultyActionButton(ManageActionButton):
    184247    """ 'Edit settings' button for faculties.
    185248    """
    186249    grok.context(IFaculty)
    187250    grok.view(FacultyPage)
    188     grok.template('manageaction')
    189     grok.require('waeup.manageUniversity')
    190 
    191 class ManageDepartmentAction(ManageUniversityAction):
     251
     252class ManageDepartmentActionButton(ManageActionButton):
    192253    """ 'Edit settings' button for departments.
    193254    """
    194255    grok.context(IDepartment)
    195256    grok.view(DepartmentPage)
    196     grok.template('manageaction')
    197     grok.require('waeup.manageUniversity')
    198 
    199 class ManageCourseAction(ManageUniversityAction):
     257
     258class ManageCourseActionButton(ManageActionButton):
    200259    """ 'Edit settings' button for courses.
    201260    """
    202261    grok.context(ICourse)
    203262    grok.view(CoursePage)
    204     grok.template('manageaction')
    205     grok.require('waeup.manageUniversity')
    206 
    207 class ManageCertificateAction(ManageUniversityAction):
     263   
     264class ManageCertificateActionButton(ManageActionButton):
    208265    """ 'Edit settings' button for certificates.
    209266    """
    210267    grok.context(ICertificate)
    211268    grok.view(CertificatePage)
    212     grok.template('manageaction')
    213     grok.require('waeup.manageUniversity')
    214 
    215 class ManageCertificateCourseAction(ManageUniversityAction):
    216     """ 'Edit settings' button for certificatecourses.
     269
     270class ManageCertificateCourseActionButton(ManageActionButton):
     271    """ 'Edit settings' button for certificate courses.
    217272    """
    218273    grok.context(ICertificateCourse)
    219274    grok.view(CertificateCoursePage)
    220     grok.template('manageaction')
    221     grok.require('waeup.manageUniversity')
    222275
    223276#
     
    285338        return '%s/@@%s' % (self.view.url(self.view.context), self.addview_name)
    286339
    287 class AddFacultiesAction(AddAction):
     340class AddFacultyActionButton(AddActionButton):
    288341    grok.context(IFacultyContainer)
    289342    grok.view(FacultyContainerPage)
    290     grok.order(4)
    291     grok.template('addaction')
    292     grok.require('waeup.manageUniversity')
    293 
    294     addview_name = 'add'
    295     addlink_text = 'Add faculty'
    296 
    297 class AddDepartmentsAction(AddAction):
     343    text = 'Add faculty'
     344   
     345class AddDepartmentActionButton(AddActionButton):
    298346    grok.context(IFaculty)
    299347    grok.view(FacultyPage)
    300     grok.order(4)
    301     grok.template('addaction')
    302     grok.require('waeup.manageUniversity')
    303 
    304     addview_name = 'add'
    305     addlink_text = 'Add department'
    306 
    307 class AddCertificateAction(AddAction):
    308     """Add-certificate button for department index page.
    309     """
     348    text = 'Add department'
     349
     350class AddCertificateActionButton(AddActionButton):
    310351    grok.context(IDepartment)
    311352    grok.view(DepartmentPage)
    312353    grok.order(3)
    313     grok.template('addaction')
    314     grok.require('waeup.manageUniversity')
    315 
    316     addview_name = 'addcertificate'
    317     addlink_text = 'Add certificate'
    318 
    319 class AddCourseAction(AddAction):
    320     """Add-course button for department index page.
    321     """
     354    text = 'Add certificate'
     355    target = 'addcertificate'
     356   
     357class AddCourseActionButton(AddActionButton):
    322358    grok.context(IDepartment)
    323359    grok.view(DepartmentPage)
    324360    grok.order(4)
    325     grok.template('addaction')
    326     grok.require('waeup.manageUniversity')
    327 
    328     addview_name = 'addcourse'
    329     addlink_text = 'Add course'
    330 
    331 class AddCertificateCourseAction(AddAction):
    332     """Add-course button for certificate index page.
    333     """
     361    text = 'Add course'
     362    target = 'addcourse'
     363
     364class AddCertificateActionButton(AddActionButton):
    334365    grok.context(ICertificate)
    335366    grok.view(CertificatePage)
    336367    grok.order(4)
    337     grok.template('addaction')
    338     grok.require('waeup.manageUniversity')
    339 
    340     addview_name = 'addcertificatecourse'
    341     addlink_text = 'Add course'
     368    text = 'Add course reference'
     369    target = 'addcertificatecourse'
    342370
    343371
Note: See TracChangeset for help on using the changeset viewer.