Project

General

Profile

« Previous | Next » 

Revision bfaad93b

Added by Frédéric Péters almost 14 years ago

Add listing of available forms to sidebar

View differences:

extra/modules/forms_ui.ptl
58 58
        is_admin = is_forms_admin()
59 59

  
60 60
        l = []
61
        l2 = []
61 62
        if user:
62 63
            for formdef in FormDef.select(order_by='name', ignore_errors=True):
63 64
                if not formdef.disabled:
64 65
                    if is_admin or formdef.receiver_id in (user.roles or []):
65 66
                        l.append(formdef)
66 67
                elif is_admin:
67
                    l.append(formdef)
68
                    l2.append(formdef)
68 69

  
69 70
        cats = Category.select(order_by = 'name')
70 71
        lists = []
......
76 77
        if t:
77 78
            lists.append((None, t))
78 79

  
79
        if not lists:
80
            raise errors.AccessForbiddenError()
80
        lists_disabled = []
81
        for c in cats:
82
            t = [x for x in l2 if x.category_id == c.id]
83
            if t:
84
                lists_disabled.append((c.name, t))
85
        t = [x for x in l2 if x.category_id is None]
86
        if t:
87
            lists_disabled.append((None, t))
81 88

  
82 89
        mid_term = ((len(lists) * 2) + sum([len(x[-1]) for x in lists])) / 2
83 90
        count = 0
......
105 112
                '<a href="../%s/">%s</a>' % (formdef.url_name, formdef.name)
106 113
                if formdef.disabled:
107 114
                    '</span>'
108
                if is_forms_admin:
109
                    if formdef.disabled:
110
                        ' (<a href="%s/enable">%s</a>) ' % (formdef.id, _('enable'))
111
                    else:
112
                        ' (<a href="%s/disable">%s</a>) ' % (formdef.id, _('disable'))
115
                if is_admin:
113 116
                    ' (<a href="%s/options" rel="popup">%s</a>)' % (formdef.id, _('options'))
114 117
                '</li>'
115 118
            '</ul>'
116 119
            '</div>'
117 120
        '</div>'
118 121

  
122
        if is_admin and lists_disabled:
123
            get_response().filter['sidebar'] = self.get_sidebar(lists_disabled)
119 124
        get_logger().info('forms backoffice - home')
120 125

  
126
    def get_sidebar [html] (self, lists_disabled):
127
        '<h3>%s</h3>' % _('Available Forms')
128
        '<p>'
129
        _('Click on forms to enable them.')
130
        '</p>'
131
        for cat_name, formdefs in lists_disabled:
132
            if cat_name:
133
                '<h4>%s</h4>' % cat_name
134
            elif len(lists) > 1:
135
                '<h4>%s</h4>' % _('Misc')
136
            '<ul>'
137
            for formdef in formdefs:
138
                '<li>'
139
                '<a href="%s/enable">%s</a>' % (formdef.id, formdef.name)
140
                '</li>'
141
            '</ul>'
142

  
121 143

  
122 144
    def _q_lookup(self, component):
123 145
        try:

Also available in: Unified diff