diff options
| author | Sébastien Theys <seb@odoo.com> | 2018-07-10 13:52:28 +0200 |
|---|---|---|
| committer | Sébastien Theys <seb@odoo.com> | 2018-07-17 11:50:35 +0200 |
| commit | f241441433046c41e4f3edd05d5d69028da1f8a7 (patch) | |
| tree | 5224ef02e0ad137f96219339b38fadeae7dca38f /addons/web/static/src/js/views/basic/basic_model.js | |
| parent | d1f1cc9c275de726de3cd2491c8d8b4866bbeb0e (diff) | |
[IMP] web: add control + create tags to customize "add a line"
The default "add a line" button creates a new line with the default values from the model. Sometimes we want to create a new line with different default values (or more generally a customized context), which is possible with this commit. Moreover it is possible to create multiple buttons for multiple default values/contexts.
This works both for in-line creation ("editable=") and dialog creation.
The new tags are:
<control> defines custom controls for the current view.
Does not support any attribute, but can have children:
<create> adds a button to create a new element on the current list.
This makes sense when the parent tree view is inside a One2many field.
If any create is defined, it will overwrite the default "add a line" button.
For more information and example, have a look at the Views documentation.
Technically, the commit will:
- parse the new XML tags (+ add appropriate validation)
- display the buttons based on the XML
- on button click/keyboard: pull up the additional context information from the button event up to the default_get
- add unit tests
- add documentation
PR #25209
Diffstat (limited to 'addons/web/static/src/js/views/basic/basic_model.js')
| -rw-r--r-- | addons/web/static/src/js/views/basic/basic_model.js | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/addons/web/static/src/js/views/basic/basic_model.js b/addons/web/static/src/js/views/basic/basic_model.js index 86308a32736..e0c516f02fb 100644 --- a/addons/web/static/src/js/views/basic/basic_model.js +++ b/addons/web/static/src/js/views/basic/basic_model.js @@ -1315,13 +1315,17 @@ var BasicModel = AbstractModel.extend({ * @param {Object} [options] * @param {string} [options.position=top] if the new record should be added * on top or on bottom of the list + * @param {Object} [options.context] additional context to be merged before + * calling the default_get (eg. to set default values) * @returns {Deferred<string>} resolves to the new record id */ _addX2ManyDefaultRecord: function (list, options) { var self = this; var position = options && options.position || 'top'; + var additionalContext = options && options.context; + var context = this._getContext(list, {additionalContext: additionalContext}); var params = { - context: this._getContext(list), + context: context, fields: list.fields, fieldsInfo: list.fieldsInfo, parentID: list.id, @@ -1799,7 +1803,10 @@ var BasicModel = AbstractModel.extend({ } break; case 'CREATE': - var options = {position: command.position}; + var options = { + context: command.context, + position: command.position, + }; def = this._addX2ManyDefaultRecord(list, options).then(function (id) { if (command.position === 'bottom' && list.orderedResIDs && list.orderedResIDs.length >= list.limit) { list.tempLimitIncrement = (list.tempLimitIncrement || 0) + 1; |
