Skip to content

Commit

Permalink
- Fix and Enhance the widget documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
RamezIssac committed Sep 17, 2023
1 parent c4792bf commit 7383c0f
Showing 1 changed file with 10 additions and 50 deletions.
60 changes: 10 additions & 50 deletions docs/source/topics/widgets.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@ You can pass arguments to the ``get_widget`` function to control aspects of its
* success_callback: string, the name of a javascript function that will be called after the report data is retrieved.
* failure_callback: string, the name of a javascript function that will be called if the report data retrieval fails.
* template_name: string, the template name used to render the widget. Default to `slick_reporting/widget_template.html`
* extra_params: string, extra parameters to pass to the report.
* report_form_selector: string, a jquery selector that will be used to find the form that will be used to pass extra parameters to the report.


This code above will be actually rendered as this in the html page:

.. code-block:: html+django

<div class="card" id="expensestotalstatement">
<div class="card" id="">
<div class="card-body">
<div data-report-widget
data-report-url="/reports/expense/expensestotalstatement/"
Expand All @@ -53,61 +55,22 @@ This code above will be actually rendered as this in the html page:
>

<!-- container for the chart -->
<div id="container" data-report-chart style="width:100%; height:400px;"></div>
<div id="container" data-report-chart>
</div>

<!-- container for the table -->
<div data-report-table>

</div>
</div>
</div>
</div>

The ``data-report-widget`` attribute is used by the javascript to find the
widget and render the report.
you can add [data-no-auto-load] to the widget to prevent the widget from loading automatically.

The ``data-report-url`` attribute is the url that will be used to fetch the data.
The ``data-extra-params`` attribute is used to pass extra parameters to the report.
The ``data-success-callback`` attribute is used to pass a javascript function that will be called after
the report data is retrieved.
The ``data-fail-callback`` attribute is used to pass a javascript function
that will be called if the report data retrieval fails.
The ``report-form-selector`` attribute is used to pass a jquery selector
that will be used to find the form that will be used to pass extra parameters
to the report.
The ``data-chart-id`` attribute is used to pass the id of the chart that will
be rendered. The ``data-display-chart-selector`` attribute is used to pass
if the report loader should display the chart selectors links.


The ``data-report-chart`` attribute is used by the javascript to find the
container for the chart. The ``data-report-table`` attribute is used by the
javascript to find the container for the table.


``get_widget`` Tag can accept a ``template_name`` parameter to render the
report using a custom template. By default it renders the
``erp_reporting/report_widget.html`` template.

Default Arguments
-----------------

extra_params
success_callback
failure_callback
display_chart
display_table
chart_id
display_title
title (default to report report title)




you can add [data-no-auto-load] to the widget to prevent report loader to get the widget data automatically.

Customization
-------------
Customization Example
---------------------

You You can customize how the widget is loading by defining your own success call-back
and fail call-back functions.
Expand All @@ -117,12 +80,9 @@ The success call-back function will receive the report data as a parameter

.. code-block:: html+django

{% load i18n static erp_reporting_tags %}
{% load i18n static slick_reporting_tags %}

<div class="widget-container">
{% get_report base_model='expense' report_slug='ExpensesTotalStatement' as ExpensesTotalStatement %}
{% get_html_panel ExpensesTotalStatement data-success-callback='my_success_callback' %}
</div>
{% get_widget_from_url url_name="product-sales" success_callback=my_success_callback %}

<script>
function my_success_callback(data, $element) {
Expand Down

0 comments on commit 7383c0f

Please sign in to comment.