====================
Working with modules
====================

For every item of the project :doc:`task tree <task_tree>` a developer can write 
code that will be executed on the client or server. In Application builder for every 
item there is two upper-right buttons **Client module** and **Server module**. 
Clicking on these will open the
:doc:`code editor </admin/code_editor>`.

Every item has a predefined set of events that could be triggered by  
application. An event is a function defined in the module of an item that starts 
with the **on_** prefix. All published events are listed in the Events tab of the 
information pane of the
:doc:`code editor </admin/code_editor>`

In the 
:doc:`code editor </admin/code_editor>`
the developer 
can write code for these events as well as define some functions. 

For example the following code means that immediately after adding a new record 
to the Invoices journal of the Demo project, the value of the invoicedate field 
will be equal to the current date.

.. code-block:: js

    function on_after_append(item) { 
        item.invoicedate.value = new Date(); 
    } 


.. note::
    These events and functions became attributes of the item and could be 
    accessed anywhere in the project code.

For example, the following code defined in the item client module will execute
on_edit_form_created event handler defined in the **Customers** item for this item.

.. code-block:: js

    function on_edit_form_created(item) { 
        task.customers.on_edit_form_created(item);
    } 
  