Although most of our code base is being processed server side, some things just require interaction on the
clients machine for a fluent user experience.
In this chapter we will try to explain some of the components we use when designing pages and how pages are usually constructed.
--------------------------
Layout
--------------------------
To ease reading of volt templates, we recommend using a fixed layout when creating templates.
The base of our rendered page always contains the standard `layout <https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/views/layouts/default.volt>`__
which is hooked via our standard frontend controller.
Below you will find the sections and their order, which we will describe briefly.
..code-block:: html
{#
{1} Copyright notice
#}
<script>
$( document ).ready(function() {
{2} UI code
});
</script>
{3} page html
{{ partial("layout_partials/base_dialog",...)}} {4} dialog forms (see getForm())
#. The copyright block, 2 clause BSD with the authors on top
#. Javascript code which belongs to this page
#. HTML code, usually starts with some :code:`<div>` containers and uses standard Bootstrap 3 layouting
#. When forms are used, these are placed last, these will be generated to the client as standard html code
The minimal implementation contains a reference to the search endpoint which should return a json resultset containing :code:`rows`
and pagination data (:code:`current`, :code:`rowCount`, :code:`total`).
..code-block:: html
$("#my_grid").UIBootgrid(
{ search:'/api/path/to/search',
get:'/api/path/to/get',
set:'/api/path/to/set',
add:'/api/path/to/add',
del:'/api/path/to/del',
toggle:'/api/path/to/toggle',
info:'/api/path/to/info'
}
);
The other optional endpoints are either used to populate a form, as defined in the :code:`data-editDialog` property on the table or
can be used to feed actions, such as **set** (set new values, return validation errors), **add** a new record, **del** an existing record
or **toggle** if the record should be enabled or disabled. :code:`info` endpoints are not used very often (and can safely be omitted), these are mainly intended as simple trigger to display an info dialog.
In some cases the developer wants to signal the user about the fact that changes need to be applied in order to be active, for this scenario one can use the :code:`data-editAlert`
property of the table, which offers the ability to show an alert after changes. Below example would be shown when the table tag contains :code:`data-editAlert="exampleChangeMessage"`
{{ lang._('After changing settings, please remember to apply them with the button below') }}
</div>
..Tip::
You can access the general settings of the jquery-bootgrid plugin using the :code:`options` property, which can be convenient when you would like to change
requests or responses as being exchanged with the server. The available options are described `here <http://www.jquery-bootgrid.com/Documentation#table>`__
We added a couple of settings to the list, which help to extend our plugin a bit more easily. Below we will explain which settings (within the options tag) are added by us:
* Boolean value which enables the use of the request handler when a :code:`get` request is executed ot fetch data for the dialog. This can be used to add parameters to the request.
* onBeforeRenderDialog
* function handler which will be called before an edit dialog is being displayed, can be used to change the otherwise static dialogs. Should return a $.Deferred() object. (e.g. :code:`return (new $.Deferred()).resolve();`)
Formatters
.......................
Formatters can be used in the grid heading to choose the presentation of an attribute, we include a couple of standard formatters which are:
* commands (commands list, edit,copy and delete)
* commandsWithInfo (same as commands, but with an info button as well)
* rowtoggle (show enabled status and act as toggle button)
* boolean (show boolean value)
Visible columns
......................
jquery-bootgrid offers the ability to add columns which are not visible by default using the :code:`data-visible` tag. When
using our wrapper, these can be used to set defaults as well,
but the users last selection is also recorded in its local browser storage as well as the number of results shown in the grid when opening the same page again.