~lifeeth/sahana-eden/ifrc

« back to all changes in this revision

Viewing changes to models/01_menu.py

  • Committer: Fran Boon
  • Date: 2012-01-18 14:26:52 UTC
  • mfrom: (1875.1.1269 eden)
  • Revision ID: fran@aidiq.com-20120118142652-1p2fvpmr0xfkfy2z
merge Trunk: S3Compose() RESTful method available from all Search results, Break up PR into more classes

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
    Global menus & breadcrumbs
5
5
"""
6
6
 
7
 
# =============================================================================
8
 
# Language Menu (available in all screens)
9
 
#s3.menu_lang = [ T("Language"), True, "#"]
10
 
#_menu_lang = []
11
 
#for language in s3.l10n_languages.keys():
12
 
#    _menu_lang.append([s3.l10n_languages[language], False, language])
13
 
#s3.menu_lang.append(_menu_lang)
14
 
 
15
 
# -----------------------------------------------------------------------------
16
 
# Help Menu (available in all screens)
17
 
#s3.menu_help = [ T("Help"), True, "#",
18
 
#        [
19
 
#            [T("Contact us"), False,
20
 
#             URL(c="default", f="contact")],
21
 
#            [T("About"), False, URL(c="default", f="about")],
22
 
#        ]
23
 
#    ]
24
 
 
25
 
# -----------------------------------------------------------------------------
26
 
# Auth Menu (available in all screens)
27
 
 
28
 
 
29
 
if not auth.is_logged_in():
30
 
 
31
 
    login_next = URL(args=request.args, vars=request.vars)
32
 
    if request.controller == "default" and \
33
 
       request.function == "user" and \
34
 
       "_next" in request.get_vars:
35
 
           login_next = request.get_vars["_next"]
36
 
 
37
 
    self_registration = deployment_settings.get_security_self_registration()
38
 
 
39
 
    if self_registration:
40
 
        s3.menu_auth = [[T("Register"),
41
 
                         URL(c="default", f="user/register")],
42
 
                        [T("Sign In"),
43
 
                         URL(c="default", f="user/login",
44
 
                             vars=dict(_next=login_next))],
45
 
                        [T("Lost Password"),
46
 
                         URL(c="default", f="user/retrieve_password")]
47
 
                        ]
 
7
if auth.permission.format in ("html"):
 
8
    # =============================================================================
 
9
    # Language Menu (available in all screens)
 
10
    #s3.menu_lang = [ T("Language"), True, "#"]
 
11
    #_menu_lang = []
 
12
    #for language in s3.l10n_languages.keys():
 
13
    #    _menu_lang.append([s3.l10n_languages[language], False, language])
 
14
    #s3.menu_lang.append(_menu_lang)
 
15
 
 
16
    # -----------------------------------------------------------------------------
 
17
    # Help Menu (available in all screens)
 
18
    #s3.menu_help = [ T("Help"), True, "#",
 
19
    #        [
 
20
    #            [T("Contact us"), False,
 
21
    #             URL(c="default", f="contact")],
 
22
    #            [T("About"), False, URL(c="default", f="about")],
 
23
    #        ]
 
24
    #    ]
 
25
 
 
26
    # -----------------------------------------------------------------------------
 
27
    # Auth Menu (available in all screens)
 
28
 
 
29
 
 
30
 
 
31
 
 
32
 
 
33
 
 
34
 
 
35
 
 
36
    if not auth.is_logged_in():
 
37
 
 
38
        login_next = URL(args=request.args, vars=request.vars)
 
39
        if request.controller == "default" and \
 
40
           request.function == "user" and \
 
41
           "_next" in request.get_vars:
 
42
               login_next = request.get_vars["_next"]
 
43
 
 
44
        self_registration = deployment_settings.get_security_self_registration()
 
45
 
 
46
        if self_registration:
 
47
            s3.menu_auth = [[T("Register"),
 
48
                             URL(c="default", f="user/register")],
 
49
                            [T("Sign In"),
 
50
                             URL(c="default", f="user/login",
 
51
                                 vars=dict(_next=login_next))],
 
52
                            [T("Lost Password"),
 
53
                             URL(c="default", f="user/retrieve_password")]
 
54
                            ]
 
55
        else:
 
56
            s3.menu_auth = [[T("Sign In"),
 
57
                             URL(c="default", f="user/login",
 
58
                                 vars=dict(_next=login_next))],
 
59
                            [T("Lost Password"),
 
60
                             URL(c="default", f="user/retrieve_password")]
 
61
                            ]
48
62
    else:
49
 
        s3.menu_auth = [[T("Sign In"),
50
 
                         URL(c="default", f="user/login",
51
 
                             vars=dict(_next=login_next))],
52
 
                        [T("Lost Password"),
53
 
                         URL(c="default", f="user/retrieve_password")]
 
63
        s3.menu_auth = [[T("Sign Out"), URL(c="default",
 
64
                                            f="user/logout")],
 
65
                        [T("Change Password"), URL(c="default",
 
66
                                                   f="user/change_password")],
54
67
                        ]
55
 
else:
56
 
    s3.menu_auth = [[T("Sign Out"), URL(c="default",
57
 
                                        f="user/logout")],
58
 
                    [T("Change Password"), URL(c="default",
59
 
                                               f="user/change_password")],
60
 
                    ]
61
 
 
62
 
 
63
 
# -----------------------------------------------------------------------------
64
 
# Menu for Admin module
65
 
# (defined here as used in several different Controller files)
66
 
admin_menu_messaging = [
67
 
            [T("Email Settings"), False,
68
 
             URL(c="msg", f="email_settings", args=[1, "update"])],
69
 
            [T("SMS Settings"), False,
70
 
             URL(c="msg", f="setting", args=[1, "update"])],
71
 
            [T("Twitter Settings"), False,
72
 
             URL(c="msg", f="twitter_settings", args=[1, "update"])],
 
68
 
 
69
 
 
70
    # -----------------------------------------------------------------------------
 
71
    # Menu for Admin module
 
72
    # (defined here as used in several different Controller files)
 
73
    admin_menu_messaging = [
 
74
                [T("Email Settings"), False,
 
75
                 URL(c="msg", f="email_settings", args=[1, "update"])],
 
76
                [T("SMS Settings"), False,
 
77
                 URL(c="msg", f="setting", args=[1, "update"])],
 
78
                [T("Twitter Settings"), False,
 
79
                 URL(c="msg", f="twitter_settings", args=[1, "update"])],
 
80
        ]
 
81
    admin_menu_options = [
 
82
        #[T("Settings"), False, URL(c="admin", f="settings"),
 
83
        #    admin_menu_messaging,
 
84
        #    # Hidden until useful again
 
85
        #    #[T("Edit Themes"), False, URL(c="admin", f="theme")]
 
86
        #],
 
87
        [T("User Management"), False, URL(c="admin", f="user"), [
 
88
            [T("Users"), False, URL(c="admin", f="user")],
 
89
            [T("Roles"), False, URL(c="admin", f="role")],
 
90
            [T("Organizations"), False, URL(c="admin", f="organisation")],
 
91
            #[T("Roles"), False, URL(c="admin", f="group")],
 
92
            #[T("Membership"), False, URL(c="admin", f="membership")],
 
93
        ]],
 
94
        [T("Database"), False, URL(c="appadmin", f="index"), [
 
95
            # @ToDo: UI for the current Import approach (S3CSV)
 
96
            [T("Import"), False, URL(c="admin", f="import_file")],
 
97
            #[T("Import"), False, URL(c="admin", f="import_data")],
 
98
            #[T("Export"), False, URL(c="admin", f="export_data")],
 
99
            #[T("Import Jobs"), False, URL(c="admin", f="import_job")],
 
100
            [T("Raw Database access"), False, URL(c="appadmin", f="index")]
 
101
        ]],
 
102
        # Hidden until ready for production
 
103
        [T("Synchronization"), False, URL(c="sync", f="index"), [
 
104
            [T("Settings"), False, aURL(p="update", c="sync", f="config",
 
105
                                        args=["1", "update"])],
 
106
            [T("Repositories"), False, URL(c="sync", f="repository")],
 
107
            [T("Log"), False, URL(c="sync", f="log")],
 
108
        ]],
 
109
        #[T("Edit Application"), False,
 
110
        # URL(a="admin", c="default", f="design", args=[request.application])],
 
111
        [T("Tickets"), False, URL(c="admin", f="errors")],
 
112
        [T("Portable App"), False, URL(c="admin", f="portable")],
73
113
    ]
74
 
admin_menu_options = [
75
 
    #[T("Settings"), False, URL(c="admin", f="settings"),
76
 
    #    admin_menu_messaging,
77
 
    #    # Hidden until useful again
78
 
    #    #[T("Edit Themes"), False, URL(c="admin", f="theme")]
79
 
    #],
80
 
    [T("User Management"), False, URL(c="admin", f="user"), [
81
 
        [T("Users"), False, URL(c="admin", f="user")],
82
 
        [T("Roles"), False, URL(c="admin", f="role")],
83
 
        [T("Organizations"), False, URL(c="admin", f="organisation")],
84
 
        #[T("Roles"), False, URL(c="admin", f="group")],
85
 
        #[T("Membership"), False, URL(c="admin", f="membership")],
86
 
    ]],
87
 
    [T("Database"), False, URL(c="appadmin", f="index"), [
88
 
        # @ToDo: UI for the current Import approach (S3CSV)
89
 
        [T("Import"), False, URL(c="admin", f="import_file")],
90
 
        #[T("Import"), False, URL(c="admin", f="import_data")],
91
 
        #[T("Export"), False, URL(c="admin", f="export_data")],
92
 
        #[T("Import Jobs"), False, URL(c="admin", f="import_job")],
93
 
        [T("Raw Database access"), False, URL(c="appadmin", f="index")]
94
 
    ]],
95
 
    # Hidden until ready for production
96
 
    [T("Synchronization"), False, URL(c="sync", f="index"), [
97
 
        [T("Settings"), False, aURL(p="update", c="sync", f="config",
98
 
                                    args=["1", "update"])],
99
 
        [T("Repositories"), False, URL(c="sync", f="repository")],
100
 
        [T("Log"), False, URL(c="sync", f="log")],
101
 
    ]],
102
 
    #[T("Edit Application"), False,
103
 
    # URL(a="admin", c="default", f="design", args=[request.application])],
104
 
    [T("Tickets"), False, URL(c="admin", f="errors")],
105
 
    [T("Portable App"), False, URL(c="admin", f="portable")],
106
 
]
107
 
 
108
 
# -----------------------------------------------------------------------------
109
 
# Modules Menu (available in all Controllers)
110
 
# NB This is hardcoded for IFRC
111
 
s3.menu_modules = []
112
 
# Home always 1st
113
 
#_module = deployment_settings.modules["default"]
114
 
#s3.menu_modules.append([_module.name_nice, False,
115
 
#                        URL(c="default", f="index")])
116
 
 
117
 
# Modules to hide due to insufficient permissions
118
 
#hidden_modules = auth.permission.hidden_modules()
119
 
 
120
 
# The Modules to display at the top level (in order)
121
 
#for module_type in [1, 2, 3, 4, 5, 6]:
122
 
#    for module in deployment_settings.modules:
123
 
#        if module in hidden_modules:
124
 
#            continue
125
 
#        _module = deployment_settings.modules[module]
126
 
#        if (_module.module_type == module_type):
127
 
#            if not _module.access:
128
 
#                s3.menu_modules.append([_module.name_nice, False,
129
 
#                                        aURL(c=module, f="index")])
130
 
#            else:
131
 
#                authorised = False
132
 
#                groups = re.split("\|", _module.access)[1:-1]
133
 
#                for group in groups:
134
 
#                    if s3_has_role(group):
135
 
#                        authorised = True
136
 
#                if authorised == True:
137
 
#                    s3.menu_modules.append([_module.name_nice, False,
138
 
#                                            URL(c=module, f="index")])
139
 
 
140
 
# Modules to display off the 'more' menu
141
 
#modules_submenu = []
142
 
#for module in deployment_settings.modules:
143
 
#    if module in hidden_modules:
144
 
#        continue
145
 
#    _module = deployment_settings.modules[module]
146
 
#    if (_module.module_type == 10):
147
 
#        if not _module.access:
148
 
#            modules_submenu.append([_module.name_nice, False,
149
 
#                                    aURL(c=module, f="index")])
150
 
#        else:
151
 
#            authorised = False
152
 
#            groups = re.split("\|", _module.access)[1:-1]
153
 
#            for group in groups:
154
 
#                if s3_has_role(group):
155
 
#                    authorised = True
156
 
#            if authorised == True:
157
 
#                modules_submenu.append([_module.name_nice, False,
158
 
#                                        URL(c=module, f="index")])
159
 
#if modules_submenu:
160
 
#    # Only show the 'more' menu if there are entries in the list
161
 
#    module_more_menu = ([T("more"), False, "#"])
162
 
#    module_more_menu.append(modules_submenu)
163
 
#    s3.menu_modules.append(module_more_menu)
164
 
 
165
 
# Admin always last
166
 
if s3_has_role(ADMIN):
167
 
    _module = deployment_settings.modules["admin"]
168
 
    s3.menu_admin = [_module.name_nice,
169
 
                     URL(c="admin", f="index"), [
170
 
                        # This menu isn't shown in IFRC Theme yet
171
 
                        #[T("Settings"), URL(c="admin", f="settings")],
172
 
                        [T("Users"), URL(c="admin", f="user")],
173
 
                        [T("Database"), URL(c="appadmin", f="index")],
174
 
                        [T("Import"), URL(c="admin", f="import_file")],
175
 
                        [T("Synchronization"), URL(c="sync", f="index")],
176
 
                        [T("Tickets"), URL(c="admin", f="errors")],
177
 
                     ]]
178
 
#else:
179
 
#    s3.menu_admin = []
180
 
 
181
 
# -----------------------------------------------------------------------------
182
 
# Build overall menu out of components
183
 
#response.menu = s3.menu_modules
184
 
#response.menu.append(s3.menu_help)
185
 
#response.menu.append(s3.menu_auth)
186
 
response.menu = s3.menu_auth
187
 
#if deployment_settings.get_gis_menu():
188
 
#    # Do not localize this string.
189
 
#    s3.gis_menu_placeholder = "GIS menu placeholder"
190
 
#    # Add a placeholder for the regions menu, which cannot be constructed
191
 
#    # until the gis_config table is available. Put it near the language menu.
192
 
#    response.menu.append(s3.gis_menu_placeholder)
193
 
if s3.menu_admin:
194
 
    response.menu.append(s3.menu_admin)
195
 
# this check is handled by s3tools for personal menu,
196
 
# language select isn't rendered like other menu items in ifrc
197
 
#if deployment_settings.get_L10n_display_toolbar():
198
 
#    response.menu.append(s3.menu_lang)
199
 
 
200
 
# Menu helpers ================================================================
201
 
def s3_menu(controller, postp=None, prep=None):
202
 
    """
