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.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.