|
| 1 | +Delete button and behavior |
| 2 | +~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 3 | + |
| 4 | +To add a delete button: |
| 5 | + |
| 6 | +.. code:: html |
| 7 | + |
| 8 | + <a class="btn btn-danger cms_delete_confirm" t-att-href="object.cms_delete_confirm_url">Delete</a> |
| 9 | + |
| 10 | +When you click on a confirmation dialog pops up. |
| 11 | + |
| 12 | +If you hit ``cancel`` the popup is closed. If you hit submit the item is |
| 13 | +deleted and you get redirected to your model's ``cms_after_delete_url``. |
| 14 | +By default is ``/``. |
| 15 | + |
| 16 | +Customization |
| 17 | +------------- |
| 18 | + |
| 19 | +Custom per-model delete messge |
| 20 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 21 | + |
| 22 | +.. code:: python |
| 23 | +
|
| 24 | + class MyModel(models.Model): |
| 25 | + _inherit = "my.model" |
| 26 | +
|
| 27 | + @api.multi |
| 28 | + def msg_content_delete_confirm(self): |
| 29 | + self.ensure_one() |
| 30 | + return _('Are you sure you want to delete "%s"?.') % self.name |
| 31 | +
|
| 32 | +Custom "after delete URL" |
| 33 | +~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 34 | + |
| 35 | +When you are viewing a content and you delete it you want to be |
| 36 | +redirected to some other place. |
| 37 | + |
| 38 | +By default you get redirected to the root of the website. |
| 39 | + |
| 40 | +To change this behavior just override the attribute in your model |
| 41 | +declaration: |
| 42 | + |
| 43 | +.. code:: python |
| 44 | +
|
| 45 | + class MyModel(models.Model): |
| 46 | + _inherit = "my.model" |
| 47 | +
|
| 48 | + cms_after_delete_url = '/foo' |
| 49 | +
|
| 50 | +Note: if you want to customize it on demand for particular pages, or you |
| 51 | +are deleting an item from another page (like a management page) you can |
| 52 | +pass ``?redirect=`` in the url, like: |
| 53 | + |
| 54 | +.. code:: html |
| 55 | + |
| 56 | + <a class="btn btn-danger cms_delete_confirm" t-attf-href="#{object.cms_delete_confirm_url}?redirect=">Delete</a> |
| 57 | + |
| 58 | +Custom global delete confirm message appeareance |
| 59 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 60 | + |
| 61 | +.. code:: xml |
| 62 | +
|
| 63 | + <template id="delete_confirm" inherit_id="cms_delete_content.delete_confirm"> |
| 64 | +
|
| 65 | + <xpath expr="//h4[@id='delete_confirm']" position="replace"> |
| 66 | + <h1 t-esc="main_object.msg_content_delete_confirm()">I want it bigger!</h1> |
| 67 | + </xpath> |
| 68 | +
|
| 69 | + </template> |
0 commit comments