203
 
        appends controller specific options to global menu
204
 
        picks up from 01_menu, called from controllers
205
 
 
206
 
        @postp - additional postprocessor,
207
 
                 assuming postp acts on response.menu_options
208
 
        @prep  - pre-processor
209
 
        @ToDo: FIXIT - alter here when you alter controller name
210
 
    """
211
 
    if controller in s3_menu_dict:
212
 
 
213
 
        if prep:
214
 
            prep()
215
 
 
216
 
        # menu
217
 
        menu_config = s3_menu_dict[controller]
218
 
        menu = menu_config["menu"]
219
 
 
220
 
        # role hooks
221
 
        if s3_has_role(AUTHENTICATED) and "on_auth" in menu_config:
222
 
            menu.extend(menu_config["on_auth"])
223
 
 
224
 
        if s3_has_role(ADMIN) and "on_admin" in menu_config:
225
 
            menu.extend(menu_config["on_admin"])
226
 
 
227
 
        if s3_has_role(EDITOR) and "on_editor" in menu_config:
228
 
            menu.extend(menu_config["on_editor"])
229
 
 
230
 
        # conditionals
231
 
        conditions = [x for x in menu_config if re.match(r"condition[0-9]+", x)]
232
 
        for condition in conditions:
233
 
            if menu_config[condition]():
234
 
                menu.extend(menu_config["conditional%s" % condition[9:]])
235
 
 
236
 
        needle = request["wsgi"]["environ"]["PATH_INFO"]
237
 
        for i in xrange(len(menu)):
238
 
            if str(menu[i][2]) in needle:
239
 
                menu[i][1] = True
240
 
                if len(menu[i]) >= 4:
241
 
                    # if has submenus to it
242
 
                    for j in xrange(len(menu[i][3])):
243
 
                        if str(menu[i][3][j][2]) == needle:
244
 
                            menu[i][3][j][1] = True
245
 
                            break
246
 
                break
247
 
 
248
 
        response.menu_options = menu
249
 
 
250
 
        if postp:
251
 
            postp()
252
 
 
253
 
# =============================================================================
254
 
# Role-dependent Menu options
255
 
# =============================================================================
256
 
if s3_has_role(ADMIN):
257
 
    pr_menu = [
258
 
            [T("Person"), False, aURL(f="person", args=None), [
259
 
                [T("New"), False, aURL(p="create", f="person", args="create")],
260
 
                [T("Search"), False, aURL(f="index")],
261
 
                [T("List All"), False, aURL(f="person")],
262
 
            ]],
263
 
            [T("Groups"), False, aURL(f="group"), [
264
 
                [T("New"), False, aURL(p="create", f="group", args="create")],
265
 
                [T("List All"), False, aURL(f="group")],
266
 
            ]],
267
 
        ]
268
 
else:
269
 
    pr_menu = []
270
 
 
271
 
# =============================================================================
272
 
# Settings-dependent Menu options
273
 
# =============================================================================
274
 
# CRUD strings for inv_recv
275
 
# (outside condtional model load since need to be visible to menus)
276
 
if deployment_settings.get_inv_shipment_name() == "order":
277
 
    ADD_RECV = T("Add Order")
278
 
    LIST_RECV = T("List Orders")
279
 
    s3.crud_strings["inv_recv"] = Storage(
280
 
        title_create = ADD_RECV,
281
 
        title_display = T("Order Details"),
282
 
        title_list = LIST_RECV,
283
 
        title_update = T("Edit Order"),
284
 
        title_search = T("Search Orders"),
285
 
        subtitle_create = ADD_RECV,
286
 
        subtitle_list = T("Orders"),
287
 
        label_list_button = LIST_RECV,
288
 
        label_create_button = ADD_RECV,
289
 
        label_delete_button = T("Delete Order"),
290
 
        msg_record_created = T("Order Created"),
291
 
        msg_record_modified = T("Order updated"),
292
 
        msg_record_deleted = T("Order canceled"),
293
 
        msg_list_empty = T("No Orders registered")
294
 
    )
295
 
else:
296
 
    ADD_RECV = T("Receive Shipment")
297
 
    LIST_RECV = T("List Received Shipments")
298
 
    s3.crud_strings["inv_recv"] = Storage(
299
 
        title_create = ADD_RECV,
300
 
        title_display = T("Received Shipment Details"),
301
 
        title_list = LIST_RECV,
302
 
        title_update = T("Edit Received Shipment"),
303
 
        title_search = T("Search Received Shipments"),
304
 
        subtitle_create = ADD_RECV,
305
 
        subtitle_list = T("Received Shipments"),
306
 
        label_list_button = LIST_RECV,
307
 
        label_create_button = ADD_RECV,
308
 
        label_delete_button = T("Delete Received Shipment"),
309
 
        msg_record_created = T("Shipment Created"),
310
 
        msg_record_modified = T("Received Shipment updated"),
311
 
        msg_record_deleted = T("Received Shipment canceled"),
312
 
        msg_list_empty = T("No Received Shipments")
313
 
    )
314
 
 
315
 
if deployment_settings.get_project_community_activity():
316
 
    list_activities_label = T("List All Communities")
317
 
    import_activities_label = T("Import Project Communities")
318
 
else:
319
 
    list_activities_label = T("List All Activities")
320
 
    import_activities_label = T("Import Project Activities")
321
 
 
322
 
if deployment_settings.get_project_drr():
323
 
    project_menu = {
324
 
        "menu": [
325
 
            [T("Projects"), False, aURL(f="project"),[
326
 
                [T("Add New Project"), False, aURL(p="create", f="project", args="create")],
327
 
                [T("List All Projects"), False, aURL(f="project")],
328
 
                [list_activities_label, False, aURL(f="activity")],
329
 
                [T("Search"), False, aURL(f="project", args="search")],
330
 
            ]],
331
 
            [T("Reports"), False, aURL(f="report"),[
332
 
                [T("Who is doing What Where"), False, aURL(f="activity", args="report")],
333
 
                [T("Beneficiaries"),
334
 
                False, aURL(f="beneficiary",
335
 
                            args="report",
336
 
                            vars=Storage(rows="project_id",
337
 
                                        cols="bnf_type$name",
338
 
                                        fact="number",
339
 
                                        aggregate="sum"))],
340
 
                [T("Funding"), False, aURL(f="organisation", args="report")],
341
 
            ]],
342
 
            [T("Import"), False, aURL(f="index"),[
343
 
                [T("Import Projects"), False, aURL(p="create", f="project",
344
 
                                                args="import")],
345
 
                [T("Import Project Organisations"), False, aURL(p="create", f="organisation",
 
114
 
 
115
    # -----------------------------------------------------------------------------
 
116
    # Modules Menu (available in all Controllers)
 
117
    # NB This is hardcoded for IFRC
 
118
    s3.menu_modules = []
 
119
    # Home always 1st
 
120
    #_module = deployment_settings.modules["default"]
 
121
    #s3.menu_modules.append([_module.name_nice, False,
 
122
    #                        URL(c="default", f="index")])
 
123
 
 
124
    # Modules to hide due to insufficient permissions
 
125
    #hidden_modules = auth.permission.hidden_modules()
 
126
 
 
127
    # The Modules to display at the top level (in order)
 
128
    #for module_type in [1, 2, 3, 4, 5, 6]:
 
129
    #    for module in deployment_settings.modules:
 
130
    #        if module in hidden_modules:
 
131
    #            continue
 
132
    #        _module = deployment_settings.modules[module]
 
133
    #        if (_module.module_type == module_type):
 
134
    #            if not _module.access:
 
135
    #                s3.menu_modules.append([_module.name_nice, False,
 
136
    #                                        aURL(c=module, f="index")])
 
137
    #            else:
 
138
    #                authorised = False
 
139
    #                groups = re.split("\|", _module.access)[1:-1]
 
140
    #                for group in groups:
 
141
    #                    if s3_has_role(group):
 
142
    #                        authorised = True
 
143
    #                if authorised == True:
 
144
    #                    s3.menu_modules.append([_module.name_nice, False,
 
145
    #                                            URL(c=module, f="index")])
 
146
 
 
147
    # Modules to display off the 'more' menu
 
148
    #modules_submenu = []
 
149
    #for module in deployment_settings.modules:
 
150
    #    if module in hidden_modules:
 
151
    #        continue
 
152
    #    _module = deployment_settings.modules[module]
 
153
    #    if (_module.module_type == 10):
 
154
    #        if not _module.access:
 
155
    #            modules_submenu.append([_module.name_nice, False,
 
156
    #                                    aURL(c=module, f="index")])
 
157
    #        else:
 
158
    #            authorised = False
 
159
    #            groups = re.split("\|", _module.access)[1:-1]
 
160
    #            for group in groups:
 
161
    #                if s3_has_role(group):
 
162
    #                    authorised = True
 
163
    #            if authorised == True:
 
164
    #                modules_submenu.append([_module.name_nice, False,
 
165
    #                                        URL(c=module, f="index")])
 
166
    #if modules_submenu:
 
167
    #    # Only show the 'more' menu if there are entries in the list
 
168
    #    module_more_menu = ([T("more"), False, "#"])
 
169
    #    module_more_menu.append(modules_submenu)
 
170
    #    s3.menu_modules.append(module_more_menu)
 
171
 
 
172
    # Admin always last
 
173
    if s3_has_role(ADMIN):
 
174
        _module = deployment_settings.modules["admin"]
 
175
        s3.menu_admin = [_module.name_nice,
 
176
                         URL(c="admin", f="index"), [
 
177
                            # This menu isn't shown in IFRC Theme yet
 
178
                            #[T("Settings"), URL(c="admin", f="settings")],
 
179
                            [T("Users"), URL(c="admin", f="user")],
 
180
                            [T("Database"), URL(c="appadmin", f="index")],
 
181
                            [T("Import"), URL(c="admin", f="import_file")],
 
182
                            [T("Synchronization"), URL(c="sync", f="index")],
 
183
                            [T("Tickets"), URL(c="admin", f="errors")],
 
184
                         ]]
 
185
    #else:
 
186
    #    s3.menu_admin = []
 
187
 
 
188
    # -----------------------------------------------------------------------------
 
189
    # Build overall menu out of components
 
190
    #response.menu = s3.menu_modules
 
191
    #response.menu.append(s3.menu_help)
 
192
    #response.menu.append(s3.menu_auth)
 
193
    response.menu = s3.menu_auth
 
194
    #if deployment_settings.get_gis_menu():
 
195
    #    # Do not localize this string.
 
196
    #    s3.gis_menu_placeholder = "GIS menu placeholder"
 
197
    #    # Add a placeholder for the regions menu, which cannot be constructed
 
198
    #    # until the gis_config table is available. Put it near the language menu.
 
199
    #    response.menu.append(s3.gis_menu_placeholder)
 
200
    if s3.menu_admin:
 
201
        response.menu.append(s3.menu_admin)
 
202
    # this check is handled by s3tools for personal menu,
 
203
    # language select isn't rendered like other menu items in ifrc
 
204
    #if deployment_settings.get_L10n_display_toolbar():
 
205
    #    response.menu.append(s3.menu_lang)
 
206
 
 
207
    # Menu helpers ================================================================
 
208
    def s3_menu(controller, postp=None, prep=None):
 
209
        """
 
210
            appends controller specific options to global menu
 
