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
165 Cancels pending edition, cleans up the list view in case of
166 creation (removes the empty record being created).
171 .. js:function:: openerp.web.ListView.get_cells_for(row)
173 Extracts the cells from a listview row, and puts them in a
174 {fieldname: cell} mapping for analysis and manipulation.
179 .. js:function:: openerp.web.ListView.with_event(event_name, event, action[, args][, trigger_params])
181 Executes ``action`` in the context of the view's editor,
182 bracketing it with cancellable event signals.
184 :param String event_name: base name for the bracketing event, will
185 be postfixed by ``:before`` and
186 ``:after`` before being called
187 (respectively before and after
188 ``action`` is executed)
189 :param Object event: object passed to the ``:before`` event
191 :param Function action: function called with the view's editor as
192 its ``this``. May return a deferred.
193 :param Array args: arguments passed to ``action``
194 :param Array trigger_params: arguments passed to the ``:after``
195 event handler alongside the results
198 Behavioral Customizations
199 +++++++++++++++++++++++++
201 .. js:function:: openerp.web.ListView.handle_onwrite(record)
203 Implements the handling of the ``onwrite`` listview attribute:
204 calls the RPC methods specified by ``@onwrite``, and if that
205 method returns an array of ids loads or reloads the records
206 corresponding to those ids.
208 :param record: record being written having triggered the
210 :type record: openerp.web.list.Record
211 :returns: deferred to all reloadings being done
216 For simpler interactions by/with external users of the listview, the
217 view provides a number of dedicated events to its lifecycle.
219 .. note:: if an event is defined as *cancellable*, it means its first
220 parameter is an object on which the ``cancel`` attribute can
221 be set. If the ``cancel`` attribute is set, the view will
222 abort its current behavior as soon as possible, and rollback
223 any state modification.
225 Generally speaking, an event should only be cancelled (by
226 setting the ``cancel`` flag to ``true``), uncancelling an
227 event is undefined as event handlers are executed on a
228 first-come-first-serve basis and later handlers may
229 re-cancel an uncancelled event.
231 .. _listview-edit-before:
233 ``edit:before`` *cancellable*
235 Invoked before the list view starts editing a record.
237 Provided with an event object with a single property ``record``,
238 holding the attributes of the record being edited (``record`` is
239 empty *but not null* for a new record)
243 Invoked after the list view has gone into an edition state,
244 provided with the attributes of the record being edited (see
245 ``edit:before``) as first parameter and the form used for the
246 edition as second parameter.
248 ``save:before`` *cancellable*
250 Invoked right before saving a pending edition, provided with an
251 event object holding the listview's editor (``editor``) and the
252 edition form (``form``)
256 Invoked after a save has been completed
258 ``cancel:before`` *cancellable*
260 Invoked before cancelling a pending edition, provided with the
261 same information as ``save:before``.
265 Invoked after a pending edition has been cancelled.
270 The list view has grown hooks for the ``keyup`` event on its edition
271 form (during edition): any such event bubbling out of the edition form
272 will be forwarded to a method ``keyup_EVENTNAME``, where ``EVENTNAME``
273 is the name of the key in ``$.ui.keyCode``.
275 The method will also get the event object (originally passed to the
276 ``keyup`` handler) as its sole parameter.
278 The base editable list view has handlers for the ``ENTER`` and
284 The list-edition modules does not generally interact with the embedded
285 formview, delegating instead to its
286 :js:class:`~openerp.web.list.Editor`.
288 .. js:class:: openerp.web.list.Editor(parent[, options])
290 The editor object provides a more convenient interface to form
291 views, and simplifies the usage of form views for semi-arbitrary
294 However, the editor does *not* task itself with being internally
295 consistent at this point: calling
296 e.g. :js:func:`~openerp.web.list.Editor.edit` multiple times in a
297 row without saving or cancelling each edit is undefined.
300 :type parent: :js:class:`~openerp.web.Widget`
301 :param EditorOptions options:
303 .. js:function:: openerp.web.list.Editor.is_editing([record_state])
305 Indicates whether the editor is currently in the process of
306 providing edition for a record.
308 Can be filtered by the state of the record being edited
309 (whether it's a record being *created* or a record being
310 *altered*), in which case it asserts both that an edition is
311 underway and that the record being edited respectively does
312 not yet exist in the database or already exists there.
314 :param record_state: state of the record being edited.
315 Either ``"new"`` or ``"edit"``.
316 :type record_state: String
319 .. js:function:: openerp.web.list.Editor.edit(record, configureField[, options])
321 Loads the provided record into the internal form view and
322 displays the form view.
324 Will also attempt to focus the first visible field of the form
327 :param Object record: record to load into the form view
328 (key:value mapping similar to the result
330 :param configureField: function called with each field of the
331 form view right after the form is
332 displayed, lets whoever called this
333 method do some last-minute
334 configuration of form fields.
335 :type configureField: Function<String, openerp.web.form.Field>
336 :param EditOptions options:
337 :returns: jQuery delegate to the form object
339 .. js:function:: openerp.web.list.Editor.save
341 Attempts to save the internal form, then hide it
343 :returns: delegate to the record under edition (with ``id``
344 added for a creation). The record is not updated
345 from when it was passed in, aside from the ``id``
348 .. js:function:: openerp.web.list.Editor.cancel
350 Attemps to cancel the edition of the internal form, then hide
353 :returns: delegate to the record under edition
355 .. js:class:: EditorOptions
357 .. js:attribute:: EditorOptions.formView
359 Form view (sub)-class to instantiate and delegate edition to.
361 By default, :js:class:`~openerp.web.FormView`
363 .. js:attribute:: EditorOptions.delegate
365 Object used to get various bits of information about how to
368 By default, uses the editor's parent widget. See
369 :js:class:`EditorDelegate` for the methods and attributes to
372 .. js:class:: EditorDelegate
374 Informal protocol defining the methods and attributes expected of
375 the :js:class:`~openerp.web.list.Editor`'s delegate.
377 .. js:attribute:: EditorDelegate.dataset
379 The dataset passed to the form view to synchronize the form
380 view and the outer widget.
382 .. js:function:: EditorDelegate.edition_view(editor)
384 Called by the :js:class:`~openerp.web.list.Editor` object to
385 get a form view (JSON) to pass along to the form view it
388 The result should be a valid form view, see :doc:`Form Notes
389 <form-notes>` for various peculiarities of the form view
392 :param editor: editor object asking for the view
393 :type editor: :js:class:`~openerp.web.list.Editor`
397 .. js:function:: EditorDelegate.prepends_on_create
399 By default, the :js:class:`~openerp.web.list.Editor` will
400 append the ids of newly created records to the
401 :js:attr:`EditorDelegate.dataset`. If this method returns
402 ``true``, it will prepend these ids instead.
404 :returns: whether new records should be prepended to the
405 dataset (instead of appended)
409 .. js:class:: EditOptions
411 Options object optionally passed into a method starting an edition
412 to configure its setup and behavior
414 .. js:attribute:: focus_field
416 Name of the field to set focus on after setting up the edition
419 If this option is not provided, or the requested field can not
420 be focused (invisible, readonly or not in the view), the first
421 visible non-readonly field is focused.
426 * The editable listview behavior has been rewritten pretty much from
427 scratch, any code touching on editability will have to be modified
429 * The overloading of :js:class:`~openerp.web.ListView.Groups` and
430 :js:class:`~openerp.web.ListView.List` for editability has been
431 drastically simplified, and most of the behavior has been moved to
432 the list view itself. Only
433 :js:func:`~openerp.web.ListView.List.row_clicked` is still
436 * A new method ``get_row_for(record) -> jQuery(tr) | null`` has been
437 added to both ListView.List and ListView.Group, it can be called
438 from the list view to get the table row matching a record (if such
441 * :js:func:`~openerp.web.ListView.do_button_action`'s core behavior
442 has been split away to
443 :js:func:`~openerp.web.ListView.handle_button`. This allows bypassing
444 overrides of :js:func:`~openerp.web.ListView.do_button_action` in a
447 Ideally, :js:func:`~openerp.web.ListView.handle_button` should not be
450 * Modifiers handling has been improved (all modifiers information
451 should now be available through :js:func:`~Column.modifiers_for`,
452 not just ``invisible``)
454 * Changed some handling of the list view's record: a record may now
455 have no id, and the listview will handle that correctly (for new
456 records being created) as well as correctly handle the ``id`` being
459 * Extended the internal collections structure of the list view with
460 `#find`_, `#succ`_ and `#pred`_.
462 .. _#find: http://underscorejs.org/#find
464 .. _#succ: http://hackage.haskell.org/packages/archive/base/latest/doc/html/Prelude.html#v:succ
466 .. _#pred: http://hackage.haskell.org/packages/archive/base/latest/doc/html/Prelude.html#v:pred