diff options
| author | Aaron Bohy <aab@odoo.com> | 2018-10-22 11:03:17 +0000 |
|---|---|---|
| committer | Aaron Bohy <aab@odoo.com> | 2018-10-23 10:56:12 +0000 |
| commit | 03fe95d6af9d96f961c47d9acfaec498966b8cfa (patch) | |
| tree | 4ae97e4007ef1642b21cdaae596201a17e3cb316 /addons/web/static/src/js/views/view_utils.js | |
| parent | 3c59add416fdba779675dc79580f6c0f56abc5a3 (diff) | |
[REF] web: small refactoring pass on some web components
(mainly views and ActionManager)
- add missing docstrings
- fix typos
- correctly order functions and imports
- put functions in correct sections
- stop using 'event' as argument of handlers
- don't call handlers directly
- remove trailing spaces/tabs
- move module created in stable version to its own file
- follow js guidelines in general
closes odoo/odoo#28024
Diffstat (limited to 'addons/web/static/src/js/views/view_utils.js')
| -rw-r--r-- | addons/web/static/src/js/views/view_utils.js | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/addons/web/static/src/js/views/view_utils.js b/addons/web/static/src/js/views/view_utils.js new file mode 100644 index 00000000000..57ae9547d2f --- /dev/null +++ b/addons/web/static/src/js/views/view_utils.js @@ -0,0 +1,47 @@ +odoo.define('web.viewUtils', function () { +"use strict"; + +var utils = { + /** + * Returns the value of a group dataPoint, i.e. the value of the groupBy + * field for the records in that group. + * + * @param {Object} group dataPoint of type list, corresponding to a group + * @param {string} groupByField the name of the groupBy field + * @returns {string | integer | false} + */ + getGroupValue: function (group, groupByField) { + var groupedByField = group.fields[groupByField]; + switch (groupedByField.type) { + case 'many2one': + return group.res_id || false; + case 'selection': + var descriptor = _.findWhere(groupedByField.selection, group.value); + return descriptor && descriptor[0]; + default: + return group.value; + } + }, + /** + * States whether or not the quick create feature is available for the given + * datapoint, depending on its groupBy field. + * + * @param {Object} list dataPoint of type list + * @returns {Boolean} true iff the kanban quick create feature is available + */ + isQuickCreateEnabled: function (list) { + var groupByField = list.groupedBy[0] && list.groupedBy[0].split(':')[0]; + if (!groupByField) { + return false; + } + var availableTypes = ['char', 'boolean', 'many2one', 'selection']; + if (!_.contains(availableTypes, list.fields[groupByField].type)) { + return false; + } + return true; + }, +}; + +return utils; + +}); |