211
            picks up from 01_menu, called from controllers
 
212
 
 
213
            @postp - additional postprocessor,
 
214
                     assuming postp acts on response.menu_options
 
215
            @prep  - pre-processor
 
216
            @ToDo: FIXIT - alter here when you alter controller name
 
217
        """
 
218
        if controller in s3_menu_dict:
 
219
 
 
220
            if prep:
 
221
                prep()
 
222
 
 
223
            # menu
 
224
            menu_config = s3_menu_dict[controller]
 
225
            menu = menu_config["menu"]
 
226
 
 
227
            # role hooks
 
228
            if s3_has_role(AUTHENTICATED) and "on_auth" in menu_config:
 
229
                menu.extend(menu_config["on_auth"])
 
230
 
 
231
            if s3_has_role(ADMIN) and "on_admin" in menu_config:
 
232
                menu.extend(menu_config["on_admin"])
 
233
 
 
234
            if s3_has_role(EDITOR) and "on_editor" in menu_config:
 
235
                menu.extend(menu_config["on_editor"])
 
236
 
 
237
            # conditionals
 
238
            conditions = [x for x in menu_config if re.match(r"condition[0-9]+", x)]
 
239
            for condition in conditions:
 
240
                if menu_config[condition]():
 
241
                    menu.extend(menu_config["conditional%s" % condition[9:]])
 
242
 
 
243
            needle = request["wsgi"]["environ"]["PATH_INFO"]
 
244
            for i in xrange(len(menu)):
 
245
                if str(menu[i][2]) in needle:
 
246
                    menu[i][1] = True
 
247
                    if len(menu[i]) >= 4:
 
248
                        # if has submenus to it
 
249
                        for j in xrange(len(menu[i][3])):
 
250
                            if str(menu[i][3][j][2]) == needle:
 
251
                                menu[i][3][j][1] = True
 
252
                                break
 
253
                    break
 
254
 
 
255
            response.menu_options = menu
 
256
 
 
257
            if postp:
 
258
                postp()
 
259
 
 
260
    # =============================================================================
 
261
    # Role-dependent Menu options
 
262
    # =============================================================================
 
263
    if s3_has_role(ADMIN):
 
264
        pr_menu = [
 
265
                [T("Person"), False, aURL(f="person", args=None), [
 
266
                    [T("New"), False, aURL(p="create", f="person", args="create")],
 
267
                    [T("Search"), False, aURL(f="index")],
 
268
                    [T("List All"), False, aURL(f="person")],
 
269
                ]],
 
270
                [T("Groups"), False, aURL(f="group"), [
 
271
                    [T("New"), False, aURL(p="create", f="group", args="create")],
 
272
                    [T("List All"), False, aURL(f="group")],
 
273
                ]],
 
274
            ]
 
275
    else:
 
276
        pr_menu = []
 
277
 
 
278
    # =============================================================================
 
279
    # Settings-dependent Menu options
 
280
    # =============================================================================
 
281
    # CRUD strings for inv_recv
 
282
    # (outside condtional model load since need to be visible to menus)
 
283
    if deployment_settings.get_inv_shipment_name() == "order":
 
284
        ADD_RECV = T("Add Order")
 
285
        LIST_RECV = T("List Orders")
 
286
        s3.crud_strings["inv_recv"] = Storage(
 
287
            title_create = ADD_RECV,
 
288
            title_display = T("Order Details"),
 
289
            title_list = LIST_RECV,
 
290
            title_update = T("Edit Order"),
 
291
            title_search = T("Search Orders"),
 
292
            subtitle_create = ADD_RECV,
 
293
            subtitle_list = T("Orders"),
 
294
            label_list_button = LIST_RECV,
 
295
            label_create_button = ADD_RECV,
 
296
            label_delete_button = T("Delete Order"),
 
297
            msg_record_created = T("Order Created"),
 
298
            msg_record_modified = T("Order updated"),
 
299
            msg_record_deleted = T("Order canceled"),
 
300
            msg_list_empty = T("No Orders registered")
 
301
        )
 
302
    else:
 
303
        ADD_RECV = T("Receive Shipment")
 
304
        LIST_RECV = T("List Received Shipments")
 
305
        s3.crud_strings["inv_recv"] = Storage(
 
306
            title_create = ADD_RECV,
 
307
            title_display = T("Received Shipment Details"),
 
308
            title_list = LIST_RECV,
 
309
            title_update = T("Edit Received Shipment"),
 
310
            title_search = T("Search Received Shipments"),
 
311
            subtitle_create = ADD_RECV,
 
312
            subtitle_list = T("Received Shipments"),
 
313
            label_list_button = LIST_RECV,
 
314
            label_create_button = ADD_RECV,
 
315
            label_delete_button = T("Delete Received Shipment"),
 
316
            msg_record_created = T("Shipment Created"),
 
317
            msg_record_modified = T("Received Shipment updated"),
 
318
            msg_record_deleted = T("Received Shipment canceled"),
 
319
            msg_list_empty = T("No Received Shipments")
 
320
        )
 
321
 
 
322
    if deployment_settings.get_project_community_activity():
 
323
        list_activities_label = T("List All Communities")
 
324
        import_activities_label = T("Import Project Communities")
 
325
    else:
 
326
        list_activities_label = T("List All Activities")
 
327
        import_activities_label = T("Import Project Activities")
 
328
 
 
329
    if deployment_settings.get_project_drr():
 
330
        project_menu = {
 
331
            "menu": [
 
332
                [T("Projects"), False, aURL(f="project"),[
 
333
                    [T("Add New Project"), False, aURL(p="create", f="project", args="create")],
 
334
                    [T("List All Projects"), False, aURL(f="project")],
 
335
                    [list_activities_label, False, aURL(f="activity")],
 
336
                    [T("Search"), False, aURL(f="project", args="search")],
 
337
                ]],
 
338
                [T("Reports"), False, aURL(f="report"),[
 
339
                    [T("Who is doing What Where"), False, aURL(f="activity", args="report")],
 
340
                    [T("Beneficiaries"),
 
341
                    False, aURL(f="beneficiary",
 
342
                                args="report",
 
343
                                vars=Storage(rows="project_id",
 
344
                                            cols="bnf_type$name",
 
345
                                            fact="number",
 
346
                                            aggregate="sum"))],
 
347
                    [T("Funding"), False, aURL(f="organisation", args="report")],
 
348
                ]],
 
349
                [T("Import"), False, aURL(f="index"),[
 
350
                    [T("Import Projects"), False, aURL(p="create", f="project",
 
351
                                                    args="import")],
 
352
                    [T("Import Project Organisations"), False, aURL(p="create", f="organisation",
 
353
                                                                    args="import")],
 
354
                    [import_activities_label, False, aURL(p="create", f="activity",
346
355
                                                                args="import")],
347
 
                [import_activities_label, False, aURL(p="create", f="activity",
348
 
                                                            args="import")],
349
 
            ]],
350
 
            [T("Activity Types"), False, aURL(f="activity_type"),[
351
 
                [T("Add New Activity Type"), False, aURL(p="create", f="activity_type", args="create")],
352
 
                [T("List All Activity Types"), False, aURL(f="activity_type")],
353
 
                #[T("Search"), False, aURL(f="activity_type", args="search")]
354
 
            ]],
355
 
            [T("Hazards"), False, aURL(f="hazard"),[
356
 
                [T("Add New Hazard"), False, aURL(p="create", f="hazard", args="create")],
357
 
                [T("List All Hazards"), False, aURL(f="hazard")],
358
 
            ]],
359
 
            [T("Project Themes"), False, aURL(f="theme"),[
360
 
                [T("Add New Theme"), False, aURL(p="create", f="theme", args="create")],
361
 
                [T("List All Themes"), False, aURL(f="theme")],
362
 
            ]],
363
 
            [T("Beneficiary Types"), False, aURL(f="beneficiary_type"),[
364
 
                [T("Add New Type"), False, aURL(p="create", f="beneficiary_type", args="create")],
365
 
                [T("List All Types"), False, aURL(f="beneficiary_type")],
366
 
            ]],
367
 
        ],
368
 
    }
369
 
elif s3_has_role("STAFF"):
370
 
    project_menu = {
371
 
        "menu": [
372
 
            [T("Projects"), False, aURL(f="project"),[
373
 
                #[T("Add New Project"), False, aURL(p="create", f="project", args="create")],
374
 
                [T("List Projects"), False, aURL(f="project")],
375
 
                [T("Open Tasks for Project"), False, aURL(f="project", vars={"tasks":1})],
376
 
            ]],
377
 
            #[T("Tasks"), False, aURL(f="task"),[
378
 
                #[T("Add New Task"), False, aURL(p="create", f="task", args="create")],
379
 
                #[T("List All Tasks"), False, aURL(f="task")],
380
 
                #[T("Search"), False, aURL(f="task", args="search")],
381
 
            #]],
382
 
            [T("Daily Work"), False, aURL(f="time"),[
383
 
                [T("My Logged Hours"), False, aURL(f="time", vars={"mine":1})],
384
 
                [T("Last Week's Work"),
385
 
                False, aURL(f="time",
386
 
                            args="report",
387
 
                            vars={"rows":"person_id",
388
 
                                "cols":"day",
389
 
                                "fact":"hours",
390
 
                                "aggregate":"sum",
391
 
                                "week":1})],
392
 
                [T("My Open Tasks"), False, aURL(f="task", vars={"mine":1})],
393
 
            ]],
394
 
        ],
395
 
        "on_admin": [
396
 
            [T("Admin"), False, None,[
397
 
                [T("Activity Types"), False, aURL(f="activity_type")],
398
 
                [T("Organizations"), False, aURL(f="organisation")],
399
 
                [T("Import Tasks"), False, aURL(p="create", f="task",
400
 
                                                args="import")],
401
 
            ]],
402
 
            [T("Reports"), False, aURL(f="report"),[
403
 
                [T("Activity Report"),
404
 
                False, aURL(f="activity",
405
 
                            args="report",
406
 
                            vars=Storage(rows="project_id",
407
 
                                        cols="name",
408
 
                                        fact="time_actual",
409
 
                                        aggregate="sum"))],
410
 
                [T("Project Time Report"),
411
 
                False, aURL(f="time",
412
 
                            args="report",
413
 
                            vars=Storage(rows="project",
414
 
                                        cols="person_id",
415
 
                                        fact="hours",
416
 
                                        aggregate="sum"))],
417
 
            ]],
418
 
        ]
419
 
    }
420
 
else:
421
 
    project_menu = {
422
 
        "menu": [
423
 
            [T("Projects"), False, aURL(f="project"),[
424
 
                [T("List All Projects"), False, aURL(f="project")],
425
 
            ]],
426
 
        ],
427
 
    }
428
 
 
429
 
# -----------------------------------------------------------------------------
430
 
org_menu = [T("Organizations"), False, aURL(c="org", f="organisation"), [
431
 
                [T("New"), False, aURL(p="create", c="org", f="organisation",
432
 
                                       args="create")],
433
 
                [T("List All"), False, aURL(c="org", f="organisation")],
434
 
                [T("Search"), False, aURL(c="org", f="organisation",
435
 
                                          args="search")],
436
 
                #[T("Import"), False, aURL(p="create", c="org", f="organisation",
437
 
                #                          args="import")]
438
 
            ]]
439
 
office_menu = [T("Offices"), False, aURL(c="org", f="office"), [
440
 
                [T("New"), False, aURL(p="create", c="org", f="office",
441
 
                                       args="create")],
442
 
                [T("List All"), False, aURL(c="org", f="office")],
443
 
                [T("Search"), False, aURL(c="org", f="office",
444
 
                                          args="search")],
445
 
                [T("Import"), False, aURL(p="create", c="org", f="office",
446
 
                                          args="import")]
447
 
            ]]
448
 
 
449
 
hrm_menu = {
450
 
        "menu": [],
451
 
 
452
 
        # NOTE: session.s3.hrm.mode is set by menu pre-processor in controller
453
 
 
454
 
        "condition1": lambda: session.s3.hrm.mode is not None,
455
 
        "conditional1": [
456
 
                [T("Profile"),
457
 
                 True, aURL(c="hrm",
458
 
                            f="person",
459
 
                            vars=dict(mode="personal"))
460
 
                ]],
461
 
 
462
 
        "condition2": lambda: (session.s3.hrm.mode is not None) and (session.s3.hrm.orgs or ADMIN in session.s3.roles),
463
 
        "conditional2": [[T("Human Resources"),
464
 
                          True, aURL(c="hrm",
465
 
                                     f="index")]],
466
 
 
467
 
        "condition3": lambda: session.s3.hrm.mode is None,
468
 
        "conditional3": [
469
 
            [T("Staff"), False, aURL(c="hrm",
470
 
                                     f="human_resource",
471
 
                                     vars=dict(group="staff")), [
472
 
                [T("New Staff Member"), False, aURL(p="create",
473
 
                                                    c="hrm",
474
 
                                                    f="human_resource",
475
 
                                                    args="create",
476
 
                                                    vars=dict(group="staff"))],
477
 
                [T("List All"), False, aURL(c="hrm",
478
 
                                            f="human_resource",
479
 
                                            vars=dict(group="staff"))],
480
 
                [T("Search"), False, aURL(c="hrm",
481
 
                                          f="human_resource",
482
 
                                          args="search",
483
 
                                          vars=dict(group="staff"))],
484
 
                [T("Report Expiring Contracts"), False, aURL(c="hrm",
485
 
                                                             f="human_resource",
486
 
                                                             vars=dict(group="staff",
487
 
                                                                       expiring=1))],
488
 
                [T("Import"), False, aURL(p="create",
489
 
                                          c="hrm",
490
 
                                          f="person",
491
 
                                          args=["import"],
492
 
                                          vars=dict(group="staff"))],
493
 
                #[T("Dashboard"), False, aURL(f="index")],
494
 
            ]],
495
 
            [T("Volunteers"), False, aURL(c="hrm",
496
 
                                          f="human_resource",
497
 
                                          vars=dict(group="volunteer")), [
498
 
                [T("New Volunteer"), False, aURL(p="create",
499
 
                                                 c="hrm",
500
 
                                                 f="human_resource",
501
 
                                                 args="create",
502
 
                                                 vars=dict(group="volunteer"))],
503
 
                [T("List All"), False, aURL(c="hrm",
504
 
                                            f="human_resource",
505
 
                                            vars=dict(group="volunteer"))],
506
 
                [T("Search"), False, aURL(c="hrm",
507
 
                                          f="human_resource",
508
 
                                          args="search",
509
 
                                          vars=dict(group="volunteer"))],
510
 
                [T("Import"), False, aURL(p="create",
511
 
                                          c="hrm",
512
 
                                          f="person",
513
 
                                          args=["import"],
514
 
                                          vars=dict(group="volunteer"))],
515
 
            ]],
516
 
            [T("Teams"), False, aURL(f="group"), [
517
 
                [T("New Team"), False, aURL(c="hrm",
518
 
                                            f="group",
519
 
                                            args="create")],
520
 
                [T("List All"), False, aURL(c="hrm",
521
 
                                            f="group")],
522
 
            ]],
523
 
            org_menu,
524
 
            office_menu,
525
 
            [T("Job Role Catalog"), False, aURL(c="hrm",
526
 
                                                f="job_role"), [
527
 
                [T("New Job Role"), False, aURL(c="hrm",
528
 
                                                f="job_role",
 
356
                ]],
 
357
                [T("Activity Types"), False, aURL(f="activity_type"),[
 
358
                    [T("Add New Activity Type"), False, aURL(p="create", f="activity_type", args="create")],
 
359
                    [T("List All Activity Types"), False, aURL(f="activity_type")],
 
360
                    #[T("Search"), False, aURL(f="activity_type", args="search")]
 
361
                ]],
 
362
                [T("Hazards"), False, aURL(f="hazard"),[
 
363
                    [T("Add New Hazard"), False, aURL(p="create", f="hazard", args="create")],
 
364
                    [T("List All Hazards"), False, aURL(f="hazard")],
 
365
                ]],
 
366
                [T("Project Themes"), False, aURL(f="theme"),[
 
367
                    [T("Add New Theme"), False, aURL(p="create", f="theme", args="create")],
 
368
                    [T("List All Themes"), False, aURL(f="theme")],
 
369
                ]],
 
370
                [T("Beneficiary Types"), False, aURL(f="beneficiary_type"),[
 
371
                    [T("Add New Type"), False, aURL(p="create", f="beneficiary_type", args="create")],
 
372
                    [T("List All Types"), False, aURL(f="beneficiary_type")],
 
373
                ]],
 
374
            ],
 
375
        }
 
376
    elif s3_has_role("STAFF"):
 
377
        project_menu = {
 
378
            "menu": [
 
379
                [T("Projects"), False, aURL(f="project"),[
 
380
                    #[T("Add New Project"), False, aURL(p="create", f="project", args="create")],
 
381
                    [T("List Projects"), False, aURL(f="project")],
 
382
                    [T("Open Tasks for Project"), False, aURL(f="project", vars={"tasks":1})],
 
383
                ]],
 
384
                #[T("Tasks"), False, aURL(f="task"),[
 
385
                    #[T("Add New Task"), False, aURL(p="create", f="task", args="create")],
 
386
                    #[T("List All Tasks"), False, aURL(f="task")],
 
387
                    #[T("Search"), False, aURL(f="task", args="search")],
 
388
                #]],
 
389
                [T("Daily Work"), False, aURL(f="time"),[
 
390
                    [T("My Logged Hours"), False, aURL(f="time", vars={"mine":1})],
 
391
                    [T("Last Week's Work"),
 
392
                    False, aURL(f="time",
 
393
                                args="report",
 
394
                                vars={"rows":"person_id",
 
395
                                    "cols":"day",
 
396
                                    "fact":"hours",
 
397
                                    "aggregate":"sum",
 
398
                                    "week":1})],
 
399
                    [T("My Open Tasks"), False, aURL(f="task", vars={"mine":1})],
 
400
                ]],
 
401
            ],
 
402
            "on_admin": [
 
403
                [T("Admin"), False, None,[
 
404
                    [T("Activity Types"), False, aURL(f="activity_type")],
 
405
                    [T("Organizations"), False, aURL(f="organisation")],
 
406
                    [T("Import Tasks"), False, aURL(p="create", f="task",
 
407
                                                    args="import")],
 
408
                ]],
 
409
                [T("Reports"), False, aURL(f="report"),[
 
410
                    [T("Activity Report"),
 
411
                    False, aURL(f="activity",
 
412
                                args="report",
 
413
                                vars=Storage(rows="project_id",
 
414
                                            cols="name",
 
415
                                            fact="time_actual",
 
416
                                            aggregate="sum"))],
 
417
                    [T("Project Time Report"),
 
418
                    False, aURL(f="time",
 
419
                                args="report",
 
420
                                vars=Storage(rows="project",
 
421
                                            cols="person_id",
 
422
                                            fact="hours",
 
423
                                            aggregate="sum"))],
 
424
                ]],
 
425
            ]
 
426
        }
 
427
    else:
 
428
        project_menu = {
 
429
            "menu": [
 
430
                [T("Projects"), False, aURL(f="project"),[
 
431
                    [T("List All Projects"), False, aURL(f="project")],
 
432
                ]],
 
433
            ],
 
434
        }
 
435
 
 
436
    # -----------------------------------------------------------------------------
 
437
    org_menu = [T("Organizations"), False, aURL(c="org", f="organisation"), [
 
438
                    [T("New"), False, aURL(p="create", c="org", f="organisation",
 
439
                                           args="create")],
 
440
                    [T("List All"), False, aURL(c="org", f="organisation")],
 
441
                    [T("Search"), False, aURL(c="org", f="organisation",
 
442
                                              args="search")],
 
443
                    #[T("Import"), False, aURL(p="create", c="org", f="organisation",
 
444
                    #                          args="import")]
 
445
                ]]
 
446
    office_menu = [T("Offices"), False, aURL(c="org", f="office"), [
 
447
                    [T("New"), False, aURL(p="create", c="org", f="office",
 
448
                                           args="create")],
 
449
                    [T("List All"), False, aURL(c="org", f="office")],
 
450
                    [T("Search"), False, aURL(c="org", f="office",
 
451
                                              args="search")],
 
452
                    [T("Import"), False, aURL(p="create", c="org", f="office",
 
453
                                              args="import")]
 
454
                ]]
 
455
 
 
456
    hrm_menu = {
 
457
            "menu": [],
 
458
 
 
459
            # NOTE: session.s3.hrm.mode is set by menu pre-processor in controller
 
460
            #       so can't simply make an if/else here :/
 
461
 
 
462
            "condition1": lambda: session.s3.hrm.mode is not None,
 
463
            "conditional1": [
 
464
                    [T("Profile"),
 
465
                     True, aURL(c="hrm",
 
466
                                f="person",
 
467
                                vars=dict(mode="personal"))
 
468
                    ]],
 
469
 
 
470
            "condition2": lambda: (session.s3.hrm.mode is not None) and (session.s3.hrm.orgs or ADMIN in session.s3.roles),
 
471
            "conditional2": [[T("Human Resources"),
 
472
                              True, aURL(c="hrm",
 
473
                                         f="index")]],
 
474
 
 
475
            "condition3": lambda: session.s3.hrm.mode is None,
 
476
            "conditional3": [
 
477
                [T("Staff"), False, aURL(c="hrm",
 
478
                                         f="human_resource",
 
479
                                         vars=dict(group="staff")), [
 
480
                    [T("New Staff Member"), False, aURL(p="create",
 
481
                                                        c="hrm",
 
482
                                                        f="human_resource",
 
483
                                                        args="create",
 
484
                                                        vars=dict(group="staff"))],
 
485
                    [T("List All"), False, aURL(c="hrm",
 
486
                                                f="human_resource",
 
487
                                                vars=dict(group="staff"))],
 
488
                    [T("Search"), False, aURL(c="hrm",
 
489
                                              f="human_resource",
 
490
                                              args="search",
 
491
                                              vars=dict(group="staff"))],
 
492
                    [T("Report Expiring Contracts"), False, aURL(c="hrm",
 
493
                                                                 f="human_resource",
 
494
                                                                 vars=dict(group="staff",
 
495
                                                                           expiring=1))],
 
496
                    [T("Import"), False, aURL(p="create",
 
497
                                              c="hrm",
 
498
                                              f="person",
 
499
                                              args=["import"],
 
500
                                              vars=dict(group="staff"))],
 
501
                    #[T("Dashboard"), False, aURL(f="index")],
 
502
                ]],
 
503
                [T("Volunteers"), False, aURL(c="hrm",
 
504
                                              f="human_resource",
 
505
                                              vars=dict(group="volunteer")), [
 
506
                    [T("New Volunteer"), False, aURL(p="create",
 
507
                                                     c="hrm",
 
508
                                                     f="human_resource",
 
509
                                                     args="create",
 
510
                                                     vars=dict(group="volunteer"))],
 
511
                    [T("List All"), False, aURL(c="hrm",
 
512
                                                f="human_resource",
 
513
                                                vars=dict(group="volunteer"))],
 
514
                    [T("Search"), False, aURL(c="hrm",
 
515
                                              f="human_resource",
 
516
                                              args="search",
 
517
                                              vars=dict(group="volunteer"))],
 
518
                    [T("Import"), False, aURL(p="create",
 
519
                                              c="hrm",
 
520
                                              f="person",
 
521
                                              args=["import"],
 
522
                                              vars=dict(group="volunteer"))],
 
523
                ]],
 
524
                [T("Teams"), False, aURL(c="hrm",
 
525
                                         f="group"), [
 
526
                    [T("New Team"), False, aURL(c="hrm",
 
527
                                                f="group",
529
528
                                                args="create")],
530
 
                [T("List All"), False, aURL(c="hrm",
531
 
                                            f="job_role")],
532
 
            ]],
533
 
            #[T("Skill Catalog"), False, URL(c="hrm",
534
 
            #                                f="skill"), [
535
 
            #    [T("New Skill"), False, aURL(p="create",
536
 
            #                                 c="hrm",
537
 
            #                                 f="skill",
538
 
            #                                 args="create")],
539
 
            #    [T("List All"), False, aURL(f="skill")],
540
 
            #    #[T("Skill Provisions"), False, aURL(f="skill_provision")],
541
 
            #]],
542
 
            [T("Training Events"), False, URL(c="hrm",
543
 
                                              f="training_event"), [
544
 
                [T("New Training Event"), False, aURL(p="create",
545
 
                                                      c="hrm",
546
 
                                                      f="training_event",
547
 
                                                      args="create")],
548
 
                [T("List All"), False, aURL(c="hrm",
549
 
                                            f="training_event")],
550
 
                [T("Import Participant List"), False, aURL(p="create",
 
529
                    [T("List All"), False, aURL(c="hrm",
 
530
                                                f="group")],
 
531
                ]],
 
532
                org_menu,
 
533
                office_menu,
 
534
                [T("Job Role Catalog"), False, aURL(c="hrm",
 
535
                                                    f="job_role"), [
 
536
                    [T("New Job Role"), False, aURL(c="hrm",
 
537
                                                    f="job_role",
 
538
                                                    args="create")],
 
539
                    [T("List All"), False, aURL(c="hrm",
 
540
                                                f="job_role")],
 
541
                ]],
 
542
                #[T("Skill Catalog"), False, URL(c="hrm",
 
543
                #                                f="skill"), [
 
544
                #    [T("New Skill"), False, aURL(p="create",
 
545
                #                                 c="hrm",
 
546
                #                                 f="skill",
 
547
                #                                 args="create")],
 
548
                #    [T("List All"), False, aURL(f="skill")],
 
549
                #    #[T("Skill Provisions"), False, aURL(f="skill_provision")],
 
550
                #]],
 
551
                [T("Training Events"), False, URL(c="hrm",
 
552
                                                  f="training_event"), [
 
553
                    [T("New Training Event"), False, aURL(p="create",
 
554
                                                          c="hrm",
 
555
                                                          f="training_event",
 
556
                                                          args="create")],
 
557
                    [T("List All"), False, aURL(c="hrm",
 
558
                                                f="training_event")],
 
559
                    [T("Import Participant List"), False, aURL(p="create",
 
560
                                                               c="hrm",
 
561
                                                               f="training",
 
562
                                                               args=["import"])],
 
563
                    [T("Training Report"), False, aURL(c="hrm",
 
564
                                                       f="training",
 
565
                                                       args=["report"],
 
566
                                                       vars=dict(rows="course_id",
 
567
                                                                 cols="month",
 
568
                                                                 fact="person_id",
 
569
                                                                 aggregate="count"))],
 
570
                ]],
 
571
                [T("Training Course Catalog"), False, URL(c="hrm",
 
572
                                                          f="course"), [
 
573
                    [T("New Training Course"), False, aURL(p="create",
551
574
                                                           c="hrm",
552
 
                                                           f="training",
553
 
                                                           args=["import"])],
554
 
                [T("Training Report"), False, aURL(c="hrm",
555
 
                                                   f="training",
556
 
                                                   args=["report"],
557
 
                                                   vars=dict(rows="course_id",
558
 
                                                             cols="month",
559
 
                                                             fact="person_id",
560
 
                                                             aggregate="count"))],
561
 
            ]],
562
 
            [T("Training Course Catalog"), False, URL(c="hrm",
563
 
                                                      f="course"), [
564
 
                [T("New Training Course"), False, aURL(p="create",
565
 
                                                       c="hrm",
566
 
                                                       f="course",
567
 
                                                       args="create")],
568
 
                [T("List All"), False, aURL(c="hrm",
569
 
                                            f="course")],
570
 
                #[T("Course Certificates"), False, aURL(c="hrm",
571
 
                #                                       f="course_certificate")],
572
 
            ]],
573
 
            # [T("Certificate Catalog"), False, URL(f="certificate"), [
574
 
                # [T("New Certificate"), False, aURL(p="create",
575
 
                                                   # f="certificate",
576
 
                                                   # args="create")],
577
 
                # [T("List All"), False, aURL(f="certificate")],
578
 
                # [T("Skill Equivalence"), False, aURL(f="certificate_skill")],
579
 
            # ]],
580
 
            # Add the "personal" section to the menu (right)
581
 
            [T("Personal Profile"), True, aURL(c="hrm",
582
 
                                               f="person",
583
 
                                               vars=dict(mode="personal"))]
584
 
        ],
585
 
    }
586
 
 
587
 
# =============================================================================
588
 
# Default Menu Configurations for Controllers
589
 
# =============================================================================
590
 
"""
591
 
    Dict structure -
