Changes between Version 8 and Version 9 of DeveloperGuidelines/DataTables
- Timestamp:
- 06/10/11 10:29:25 (13 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
DeveloperGuidelines/DataTables
v8 v9 76 76 [[BR]] 77 77 === Adding Buttons === 78 With the default settings two buttons are provided, Open and Delete. Additional buttons can be added by using the actions, or more fully, response.s3.actions. The following code will add an "Import" button 78 With the default settings two buttons are provided, Open and Delete. Additional buttons can be added by using the actions, or more fully, response.s3.actions. The following code will add an "Import" button. 79 79 {{{ 80 80 #!div style="font-size: 80%" … … 82 82 {{{#!python 83 83 def postp(r, output): 84 response.s3.actions = [ 85 dict(label=str(UPDATE), _class="action-btn", 86 url=str(URL(r=request, 87 c=module, 88 f=resourcename, 89 args=["[id]", "update"]))), 90 dict(label=str(DELETE), _class="action-btn", 91 url=str(URL(r=request, 92 c=module, 93 f=resourcename, 94 args=["[id]", "delete"]))), 84 s3_action_buttons(r) 85 response.s3.actions = \ 86 response.s3.actions + [ 95 87 dict(label=str(T("Import")), _class="action-btn", 96 88 url=str(URL(r=request, 97 89 c=module, 98 90 f=resourcename, 99 args=["[id]", "import"]))), 91 args=["[id]", "import"])) 92 ), 100 93 ] 101 94 return output 102 95 }}} 103 96 }}} 104 Notice that before the Open and Delete buttons were provided, now they need to be explicitly added .97 Notice that before the Open and Delete buttons were provided, now they need to be explicitly added with the call to s3_action_buttons(r), this will also perform the correct permission checks. 105 98 [[BR]] 106 99 [[Image(DataTable_Plus_Import_Btn.png)]] 107 100 [[BR]] 108 101 === Adding Buttons conditionally === 109 Maybe you don't want the ability to import every file. Such as files that are older than a certain date. 102 Maybe you don't want the ability to import every file. Such as files that are older than a certain date. Also actions can be (and should be) restricted to the users permissions. For more example on how to apply restrictions to a users permissions see the code for s3_action_buttons() in models/00_utils. 110 103 {{{ 111 104 #!div style="font-size: 80%" … … 118 111 rows = db(query).select(r.table.id) 119 112 restrict = [str(row.id) for row in rows] 120 response.s3.actions = [ 121 dict(label=str(UPDATE), _class="action-btn", 122 url=str(URL(r=request, 123 c=module, 124 f=resourcename, 125 args=["[id]", "update"]))), 126 dict(label=str(DELETE), _class="action-btn", 127 url=str(URL(r=request, 128 c=module, 129 f=resourcename, 130 args=["[id]", "delete"]))), 113 s3_action_buttons(r) 114 response.s3.actions = \ 115 response.s3.actions + [ 131 116 dict(label=str(T("Import")), _class="action-btn", 132 117 url=str(URL(r=request,