Changes between Version 8 and Version 9 of DeveloperGuidelines/DataTables


Ignore:
Timestamp:
06/10/11 10:29:25 (10 years ago)
Author:
graeme
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • DeveloperGuidelines/DataTables

    v8 v9  
    7676[[BR]]
    7777=== 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
     78With 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.
    7979{{{
    8080#!div style="font-size: 80%"
     
    8282  {{{#!python
    8383    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 + [
    9587                                dict(label=str(T("Import")), _class="action-btn",
    9688                                     url=str(URL(r=request,
    9789                                                 c=module,
    9890                                                 f=resourcename,
    99                                                  args=["[id]", "import"]))),
     91                                                 args=["[id]", "import"]))
     92                                     ),
    10093                              ]
    10194        return output
    10295   }}}
    10396}}}
    104 Notice that before the Open and Delete buttons were provided, now they need to be explicitly added.
     97Notice 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.
    10598[[BR]]
    10699[[Image(DataTable_Plus_Import_Btn.png)]]
    107100[[BR]]
    108101=== 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.
     102Maybe 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.
    110103{{{
    111104#!div style="font-size: 80%"
     
    118111        rows = db(query).select(r.table.id)
    119112        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 + [
    131116                                dict(label=str(T("Import")), _class="action-btn",
    132117                                     url=str(URL(r=request,