592
 
        Key - controller name
593
 
        Value - Dict
594
 
            - menu      : default menu options
595
 
            - on_admin  : extensions for ADMIN role
596
 
            - on_editor : extensions for EDITOR role
597
 
        @NOTE: subject to change depending on changes in S3Menu / requirements
598
 
"""
599
 
s3_menu_dict = {
600
 
 
601
 
    # ASSET Controller
602
 
    # -------------------------------------------------------------------------
603
 
    "asset": {
604
 
        "menu": [
605
 
            #[T("Home"), False, aURL(c="asset", f="index")],
606
 
            [T("Assets"), False, aURL(c="asset", f="asset"),
607
 
            [
608
 
                [T("New"), False, aURL(p="create", c="asset", f="asset",
609
 
                                       args="create")],
610
 
                [T("List All"), False, aURL(c="asset", f="asset")],
611
 
                [T("Search"), False, aURL(c="asset", f="asset",
612
 
                                          args="search")],
613
 
                [T("Import"), False, aURL(p="create", c="asset", f="asset",
614
 
                                          args="import")],
615
 
            ]],
616
 
            [T("Items"), False, aURL(c="asset", f="item"),
617
 
            [
618
 
                [T("New"), False, aURL(p="create", c="asset", f="item",
619
 
                                      args="create")],
620
 
                [T("List All"), False, aURL(c="asset", f="item")],
621
 
            ]],
622
 
        ]
623
 
    },
624
 
 
625
 
    # CR / Shelter Registry Controller
626
 
    # -------------------------------------------------------------------------
627
 
    "cr": {
628
 
        "menu": [
629
 
            [ # @ToDo - Fix s3.crud_strings["cr_shelter"].subtitle_list
630
 
            T("Camps") if deployment_settings.get_ui_camp() \
631
 
            else T("Shelters"),
632
 
                                False, aURL(f="shelter"), [
633
 
                                        [T("New"), False, aURL(p="create", f="shelter", args="create")],
634
 
                [T("List All"), False, aURL(f="shelter")],
635
 
                # @ToDo Search by type, services, location, available space
636
 
                #[T("Search"), False, URL(f="shelter", args="search")],
637
 
            ]],
638
 
        ],
639
 
 
640
 
        "on_editor": [
641
 
            [
642
 
                T("Camp Types and Services") if deployment_settings.get_ui_camp() \
643
 
                else T("Shelter Types and Services"),
644
 
                False, URL(f="#"),
645
 
                [
646
 
                    [T("List / Add Services"), False, URL(f="shelter_service")],
647
 
                    [T("List / Add Types"), False, URL(f="shelter_type")],
648
 
 
649
 
                ]
650
 
            ],
651
 
        ]
652
 
    },
653
 
 
654
 
    # DOC / Document Library
655
 
    # -------------------------------------------------------------------------
656
 
    "doc": {
657
 
        "menu": [
658
 
            [T("Documents"), False, aURL(f="document"),[
659
 
                [T("New"), False, aURL(p="create", f="document", args="create")],
660
 
                [T("List All"), False, aURL(f="document")],
661
 
                #[T("Search"), False, aURL(f="ireport", args="search")]
662
 
            ]],
663
 
              [T("Photos"), False, aURL(f="image"),[
664
 
                [T("New"), False, aURL(p="create", f="image", args="create")],
665
 
                [T("List All"), False, aURL(f="image")],
666
 
                #[T("Bulk Uploader"), False, aURL(f="bulk_upload")]
667
 
                #[T("Search"), False, aURL(f="ireport", args="search")]
668
 
            ]]],
669
 
    },
670
 
 
671
 
    # EVENT / Event Module
672
 
    # -------------------------------------------------------------------------
673
 
    "event": {
674
 
        "menu": [
675
 
                    [T("Scenarios"), False, aURL(c="scenario", f="scenario"), [
676
 
                        [T("New Scenario"), False, aURL(p="create", c="scenario",
677
 
                                                        f="scenario",
678
 
                                                        args="create")],
679
 
                        [T("View All"), False, aURL(c="scenario", f="scenario")]
680
 
                    ]],
681
 
                    [T("Events"), False, aURL(c="event", f="event"), [
682
 
                        [T("New Event"), False, aURL(p="create", c="event", f="event",
683
 
                                                     args="create")],
684
 
                        [T("View All"), False, aURL(c="event", f="event")]
685
 
                    ]],
686
 
                ]   \
687
 
                if deployment_settings.has_module("scenario") else \
688
 
                [
689
 
                    [T("Events"), False, aURL(c="event", f="event"), [
690
 
                        [T("New Event"), False, aURL(p="create", c="event", f="event",
691
 
                                                     args="create")],
692
 
                        [T("View All"), False, aURL(c="event", f="event")]
 
575
                                                           f="course",
 
576
                                                           args="create")],
 
577
                    [T("List All"), False, aURL(c="hrm",
 
578
                                                f="course")],
 
579
                    #[T("Course Certificates"), False, aURL(c="hrm",
 
580
                    #                                       f="course_certificate")],
 
581
                ]],
 
582
                # [T("Certificate Catalog"), False, URL(f="certificate"), [
 
583
                    # [T("New Certificate"), False, aURL(p="create",
 
584
                                                       # f="certificate",
 
585
                                                       # args="create")],
 
586
                    # [T("List All"), False, aURL(f="certificate")],
 
587
                    # [T("Skill Equivalence"), False, aURL(f="certificate_skill")],
 
588
                # ]],
 
589
                # Add the "personal" section to the menu (right)
 
590
                [T("Personal Profile"), True, aURL(c="hrm",
 
591
                                                   f="person",
 
592
                                                   vars=dict(mode="personal"))]
 
593
            ],
 
594
        }
 
595
 
 
596
    # =============================================================================
 
597
    # Default Menu Configurations for Controllers
 
598
    # =============================================================================
 
599
    """
 
