Ignore:
Timestamp:
26 Feb 2014, 07:54:30 (11 years ago)
Author:
Henrik Bettermann
Message:
  • JSAction has been deprecated. KofaAction? can be used instead. Additional parameters can be used in @action decorators to enable tooltips and/or warning windows. The old @jsaction decorator still triggers a default warning message.
Location:
main/waeup.kofa/trunk/src/waeup/kofa
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/applicants/browser.py

    r11254 r11437  
    4747from waeup.kofa.browser.breadcrumbs import Breadcrumb
    4848from waeup.kofa.browser.layout import (
    49     NullValidator, jsaction, action, UtilityView, JSAction)
     49    NullValidator, jsaction, action, UtilityView)
    5050from waeup.kofa.browser.pages import (
    5151    add_local_role, del_local_roles, doll_up, ExportCSVView)
     
    6464grok.context(IKofaObject) # Make IKofaObject the default context
    6565
    66 class SubmitJSAction(JSAction):
    67 
    68     msg = _('\'You can not edit your application records after final submission.'
    69             ' You really want to submit?\'')
    70 
    71 class submitaction(grok.action):
    72 
    73     def __call__(self, success):
    74         action = SubmitJSAction(self.label, success=success, **self.options)
    75         self.actions.append(action)
    76         return action
     66WARNING = _('You can not edit your application records after final submission.'
     67            ' You really want to submit?')
    7768
    7869class ApplicantsRootPage(KofaDisplayFormPage):
     
    10331024        return
    10341025
    1035     @submitaction(_('Final Submit'))
     1026    @action(_('Final Submit'), warning=WARNING)
    10361027    def finalsubmit(self, **data):
    10371028        if self.upload_success is False:  # False is not None!
  • main/waeup.kofa/trunk/src/waeup/kofa/browser/layout.py

    r11254 r11437  
    6969class KofaAction(Action):
    7070
    71     def __init__(self, label, style='', **options):
     71    def __init__(self, label, style='', tooltip='', warning='', **options):
    7272        super(KofaAction, self).__init__(label, **options)
    7373        self.style = style
     74        self.tooltip = tooltip
     75        self.warning = warning
    7476        if style == '':
    7577            self.style = 'default'
    76        
    7778
    7879    def render(self):
     
    8283        if isinstance(label, Message):
    8384            label = translate(self.label, context=self.form.request)
    84         return ('<input type="submit" id="%s" name="%s" value="%s"'
    85                 ' class="btn btn-%s"/>' %
    86                 (self.__name__, self.__name__, escape(label, quote=True),
    87                 self.style))
     85        if self.warning:
     86            warning = translate(self.warning, context=self.form.request)
     87            self.warning = ' onclick="return window.confirm(\'%s\')"' % warning
     88        if self.tooltip:
     89            tooltip = translate(self.tooltip, context=self.form.request)
     90            self.tooltip = ' data-toggle="tooltip" title="%s"' % tooltip
     91        if self.style:
     92            style = ' class="btn btn-%s"' % self.style
     93        else:
     94            style = ' class="btn btn-default"'
     95        html = ('<input type="submit" id="%s" name="%s" value="%s"' %
     96                (self.__name__, self.__name__, escape(label, quote=True))
     97                + style + self.tooltip + self.warning
     98                + ' />')
     99        return html
    88100
    89101class jsaction(grok.action):
    90102
     103    msg = _('Are you sure?')
     104
    91105    def __call__(self, success):
    92         action = JSAction(self.label, success=success, **self.options)
     106        action = KofaAction(self.label,
     107                            success=success, warning=self.msg,
     108                            **self.options)
    93109        self.actions.append(action)
    94110        return action
    95 
    96 class JSAction(Action):
    97 
    98     msg = _('\'Are you sure?\'')
    99 
    100     def __init__(self, label, style='', **options):
    101         super(JSAction, self).__init__(label, **options)
    102         self.style = style
    103         if style == '':
    104             self.style = 'default'
    105 
    106     def render(self):
    107         if not self.available():
    108             return ''
    109         label = self.label
    110         if isinstance(label, Message):
    111             label = translate(self.label, context=self.form.request)
    112         msg = translate(self.msg, context=self.form.request)
    113         return ('<input type="submit" id="%s" name="%s" value="%s"'
    114                 ' class="btn btn-%s" onclick="return window.confirm(%s)" />' %
    115                 (self.__name__, self.__name__, escape(label, quote=True),
    116                  self.style, msg)
    117                 )
    118111
    119112def NullValidator(*args, **kw):
Note: See TracChangeset for help on using the changeset viewer.