Changeset 7328


Ignore:
Timestamp:
11 Dec 2011, 10:17:35 (13 years ago)
Author:
Henrik Bettermann
Message:

Implement a new Action class which renders a JS onclick command.

Location:
main/waeup.sirp/trunk/src/waeup/sirp/browser
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/trunk/src/waeup/sirp/browser/layout.py

    r7321 r7328  
    2222from datetime import date, datetime
    2323import grokcore.view
     24from cgi import escape
     25from zope.i18nmessageid import Message
    2426from hurry.resource import mode
    2527from megrok.layout import Page, Layout, Form, EditForm, DisplayForm, AddForm
     
    2729from zope.component import getUtility, queryUtility, ComponentLookupError
    2830from zope.formlib.utility import setUpWidgets
     31from grokcore.formlib.formlib import Action
    2932from zope.interface import Interface
    3033from zope.site.hooks import getSite
     
    4952default_primary_nav_template.__grok_name__ = 'default_primary_nav'
    5053
     54class jsaction(grok.action):
     55
     56    def __call__(self, success):
     57        action = JSAction(self.label, success=success, **self.options)
     58        self.actions.append(action)
     59        return action
     60
     61class JSAction(Action):
     62
     63    msg = '\'Are you sure?\''
     64
     65    def render(self):
     66        if not self.available():
     67            return ''
     68        label = self.label
     69        if isinstance(label, Message):
     70            label = zope.i18n.translate(self.label, context=self.form.request)
     71        return ('<input type="submit" id="%s" name="%s" value="%s"'
     72                ' class="button" onclick="return confirmPost(%s)" />' %
     73                (self.__name__, self.__name__, escape(label, quote=True), self.msg)
     74                )
    5175
    5276def NullValidator(*args, **kw):
  • main/waeup.sirp/trunk/src/waeup/sirp/browser/pages.py

    r7321 r7328  
    5959from waeup.sirp.authentication import get_principal_role_manager
    6060from waeup.sirp.utils.helpers import get_user_account, send_mail
     61from waeup.sirp.browser.layout import jsaction, JSAction
    6162
    6263grok.context(ISIRPObject)
     
    595596        tabs.need()
    596597        datatable.need()
     598        warning.need()
    597599        return super(ConfigurationContainerManageFormPage, self).update()
    598600
     
    617619            yield(dict(url=url, name=key, title=title))
    618620
    619     # ToDo: Show warning message before deletion
    620     @grok.action('Remove selected')
     621    @jsaction('Remove selected')
    621622    def delSessonConfigurations(self, **data):
    622623        delSubobjects(self, redirect='@@index', tab='2')
     
    12041205    def update(self):
    12051206        tabs.need()
    1206         #warning.need()
     1207        warning.need()
    12071208        return super(FacultyContainerManageFormPage, self).update()
    12081209
    1209     # ToDo: Show warning message before deletion
    1210     @grok.action('Remove selected')
     1210    @jsaction('Remove selected')
    12111211    def delFaculties(self, **data):
    12121212        delSubobjects(self, redirect='@@manage', tab='1')
     
    12951295    def update(self):
    12961296        tabs.need()
     1297        warning.need()
    12971298        datatable.need()
    12981299        return super(FacultyManageFormPage, self).update()
     
    13121313        return get_users_with_local_roles(self.context)
    13131314
    1314     # ToDo: Show warning message before deletion
    1315     @grok.action('Remove selected')
     1315    @jsaction('Remove selected')
    13161316    def delDepartments(self, **data):
    13171317        delSubobjects(self, redirect='@@manage', tab='2')
     
    14711471    def update(self):
    14721472        tabs.need()
     1473        warning.need()
    14731474        datatable.need()
    14741475        super(DepartmentManageFormPage, self).update()
     
    14941495        return
    14951496
    1496     # ToDo: Show warning message before deletion
    1497     @grok.action('Remove selected courses')
     1497    @jsaction('Remove selected courses')
    14981498    def delCourses(self, **data):
    14991499        delSubobjects(
     
    15011501        return
    15021502
    1503     @grok.action('Remove selected certificates')
     1503    @jsaction('Remove selected certificates')
    15041504    def delCertificates(self, **data):
    15051505        delSubobjects(
     
    17101710    def update(self):
    17111711        tabs.need()
    1712         #warning.need()
     1712        warning.need()
    17131713        datatable.need()
    17141714        return super(CertificateManageFormPage, self).update()
     
    17211721        return
    17221722
    1723     # ToDo: Show warning message before deletion
    1724     @grok.action('Remove selected course referrers')
     1723    @jsaction('Remove selected course referrers')
    17251724    def delCertificateCourses(self, **data):
    17261725        delSubobjects(self, redirect='@@manage', tab='2')
  • main/waeup.sirp/trunk/src/waeup/sirp/browser/resources.py

    r7321 r7328  
    113113#:   .. code-block:: html
    114114#:
    115 #:        <input type="submit" name="xyz" value="abc"/>
    116 #:               onclick="return confirmPost('Are you sure?')">
     115#:        <input type="submit" name="xyz" value="abc">
     116#:               onclick="return confirmPost('Are you sure?')"/>
    117117warning = ResourceInclusion(waeup_sirp, 'warning.js')
    118118
Note: See TracChangeset for help on using the changeset viewer.