7 The list view provides a few style hook classes for re-styling of list views in
12 The root element of the list view, styling rules should be rooted
15 ``table.oe_list_content``
17 The root table for the listview, accessory components may be
18 generated or added outside this section, this is the list view
23 The action buttons array for the list view, with its sub-elements
27 The default "Create"/"Add" button of the list view
31 The "alternative choice" for the list view, by default text
32 along the lines of "or import" with a link.
34 ``.oe_list_field_cell``
36 The cell (``td``) for a given field of the list view, cells which
37 are *not* fields (e.g. name of a group, or number of items in a
38 group) will not have this class. The field cell can be further
43 Numeric cell types (integer and float)
47 Action button (``button`` tag in the view) inside the cell
53 ``.oe_list_field_$type``
55 Additional class for the precise type of the cell, ``$type``
56 is the field's @widget if there is one, otherwise it's the
59 ``.oe_list_record_selector``
66 The editable list view module adds a few supplementary style hook
67 classes, for edition situations:
71 Added to both ``.oe_list`` and ``.oe_list_button`` (as the
72 buttons may be outside of the list view) when a row of the list is
73 currently being edited.
77 Class set on the row being edited itself. Note that the edition
78 form is *not* contained within the row, this allows for styling or
79 modifying the row while it's being edited separately. Mostly for
80 fields which can not be edited (e.g. read-only fields).
86 List view edition is an extension to the base listview providing the
87 capability of inline record edition by delegating to an embedded form
93 The editability status of a list view can be queried through the
94 :js:func:`~openerp.web.ListView.editable` method, will return a falsy
95 value if the listview is not currently editable.
97 The editability status is based on three flags:
101 If present, can be either ``"top"`` or ``"bottom"``. Either will
102 make the list view editable, with new records being respectively
103 created at the top or at the bottom of the view.
105 ``context.set_editable``
107 Boolean flag extracted from a search context (during the
108 :js:func:`~openerp.web.ListView.do_search`` handler), ``true``
109 will make the view editable (from the top), ``false`` or the
110 absence of the flag is a noop.
112 ``defaults.editable``
114 Like ``tree/@editable``, one of absent (``null``)), ``"top"`` or
115 ``"bottom"``, fallback for the list view if none of the previous
118 These three flags can only *make* a listview editable, they can *not*
119 override a previously set flag. To do that, a listview user should
120 instead cancel :ref:`the edit:before event <listview-edit-before>`.
122 The editable list view module adds a number of methods to the list
123 view, on top of implementing the :js:class:`EditorDelegate` protocol:
128 .. js:function:: openerp.web.ListView.ensure_saved
130 Attempts to resolve the pending edition, if any, by saving the
131 edited row's current state.
133 :returns: delegate resolving to all editions having been saved, or
134 rejected if a pending edition could not be saved
135 (e.g. validation failure)
137 .. js:function:: openerp.web.ListView.start_edition([record][, options])
139 Starts editing the provided record inline, through an overlay form
140 view of editable fields in the record.
142 If no record is provided, creates a new one according to the
143 editability configuration of the list view.
145 This method resolves any pending edition when invoked, before
146 starting a new edition.
148 :param record: record to edit, or null to create a new record
149 :type record: :js:class:`~openerp.web.list.Record`
150 :param EditOptions options:
151 :returns: delegate to the form used for the edition
153 .. js:function:: openerp.web.ListView.save_edition
155 Resolves the pending edition.
157 :returns: delegate to the save being completed, resolves to an
158 object with two attributes ``created`` (flag indicating
159 whether the saved record was just created or was
160 updated) and ``record`` the reloaded record having been
163 .. js:function:: openerp.web.ListView.cancel_edition([force=false])
165 Cancels pending edition, cleans up the list view in case of
166 creation (removes the empty record being created).
168 :param Boolean force: doesn't check if the user has added any
169 data, discards the edition unconditionally
174 .. js:function:: openerp.web.ListView.get_cells_for(row)
176 Extracts the cells from a listview row, and puts them in a
177 {fieldname: cell} mapping for analysis and manipulation.
182 .. js:function:: openerp.web.ListView.with_event(event_name, event, action[, args][, trigger_params])
184 Executes ``action`` in the context of the view's editor,
185 bracketing it with cancellable event signals.
187 :param String event_name: base name for the bracketing event, will
188 be postfixed by ``:before`` and
189 ``:after`` before being called
190 (respectively before and after
191 ``action`` is executed)
192 :param Object event: object passed to the ``:before`` event
194 :param Function action: function called with the view's editor as
195 its ``this``. May return a deferred.
196 :param Array args: arguments passed to ``action``
197 :param Array trigger_params: arguments passed to the ``:after``
198 event handler alongside the results
201 Behavioral Customizations
202 +++++++++++++++++++++++++
204 .. js:function:: openerp.web.ListView.handle_onwrite(record)
206 Implements the handling of the ``onwrite`` listview attribute:
207 calls the RPC methods specified by ``@onwrite``, and if that
208 method returns an array of ids loads or reloads the records
209 corresponding to those ids.
211 :param record: record being written having triggered the
213 :type record: openerp.web.list.Record
214 :returns: deferred to all reloadings being done
219 For simpler interactions by/with external users of the listview, the
220 view provides a number of dedicated events to its lifecycle.
222 .. note:: if an event is defined as *cancellable*, it means its first
223 parameter is an object on which the ``cancel`` attribute can
224 be set. If the ``cancel`` attribute is set, the view will
225 abort its current behavior as soon as possible, and rollback
226 any state modification.
228 Generally speaking, an event should only be cancelled (by
229 setting the ``cancel`` flag to ``true``), uncancelling an
230 event is undefined as event handlers are executed on a
231 first-come-first-serve basis and later handlers may
232 re-cancel an uncancelled event.
234 .. _listview-edit-before:
236 ``edit:before`` *cancellable*
238 Invoked before the list view starts editing a record.
240 Provided with an event object with a single property ``record``,
241 holding the attributes of the record being edited (``record`` is
242 empty *but not null* for a new record)
246 Invoked after the list view has gone into an edition state,
247 provided with the attributes of the record being edited (see
248 ``edit:before``) as first parameter and the form used for the
249 edition as second parameter.
251 ``save:before`` *cancellable*
253 Invoked right before saving a pending edition, provided with an
254 event object holding the listview's editor (``editor``) and the
255 edition form (``form``)
259 Invoked after a save has been completed
261 ``cancel:before`` *cancellable*
263 Invoked before cancelling a pending edition, provided with the
264 same information as ``save:before``.
268 Invoked after a pending edition has been cancelled.
273 The list view has grown hooks for the ``keyup`` event on its edition
274 form (during edition): any such event bubbling out of the edition form
275 will be forwarded to a method ``keyup_EVENTNAME``, where ``EVENTNAME``
276 is the name of the key in ``$.ui.keyCode``.
278 The method will also get the event object (originally passed to the
279 ``keyup`` handler) as its sole parameter.
281 The base editable list view has handlers for the ``ENTER`` and
287 The list-edition modules does not generally interact with the embedded
288 formview, delegating instead to its
289 :js:class:`~openerp.web.list.Editor`.
291 .. js:class:: openerp.web.list.Editor(parent[, options])
293 The editor object provides a more convenient interface to form
294 views, and simplifies the usage of form views for semi-arbitrary
297 However, the editor does *not* task itself with being internally
298 consistent at this point: calling
299 e.g. :js:func:`~openerp.web.list.Editor.edit` multiple times in a
300 row without saving or cancelling each edit is undefined.
303 :type parent: :js:class:`~openerp.web.Widget`
304 :param EditorOptions options:
306 .. js:function:: openerp.web.list.Editor.is_editing([record_state])
308 Indicates whether the editor is currently in the process of
309 providing edition for a record.
311 Can be filtered by the state of the record being edited
312 (whether it's a record being *created* or a record being
313 *altered*), in which case it asserts both that an edition is
314 underway and that the record being edited respectively does
315 not yet exist in the database or already exists there.
317 :param record_state: state of the record being edited.
318 Either ``"new"`` or ``"edit"``.
319 :type record_state: String
322 .. js:function:: openerp.web.list.Editor.edit(record, configureField[, options])
324 Loads the provided record into the internal form view and
325 displays the form view.
327 Will also attempt to focus the first visible field of the form
330 :param Object record: record to load into the form view
331 (key:value mapping similar to the result
333 :param configureField: function called with each field of the
334 form view right after the form is
335 displayed, lets whoever called this
336 method do some last-minute
337 configuration of form fields.
338 :type configureField: Function<String, openerp.web.form.Field>
339 :param EditOptions options:
340 :returns: jQuery delegate to the form object
342 .. js:function:: openerp.web.list.Editor.save
344 Attempts to save the internal form, then hide it
346 :returns: delegate to the record under edition (with ``id``
347 added for a creation). The record is not updated
348 from when it was passed in, aside from the ``id``
351 .. js:function:: openerp.web.list.Editor.cancel([force=false])
353 Attemps to cancel the edition of the internal form, then hide
356 :param Boolean force: unconditionally cancels the edition of
357 the internal form, even if the user has
358 already entered data in it.
359 :returns: delegate to the record under edition
361 .. js:class:: EditorOptions
363 .. js:attribute:: EditorOptions.formView
365 Form view (sub)-class to instantiate and delegate edition to.
367 By default, :js:class:`~openerp.web.FormView`
369 .. js:attribute:: EditorOptions.delegate
371 Object used to get various bits of information about how to
374 By default, uses the editor's parent widget. See
375 :js:class:`EditorDelegate` for the methods and attributes to
378 .. js:class:: EditorDelegate
380 Informal protocol defining the methods and attributes expected of
381 the :js:class:`~openerp.web.list.Editor`'s delegate.
383 .. js:attribute:: EditorDelegate.dataset
385 The dataset passed to the form view to synchronize the form
386 view and the outer widget.
388 .. js:function:: EditorDelegate.edition_view(editor)
390 Called by the :js:class:`~openerp.web.list.Editor` object to
391 get a form view (JSON) to pass along to the form view it
394 The result should be a valid form view, see :doc:`Form Notes
395 <form-notes>` for various peculiarities of the form view
398 :param editor: editor object asking for the view
399 :type editor: :js:class:`~openerp.web.list.Editor`
403 .. js:function:: EditorDelegate.prepends_on_create
405 By default, the :js:class:`~openerp.web.list.Editor` will
406 append the ids of newly created records to the
407 :js:attr:`EditorDelegate.dataset`. If this method returns
408 ``true``, it will prepend these ids instead.
410 :returns: whether new records should be prepended to the
411 dataset (instead of appended)
415 .. js:class:: EditOptions
417 Options object optionally passed into a method starting an edition
418 to configure its setup and behavior
420 .. js:attribute:: focus_field
422 Name of the field to set focus on after setting up the edition
425 If this option is not provided, or the requested field can not
426 be focused (invisible, readonly or not in the view), the first
427 visible non-readonly field is focused.
432 * The editable listview behavior has been rewritten pretty much from
433 scratch, any code touching on editability will have to be modified
435 * The overloading of :js:class:`~openerp.web.ListView.Groups` and
436 :js:class:`~openerp.web.ListView.List` for editability has been
437 drastically simplified, and most of the behavior has been moved to
438 the list view itself. Only
439 :js:func:`~openerp.web.ListView.List.row_clicked` is still
442 * A new method ``get_row_for(record) -> jQuery(tr) | null`` has been
443 added to both ListView.List and ListView.Group, it can be called
444 from the list view to get the table row matching a record (if such
447 * :js:func:`~openerp.web.ListView.do_button_action`'s core behavior
448 has been split away to
449 :js:func:`~openerp.web.ListView.handle_button`. This allows bypassing
450 overrides of :js:func:`~openerp.web.ListView.do_button_action` in a
453 Ideally, :js:func:`~openerp.web.ListView.handle_button` should not be
456 * Modifiers handling has been improved (all modifiers information
457 should now be available through :js:func:`~Column.modifiers_for`,
458 not just ``invisible``)
460 * Changed some handling of the list view's record: a record may now
461 have no id, and the listview will handle that correctly (for new
462 records being created) as well as correctly handle the ``id`` being
465 * Extended the internal collections structure of the list view with
466 `#find`_, `#succ`_ and `#pred`_.
468 .. _#find: http://underscorejs.org/#find
470 .. _#succ: http://hackage.haskell.org/packages/archive/base/latest/doc/html/Prelude.html#v:succ
472 .. _#pred: http://hackage.haskell.org/packages/archive/base/latest/doc/html/Prelude.html#v:pred