From ef35702cbcc10caa203eccdfe6ea5166fdac15c4 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Thu, 11 May 2017 10:47:18 +0200 Subject: [PATCH] [FIX] web: remove some memory leak --- .../web/static/src/js/fields/basic_fields.js | 3 +- .../static/src/js/fields/relational_fields.js | 5 ++ .../views/calendar/calendar_quick_create.js | 52 +++++++++---------- .../static/src/js/views/form/form_renderer.js | 2 + .../src/js/views/graph/graph_controller.js | 2 +- .../src/js/views/pivot/pivot_renderer.js | 19 +++++-- 6 files changed, 50 insertions(+), 33 deletions(-) diff --git a/addons/web/static/src/js/fields/basic_fields.js b/addons/web/static/src/js/fields/basic_fields.js index 17cac8e86e5..921169e5ab6 100644 --- a/addons/web/static/src/js/fields/basic_fields.js +++ b/addons/web/static/src/js/fields/basic_fields.js @@ -1758,7 +1758,8 @@ var JournalDashboardGraph = AbstractField.extend({ this.data = JSON.parse(this.value); }, start: function () { - nv.utils.windowResize(this._onResize.bind(this)); + this._onResize = this._onResize.bind(this); + nv.utils.windowResize(this._onResize); return this._super.apply(this, arguments); }, destroy: function () { diff --git a/addons/web/static/src/js/fields/relational_fields.js b/addons/web/static/src/js/fields/relational_fields.js index 51986224c78..10d72a1398d 100644 --- a/addons/web/static/src/js/fields/relational_fields.js +++ b/addons/web/static/src/js/fields/relational_fields.js @@ -1072,6 +1072,11 @@ var FieldMany2ManyBinaryMultiFiles = AbstractField.extend({ this._generatedMetadata(); }, + destroy: function () { + this._super(); + $(window).off(this.fileupload_id); + }, + //-------------------------------------------------------------------------- // Private //-------------------------------------------------------------------------- diff --git a/addons/web/static/src/js/views/calendar/calendar_quick_create.js b/addons/web/static/src/js/views/calendar/calendar_quick_create.js index 2e6fcae5cf5..c63ad5a47f2 100644 --- a/addons/web/static/src/js/views/calendar/calendar_quick_create.js +++ b/addons/web/static/src/js/views/calendar/calendar_quick_create.js @@ -17,6 +17,10 @@ var QWeb = core.qweb; * @type {*} */ var QuickCreate = Dialog.extend({ + events: _.extend({}, Dialog.events, { + 'keyup input': '_onkeyup', + }), + /** * @constructor * @param {Widget} parent @@ -32,7 +36,6 @@ var QuickCreate = Dialog.extend({ // Can hold data pre-set from where you clicked on agenda this.dataTemplate = dataTemplate || {}; this.dataCalendar = dataCalendar; - this.$input = $(); var self = this; this._super(parent, { @@ -46,7 +49,7 @@ var QuickCreate = Dialog.extend({ }}, {text: _t("Edit"), click: function () { dataCalendar.disableQuickCreate = true; - dataCalendar.title = self.$input.val().trim(); + dataCalendar.title = self.$('input').val().trim(); dataCalendar.on_save = self.destroy.bind(self); self.trigger_up('openCreate', dataCalendar); }}, @@ -55,37 +58,13 @@ var QuickCreate = Dialog.extend({ $content: QWeb.render('CalendarView.quick_create', {widged: this}) }); }, - /** - * @override - * @returns {Deferred} - */ - start: function () { - var self = this; - - if (this.options.disableQuickCreate) { - this.slow_create(); - return; - } - this.$input = this.$('input').keyup(function enterHandler (e) { - if(e.keyCode === $.ui.keyCode.ENTER) { - self.$input.off('keyup', enterHandler); - if (!self._quickAdd(self.dataCalendar)){ - self.$input.on('keyup', enterHandler); - } - } else if (e.keyCode === $.ui.keyCode.ESCAPE && self._buttons) { - self.close(); - } - }); - - return this._super(); - }, //-------------------------------------------------------------------------- // Public //-------------------------------------------------------------------------- focus: function () { - this.$input.focus(); + this.$('input').focus(); }, //-------------------------------------------------------------------------- @@ -110,10 +89,27 @@ var QuickCreate = Dialog.extend({ */ _quickAdd: function (dataCalendar) { dataCalendar = $.extend({}, this.dataTemplate, dataCalendar); - var val = this.$input.val().trim(); + var val = this.$('input').val().trim(); dataCalendar.title = val; return (val)? this.trigger_up('quickCreate', {data: dataCalendar, options: this.options}) : false; }, + /** + * @private + * @param {keyEvent} event + */ + _onkeyup: function (event) { + if (this._flagEnter) { + return; + } + if(event.keyCode === $.ui.keyCode.ENTER) { + this._flagEnter = true; + if (!this._quickAdd(this.dataCalendar)){ + this._flagEnter = false; + } + } else if (event.keyCode === $.ui.keyCode.ESCAPE && this._buttons) { + this.close(); + } + }, }); return QuickCreate; diff --git a/addons/web/static/src/js/views/form/form_renderer.js b/addons/web/static/src/js/views/form/form_renderer.js index 214b880d53d..b4f445cc8eb 100644 --- a/addons/web/static/src/js/views/form/form_renderer.js +++ b/addons/web/static/src/js/views/form/form_renderer.js @@ -724,6 +724,8 @@ var FormRenderer = BasicRenderer.extend({ return $.when.apply($, defs).then(function () { self._updateView($form.contents()); + }, function () { + $form.remove(); }); }, /** diff --git a/addons/web/static/src/js/views/graph/graph_controller.js b/addons/web/static/src/js/views/graph/graph_controller.js index 040311a3919..388d390701c 100644 --- a/addons/web/static/src/js/views/graph/graph_controller.js +++ b/addons/web/static/src/js/views/graph/graph_controller.js @@ -30,7 +30,7 @@ var GraphController = AbstractController.extend({ destroy: function () { if (this.$buttons) { // remove jquery's tooltip() handlers - this.$buttons.find('button').off(); + this.$buttons.find('button').off().tooltip('destroy'); } this._super.apply(this, arguments); }, diff --git a/addons/web/static/src/js/views/pivot/pivot_renderer.js b/addons/web/static/src/js/views/pivot/pivot_renderer.js index c38f8b6b768..a37e65b104b 100644 --- a/addons/web/static/src/js/views/pivot/pivot_renderer.js +++ b/addons/web/static/src/js/views/pivot/pivot_renderer.js @@ -7,6 +7,9 @@ var field_utils = require('web.field_utils'); var PivotRenderer = AbstractRenderer.extend({ tagName: 'table', className: 'table-hover table-condensed table-bordered', + events: _.extend({}, AbstractRenderer.prototype.events, { + 'hover td': '_onTdHover', + }), //-------------------------------------------------------------------------- // Private @@ -34,9 +37,6 @@ var PivotRenderer = AbstractRenderer.extend({ } this._renderHeaders($thead, this.state.headers); this._renderRows($tbody, this.state.rows); - $table.on('hover', 'td', function () { - $table.find('col:eq(' + $(this).index()+')').toggleClass('hover'); - }); // todo: make sure the next line does something $table.find('.o_pivot_header_cell_opened,.o_pivot_header_cell_closed').tooltip(); this.$el.html($table.contents()); @@ -139,6 +139,19 @@ var PivotRenderer = AbstractRenderer.extend({ } }, + //-------------------------------------------------------------------------- + // Handlers + //-------------------------------------------------------------------------- + + /** + * @private + * @param {MouseEvent} event + */ + _onTdHover: function (event) { + var $td = $(event.target); + $td.closest('table').find('col:eq(' + $td.index()+')').toggleClass('hover'); + } + }); return PivotRenderer;