====
view
====

.. js:function:: view(container)

**domain**: client 

**language**: javascript

**class** :doc:`Item class </refs/client/item_api>`

Description
===========

Use ``view`` method to create a view form of the item.

The method check if the javascript modules of the item and its owner are loaded,
and if not (the **Dynamic JS modules loading** 
:doc:`parameter of the project </admin/project/parameters>`
is set) then loads them.

Then it searches for an item html template in the task 
:doc:`templates </refs/client/task/at_templates>`
attribute (See 
:doc:`Forms </programming/interface/forms>`
) and creates a 
clone of the template and assigns it to the item 
:doc:`view_form <at_view_form>`
attribute.

If ``container`` parameter is specified the method empties it and appends the 
html template to it. Otherwise it creates a modal form and appends the 
html to it.

Triggers the 
:doc:`on_view_form_created </refs/client/task/on_view_form_created>`
of the task.

Triggers the 
:doc:`on_view_form_created </refs/client/group/on_view_form_created>`
of the group that owners the item, if one is defined for the group.

Triggers the 
:doc:`on_view_form_created <on_view_form_created>`
of the item, if one is defined.

Assigns the JQuery keyup and keydown events to the view_form so 
that when an JQuery event of the window occurs, the ``on_view_form_keyup`` and 
``on_view_form_keydown`` events are triggered. They are triggered (if defined) 
in the same way: first the task event handler, the group event handler and 
then the event handler of the item itself. After that the JQuery stopPropagation 
method of the event is called.

If the form is modal, shows it. Before showing the form the method applies 
options specidied in the 
:doc:`view_options <at_view_options>` 
attribute.

Triggers the 
:doc:`on_view_form_shown </refs/client/task/on_view_form_shown>`
of the task.

Triggers the 
:doc:`on_view_form_shown </refs/client/group/on_view_form_shown>`
of the group that owners the item, if one is defined for the group.

Triggers the 
:doc:`on_view_form_shown <on_view_form_shown>`
of the item, if one is defined.

Example
=======

In the following code the view for of the **Tasks** journal is created in the
on_page_loaded event handler:

.. code-block:: js

    function on_page_loaded(task) {
    
        $("#title").html(task.item_caption);
        if (task.safe_mode) {
            $("#user-info").text(task.user_info.role_name + ' ' + task.user_info.user_name);
            $('#log-out')
            .show()
            .click(function(e) {
                e.preventDefault();
                task.logout();
            });
        }
    
        task.tasks.view($("#content"));
        
        $(window).on('resize', function() {
            resize(task);
        });
    } 

See also
========

:doc:`Forms </programming/interface/forms>`

:doc:`Creating view forms </programming/interface/view_forms>`

:doc:`view_form <at_view_form>`

:doc:`view_options <at_view_options>`

:doc:`close_view_form <m_close_view_form>`


