From 49b8eed40857a9e352c8c9b8c90715a065eccd5c Mon Sep 17 00:00:00 2001 From: alexkuhn Date: Fri, 27 Oct 2017 11:43:51 +0200 Subject: [IMP] web: new utils function traversePath (#20521) Enhanced version of the traverse function in utils, so that it also builds the paths to any tree element. There is a function visit in /enterprise/web_enterprise/static/src/js/app_switcher.js that has almost the same purpose as traverse in /odoo/addons/web/static/src/js/utility.js. It seems more appropriate to move visit to utility.js. Also, in order to keep good performance of traverse, it might be better to add an additional 'enhanced' version of traverse instead of making changes on traverse. Hence the newly added function traversePath. --- addons/web/static/src/js/core/utils.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'addons/web/static/src/js/core/utils.js') diff --git a/addons/web/static/src/js/core/utils.js b/addons/web/static/src/js/core/utils.js index ac9310dce90..3fc88ac5b20 100644 --- a/addons/web/static/src/js/core/utils.js +++ b/addons/web/static/src/js/core/utils.js @@ -457,6 +457,20 @@ var utils = { _.each(tree.children, function (c) { utils.traverse(c, f); }); } }, + /** + * Enhanced traverse function with 'path' building on traverse. + * + * @param {Object} tree an object describing a tree structure + * @param {function} f a callback + * @param {Object} path the path to the current 'tree' object + */ + traversePath: function (tree, f, path) { + path = path || []; + f(tree, path); + _.each(tree.children, function (node) { + utils.traversePath(node, f, path.concat(tree)); + }); + }, /** * Visit a tree of objects and freeze all * -- cgit v1.2.3