forked from Techsystech/web
[MIG] web_remember_tree_column_width: Migration to 16.0
parent
6223f88e9a
commit
4ed7c0052b
|
@ -0,0 +1 @@
|
||||||
|
../../../../web_remember_tree_column_width
|
|
@ -0,0 +1,6 @@
|
||||||
|
import setuptools
|
||||||
|
|
||||||
|
setuptools.setup(
|
||||||
|
setup_requires=['setuptools-odoo'],
|
||||||
|
odoo_addon=True,
|
||||||
|
)
|
|
@ -5,10 +5,11 @@
|
||||||
"website": "https://github.com/OCA/web",
|
"website": "https://github.com/OCA/web",
|
||||||
"license": "LGPL-3",
|
"license": "LGPL-3",
|
||||||
"category": "Extra Tools",
|
"category": "Extra Tools",
|
||||||
"version": "15.0.1.0.1",
|
"version": "16.0.1.0.0",
|
||||||
"maintainers": [
|
"maintainers": [
|
||||||
"frahikLV",
|
"frahikLV",
|
||||||
"luisg123v",
|
"luisg123v",
|
||||||
|
"cuongnmtm",
|
||||||
],
|
],
|
||||||
"depends": [
|
"depends": [
|
||||||
"web",
|
"web",
|
||||||
|
@ -16,8 +17,7 @@
|
||||||
"data": [],
|
"data": [],
|
||||||
"assets": {
|
"assets": {
|
||||||
"web.assets_backend": [
|
"web.assets_backend": [
|
||||||
"web_remember_tree_column_width/static/src/js/list_renderer.js",
|
"web_remember_tree_column_width/static/src/**/*",
|
||||||
"web_remember_tree_column_width/static/src/scss/main.scss",
|
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
"installable": True,
|
"installable": True,
|
||||||
|
|
|
@ -1,2 +1,5 @@
|
||||||
* Francisco Javier Luna Vázquez <fluna@vauxoo.com>
|
* Francisco Javier Luna Vázquez <fluna@vauxoo.com>
|
||||||
* Tomás Álvarez <tomas@vauxoo.com>
|
* Tomás Álvarez <tomas@vauxoo.com>
|
||||||
|
* `Komit <https://komit-consulting.com/>`_:
|
||||||
|
|
||||||
|
* Cuong Nguyen Mtm <cuong.nmtm@komit-consulting.com>
|
||||||
|
|
|
@ -1 +1,5 @@
|
||||||
Vauxoo
|
* Vauxoo
|
||||||
|
|
||||||
|
The migration of this module from 15.0 to 16.0 was financially supported by:
|
||||||
|
|
||||||
|
* Komit (https://komit-consulting.com/)
|
||||||
|
|
|
@ -0,0 +1,61 @@
|
||||||
|
/** @odoo-module **/
|
||||||
|
|
||||||
|
import {ListRenderer} from "@web/views/list/list_renderer";
|
||||||
|
import {browser} from "@web/core/browser/browser";
|
||||||
|
import {patch} from "web.utils";
|
||||||
|
|
||||||
|
patch(ListRenderer.prototype, "web_remember_tree_column_width.ListRenderer", {
|
||||||
|
/**
|
||||||
|
* @override
|
||||||
|
*/
|
||||||
|
computeColumnWidthsFromContent() {
|
||||||
|
const columnWidths = this._super.apply(this, arguments);
|
||||||
|
const table = this.tableRef.el;
|
||||||
|
const thElements = [...table.querySelectorAll("thead th:not(.o_list_button)")];
|
||||||
|
thElements.forEach((el, elIndex) => {
|
||||||
|
const fieldName = $(el).data("name");
|
||||||
|
if (this.props.list.resModel && fieldName && browser.localStorage) {
|
||||||
|
const storedWidth = browser.localStorage.getItem(
|
||||||
|
`odoo.columnWidth.${this.props.list.resModel}.${fieldName}`
|
||||||
|
);
|
||||||
|
if (storedWidth) {
|
||||||
|
columnWidths[elIndex] = parseInt(storedWidth, 10);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return columnWidths;
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @override
|
||||||
|
*/
|
||||||
|
onStartResize(ev) {
|
||||||
|
this._super.apply(this, arguments);
|
||||||
|
const resizeStoppingEvents = ["keydown", "mousedown", "mouseup"];
|
||||||
|
const $th = $(ev.target.closest("th"));
|
||||||
|
if (!$th || !$th.is("th")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const saveWidth = (saveWidthEv) => {
|
||||||
|
if (saveWidthEv.type === "mousedown" && saveWidthEv.which === 1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ev.preventDefault();
|
||||||
|
ev.stopPropagation();
|
||||||
|
const fieldName = $th.length ? $th.data("name") : undefined;
|
||||||
|
if (this.props.list.resModel && fieldName && browser.localStorage) {
|
||||||
|
browser.localStorage.setItem(
|
||||||
|
"odoo.columnWidth." + this.props.list.resModel + "." + fieldName,
|
||||||
|
parseInt(($th[0].style.width || "0").replace("px", ""), 10) || 0
|
||||||
|
);
|
||||||
|
}
|
||||||
|
for (const eventType of resizeStoppingEvents) {
|
||||||
|
browser.removeEventListener(eventType, saveWidth);
|
||||||
|
}
|
||||||
|
document.activeElement.blur();
|
||||||
|
};
|
||||||
|
for (const eventType of resizeStoppingEvents) {
|
||||||
|
browser.addEventListener(eventType, saveWidth);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
|
@ -1,69 +0,0 @@
|
||||||
odoo.define("web_remember_tree_column_width.ListRenderer", function (require) {
|
|
||||||
"use strict";
|
|
||||||
|
|
||||||
const ListRenderer = require("web.ListRenderer");
|
|
||||||
ListRenderer.include({
|
|
||||||
events: Object.assign({}, ListRenderer.prototype.events, {
|
|
||||||
"pointerdown th .o_resize": "_onMouseDownResize",
|
|
||||||
mouseup: "_onMouseUpResize",
|
|
||||||
}),
|
|
||||||
_onMouseDownResize: function () {
|
|
||||||
this.resizeInProgress = true;
|
|
||||||
},
|
|
||||||
_getLocalStorageWidthColumnName: function (model, field) {
|
|
||||||
return "odoo.columnWidth." + model + "." + field;
|
|
||||||
},
|
|
||||||
_onMouseUpResize: function (ev) {
|
|
||||||
if (this.resizeInProgress) {
|
|
||||||
this.resizeInProgress = false;
|
|
||||||
const target = $(ev.target);
|
|
||||||
const $th = target.is("th") ? target : target.parent("th");
|
|
||||||
const fieldName = $th.length ? $th.data("name") : undefined;
|
|
||||||
if (
|
|
||||||
this.state &&
|
|
||||||
this.state.model &&
|
|
||||||
fieldName &&
|
|
||||||
window.localStorage
|
|
||||||
) {
|
|
||||||
window.localStorage.setItem(
|
|
||||||
this._getLocalStorageWidthColumnName(
|
|
||||||
this.state.model,
|
|
||||||
fieldName
|
|
||||||
),
|
|
||||||
parseInt(($th[0].style.width || "0").replace("px", "")) || 0
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
_squeezeTable: function () {
|
|
||||||
const columnWidths = this._super.apply(this, arguments);
|
|
||||||
|
|
||||||
const table = this.el.getElementsByTagName("table")[0];
|
|
||||||
const thead = table.getElementsByTagName("thead")[0];
|
|
||||||
const thElements = [...thead.getElementsByTagName("th")];
|
|
||||||
|
|
||||||
const self = this;
|
|
||||||
thElements.forEach(function (el, elIndex) {
|
|
||||||
const fieldName = $(el).data("name");
|
|
||||||
if (
|
|
||||||
self.state &&
|
|
||||||
self.state.model &&
|
|
||||||
fieldName &&
|
|
||||||
window.localStorage
|
|
||||||
) {
|
|
||||||
const storedWidth = window.localStorage.getItem(
|
|
||||||
self._getLocalStorageWidthColumnName(
|
|
||||||
self.state.model,
|
|
||||||
fieldName
|
|
||||||
)
|
|
||||||
);
|
|
||||||
if (storedWidth) {
|
|
||||||
columnWidths[elIndex] = parseInt(storedWidth);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return columnWidths;
|
|
||||||
},
|
|
||||||
});
|
|
||||||
});
|
|
|
@ -2,7 +2,3 @@ th.o_column_sortable {
|
||||||
max-width: none !important;
|
max-width: none !important;
|
||||||
min-width: 0 !important;
|
min-width: 0 !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
.o_optional_columns_dropdown_toggle {
|
|
||||||
height: 25px;
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue