[ADD] protocol to allow sidebar to query its parent view for context data
bzr revid: xmo@openerp.com-20111121140908-e9b3eygtt42m9bnp
This commit is contained in:
parent
a787b202d4
commit
542928adde
|
@ -708,11 +708,12 @@ session.web.Sidebar = session.web.Widget.extend({
|
|||
});
|
||||
return false;
|
||||
}
|
||||
var additional_context = {
|
||||
self.widget_parent.sidebar_context().then(function (context) {
|
||||
var additional_context = _.extend({
|
||||
active_id: ids[0],
|
||||
active_ids: ids,
|
||||
active_model: self.widget_parent.dataset.model
|
||||
};
|
||||
}, context);
|
||||
self.rpc("/web/action/load", {
|
||||
action_id: item.action.id,
|
||||
context: additional_context
|
||||
|
@ -723,6 +724,7 @@ session.web.Sidebar = session.web.Widget.extend({
|
|||
result.result.flags.new_window = true;
|
||||
self.do_action(result.result);
|
||||
});
|
||||
});
|
||||
},
|
||||
do_fold: function() {
|
||||
this.$element.addClass('closed-sidebar').removeClass('open-sidebar');
|
||||
|
@ -979,6 +981,9 @@ session.web.View = session.web.Widget.extend(/** @lends session.web.View# */{
|
|||
});
|
||||
},
|
||||
on_sidebar_view_log: function() {
|
||||
},
|
||||
sidebar_context: function () {
|
||||
return $.Deferred().resolve({}).promise();
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -292,7 +292,8 @@ to help you get started:
|
|||
.. toctree::
|
||||
:maxdepth: 1
|
||||
|
||||
guides/client-action.rst
|
||||
guides/client-action
|
||||
guides/sidebar-protocol
|
||||
|
||||
Utility behaviors
|
||||
-----------------
|
||||
|
|
|
@ -0,0 +1,78 @@
|
|||
Adding a sidebar to a view
|
||||
==========================
|
||||
|
||||
Initialization
|
||||
--------------
|
||||
|
||||
Each view has the responsibility to create its sidebar (or not) if and only if
|
||||
the ``sidebar`` flag is set in its options.
|
||||
|
||||
In that case, it should use the ``sidebar_id`` value (from its options) to
|
||||
initialize the sidebar at the right position in the DOM:
|
||||
|
||||
.. code-block:: javascript
|
||||
|
||||
if (this.options.sidebar && this.options.sidebar_id) {
|
||||
this.sidebar = new openerp.web.Sidebar(this, this.options.sidebar_id);
|
||||
this.sidebar.start();
|
||||
}
|
||||
|
||||
Because the sidebar is an old-style widget, it must be started after being
|
||||
initialized.
|
||||
|
||||
Sidebar communication protocol
|
||||
------------------------------
|
||||
|
||||
In order to behave correctly, a sidebar needs informations from its parent
|
||||
view.
|
||||
|
||||
This information is extracted via a very basic protocol consisting of a
|
||||
property and two methods:
|
||||
|
||||
.. js:attribute:: dataset
|
||||
|
||||
the view's dataset, used to fetch the currently active model and provide it
|
||||
to remote action handlers as part of the basic context
|
||||
|
||||
.. js:function:: get_selected_ids()
|
||||
|
||||
Used to query the parent view for the set of currently available record
|
||||
identifiers. Used to setup the basic context's ``active_id`` and
|
||||
``active_ids`` keys.
|
||||
|
||||
.. warning::
|
||||
|
||||
:js:func:`get_selected_ids` must return at least one id
|
||||
|
||||
:returns: an array of at least one id
|
||||
:rtype: Array<Number>
|
||||
|
||||
.. js:function:: sidebar_context()
|
||||
|
||||
Queries the view for additional context data to provide to the sidebar.
|
||||
|
||||
:js:class:`~openerp.base.View` provides a default NOOP implementation,
|
||||
which simply resolves to an empty object.
|
||||
|
||||
:returns: a promise yielding an object on success, this object is mergeed
|
||||
into the sidebar's own context
|
||||
:rtype: $.Deferred<Object>
|
||||
|
||||
Programmatic folding and unfolding
|
||||
----------------------------------
|
||||
|
||||
The sidebar object starts folded. It provides three methods to handle its
|
||||
folding status:
|
||||
|
||||
.. js:function:: do_toggle
|
||||
|
||||
Toggles the status of the sidebar
|
||||
|
||||
.. js:function:: do_fold
|
||||
|
||||
Forces the sidebar closed if it's currently open
|
||||
|
||||
.. js:function:: do_unfold
|
||||
|
||||
Forces the sidebar open if it's currently closed
|
||||
|
Loading…
Reference in New Issue