Xavier (Open ERP) has proposed merging
lp:~openerp-dev/openerp-web/6.1-574845-xmo into lp:openerp-web/6.1.
Requested reviews:
OpenERP Core Team (openerp)
For more details, see:
https://code.launchpad.net/~openerp-dev/openerp-web/6.1-574845-xmo/+merge/111624
Fixes mis-handling of action (buttons) in editable o2m while or after editing a
row:
1. after a row has been edited (and saved, but without saving the form
containing the o2m field), executing an action (via an action button) would
lose all data entered by the user before executing the action
2. during row edition, executing an actin (via an action button) would
correctly save all user data and execute the action but would fail to reload
the row afterwards, leaving the user believing the action has not correctly
executed
--
https://code.launchpad.net/~openerp-dev/openerp-web/6.1-574845-xmo/+merge/111624
Your team OpenERP R&D Team is subscribed to branch
lp:~openerp-dev/openerp-web/6.1-574845-xmo.
=== modified file 'addons/web/static/src/js/view_form.js'
--- addons/web/static/src/js/view_form.js 2012-06-14 08:40:09 +0000
+++ addons/web/static/src/js/view_form.js 2012-06-22 15:30:35 +0000
@@ -479,7 +479,7 @@
* record or saving an existing one depending on whether the record
* already has an id property.
*
- * @param {Function} success callback on save success
+ * @param {Function} [success] callback on save success
* @param {Boolean} [prepend_on_create=false] if ``do_save`` creates a new record, should that record be inserted at the start of the dataset (by default, records are added at the end)
*/
do_save: function(success, prepend_on_create) {
@@ -2609,7 +2609,7 @@
var button_result = self.o2m.dataset.call_button.apply(self.o2m.dataset, arguments);
self.o2m.reload_current_view();
return button_result;
- }
+ };
pop.on_write.add(function(id, data) {
self.o2m.dataset.write(id, data, {}, function(r) {
self.o2m.reload_current_view();
@@ -2617,9 +2617,39 @@
});
},
do_button_action: function (name, id, callback) {
- var self = this;
- var def = $.Deferred().then(callback).then(function() {self.o2m.view.reload();});
- return this._super(name, id, _.bind(def.resolve, def));
+ var _super = _.bind(this._super, this);
+
+ this.o2m.view.do_save().then(function () {
+ _super(name, id, callback);
+ });
+ },
+ reload_content: function () {
+ var self = this;
+ return this._super().then(function () {
+ _.each(self.groups.children, self.proxy('hook_form_action'));
+ });
+ },
+ /**
+ * Goes through all the lists in order to override their form's
+ * execute_action to perform a simple reload_record after the action is
+ * done.
+ *
+ * Goes through ListView.List.save_row to do so, to ensure it has a valid
+ * form as there are no other hook points
+ */
+ hook_form_action: function (list) {
+ var self = this;
+ var _save_row = list.save_row;
+ list.save_row = function () {
+ var _execute_action = this.edition_form.do_execute_action;
+ this.edition_form.do_execute_action = function (action, dataset, record_id, _callback) {
+ return _execute_action.call(this, action, dataset, record_id, function () {
+ self.reload_record(
+ self.records.get(record_id));
+ });
+ };
+ return _save_row.apply(this, arguments);
+ }
}
});
=== modified file 'addons/web/static/src/js/view_list.js'
--- addons/web/static/src/js/view_list.js 2012-06-06 12:31:15 +0000
+++ addons/web/static/src/js/view_list.js 2012-06-22 15:30:35 +0000
@@ -479,6 +479,19 @@
reload: function () {
return this.reload_content();
},
+ reload_record: function (record) {
+ return this.dataset.read_ids(
+ [record.get('id')],
+ _.pluck(_(this.columns).filter(function (r) {
+ return r.tag === 'field';
+ }), 'name')
+ ).then(function (records) {
+ _(records[0]).each(function (value, key) {
+ record.set(key, value, {silent: true});
+ });
+ record.trigger('change', record);
+ });
+ },
do_load_state: function(state, warm) {
var reload = false;
@@ -1018,17 +1031,7 @@
* @returns {$.Deferred} promise to the finalization of the reloading
*/
reload_record: function (record) {
- return this.dataset.read_ids(
- [record.get('id')],
- _.pluck(_(this.columns).filter(function (r) {
- return r.tag === 'field';
- }), 'name')
- ).then(function (records) {
- _(records[0]).each(function (value, key) {
- record.set(key, value, {silent: true});
- });
- record.trigger('change', record);
- });
+ return this.view.reload_record(record);
},
/**
* Renders a list record to HTML
_______________________________________________
Mailing list: https://launchpad.net/~openerp-dev-gtk
Post to : [email protected]
Unsubscribe : https://launchpad.net/~openerp-dev-gtk
More help : https://help.launchpad.net/ListHelp