diff options
| author | Raphael Collet <rco@openerp.com> | 2015-10-29 13:51:32 +0100 |
|---|---|---|
| committer | Raphael Collet <rco@openerp.com> | 2015-11-02 10:57:18 +0100 |
| commit | f72594bcc6bd30b1f3257fc2ad2cc8c4c682e8a0 (patch) | |
| tree | 7e3bbb4e3532a0a56d3c2827141ee338f7d4c900 /addons/web/static/src/js/framework | |
| parent | 7d220a1eeb69f119f97214f144176705a203d357 (diff) | |
[IMP] web: add a generic notification feature inside form views
The notification box remains on the form until either:
- the user closes it explicitly, or
- the user edits the record, or
- the form view is refreshed (switch to another record, or refresh form).
Add a method `once` to `EventDispatcherMixin`, as it is convenient.
Make `FormView` trigger events `to_view_mode` and `to_edit_mode`.
Diffstat (limited to 'addons/web/static/src/js/framework')
| -rw-r--r-- | addons/web/static/src/js/framework/mixins.js | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/addons/web/static/src/js/framework/mixins.js b/addons/web/static/src/js/framework/mixins.js index e9f9b2c94b0..2f96da09872 100644 --- a/addons/web/static/src/js/framework/mixins.js +++ b/addons/web/static/src/js/framework/mixins.js @@ -268,6 +268,17 @@ var EventDispatcherMixin = _.extend({}, ParentedMixin, { }); return this; }, + once: function(events, dest, func) { + // similar to this.on(), but func is executed only once + var self = this + if (typeof func !== "function") { + throw new Error("Event handler must be a function."); + } + self.on(events, dest, function what() { + func.apply(this, arguments); + self.off(events, dest, what); + }); + }, trigger: function() { this.__edispatcherEvents.trigger.apply(this.__edispatcherEvents, arguments); return this; |
