Skip to content
Permalink
Browse files

fixup! [IMP] web, base: put buttons in list group headers

  • Loading branch information...
mge-odoo committed Mar 19, 2019
1 parent 57cef31 commit adb80127ba649b113afdfeec5e8bfcb7f9b39d0b
@@ -26,7 +26,6 @@ var ListController = BasicController.extend({
custom_events: _.extend({}, BasicController.prototype.custom_events, {
add_record: '_onAddRecord',
button_clicked: '_onButtonClicked',
group_button_clicked: '_onGroupButtonClicked',
edit_line: '_onEditLine',
save_line: '_onSaveLine',
resequence: '_onResequence',
@@ -562,45 +561,6 @@ var ListController = BasicController.extend({
});
new DataExport(this, record, defaultExportFields).open();
},
/**
* Handles a click on a group button by performing its action.
* Similar to @see _callButtonAction
*
* @private
* @param {OdooEvent} ev
* @param {OdooEvent} ev.data.attrs
* @param {OdooEvent} ev.data.group_id
*/
_onGroupButtonClicked: function (ev) {
ev.stopPropagation();

var self = this;
var def = new Promise(function (resolve, reject) {
var reload = function () {
return self.isDestroyed() ? Promise.resolve() : self.reload();
};
var list = self.model.get(self.handle);
var groupByField = list.fields[list.groupedBy[0]];
var group = self.model.get(ev.data.group_id);

self.trigger_up('execute_action', {
action_data: _.extend({}, ev.data.attrs, {
context: group.getContext({ additionalContext: ev.data.attrs.context || {} }),
}),
env: {
context: group.getContext(),
currentID: group.res_id,
model: groupByField.relation,
},
on_success: resolve,
on_fail: function () {
self.update({}, { reload: false }).then(reject).guardedCatch(reject);
},
on_closed: reload,
});
});
return this.alive(def);
},
/**
* Force a resequence of the records curently on this page.
*
@@ -18,11 +18,9 @@ odoo.define('web.ListModel', function (require) {
get: function () {
var result = this._super.apply(this, arguments);
var dp = result && this.localData[result.id];
if (dp) {
if (dp.groupData) {
result.groupData = $.extend(true, {}, dp.groupData);
result.evalModifiers = dp.evalModifiers;
}
if (dp && dp.groupData) {
// TODO: not sure I need to deep copy it, it's a datapoint
result.groupData = $.extend(true, {}, dp.groupData);
}
return result;
},
@@ -39,19 +37,6 @@ odoo.define('web.ListModel', function (require) {
// Private
//--------------------------------------------------------------------------

/**
* Overriden to consider `groupData` in `<groupby><button>` modifiers.
*
* @override
* @private
*/
_getEvalContext: function (element) {
var result = this._super.apply(this, arguments);
if (element.type === 'list' && element.groupData) {
result = _.extend({}, result, element.groupData);
}
return result;
},
/**
*
* @override
@@ -98,7 +83,18 @@ odoo.define('web.ListModel', function (require) {
}).then(function (result) {
_.each(list.data, function (id) {
var dp = self.localData[id];
dp.groupData = _.findWhere(result, { id: dp.res_id });
var groupData = _.findWhere(result, { id: dp.res_id });
var fvg = self.groups[groupByFieldName];
dp.groupData = self._makeDataPoint({
context: dp.context,
data: groupData,
fields: fvg.fields,
fieldsInfo: fvg.fieldsInfo,
modelName: fvg.model,
parentID: dp.id,
res_id: dp.res_id,
viewType: dp.viewType,
});
});
});
}
@@ -431,14 +431,14 @@ var ListRenderer = BasicRenderer.extend({
textAsTitle: !!node.attrs.icon,
});
this._handleAttributes($button, node);
this._registerModifiers(node, list, $button);
this._registerModifiers(node, list.groupData, $button);

// TODO this should be moved to a handler
$button.on("click", function (e) {
e.stopPropagation();
self.trigger_up('group_button_clicked', {
self.trigger_up('button_clicked', {
attrs: node.attrs,
group_id: list.id,
record: list.groupData,
});
});
return $button;
@@ -1783,6 +1783,33 @@ QUnit.module('Views', {
list.destroy();
});

QUnit.test('reload list view with groupby node', async function (assert) {
assert.expect(2);

var list = await createView({
View: ListView,
model: 'foo',
data: this.data,
arch: '<tree expand="1">' +
'<field name="foo"/>' +
'<groupby name="currency_id">' +
'<field name="position"/>' +
'<button string="Button 1" type="object" name="button_method" attrs=\'{"invisible": [("position", "=", "after")]}\'/>' +
'</groupby>' +
'</tree>',
groupBy: ['currency_id'],
});

assert.containsOnce(list, '.o_group_header button:not(.o_invisible_modifier)',
"there should be one visible button");

await list.reload({ domain: [] });
assert.containsOnce(list, '.o_group_header button:not(.o_invisible_modifier)',
"there should still be one visible button");

list.destroy();
});

QUnit.test('list view, editable, without data', async function (assert) {
assert.expect(13);

0 comments on commit adb8012

Please sign in to comment.
You can’t perform that action at this time.