From cd96727f50b7bd25e9338e7c0cff7daf63439f53 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Mon, 6 Aug 2012 15:52:48 +0200 Subject: [PATCH 1/7] [CHG] insert the 'Add a row' link before the padding rows bzr revid: xmo@openerp.com-20120806135248-onwslw7ge72tolwn --- addons/web/static/src/js/view_form.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index c4e13dabae2..dae81a8394b 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -3520,8 +3520,14 @@ instance.web.form.One2ManyList = instance.web.ListView.List.extend({ self.view.do_add_record(); }); }); - this.$current.append( - $('').append($cell)) + + var $padding = this.$current.find('tr:not([data-id]):first'); + var $newrow = $('').append($cell); + if ($padding.length) { + $padding.before($newrow); + } else { + this.$current.append($newrow) + } } }); From 9149dc60d8acd49de89efea6e61711faab5192d3 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Mon, 6 Aug 2012 15:55:36 +0200 Subject: [PATCH 2/7] [CHG] make 'add a row' a link bzr revid: xmo@openerp.com-20120806135536-4x6qacw8qp91le2g --- addons/web/static/src/js/view_form.js | 39 ++++++++++++++------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index dae81a8394b..661a230d89f 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -3501,25 +3501,26 @@ instance.web.form.One2ManyList = instance.web.ListView.List.extend({ var $cell = $('', { colspan: columns, 'class': 'oe_form_field_one2many_list_row_add' - }).text(_t("Add a row")) - .mousedown(function () { - // FIXME: needs to be an official API somehow - if (self.view.editor.is_editing()) { - self.view.__ignore_blur = true; - } - }) - .click(function (e) { - e.preventDefault(); - e.stopPropagation(); - // FIXME: there should also be an API for that one - if (self.view.editor.form.__blur_timeout) { - clearTimeout(self.view.editor.form.__blur_timeout); - self.view.editor.form.__blur_timeout = false; - } - self.view.ensure_saved().then(function () { - self.view.do_add_record(); - }); - }); + }).append( + $('', {href: '#'}).text(_t("Add a row")) + .mousedown(function () { + // FIXME: needs to be an official API somehow + if (self.view.editor.is_editing()) { + self.view.__ignore_blur = true; + } + }) + .click(function (e) { + e.preventDefault(); + e.stopPropagation(); + // FIXME: there should also be an API for that one + if (self.view.editor.form.__blur_timeout) { + clearTimeout(self.view.editor.form.__blur_timeout); + self.view.editor.form.__blur_timeout = false; + } + self.view.ensure_saved().then(function () { + self.view.do_add_record(); + }); + })); var $padding = this.$current.find('tr:not([data-id]):first'); var $newrow = $('').append($cell); From 3f955f05250614174be25d190c7d988d0a69b9aa Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Mon, 6 Aug 2012 16:34:10 +0200 Subject: [PATCH 3/7] [CHG] delete o2m lines without warning bzr revid: xmo@openerp.com-20120806143410-ohzypxj3r8bbz08w --- addons/web/static/src/js/view_form.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index 661a230d89f..1f22529ba2a 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -3481,6 +3481,16 @@ instance.web.form.One2ManyListView = instance.web.ListView.extend({ // the current row *anyway*, then create a new one/edit the next one) this.__ignore_blur = true; this._super.apply(this, arguments); + }, + do_delete: function (ids) { + // wheeee + var confirm = window.confirm; + window.confirm = function () { return true; }; + try { + return this._super(ids); + } finally { + window.confirm = confirm; + } } }); instance.web.form.One2ManyList = instance.web.ListView.List.extend({ From d8e2bec1580f8a4635f9cfa52be5001a777cd35b Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Mon, 6 Aug 2012 17:00:02 +0200 Subject: [PATCH 4/7] [FIX] state of editor after cancelled cancel() (haha), handling of a record being edited during o2m deletion bzr revid: xmo@openerp.com-20120806150002-45c8mjq9dk5hck7y --- addons/web/static/src/js/view_form.js | 26 ++++++++++++++----- .../web/static/src/js/view_list_editable.js | 13 +++++----- doc/list-view.rst | 10 +++++-- 3 files changed, 34 insertions(+), 15 deletions(-) diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index 1f22529ba2a..cc92244ce81 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -3483,14 +3483,26 @@ instance.web.form.One2ManyListView = instance.web.ListView.extend({ this._super.apply(this, arguments); }, do_delete: function (ids) { - // wheeee - var confirm = window.confirm; - window.confirm = function () { return true; }; - try { - return this._super(ids); - } finally { - window.confirm = confirm; + var self = this; + var next = $.when(); + var _super = this._super; + // handle deletion of an item which does not exist + // TODO: better handle that in the editable list? + var false_id_index = _(ids).indexOf(false); + if (false_id_index !== -1) { + ids.splice(false_id_index, 1); + next = this.cancel_edition(true); } + return next.pipe(function () { + // wheeee + var confirm = window.confirm; + window.confirm = function () { return true; }; + try { + return _super.call(self, ids); + } finally { + window.confirm = confirm; + } + }); } }); instance.web.form.One2ManyList = instance.web.ListView.List.extend({ diff --git a/addons/web/static/src/js/view_list_editable.js b/addons/web/static/src/js/view_list_editable.js index 038593c54c3..3a574c30e56 100644 --- a/addons/web/static/src/js/view_list_editable.js +++ b/addons/web/static/src/js/view_list_editable.js @@ -281,16 +281,17 @@ openerp.web.list_editable = function (instance) { }); }, /** + * @param {Boolean} [force=false] discards the data even if the form has been edited * @return {jQuery.Deferred} */ - cancel_edition: function () { + cancel_edition: function (force) { var self = this; return this.with_event('cancel', { editor: this.editor, form: this.editor.form, cancel: false }, function () { - return this.editor.cancel().pipe(function (attrs) { + return this.editor.cancel(force).pipe(function (attrs) { if (attrs.id) { var record = self.records.get(attrs.id); if (!record) { @@ -717,13 +718,13 @@ openerp.web.list_editable = function (instance) { return self.cancel(); }); }, - cancel: function () { - var record = this.record; - this.record = null; - if (!this.form.can_be_discarded()) { + cancel: function (force) { + if (!(force || this.form.can_be_discarded())) { return $.Deferred().reject({ message: "The form's data can not be discarded"}).promise(); } + var record = this.record; + this.record = null; this.form.do_hide(); return $.when(record); } diff --git a/doc/list-view.rst b/doc/list-view.rst index 83925d82f46..24c7bb3beb4 100644 --- a/doc/list-view.rst +++ b/doc/list-view.rst @@ -160,11 +160,14 @@ Interaction Methods updated) and ``record`` the reloaded record having been edited. -.. js:function:: openerp.web.ListView.cancel_edition +.. js:function:: openerp.web.ListView.cancel_edition([force=false]) Cancels pending edition, cleans up the list view in case of creation (removes the empty record being created). + :param Boolean force: doesn't check if the user has added any + data, discards the edition unconditionally + Utility Methods +++++++++++++++ @@ -345,11 +348,14 @@ formview, delegating instead to its from when it was passed in, aside from the ``id`` attribute. - .. js:function:: openerp.web.list.Editor.cancel + .. js:function:: openerp.web.list.Editor.cancel([force=false]) Attemps to cancel the edition of the internal form, then hide the form + :param Boolean force: unconditionally cancels the edition of + the internal form, even if the user has + already entered data in it. :returns: delegate to the record under edition .. js:class:: EditorOptions From d9291d50c817f0eeb6210909322b241d21b3484e Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Tue, 7 Aug 2012 09:26:50 +0200 Subject: [PATCH 5/7] [FIX] conflict between form autoblur thing and focus management in editable o2m bzr revid: xmo@openerp.com-20120807072650-ia0u56u8z20tgbfw --- addons/web/static/src/js/view_form.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index cc92244ce81..7549dffa961 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -3338,6 +3338,7 @@ instance.web.form.One2ManyListView = instance.web.ListView.extend({ ListType: instance.web.form.One2ManyList })); this.on('edit:before', this, this.proxy('_before_edit')); + this.on('edit:after', this, this.proxy('_after_edit')); this.on('save:before cancel:before', this, this.proxy('_before_unedit')); this.records @@ -3448,6 +3449,12 @@ instance.web.form.One2ManyListView = instance.web.ListView.extend({ this.__ignore_blur = false; this.editor.form.on('blurred', this, this._on_form_blur); }, + _after_edit: function () { + // The form's blur thing may be jiggered during the edition setup, + // potentially leading to the o2m instasaving the row. Cancel any + // blurring triggered the edition startup here + this.editor.form.widgetFocused(); + }, _before_unedit: function () { this.editor.form.off('blurred', this, this._on_form_blur); }, From 741a1541dac31f966b9f86b2fd663d1a89ba413f Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Tue, 7 Aug 2012 11:23:17 +0200 Subject: [PATCH 6/7] [FIX] action button on row being *created* in editable list view Altered action button workflow: * Action callback (passed to ``do_button_action``) now *takes* a record id instead of closing over it, in case the original list does not have an id to start with * ``handle_button`` partially applies the id *it* got to the callback via ``_.bind`` * Editable list view override of ``do_button_action`` uses ``id`` it got from ``ensure_saved`` in case it got id=false in bzr revid: xmo@openerp.com-20120807092317-wk0xyfzrhxc89t94 --- addons/web/static/src/js/view_list.js | 11 ++++++++--- addons/web/static/src/js/view_list_editable.js | 9 ++++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/addons/web/static/src/js/view_list.js b/addons/web/static/src/js/view_list.js index 57be3ca6db1..4bce8d639f8 100644 --- a/addons/web/static/src/js/view_list.js +++ b/addons/web/static/src/js/view_list.js @@ -674,6 +674,10 @@ instance.web.ListView = instance.web.View.extend( /** @lends instance.web.ListVi * Base handling of buttons, can be called when overriding do_button_action * in order to bypass parent overrides. * + * The callback will be provided with the ``id`` as its parameter, in case + * handle_button's caller had to alter the ``id`` (or even create one) + * while not being ``callback``'s creator. + * * This method should not be overridden. * * @param {String} name action name @@ -699,7 +703,8 @@ instance.web.ListView = instance.web.View.extend( /** @lends instance.web.ListVi c.add(action.context); } action.context = c; - this.do_execute_action(action, this.dataset, id, callback); + this.do_execute_action( + action, this.dataset, id, _.bind(callback, null, id)); }, /** * Handles the activation of a record (clicking on it) @@ -991,8 +996,8 @@ instance.web.ListView.List = instance.web.Class.extend( /** @lends instance.web. // of digits, nice when storing actual numbers, not nice when // storing strings composed only of digits. Force the action // name to be a string - $(self).trigger('action', [field.toString(), record_id, function () { - return self.reload_record(self.records.get(record_id)); + $(self).trigger('action', [field.toString(), record_id, function (id) { + return self.reload_record(self.records.get(id)); }]); }) .delegate('a', 'click', function (e) { diff --git a/addons/web/static/src/js/view_list_editable.js b/addons/web/static/src/js/view_list_editable.js index 3a574c30e56..78fef767f5a 100644 --- a/addons/web/static/src/js/view_list_editable.js +++ b/addons/web/static/src/js/view_list_editable.js @@ -135,10 +135,13 @@ openerp.web.list_editable = function (instance) { make_editor: function () { return new instance.web.list.Editor(this); }, - do_button_action: function () { + do_button_action: function (name, id, callback) { var self = this, args = arguments; - this.ensure_saved().then(function () { - self.handle_button.apply(self, args); + this.ensure_saved().then(function (done) { + if (!id && done.created) { + id = done.record.get('id'); + } + self.handle_button.call(self, name, id, callback); }); }, /** From 1277086229efee81388d9236e847ab1c7d0345d3 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Tue, 7 Aug 2012 11:31:07 +0200 Subject: [PATCH 7/7] [FIX] remove margins from oe_form_nosheet in editable list view Avoids list view moving around when edition starts (and form view is shown so fields can be used) bzr revid: xmo@openerp.com-20120807093107-2cqww3fmstd62to0 --- addons/web/static/src/css/base.css | 5 +++++ addons/web/static/src/css/base.sass | 15 ++++++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/addons/web/static/src/css/base.css b/addons/web/static/src/css/base.css index 8f35c81de2d..7944570d16c 100644 --- a/addons/web/static/src/css/base.css +++ b/addons/web/static/src/css/base.css @@ -2340,6 +2340,11 @@ .openerp .oe_list { position: relative; } +.openerp .oe_list .oe_form .oe_form_nosheet { + margin: 0; + padding: 0; + border: none; +} .openerp .oe_list .oe_form .oe_form_field { width: auto; position: absolute; diff --git a/addons/web/static/src/css/base.sass b/addons/web/static/src/css/base.sass index 688c306169b..29d5ac1e87b 100644 --- a/addons/web/static/src/css/base.sass +++ b/addons/web/static/src/css/base.sass @@ -1831,11 +1831,16 @@ $sheet-max-width: 860px .oe_list position: relative - .oe_form .oe_form_field - width: auto - position: absolute - margin: 0 !important // dammit - padding: 0 + .oe_form + .oe_form_nosheet + margin: 0 // FIXME: either class or border should not be by default + padding: 0 + border: none + .oe_form_field + width: auto + position: absolute + margin: 0 !important // dammit + padding: 0 .oe_list_content width: 100%