[FIX] board: properly render with twice same action
Before this rev., the dashboard wasn't rendered correctly when the same action (same action id) was several times in the dashboard. For instance, if the dashboard contained the list and kanban view of an action, both views were rendered in the same block, leaving the other one empty. Moreover, (un)foldeing one automatically (un)folded the other one. This was because the action id was used to identify each view, but this id is not unique in the dashboard. We now use a generated id instead, which is unique.
This commit is contained in:
@@ -279,25 +279,26 @@ FormRenderer.include({
|
||||
children: []
|
||||
});
|
||||
}
|
||||
|
||||
// register actions, alongside a generated unique ID
|
||||
_.each(node.children, function (column, column_index) {
|
||||
_.each(column.children, function (action, action_index) {
|
||||
action.attrs.id = 'action_' + column_index + '_' + action_index;
|
||||
self.actionsDescr[action.attrs.id] = action.attrs;
|
||||
});
|
||||
});
|
||||
|
||||
var $html = $('<div>').append($(QWeb.render('DashBoard', {node: node})));
|
||||
|
||||
// render each view
|
||||
_.each(node.children, function (column, column_index) {
|
||||
_.each(column.children, function (action, action_index) {
|
||||
var attrs = action.attrs;
|
||||
var domain = Domain.prototype.stringToArray(attrs.domain, {});
|
||||
var context = new Context(attrs.context);
|
||||
var actionID = _.str.toNumber(attrs.name);
|
||||
self.actionsDescr[actionID] = attrs;
|
||||
var $node = $html.find('.oe_action[data-id=' + actionID + '] .oe_content');
|
||||
self.defs.push(self._createController({
|
||||
$node: $node,
|
||||
actionID: actionID,
|
||||
context: context,
|
||||
domain: domain,
|
||||
viewType: attrs.view_mode,
|
||||
}));
|
||||
});
|
||||
_.each(this.actionsDescr, function (action) {
|
||||
self.defs.push(self._createController({
|
||||
$node: $html.find('.oe_action[data-id=' + action.id + '] .oe_content'),
|
||||
actionID: _.str.toNumber(action.name),
|
||||
context: new Context(action.context),
|
||||
domain: Domain.prototype.stringToArray(action.domain, {}),
|
||||
viewType: action.view_mode,
|
||||
}));
|
||||
});
|
||||
$html.find('.oe_dashboard_column').sortable({
|
||||
connectWith: '.oe_dashboard_column',
|
||||
@@ -341,7 +342,7 @@ FormRenderer.include({
|
||||
*/
|
||||
_onFoldClick: function (event) {
|
||||
var $e = $(event.currentTarget);
|
||||
var $action = $e.parents('.oe_action:first');
|
||||
var $action = $e.closest('.oe_action');
|
||||
var id = $action.data('id');
|
||||
var actionAttrs = this.actionsDescr[id];
|
||||
|
||||
|
||||
@@ -108,6 +108,9 @@
|
||||
}
|
||||
.oe_content {
|
||||
padding: 0 12px 12px 12px;
|
||||
&.oe_folded {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
// Override border of many2manytags defined for form_views
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
</table>
|
||||
</t>
|
||||
<t t-name="DashBoard.action">
|
||||
<div t-att-data-id="action.attrs.name" class="oe_action">
|
||||
<div t-att-data-id="action.attrs.id" class="oe_action">
|
||||
<h2 t-attf-class="oe_header #{action.attrs.string ? '' : 'oe_header_empty'}">
|
||||
<span class="oe_header_txt"> <t t-esc="action.attrs.string"/> </span>
|
||||
<input class = "oe_header_text" type="text"/>
|
||||
@@ -27,8 +27,7 @@
|
||||
<span class='oe_icon oe_minimize oe_fold' t-if="!action.attrs.fold"></span>
|
||||
<span class='oe_icon oe_maximize oe_fold' t-if="action.attrs.fold"></span>
|
||||
</h2>
|
||||
|
||||
<div t-attf-id="#{element_id}_action_#{column_index}_#{action_index}" class="oe_content" t-att-style="action.attrs.fold ? 'display: none' : null"></div>
|
||||
<div t-att-class="'oe_content' + (action.attrs.fold ? ' oe_folded' : '')"/>
|
||||
</div>
|
||||
</t>
|
||||
<t t-name="DashBoard.layouts">
|
||||
|
||||
@@ -326,4 +326,55 @@ QUnit.test('can drag and drop a view', function (assert) {
|
||||
form.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('twice the same action in a dashboard', function (assert) {
|
||||
assert.expect(2);
|
||||
|
||||
var form = createView({
|
||||
View: FormView,
|
||||
model: 'board',
|
||||
data: this.data,
|
||||
arch: '<form string="My Dashboard">' +
|
||||
'<board style="2-1">' +
|
||||
'<column>' +
|
||||
'<action context="{}" view_mode="list" string="ABC" name="51" domain="[]"></action>' +
|
||||
'<action context="{}" view_mode="kanban" string="DEF" name="51" domain="[]"></action>' +
|
||||
'</column>' +
|
||||
'</board>' +
|
||||
'</form>',
|
||||
mockRPC: function (route) {
|
||||
if (route === '/board/static/src/img/layout_1-1-1.png') {
|
||||
return $.when();
|
||||
}
|
||||
if (route === '/web/action/load') {
|
||||
return $.when({
|
||||
res_model: 'partner',
|
||||
views: [[4, 'list'],[5, 'kanban']],
|
||||
});
|
||||
}
|
||||
if (route === '/web/view/add_custom') {
|
||||
assert.step('add custom');
|
||||
return $.when(true);
|
||||
}
|
||||
return this._super.apply(this, arguments);
|
||||
},
|
||||
archs: {
|
||||
'partner,4,list':
|
||||
'<tree string="Partner"><field name="foo"/></tree>',
|
||||
'partner,5,kanban':
|
||||
'<kanban><templates><t t-name="kanban-box">' +
|
||||
'<div><field name="foo"/></div>' +
|
||||
'</t></templates></kanban>',
|
||||
},
|
||||
});
|
||||
|
||||
var $firstAction = form.$('.oe_action:contains(ABC)');
|
||||
assert.strictEqual($firstAction.find('.o_list_view').length, 1,
|
||||
"list view should be displayed in 'ABC' block");
|
||||
var $secondAction = form.$('.oe_action:contains(DEF)');
|
||||
assert.strictEqual($secondAction.find('.o_kanban_view').length, 1,
|
||||
"kanban view should be displayed in 'DEF' block");
|
||||
|
||||
form.destroy();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user