600
        Dict structure -
 
601
            Key - controller name
 
602
            Value - Dict
 
603
                - menu      : default menu options
 
604
                - on_admin  : extensions for ADMIN role
 
605
                - on_editor : extensions for EDITOR role
 
606
            @NOTE: subject to change depending on changes in S3Menu / requirements
 
607
    """
 
608
    s3_menu_dict = {
 
609
 
 
610
        # ASSET Controller
 
611
        # -------------------------------------------------------------------------
 
612
        "asset": {
 
613
            "menu": [
 
614
                #[T("Home"), False, aURL(c="asset", f="index")],
 
615
                [T("Assets"), False, aURL(c="asset", f="asset"),
 
616
                [
 
617
                    [T("New"), False, aURL(p="create", c="asset", f="asset",
 
618
                                           args="create")],
 
619
                    [T("List All"), False, aURL(c="asset", f="asset")],
 
620
                    [T("Search"), False, aURL(c="asset", f="asset",
 
621
                                              args="search")],
 
622
                    [T("Import"), False, aURL(p="create", c="asset", f="asset",
 
623
                                              args="import")],
 
624
                ]],
 
625
                [T("Items"), False, aURL(c="asset", f="item"),
 
626
                [
 
627
                    [T("New"), False, aURL(p="create", c="asset", f="item",
 
628
                                          args="create")],
 
629
                    [T("List All"), False, aURL(c="asset", f="item")],
 
630
                ]],
 
631
            ]
 
632
        },
 
633
 
 
634
        # CR / Shelter Registry Controller
 
635
        # -------------------------------------------------------------------------
 
636
        "cr": {
 
637
            "menu": [
 
638
                [ # @ToDo - Fix s3.crud_strings["cr_shelter"].subtitle_list
 
639
                T("Camps") if deployment_settings.get_ui_camp() \
 
640
                else T("Shelters"),
 
641
                    False, aURL(f="shelter"), [
 
642
                        [T("New"), False, aURL(p="create", f="shelter", args="create")],
 
643
                    [T("List All"), False, aURL(f="shelter")],
 
644
                    # @ToDo Search by type, services, location, available space
 
645
                    #[T("Search"), False, URL(f="shelter", args="search")],
 
646
                ]],
 
647
            ],
 
648
 
 
649
            "on_editor": [
 
650
                [
 
651
                    T("Camp Types and Services") if deployment_settings.get_ui_camp() \
 
652
                    else T("Shelter Types and Services"),
 
653
                    False, URL(f="#"),
 
654
                    [
 
655
                        [T("List / Add Services"), False, URL(f="shelter_service")],
 
656
                        [T("List / Add Types"), False, URL(f="shelter_type")],
 
657
 
 
658
                    ]
 
659
                ],
 
660
            ]
 
661
        },
 
662
 
 
663
        # DOC / Document Library
 
664
        # -------------------------------------------------------------------------
 
665
        "doc": {
 
666
            "menu": [
 
667
                [T("Documents"), False, aURL(f="document"),[
 
668
                    [T("New"), False, aURL(p="create", f="document", args="create")],
 
669
                    [T("List All"), False, aURL(f="document")],
 
670
                    #[T("Search"), False, aURL(f="ireport", args="search")]
 
671
                ]],
 
672
                  [T("Photos"), False, aURL(f="image"),[
 
673
                    [T("New"), False, aURL(p="create", f="image", args="create")],
 
674
                    [T("List All"), False, aURL(f="image")],
 
675
                    #[T("Bulk Uploader"), False, aURL(f="bulk_upload")]
 
676
                    #[T("Search"), False, aURL(f="ireport", args="search")]
 
677
                ]]],
 
678
        },
 
679
 
 
680
        # EVENT / Event Module
 
681
        # -------------------------------------------------------------------------
 
682
        "event": {
 
683
            "menu": [
 
684
                        [T("Scenarios"), False, aURL(c="scenario", f="scenario"), [
 
685
                            [T("New Scenario"), False, aURL(p="create", c="scenario",
 
686
                                                            f="scenario",
 
687
                                                            args="create")],
 
688
                            [T("View All"), False, aURL(c="scenario", f="scenario")]
 
689
                        ]],
 
690
                        [T("Events"), False, aURL(c="event", f="event"), [
 
691
                            [T("New Event"), False, aURL(p="create", c="event", f="event",
 
692
                                                         args="create")],
 
693
                            [T("View All"), False, aURL(c="event", f="event")]
 
694
                        ]],
 
695
                    ]   \
 
696
                    if deployment_settings.has_module("scenario") else \
 
697
                    [
 
698
                        [T("Events"), False, aURL(c="event", f="event"), [
 
699
                            [T("New Event"), False, aURL(p="create", c="event", f="event",
 
700
                                                         args="create")],
 
701
                            [T("View All"), False, aURL(c="event", f="event")]
 
702
                        ]]
 
703
                    ],
 
704
        },
 
705
 
 
706
        # GIS / GIS Controllers
 
707
        # -------------------------------------------------------------------------
 
708
        "gis": {
 
709
            "menu": [
 
710
                #[T("Locations"), False, aURL(f="location"), [
 
711
                #    [T("New Location"), False, aURL(p="create", f="location",
 
712
                #                                    args="create")],
 
713
                #    [T("New Location Group"), False, aURL(p="create", f="location",
 
714
                #                                          args="create",
 
715
                #                                          vars={"group": 1})],
 
716
                #    [T("List All"), False, aURL(f="location")],
 
717
                #    [T("Search"), False, aURL(f="location", args="search")],
 
718
                #    #[T("Geocode"), False, aURL(f="geocode_manual")],
 
719
                #]],
 
720
                #[T("Fullscreen Map"), False, aURL(f="map_viewing_client")],
 
721
                ## Currently not got geocoding support
 
722
                ##[T("Bulk Uploader"), False, aURL(c="doc", f="bulk_upload")]
 
723
            ],
 
724
 
 
725
            #"condition1": lambda: not deployment_settings.get_security_map() or s3_has_role(MAP_ADMIN),
 
726
            #"conditional1": [[T("Service Catalogue"), False, URL(f="map_service_catalogue")]]
 
727
        },
 
728
 
 
729
        # HMS / Hospital Status Assessment and Request Management System
 
730
        # -------------------------------------------------------------------------
 
731
        "hms": {
 
732
            "menu": [
 
733
                [T("Hospitals"), False, aURL(f="hospital", args="search"), [
 
734
                    [T("New"), False, aURL(p="create", f="hospital",
 
735
                                           args="create")],
 
736
                    [T("Search"), False, aURL(f="hospital", args="search")],
 
737
                    [T("List All"), False, aURL(f="hospital")],
 
738
                    #["----", False, None],
 
739
                    #[T("Show Map"), False, URL(c="gis", f="map_viewing_client",
 
740
                                               #vars={"kml_feed" : "%s/hms/hospital.kml" %
 
741
                                                     #s3.base_url,
 
742
                                                     #"kml_name" : "Hospitals_"})],
 
743
                ]],
 
744
                [T("Help"), False, URL(f="index")]
 
745
            ],
 
746
        },
 
747
 
 
748
        # HRM
 
749
        # -------------------------------------------------------------------------
 
750
        "hrm": hrm_menu,
 
751
 
 
752
        # INV / Inventory
 
753
        # -------------------------------------------------------------------------
 
754
        "inv": {
 
755
            "menu": [
 
756
                    #[T("Home"), False, aURL(c="inv", f="index")],
 
757
                    [T("Warehouses"), False, aURL(c="inv", f="warehouse"), [
 
758
                        [T("New"), False, aURL(p="create", c="inv",
 
759
                                               f="warehouse",
 
760
                                               args="create")],
 
761
                        [T("List All"), False, aURL(c="inv", f="warehouse")],
 
762
                        [T("Search"), False, aURL(c="inv", f="warehouse",
 
763
                                                  args="search")],
 
764
                        [T("Search Inventory Items"),
 
765
                            False, aURL(c="inv", f="inv_item",
 
766
                                        args="search")],
 
767
                        [T("Import Warehouses"),
 
768
                            False, aURL(p="create", c="inv", f="warehouse",
 
769
                                        args=["import"],
 
770
                                        vars={"extra_data":True})],
 
771
                        [T("Import Stock Levels"),
 
772
                            False, aURL(p="create", c="inv", f="inv_item",
 
773
                                        args=["import"])],
 
774
                    ]],
 
775
                    [s3.crud_strings.inv_recv.subtitle_list, False, aURL(c="inv", f="recv"), [
 
776
                        [T("New"), False, aURL(p="create", c="inv",
 
777
                                               f="recv",
 
778
                                               args="create")],
 
779
                        [T("List All"), False, aURL(c="inv", f="recv")],
 
780
                        [s3.crud_strings.inv_recv.title_search, False, aURL(c="inv", f="recv",
 
781
                                                 args="search")],
 
782
                    ]],
 
783
                    [T("Sent Shipments"), False, aURL(c="inv", f="send"), [
 
784
                        [T("New"), False, aURL(p="create", c="inv",
 
785
                                               f="send",
 
786
                                               args="create")],
 
787
                        [T("List All"), False, aURL(c="inv", f="send")],
 
788
                    ]],
 
789
                    [T("Items"), False, aURL(c="supply", f="item"), [
 
790
                        [T("New"), False, aURL(p="create", c="supply",
 
791
                                               f="item",
 
792
                                               args="create")],
 
793
                        [T("List All"), False, aURL(c="supply", f="item")],
 
794
                        [T("Search"), False, aURL(c="supply", f="catalog_item",
 
795
                                                 args="search")],
 
796
                    ]],
 
797
 
 
798
 
 
799
 
 
800
 
 
801
                    # Catalog Items moved to be next to the Item Categories
 
802
                    #[T("Catalog Items"), False, aURL(c="supply", f="catalog_item"), [
 
803
                    #    [T("New"), False, aURL(p="create", c="supply", f="catalog_item",
 
804
                    #                          args="create")],
 
805
                    #    [T("List All"), False, aURL(c="supply", f="catalog_item")],
 
806
                    #    [T("Search"), False, aURL(c="supply", f="catalog_item",
 
807
                    #                             args="search")],
 
808
                    ##]],
 
809
                    #
 
810
                    [T("Catalogs"), False, aURL(c="supply", f="catalog"), [
 
811
                        [T("New"), False, aURL(p="create", c="supply",
 
812
                                               f="catalog",
 
813
                                               args="create")],
 
814
                        [T("List All"), False, aURL(c="supply", f="catalog")],
 
815
                        #[T("Search"), False, aURL(c="supply", f="catalog",
 
816
                        #                         args="search")],
693
817
                    ]]
694
818
                ],
695
 
    },
696
 
 
697
 
    # GIS / GIS Controllers
698
 
    # -------------------------------------------------------------------------
699
 
    "gis": {
700
 
        "menu": [
701
 
            #[T("Locations"), False, aURL(f="location"), [
702
 
            #    [T("New Location"), False, aURL(p="create", f="location",
703
 
            #                                    args="create")],
704
 
            #    [T("New Location Group"), False, aURL(p="create", f="location",
705
 
            #                                          args="create",
706
 
            #                                          vars={"group": 1})],
707
 
            #    [T("List All"), False, aURL(f="location")],
708
 
            #    [T("Search"), False, aURL(f="location", args="search")],
709
 
            #    #[T("Geocode"), False, aURL(f="geocode_manual")],
710
 
            #]],
711
 
            #[T("Fullscreen Map"), False, aURL(f="map_viewing_client")],
712
 
            ## Currently not got geocoding support
713
 
            ##[T("Bulk Uploader"), False, aURL(c="doc", f="bulk_upload")]
714
 
        ],
715
 
 
716
 
        #"condition1": lambda: not deployment_settings.get_security_map() or s3_has_role(MAP_ADMIN),
717
 
        #"conditional1": [[T("Service Catalogue"), False, URL(f="map_service_catalogue")]]
718
 
    },
719
 
 
720
 
    # HMS / Hospital Status Assessment and Request Management System
721
 
    # -------------------------------------------------------------------------
722
 
    "hms": {
723
 
        "menu": [
724
 
            [T("Hospitals"), False, aURL(f="hospital", args="search"), [
725
 
                [T("New"), False, aURL(p="create", f="hospital",
726
 
                                       args="create")],
727
 
                [T("Search"), False, aURL(f="hospital", args="search")],
728
 
                [T("List All"), False, aURL(f="hospital")],
729
 
                #["----", False, None],
730
 
                #[T("Show Map"), False, URL(c="gis", f="map_viewing_client",
731
 
                                           #vars={"kml_feed" : "%s/hms/hospital.kml" %
732
 
                                                 #s3.base_url,
733
 
                                                 #"kml_name" : "Hospitals_"})],
734
 
            ]],
735
 
            [T("Help"), False, URL(f="index")]
736
 
        ],
737
 
    },
738
 
 
739
 
    # HRM
740
 
    # -------------------------------------------------------------------------
741
 
    "hrm": hrm_menu,
742
 
 
743
 
    # INV / Inventory
744
 
    # -------------------------------------------------------------------------
745
 
    "inv": {
746
 
        "menu": [
747
 
                #[T("Home"), False, aURL(c="inv", f="index")],
748
 
                [T("Warehouses"), False, aURL(c="inv", f="warehouse"), [
749
 
                    [T("New"), False, aURL(p="create", c="inv",
750
 
                                           f="warehouse",
 
819
 
 
820
 
 
821
            "on_admin": [[T("Item Categories"), False, aURL(c="supply", f="item_category"), [
 
822
                    [T("New Item Category"), False, aURL(p="create",
 
823
                                                         c="supply",
 
824
                                                         f="item_category",
 
825
                                                         args="create")],
 
826
                    [T("List All"), False, aURL(c="supply", f="item_category")]
 
827
                ]]]
 
828
        },
 
829
 
 
830
        # IRS / Incident Report System
 
831
        # -------------------------------------------------------------------------
 
832
        "irs": {
 
833
            "menu": [
 
834
                [T("Events"), False, aURL(f="ireport"),[
 
835
                    [T("New"), False, aURL(p="create", f="ireport", args="create")],
 
836
                    [T("List All"), False, aURL(f="ireport")],
 
837
                    #[T("Search"), False, aURL(f="ireport", args="search")]
 
838
                ]],
 
839
            ],
 
840
 
 
841
            "on_admin": [[T("Event Categories"), False, aURL(f="icategory"),[
 
842
                    [T("New"), False, aURL(p="create", f="icategory", args="create")],
 
843
                    [T("List All"), False, aURL(f="icategory")],
 
844
                ]],
 
845
                #["Ushahidi " + T("Import"), False, aURL(f="ireport", args="ushahidi")]
 
846
            ]
 
847
        },
 
848
 
 
849
        # SURVEY / Survey Controller
 
850
        # -------------------------------------------------------------------------
 
851
        "survey": {
 
852
            "menu": [
 
853
                [T("Assessment Templates"), False, aURL(f="template"), [
 
854
                    #[T("New"), False, aURL(p="create", f="template", args="create")],
 
855
                    [T("List All"), False, aURL(f="template")],
 
856
                ]],
 
857
                #[T("Section"), False, aURL(f="section"), [
 
858
                #    [T("New"), False, aURL(p="create", f="section", args="create")],
 
859
                #    [T("List All"), False, aURL(f="section")]]],
 
860
                [T("Event Assessments"), False, aURL(f="series"), [
 
861
                    [T("New"), False, aURL(p="create", f="series", args="create")],
 
862
                    [T("List All"), False, aURL(f="series")],
 
863
                ]],
 
864
                ],
 
865
            "on_admin": [
 
866
                [T("Administration"), False, aURL(f="complete"), [
 
867
                    #[T("New"), False, aURL(p="create", f="complete", args="create")],
 
868
                    #[T("List All"), False, aURL(f="complete")],
 
869
                    [T("Import Templates"), False, aURL(f="question_list",
 
870
                                                        args="import")],
 
871
                    [T("Import Completed Responses"), False, aURL(f="complete",
 
872
                                                                  args="import")]
 
873
                ]],
 
874
                ]
 
875
        },
 
876
 
 
877
        # MSG / Messaging Controller
 
878
        # -------------------------------------------------------------------------
 
879
        "msg": {
 
880
            "menu": [
 
881
                [T("Compose"), False, URL(c="msg", f="compose")],
 
882
                [T("Distribution groups"), False, aURL(f="group"), [
 
883
                    [T("List/Add"), False, aURL(f="group")],
 
884
                    [T("Group Memberships"), False, aURL(f="group_membership")],
 
885
                ]],
 
886
                [T("Log"), False, aURL(f="log")],
 
887
                [T("Outbox"), False, aURL(f="outbox")],
 
888
                #[T("Search Twitter Tags"), False, aURL(f="twitter_search"),[
 
889
                #    [T("Queries"), False, aURL(f="twitter_search")],
 
890
                #    [T("Results"), False, aURL(f="twitter_search_results")]
 
891
                #]],
 
892
                #["CAP", False, aURL(f="tbc")]
 
893
            ],
 
894
 
 
895
            "on_admin": [
 
896
                [T("Administration"), False, URL(f="#"), admin_menu_messaging],
 
897
            ]
 
898
        },
 
899
 
 
900
        # ORG / Organization Registry
 
901
        # -------------------------------------------------------------------------
 
902
        "org": hrm_menu,
 
903
 
 
904
        # PATIENT / Patient Tracking Module
 
905
        # -------------------------------------------------------------------------
 
906
        "patient": {
 
907
            "menu": [[T("Patients"),
 
908
                      False, URL(f="patient"),[
 
909
                        [T("New"), False,
 
910
                         aURL(p="create", f="patient",
 
911
                              args="create")],
 
912
                        [T("List All"), False,
 
913
                         aURL(f="patient")],
 
914
                        [T("Search"), False,
 
915
                         aURL(f="patient",
 
916
                              args="search")]
 
917
                     ]]],
 
918
        },
 
919
 
 
920
        # PR / VITA Person Registry
 
921
        # --------------------------------------------------------------------------
 
922
        "pr": {
 
923
            "menu": pr_menu
 
924
        },
 
925
 
 
926
        # PROC / Procurement
 
927
        # -------------------------------------------------------------------------
 
928
        "proc": {
 
929
            "menu": [
 
930
                [T("Home"), False, aURL(f="index")],
 
931
                [T("Procurement Plans"), False, aURL(f="plan"),[
 
932
                    [T("New"), False, aURL(p="create", f="plan", args="create")],
 
933
                    [T("List All"), False, aURL(f="plan")],
 
934
                    #[T("Search"), False, aURL(f="plan", args="search")]
 
935
                ]],
 
936
                [T("Suppliers"), False, aURL(f="supplier"),[
 
937
                    [T("New"), False, aURL(p="create", f="supplier", args="create")],
 
938
                    [T("List All"), False, aURL(f="supplier")],
 
939
                    #[T("Search"), False, aURL(f="supplier", args="search")]
 
940
                ]],
 
941
            ],
 
942
 
 
943
        },
 
944
 
 
945
        # PROJECT / Project Tracking & Management
 
946
        # -------------------------------------------------------------------------
 
947
        "project": project_menu,
 
948
 
 
949
        # REQ / Request Management
 
950
        # -------------------------------------------------------------------------
 
951
        "req": {
 
952
            "menu": [[T("Requests"), False, aURL(c="req", f="req"), [
 
953
                        [T("New"), False, aURL(p="create", c="req", f="req",
 
954
                                               args="create")],
 
955
                        [T("List All"), False, aURL(c="req", f="req")],
 
956
                        [T("List All Requested Items"), False, aURL(c="req", f="req_item")],
 
957
                        [T("List All Requested Skills"), False, aURL(c="req", f="req_skill")],
 
958
                        #[T("Search Requested Items"), False, aURL(c="req",
 
959
                        #                                          f="req_item",
 
960
                        #                                          args="search")],
 
961
                    ]],
 
962
                    [T("Commitments"), False, aURL(c="req", f="commit"), [
 
963
                        [T("List All"), False, aURL(c="req", f="commit")]
 
964
                    ]],
 
965
                ]
 
966
        },
 
967
 
 
968
        # SYNC
 
969
        # -------------------------------------------------------------------------
 
970
        "sync": {
 
971
            "menu": admin_menu_options
 
972
        },
 
973
 
 
974
        # VEHICLE
 
975
        # -------------------------------------------------------------------------
 
976
        "vehicle": {
 
977
            "menu": [
 
978
                #[T("Home"), False, aURL(c="vehicle", f="index")],
 
979
                [T("Vehicles"), False, aURL(c="vehicle", f="vehicle"),
 
980
                [
 
981
                    [T("New"), False, aURL(p="create", c="vehicle", f="vehicle",
751
982
                                           args="create")],
752
 
                    [T("List All"), False, aURL(c="inv", f="warehouse")],
753
 
                    [T("Search"), False, aURL(c="inv", f="warehouse",
 
983
                    [T("List All"), False, aURL(c="vehicle", f="vehicle")],
 
984
                    [T("Search"), False, aURL(c="vehicle", f="vehicle",
754
985
                                              args="search")],
755
 
                    [T("Search Inventory Items"),
756
 
                        False, aURL(c="inv", f="inv_item",
757
 
                                    args="search")],
758
 
                    [T("Import Warehouses"),
759
 
                        False, aURL(p="create", c="inv", f="warehouse",
760
 
                                    args=["import"],
761
 
                                    vars={"extra_data":True})],
762
 
                    [T("Import Stock Levels"),
763
 
                        False, aURL(p="create", c="inv", f="inv_item",
764
 
                                    args=["import"])],
765
 
                ]],
766
 
                [s3.crud_strings.inv_recv.subtitle_list, False, aURL(c="inv", f="recv"), [
767
 
                    [T("New"), False, aURL(p="create", c="inv",
768
 
                                           f="recv",
769
 
                                           args="create")],
770
 
                    [T("List All"), False, aURL(c="inv", f="recv")],
771
 
                    [s3.crud_strings.inv_recv.title_search, False, aURL(c="inv", f="recv",
772
 
                                             args="search")],
773
 
                ]],
774
 
                [T("Sent Shipments"), False, aURL(c="inv", f="send"), [
775
 
                    [T("New"), False, aURL(p="create", c="inv",
776
 
                                           f="send",
777
 
                                           args="create")],
778
 
                    [T("List All"), False, aURL(c="inv", f="send")],
779
 
                ]],
780
 
                [T("Items"), False, aURL(c="supply", f="item"), [
781
 
                    [T("New"), False, aURL(p="create", c="supply",
782
 
                                           f="item",
783
 
                                           args="create")],
784
 
                    [T("List All"), False, aURL(c="supply", f="item")],
785
 
                    [T("Search"), False, aURL(c="supply", f="catalog_item",
786
 
                                             args="search")],
787
 
                ]],
788
 
 
789
 
                # Catalog Items moved to be next to the Item Categories
790
 
                #[T("Catalog Items"), False, aURL(c="supply", f="catalog_item"), [
791
 
                #    [T("New"), False, aURL(p="create", c="supply", f="catalog_item",
792
 
                #                          args="create")],
793
 
                #    [T("List All"), False, aURL(c="supply", f="catalog_item")],
794
 
                #    [T("Search"), False, aURL(c="supply", f="catalog_item",
795
 
                #                             args="search")],
796
 
                ##]],
797
 
                #
798
 
                [T("Catalogs"), False, aURL(c="supply", f="catalog"), [
799
 
                    [T("New"), False, aURL(p="create", c="supply",
800
 
                                           f="catalog",
801
 
                                           args="create")],
802
 
                    [T("List All"), False, aURL(c="supply", f="catalog")],
803
 
                    #[T("Search"), False, aURL(c="supply", f="catalog",
804
 
                    #                         args="search")],
805
 
                ]]
806
 
            ],
807
 
 
808
 
        "on_admin": [[T("Item Categories"), False, aURL(c="supply", f="item_category"), [
809
 
                [T("New Item Category"), False, aURL(p="create",
810
 
                                                     c="supply",
811
 
                                                     f="item_category",
812
 
                                                     args="create")],
813
 
                [T("List All"), False, aURL(c="supply", f="item_category")]
814
 
            ]]]
815
 
    },
816
 
 
817
 
    # IRS / Incident Report System
818
 
    # -------------------------------------------------------------------------
819
 
    "irs": {
820
 
        "menu": [
821
 
            [T("Events"), False, aURL(f="ireport"),[
822
 
                [T("New"), False, aURL(p="create", f="ireport", args="create")],
823
 
                [T("List All"), False, aURL(f="ireport")],
824
 
                #[T("Search"), False, aURL(f="ireport", args="search")]
825
 
            ]],
826
 
        ],
827
 
 
828
 
        "on_admin": [[T("Event Categories"), False, aURL(f="icategory"),[
829
 
                [T("New"), False, aURL(p="create", f="icategory", args="create")],
830
 
                [T("List All"), False, aURL(f="icategory")],
831
 
            ]],
832
 
            #["Ushahidi " + T("Import"), False, aURL(f="ireport", args="ushahidi")]
833
 
        ]
834
 
    },
835
 
 
836
 
    # SURVEY / Survey Controller
837
 
    # -------------------------------------------------------------------------
838
 
    "survey": {
839
 
        "menu": [
840
 
            [T("Assessment Templates"), False, aURL(f="template"), [
841
 
                #[T("New"), False, aURL(p="create", f="template", args="create")],
842
 
                [T("List All"), False, aURL(f="template")],
843
 
            ]],
844
 
            #[T("Section"), False, aURL(f="section"), [
845
 
            #    [T("New"), False, aURL(p="create", f="section", args="create")],
846
 
            #    [T("List All"), False, aURL(f="section")]]],
847
 
            [T("Event Assessments"), False, aURL(f="series"), [
848
 
                [T("New"), False, aURL(p="create", f="series", args="create")],
849
 
                [T("List All"), False, aURL(f="series")],
850
 
            ]],
851
 
            ],
852
 
        "on_admin": [
853
 
            [T("Administration"), False, aURL(f="complete"), [
854
 
                #[T("New"), False, aURL(p="create", f="complete", args="create")],
855
 
                #[T("List All"), False, aURL(f="complete")],
856
 
                [T("Import Templates"), False, aURL(f="question_list",
857
 
                                                    args="import")],
858
 
                [T("Import Completed Responses"), False, aURL(f="complete",
859
 
                                                              args="import")]
860
 
            ]],
861
 
            ]
862
 
    },
863
 
 
864
 
    # MSG / Messaging Controller
865
 
    # -------------------------------------------------------------------------
866
 
    "msg": {
867
 
        "menu": [
868
 
            [T("Compose"), False, URL(c="msg", f="compose")],
869
 
            [T("Distribution groups"), False, aURL(f="group"), [
870
 
                [T("List/Add"), False, aURL(f="group")],
871
 
                [T("Group Memberships"), False, aURL(f="group_membership")],
872
 
            ]],
873
 
            [T("Log"), False, aURL(f="log")],
874
 
            [T("Outbox"), False, aURL(f="outbox")],
875
 
            #[T("Search Twitter Tags"), False, aURL(f="twitter_search"),[
876
 
            #    [T("Queries"), False, aURL(f="twitter_search")],
877
 
            #    [T("Results"), False, aURL(f="twitter_search_results")]
878
 
            #]],
879
 
            #["CAP", False, aURL(f="tbc")]
880
 
        ],
881
 
 
882
 
        "on_admin": [
883
 
            [T("Administration"), False, URL(f="#"), admin_menu_messaging],
884
 
        ]
885
 
    },
886
 
 
887
 
    # ORG / Organization Registry
888
 
    # -------------------------------------------------------------------------
889
 
    "org": hrm_menu,
890
 
 
891
 
    # PATIENT / Patient Tracking Module
892
 
    # -------------------------------------------------------------------------
893
 
    "patient": {
894
 
        "menu": [[T("Patients"),
895
 
                  False, URL(f="patient"),[
896
 
                    [T("New"), False,
897
 
                     aURL(p="create", f="patient",
898
 
                          args="create")],
899
 
                    [T("List All"), False,
900
 
                     aURL(f="patient")],
901
 
                    [T("Search"), False,
902
 
                     aURL(f="patient",
903
 
                          args="search")]
904
 
                 ]]],
905
 
    },
906
 
 
907
 
    # PR / VITA Person Registry
908
 
    # --------------------------------------------------------------------------
909
 
    "pr": {
910
 
        "menu": pr_menu
911
 
    },
912
 
 
913
 
    # PROC / Procurement
914
 
    # -------------------------------------------------------------------------
915
 
    "proc": {
916
 
        "menu": [
917
 
            [T("Home"), False, aURL(f="index")],
918
 
            [T("Procurement Plans"), False, aURL(f="plan"),[
919
 
                [T("New"), False, aURL(p="create", f="plan", args="create")],
920
 
                [T("List All"), False, aURL(f="plan")],
921
 
                #[T("Search"), False, aURL(f="plan", args="search")]
922
 
            ]],
923
 
            [T("Suppliers"), False, aURL(f="supplier"),[
924
 
                [T("New"), False, aURL(p="create", f="supplier", args="create")],
925
 
                [T("List All"), False, aURL(f="supplier")],
926
 
                #[T("Search"), False, aURL(f="supplier", args="search")]
927
 
            ]],
928
 
        ],
929
 
 
930
 
    },
931
 
 
932
 
    # PROJECT / Project Tracking & Management
933
 
    # -------------------------------------------------------------------------
934
 
    "project": project_menu,
935
 
 
936
 
    # REQ / Request Management
937
 
    # -------------------------------------------------------------------------
938
 
    "req": {
939
 
        "menu": [[T("Requests"), False, aURL(c="req", f="req"), [
940
 
                    [T("New"), False, aURL(p="create", c="req", f="req",
941
 
                                           args="create")],
942
 
                    [T("List All"), False, aURL(c="req", f="req")],
943
 
                    [T("List All Requested Items"), False, aURL(c="req", f="req_item")],
944
 
                    [T("List All Requested Skills"), False, aURL(c="req", f="req_skill")],
945
 
                    #[T("Search Requested Items"), False, aURL(c="req",
946
 
                    #                                          f="req_item",
947
 
                    #                                          args="search")],
948
 
                ]],
949
 
                [T("Commitments"), False, aURL(c="req", f="commit"), [
950
 
                    [T("List All"), False, aURL(c="req", f="commit")]
951
 
                ]],
952
 
            ]
953
 
    },
954
 
 
955
 
    # SYNC
956
 
    # -------------------------------------------------------------------------
957
 
    "sync": {
958
 
        "menu": admin_menu_options
959
 
    },
960
 
 
961
 
    # VEHICLE
962
 
    # -------------------------------------------------------------------------
963
 
    "vehicle": {
964
 
        "menu": [
965
 
            #[T("Home"), False, aURL(c="vehicle", f="index")],
966
 
            [T("Vehicles"), False, aURL(c="vehicle", f="vehicle"),
967
 
            [
968
 
                [T("New"), False, aURL(p="create", c="vehicle", f="vehicle",
969
 
                                       args="create")],
970
 
                [T("List All"), False, aURL(c="vehicle", f="vehicle")],
971
 
                [T("Search"), False, aURL(c="vehicle", f="vehicle",
972
 
                                          args="search")],
973
 
            ]],
974
 
        ]
975
 
    },
976
 
 
977
 
    # ADMIN
978
 
    # -------------------------------------------------------------------------
979
 
    "admin": {
980
 
        "menu": admin_menu_options
981
 
    },
982
 
    "appadmin": {
983
 
        "menu": admin_menu_options
984
 
    },
985
 
 
986
 
    "default": {
987
 
        "menu": [
988
 
            [T("Site"), False, aURL(c="default"),
989
 
            [
990
 
                [T("Sign in"), True, aURL(c="default", f="user", args="login")],
991
 
            ]
992
 
        ]]
 
986
                ]],
 
987
            ]
 
988
        },
 
989
 
 
990
        # ADMIN
 
991
        # -------------------------------------------------------------------------
 
992
        "admin": {
 
993
            "menu": admin_menu_options
 
994
        },
 
995
        "appadmin": {
 
996
            "menu": admin_menu_options
 
997
        },
 
998
 
 
999
        "default": {
 
1000
            "menu": [
 
1001
                [T("Site"), False, aURL(c="default"),
 
1002
                [
 
1003
                    [T("Sign in"), True, aURL(c="default", f="user", args="login")],
 
1004
                ]
 
1005
            ]]
 
1006
        }
 
1007
 
993
1008
    }
994
1009
 
995
 
}
996
 
 
997
 
# Duplicate menus - some controllers might re-use menu defined in certain models Eg. inv, supply
998
 
s3_menu_dict["supply"] = s3_menu_dict["inv"]
999
 
s3_menu_dict["scenario"] = s3_menu_dict["event"]
1000
 
 
1001
 
# =============================================================================
1002
 
# Breadcrumbs
1003
 
# =============================================================================
1004
 
def get_menu_label_and_state(menu_dict, # yikes
1005
 
                             controller,
1006
 
                             function,
1007
 
                             args = None,
1008
 
                             vars = None
1009
 
                            ):
1010
 
    """ Support Breadcrumbs """
1011
 
 
1012
 
    # Look at the menu for this Controller
1013
 
    menu_spec = menu_dict[controller]["menu"]
1014
 
    if not menu_spec:
1015
 
        try:
1016
 
            # e.g. HRM
1017
 
            menu_spec = menu_dict[controller]["conditional1"]
1018
 
        except KeyError:
1019
 
            # e.g. GIS
1020
 
            pass
1021
 
    # Go through each entry in turn to find a match
1022
 
    # Main menu
1023
 
    for menu_item in menu_spec:
1024
 
        (label, active, url) = menu_item[:3]
1025
 
        if url:
1026
 
            url_parts = url.split("/")[1:]
1027
 
            # Check we're in the correct function
1028
 
            url_app, url_controller, url_function = url_parts[:3]
1029
 
            if vars:
1030
 
                _url_args = url_parts[3:]
1031
 
                if _url_args:
1032
 
                    url_args, url_vars = _url_args[len(_url_args) - 1].split("?")
1033
 
                elif "?" in url_function:
1034
 
                    url_function, url_vars = url_function.split("?")
1035
 
                    url_args = None
 
1010
    # Duplicate menus - some controllers might re-use menu defined in certain models Eg. inv, supply
 
1011
    s3_menu_dict["supply"] = s3_menu_dict["inv"]
 
1012
    s3_menu_dict["scenario"] = s3_menu_dict["event"]
 
1013
 
 
1014
    # =============================================================================
 
1015
    # Breadcrumbs
 
1016
    # =============================================================================
 
1017
    def get_menu_label_and_state(menu_dict, # yikes
 
1018
                                 controller,
 
1019
                                 function,
 
1020
                                 args = None,
 
1021
                                 vars = None
 
1022
                                ):
 
1023
        """ Support Breadcrumbs """
 
1024
 
 
1025
        # Look at the menu for this Controller
 
1026
        menu_spec = menu_dict[controller]["menu"]
 
1027
        if not menu_spec:
 
1028
            try:
 
1029
                # e.g. HRM
 
1030
                menu_spec = menu_dict[controller]["conditional1"]
 
1031
            except KeyError:
 
1032
                # e.g. GIS
 
1033
                pass
 
1034
        # Go through each entry in turn to find a match
 
1035
        # Main menu
 
1036
        for menu_item in menu_spec:
 
1037
            (label, active, url) = menu_item[:3]
 
1038
            if url:
 
1039
                url_parts = url.split("/")[1:]
 
1040
                # Check we're in the correct function
 
1041
                url_app, url_controller, url_function = url_parts[:3]
 
1042
                if vars:
 
1043
                    _url_args = url_parts[3:]
 
1044
                    if _url_args:
 
1045
                        url_args, url_vars = _url_args[len(_url_args) - 1].split("?")
 
1046
                    elif "?" in url_function:
 
1047
                        url_function, url_vars = url_function.split("?")
 
1048
                        url_args = None
 
1049
                    else:
 
1050
                        url_vars = None
 
1051
                        url_args = None
 
1052
                elif args:
 
1053
                    url_args = url_parts[3:]
 
1054
                    url_vars = None
1036
1055
                else:
 
1056
                    url_args = None
1037
1057
                    url_vars = None
1038
 
                    url_args = None
1039
 
            elif args:
1040
 
                url_args = url_parts[3:]
1041
 
                url_vars = None
 
1058
 
 
1059
                if url_function == function:
 
1060
                    if not args or url_args == args:
 
1061
                        if not vars or url_vars == vars:
 
1062
                            # We found the correct menu entry
 
1063
                            return label, active
 
1064
            # Try the submenus
 
1065
            try:
 
1066
                submenus = menu_item[3]
 
1067
            except IndexError:
 
1068
                # No Submenus defined for this main menu
 
1069
                pass
1042
1070
            else:
1043
 
                url_args = None
1044
 
                url_vars = None
1045
 
 
1046
 
            if url_function == function:
1047
 
                if not args or url_args == args:
1048
 
                    if not vars or url_vars == vars:
1049
 
                        # We found the correct menu entry
1050
 
                        return label, active
1051
 
        # Try the submenus
1052
 
        try:
1053
 
            submenus = menu_item[3]
1054
 
        except IndexError:
1055
 
            # No Submenus defined for this main menu
1056
 
            pass
1057
 
        else:
1058
 
            for submenu_item in submenus:
1059
 
                if submenu_item:
1060
 
                    (sub_label, sub_active, sub_url) = submenu_item[:3]
1061
 
                    if sub_url:
1062
 
                        sub_url_parts = sub_url.split("/")[1:]
1063
 
                        # Check we're in the correct function
1064
 
                        sub_url_app, sub_url_con, sub_url_func = sub_url_parts[:3]
1065
 
                        if vars:
1066
 
                            _sub_url_args = sub_url_parts[3:]
1067
 
                            if _sub_url_args and "?" in _sub_url_args:
1068
 
                                sub_url_args, sub_url_vars = _sub_url_args[len(_sub_url_args) - 1].split("?")
1069
 
                            elif "?" in sub_url_func:
1070
 
                                sub_url_func, sub_url_vars = sub_url_func.split("?")
1071
 
                                sub_url_args = None
 
1071
                for submenu_item in submenus:
 
1072
                    if submenu_item:
 
1073
                        (sub_label, sub_active, sub_url) = submenu_item[:3]
 
1074
                        if sub_url:
 
1075
                            sub_url_parts = sub_url.split("/")[1:]
 
1076
                            # Check we're in the correct function
 
1077
                            sub_url_app, sub_url_con, sub_url_func = sub_url_parts[:3]
 
1078
                            if vars:
 
1079
                                _sub_url_args = sub_url_parts[3:]
 
1080
                                if _sub_url_args and "?" in _sub_url_args:
 
1081
                                    sub_url_args, sub_url_vars = _sub_url_args[len(_sub_url_args) - 1].split("?")
 
1082
                                elif "?" in sub_url_func:
 
1083
                                    sub_url_func, sub_url_vars = sub_url_func.split("?")
 
1084
                                    sub_url_args = None
 
1085
                                else:
 
1086
                                    sub_url_vars = None
 
1087
                                    sub_url_args = None
 
1088
                            elif args:
 
1089
                                sub_url_args = sub_url_parts[3:]
 
1090
                                sub_url_vars = None
1072
1091
                            else:
 
1092
                                sub_url_args = None
1073
1093
                                sub_url_vars = None
1074
 
                                sub_url_args = None
1075
 
                        elif args:
1076
 
                            sub_url_args = sub_url_parts[3:]
1077
 
                            sub_url_vars = None
1078
 
                        else:
1079
 
                            sub_url_args = None
1080
 
                            sub_url_vars = None
1081
 
                        if sub_url_func == function:
1082
 
                            if not args or sub_url_args == args:
1083
 
                                if not vars or sub_url_vars == vars:
1084
 
                                    # We found the correct menu entry
1085
 
                                    return sub_label, sub_active
1086
 
 
1087
 
    return ("", False)
1088
 
 
1089
 
# -----------------------------------------------------------------------------
1090
 
def define_breadcrumbs():
1091
 
    breadcrumbs = [(deployment_settings.modules["default"].name_nice, True,
1092
 
                    "/%s" % request.application)]
1093
 
    if request.controller != "default":
1094
 
        try:
1095
 
            controllerLabel = deployment_settings.modules[request.controller].name_nice
1096
 
        except KeyError:
1097
 
            controllerLabel = "."
1098
 
        breadcrumbs.append(
1099
 
            (controllerLabel,
1100
 
             True,
1101
 
             "/%s/%s" % (request.application, request.controller)
1102
 
            )
1103
 
        )
1104
 
    if request.function != "index":
1105
 
        breadcrumbs.append(
1106
 
            (get_menu_label_and_state(s3_menu_dict,
1107
 
                                      request.controller,
1108
 
                                      request.function) + \
1109
 
             (URL(c=request.controller,
1110
 
                  f=request.function),)
1111
 
            )
1112
 
        )
1113
 
    if request.args(0):
1114
 
        try:
1115
 
            # Ignore this argument if it's the ID of a record
1116
 
            int(request.args[0])
1117
 
        except ValueError:
 
1094
                            if sub_url_func == function:
 
1095
                                if not args or sub_url_args == args:
 
1096
                                    if not vars or sub_url_vars == vars:
 
1097
                                        # We found the correct menu entry
 
1098
                                        return sub_label, sub_active
 
1099
 
 
1100
        return ("", False)
 
1101
 
 
1102
    # -----------------------------------------------------------------------------
 
1103
    def define_breadcrumbs():
 
1104
        breadcrumbs = [(deployment_settings.modules["default"].name_nice, True,
 
1105
                        "/%s" % request.application)]
 
1106
        if request.controller != "default":
 
1107
            try:
 
1108
                controllerLabel = deployment_settings.modules[request.controller].name_nice
 
1109
            except KeyError:
 
1110
                controllerLabel = "."
 
1111
            breadcrumbs.append(
 
1112
                (controllerLabel,
 
1113
                 True,
 
1114
                 "/%s/%s" % (request.application, request.controller)
 
1115
                )
 
1116
            )
 
1117
        if request.function != "index":
1118
1118
            breadcrumbs.append(
1119
1119
                (get_menu_label_and_state(s3_menu_dict,
1120
1120
                                          request.controller,
1121
 
                                          request.function,
1122
 
                                          request.args,
1123
 
                                          request.vars) + \
 
1121
                                          request.function) + \
1124
1122
                 (URL(c=request.controller,
1125
 
                      f=request.function,
1126
 
                      args = request.args),)
 
1123
                      f=request.function),)
1127
1124
                )
1128
1125
            )
1129
 
    return breadcrumbs
1130
 
 
1131
 
breadcrumbs = define_breadcrumbs()
1132
 
 
 
1126
        if request.args(0):
 
1127
            try:
 
1128
                # Ignore this argument if it's the ID of a record
 
1129
                int(request.args[0])
 
1130
            except ValueError:
 
1131
                breadcrumbs.append(
 
1132
                    (get_menu_label_and_state(s3_menu_dict,
 
1133
                                              request.controller,
 
1134
                                              request.function,
 
1135
                                              request.args,
 
1136
                                              request.vars) + \
 
1137
                     (URL(c=request.controller,
 
1138
                          f=request.function,
 
1139
                          args = request.args),)
 
1140
                    )
 
1141
                )
 
1142
        return breadcrumbs
 
1143
 
 
1144
    breadcrumbs = define_breadcrumbs()
 
1145
 
 
1146
else:
 
1147
    s3_menu = lambda *args, **vars: None
 
1148
    s3.menu_lang = []
 
1149
    s3.menu_help = []
 
1150
    s3.menu_auth = []
 
1151
    s3.menu_modules = []
 
1152
    response.menu = []
 
1153
    breadcrumbs = []
1133
1154
 
1134
1155
# END =========================================================================