diff options
| author | Adrien Dieudonne <adr@odoo.com> | 2018-07-06 14:22:58 +0200 |
|---|---|---|
| committer | Adrien Dieudonne <adr@odoo.com> | 2018-07-06 14:22:58 +0200 |
| commit | 3ebff1f4721dd4a9057db4d26162c57c8506700a (patch) | |
| tree | e3b02fcc528dcc3a0ae50b55a5d3a1d4708ab992 /addons/web/static/src/js/widgets | |
| parent | f9a68d5e778da0ff4e1f1a0936b51b98a822a15a (diff) | |
| parent | 11b7857af63a35e81daa495bcb3522b3915f32ca (diff) | |
[MERGE] *: Easy date filters
This commit allow to create easily a range of periods (related to a field
of date or datetime type) to select in the filters menu.
Two new attributes on elements with tag 'filter' are now usable
in combination in a search view arch:
- date: string.
A valid field name with associated type date or datetime
- default_period: string (optional).
To choose in the following list:
- 'today'
- 'this_week'
- 'this_month' (default)
- 'this_quarter'
- 'this_year'
- 'yesterday'
- 'last_week'
- 'last_month'
- 'last_quarter'
- 'last_year'
- 'last_7_days'
- 'last_30_days'
- 'last_365_days'
Example:
<filter string="Creation Date" name="period_generator" date="create_date" default_period="this_quarter"/>
Note: the attribute 'domain' can not be used for such filters.
The generated domains are dynamic and can be saved as such
via the favorites menu.
task-10532
Diffstat (limited to 'addons/web/static/src/js/widgets')
| -rw-r--r-- | addons/web/static/src/js/widgets/data_export.js | 4 | ||||
| -rw-r--r-- | addons/web/static/src/js/widgets/dropdown_menu.js | 107 |
2 files changed, 50 insertions, 61 deletions
diff --git a/addons/web/static/src/js/widgets/data_export.js b/addons/web/static/src/js/widgets/data_export.js index 68c8b23af13..8a09f7fa034 100644 --- a/addons/web/static/src/js/widgets/data_export.js +++ b/addons/web/static/src/js/widgets/data_export.js @@ -6,7 +6,7 @@ var crash_manager = require('web.crash_manager'); var data = require('web.data'); var Dialog = require('web.Dialog'); var framework = require('web.framework'); -var pyeval = require('web.pyeval'); +var pyUtils = require('web.py_utils'); var QWeb = core.qweb; var _t = core._t; @@ -467,7 +467,7 @@ var DataExport = Dialog.extend({ fields: exported_fields, ids: this.ids_to_export, domain: this.domain, - context: pyeval.eval('contexts', [this.record.getContext()]), + context: pyUtils.eval('contexts', [this.record.getContext()]), import_compat: !!this.$import_compat_radios.filter(':checked').val(), })}, complete: framework.unblockUI, diff --git a/addons/web/static/src/js/widgets/dropdown_menu.js b/addons/web/static/src/js/widgets/dropdown_menu.js index d7e4bff32a4..335eed80e0e 100644 --- a/addons/web/static/src/js/widgets/dropdown_menu.js +++ b/addons/web/static/src/js/widgets/dropdown_menu.js @@ -6,33 +6,39 @@ var Widget = require('web.Widget'); var QWeb = core.qweb; -// interface IItem { -// itemId: string; -// description: string; -// groupId: string; -// isActive: boolean; (optional) -// isOpen: boolean; (optional) -// isRemovable: boolean; (optional) -// options: array of objects with 'optionId' and 'description' keys; (optional) -// defaultOptionId: string refers to an optionId (optional) -// currentOptionId: string refers to an optionId that is activated if item is active (optional) -// } + var DropdownMenu = Widget.extend({ template: 'web.DropdownMenu', events: { 'click li.o_menu_item': '_onItemClick', 'click li.o_item_option': '_onOptionClick', - 'click li.o_menu_item span.o_submenu_switcher': '_openItemOptions', 'click span.o_trash_button': '_onTrashClick', 'hidden.bs.dropdown': '_onBootstrapClose', }, /** + * override + * * @param {Widget} parent - * @param {Object} dropdowHeader object with keys 'title' and 'icon' - * @param {Object} items values are arrays of items (see interface IItems) - * @param {Object} itemGenerator + * @param {Object} dropdowHeader object used to customize the dropdown menu. The keys: + * - 'title' (e.g. 'Group By') + * - 'icon' (e.g. 'fa-bars') + * - 'symbol' (e.g. 'caret') + * - 'category' (describes the type of items) + * - 'style' (button style) + * @param {Object} items list of menu items (type IGMenuItem below) + * interface IMenuItem { + * itemId: string; (optional) unique id associated with the item + * description: string; label printed on screen + * groupId: string; + * isActive: boolean; (optional) determines if the item is considered active + * isOpen: boolean; (optional) in case there are options the submenu presenting the options + * is opened or closed according to isOpen + * isRemovable: boolean; (optional) can be removed from menu + * options: array of objects with 'optionId' and 'description' keys; (optional) + * currentOptionId: string refers to an optionId that is activated if item is active (optional) + * } */ init: function (parent, dropdownHeader, items) { this._super(parent); @@ -49,7 +55,9 @@ var DropdownMenu = Widget.extend({ this.items = _.sortBy(items, 'groupId'); _.each(this.items, this._prepareItem.bind(this)); }, - + /** + * override + */ start: function () { this.$menu = this.$('.o_dropdown_menu'); }, @@ -93,7 +101,6 @@ var DropdownMenu = Widget.extend({ }; this.trigger_up('menu_item_deleted', eventData); }, - /** * @private */ @@ -103,17 +110,21 @@ var DropdownMenu = Widget.extend({ this.$('ul.o_dropdown_menu').prepend($(newMenuItems)); }, /** + * this function computes some default values for some of the item keys + * according to values passed at initialization + * * @private * @param {Object} item */ _prepareItem: function (item) { + item.itemId = item.itemId || _.uniqueId('__item__'); item.isOpen = item.isOpen || false; item.isRemovable = item.isRemovable || false; - item.hasOptions = item.options && item.options.length !== 0 ? true : false; - item.defaultOptionId = item.hasOptions ? - (item.defaultOptionId || item.options[0].optionId) : - false; - item.currentOptionId = item.isActive ? (item.currentOptionId || item.defaultOptionId ) : false; + if (item.options && item.options.length !== 0) { + item.options = _.sortBy(item.options, 'groupId'); + item.hasOptions = true; + item.currentOptionId = item.isActive && item.currentOptionId ? item.currentOptionId : false; + } }, /** * @private @@ -121,23 +132,21 @@ var DropdownMenu = Widget.extend({ */ _toggleMenuItem: function (itemId) { var item = _.findWhere(this.items, {itemId: itemId}); - item.isActive = !item.isActive; - var eventData = { - category: this.dropdownCategory, - itemId: itemId, - isActive: item.isActive, - groupId: item.groupId, - }; + if (!item.hasOptions) { + item.isActive = !item.isActive; + var eventData = { + category: this.dropdownCategory, + itemId: itemId, + isActive: item.isActive, + groupId: item.groupId, + }; + this._renderMenuItems(); + this.trigger_up('menu_item_toggled', eventData); + } if (item.hasOptions) { - if (item.isActive) { - item.currentOptionId = item.defaultOptionId; - eventData.optionId = item.currentOptionId; - } else { - item.currentOptionId = false; - } + item.isOpen = !item.isOpen; + this._renderMenuItems(); } - this._renderMenuItems(); - this.trigger_up('menu_item_toggled', eventData); }, /** * @private @@ -168,19 +177,11 @@ var DropdownMenu = Widget.extend({ this.trigger_up('item_option_changed', eventData); } }, - /** - * @private - * @param {string} itemId - */ - _toggleMenuOptions: function (itemId) { - var item = _.findWhere(this.items, {itemId: itemId}); - item.isOpen = !item.isOpen; - this._renderMenuItems(); - }, //-------------------------------------------------------------------------- // Handlers //-------------------------------------------------------------------------- + /** * This method is called when Bootstrap trigger a 'close' event (for example * when the user clicks outside the dropdown menu). @@ -224,20 +225,8 @@ var DropdownMenu = Widget.extend({ var itemId = $(event.currentTarget).data('id'); this._removeItem(itemId); }, - /** - * @private - * @param {MouseEvent} event - */ - _openItemOptions: function (event) { - // we preventdefault the event here to avoid changing the hash # in the - // url. - event.preventDefault(); - event.stopPropagation(); - var itemId = $(event.currentTarget).data('id'); - this._toggleMenuOptions(itemId); - }, }); return DropdownMenu; -});
\ No newline at end of file +}); |
