Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kanban mobile rtl #32893

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
43 changes: 30 additions & 13 deletions addons/web/static/src/js/views/kanban/kanban_renderer_mobile.js
Expand Up @@ -90,10 +90,15 @@ KanbanRenderer.include({
var index = _.findIndex(this.widgets, {db_id: localID});
var $column = this.widgets[index].$el;
var left = $column.css('left');
var right = $column.css('right');
var scrollTop = $column.scrollTop();
return this._super.apply(this, arguments).then(function () {
$column = self.widgets[index].$el;
$column.css({left: left});
if (_t.database.parameters.direction === 'rtl') {
$column.css({right: right});
} else {
$column.css({left: left});
}
$column.scrollTop(scrollTop); // required when clicking on 'Load More'
self._enableSwipe();
});
Expand All @@ -114,10 +119,14 @@ KanbanRenderer.include({
var currentColumn = this.widgets[this.activeColumnIndex];
currentColumn.$el.swipe({
swipeLeft: function () {
self._moveToGroup(self.activeColumnIndex + 1, self.ANIMATE);
var moveToIndex = _t.database.parameters.direction === 'rtl' ?
self.activeColumnIndex - 1 : self.activeColumnIndex + 1;
self._moveToGroup(moveToIndex, self.ANIMATE);
},
swipeRight: function () {
self._moveToGroup(self.activeColumnIndex - 1, self.ANIMATE);
var moveToIndex = _t.database.parameters.direction === 'rtl' ?
self.activeColumnIndex + 1 : self.activeColumnIndex - 1;
self._moveToGroup(moveToIndex, self.ANIMATE);
}
});
},
Expand All @@ -137,33 +146,41 @@ KanbanRenderer.include({
}
var def = $.Deferred();
this.activeColumnIndex = moveToIndex;
var isRTL = _t.database.parameters.direction === 'rtl';
var direction = isRTL ? 'right' : 'left';
var column = this.widgets[this.activeColumnIndex];
this.trigger_up('kanban_load_records', {
columnID: column.db_id,
onSuccess: function () {
// update the columns and tabs positions (optionally with an animation)
var updateFunc = animate ? 'animate' : 'css';
self.$('.o_kanban_mobile_tab').removeClass('o_current');
var updateColumn = function ($column, val) {
isRTL ? $column[updateFunc]({right: val}) : $column[updateFunc]({left: val});
};
var updateTab = function ($tab, val) {
isRTL ? $tab[updateFunc]({right: val}) : $tab[updateFunc]({left: val});
};
_.each(self.widgets, function (column, index) {
var columnID = column.id || column.db_id;
var $column = self.$('.o_kanban_group[data-id="' + columnID + '"]');
var $tab = self.$('.o_kanban_mobile_tab[data-id="' + columnID + '"]');
if (index === moveToIndex - 1) {
$column[updateFunc]({left: '-100%'});
$tab[updateFunc]({left: '0%'});
updateColumn($column, '-100%');
updateTab($tab, '0%');
} else if (index === moveToIndex + 1) {
$column[updateFunc]({left: '100%'});
$tab[updateFunc]({left: '100%'});
updateColumn($column, '100%');
updateTab($tab, '100%');
} else if (index === moveToIndex) {
$column[updateFunc]({left: '0%'});
$tab[updateFunc]({left: '50%'});
updateColumn($column, '0%');
updateTab($tab, '50%');
$tab.addClass('o_current');
} else if (index < moveToIndex) {
$column.css({left: '-100%'});
$tab[updateFunc]({left: '-100%'});
$column.css(direction, '-100%');
updateTab($tab, '-100%');
} else if (index > moveToIndex) {
$column.css({left: '100%'});
$tab[updateFunc]({left: '200%'});
$column.css(direction, '100%');
updateTab($tab, '200%');
}
});
def.resolve();
Expand Down
31 changes: 31 additions & 0 deletions addons/web/static/tests/views/kanban_mobile_tests.js
@@ -1,10 +1,12 @@
odoo.define('web.kanban_mobile_tests', function (require) {
"use strict";

var core = require('web.core');
var KanbanView = require('web.KanbanView');
var testUtils = require('web.test_utils');

var createView = testUtils.createView;
var _t = core._t;

QUnit.module('Views', {
beforeEach: function () {
Expand Down Expand Up @@ -104,6 +106,35 @@ QUnit.module('Views', {

kanban.destroy();
});

QUnit.test('mobile grouped rendering in rtl direction', function (assert) {
assert.expect(2);

var direction = _t.database.parameters.direction;
_t.database.parameters.direction = 'rtl';

var kanban = createView({
View: KanbanView,
model: 'partner',
data: this.data,
arch: '<kanban class="o_kanban_test o_kanban_small_column" on_create="quick_create">' +
'<templates><t t-name="kanban-box">' +
'<div><field name="foo"/></div>' +
'</t></templates>' +
'</kanban>',
domain: [['product_id', '!=', false]],
groupBy: ['product_id'],
});

assert.strictEqual(kanban.$('.o_kanban_mobile_tab:first')[0].style.right, '50%',
"first tab should have 50% right")
assert.strictEqual(kanban.$('.o_kanban_mobile_tab:nth(1)')[0].style.right, '100%',
"second tab should have 100% right")

kanban.destroy();
_t.database.parameters.direction = direction;
});

QUnit.test('mobile grouped with undefined column', function (assert) {
assert.expect(3);

Expand Down