odoo原生常用的reload动作,是整个框架的刷新,源码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
// * Client action to reload the whole interface. // * If params.menu_id, it opens the given menu entry. // * If params.wait, reload will wait the openerp server to be reachable before reloading function Reload(parent, action) { var params = action.params || {}; var menu_id = params.menu_id || false; var l = window.location; var sobj = $.deparam(l.search.substr(1)); if (params.url_search) { sobj = _.extend(sobj, params.url_search); } var search = '?' + $.param(sobj); var hash = l.hash; if (menu_id) { hash = "#menu_id=" + menu_id; } var url = l.protocol + "//" + l.host + l.pathname + search + hash; redirect(url, params.wait); } core.action_registry.add("reload", Reload); |
还有一个reload_context动作,整体刷新前会先刷新session上下文是否正常,源码如下:
1 2 3 4 5 6 7 8 9 10 11 12 |
/** * Client action to refresh the session context (making sure * HTTP requests will have the right one) then reload the * whole interface. */ function ReloadContext (parent, action) { // side-effect of get_session_info is to refresh the session context session.rpc("/web/session/get_session_info", {}).then(function() { Reload(parent, action); }); } core.action_registry.add("reload_context", ReloadContext); |
现在需要对一些轻量级的通用场景进行视图层级的数据重载刷新支持,以提高用户体验的舒适度,核心代码如下:
1 2 3 4 5 6 7 8 9 10 |
/** * author: i@renjie.me */ function ReloadView(parent, action) { var inner_widget = parent.inner_widget; var active_view = inner_widget.active_view; var controller = active_view.controller; controller.reload(); } core.action_registry.add("reload_view", ReloadView); |
之后就可以在odoo任何层级应用代码里跟调用reload和reload_context一样快捷方便的使用reload_view动作