summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/chrome/web_client.js
AgeCommit message (Collapse)Author
2021-04-28[FIX] web: web client boot when user has not apps availableXavier Morel
This mostly an issue when trying to run just the tests of `web` (aka `-iweb`) with only community modules available, `TestMenusDemoLight.test_01_click_apps_menus_as_demo`, wait for the ready code times out: AssertionError: False is not true : The ready "odoo.isReady === true" code was always falsy and the test suite fails. The ready code simply checks that `odoo.isReady` is set. The web client sets `isReady` when `webclient_started` is triggered (specifically in `_onWebClientStarted`, which is the handler for that event). [The community web client only triggers `webclient_started` at the end of `doAction`][0] meaning the community client is considered ready until after the first action has executed. [The first action is executed by `show_application`][1] whose process is the following: 1. load and initialize the menus 2. if an action is specified in the URL, run that 3. otherwise if the user has a home action, run that 4. otherwise run the first menu's action When installing only `web`, the only menus which could be available are Apps and Settings, and the demo user has access to neither. This means the demo user has no applications, and opening the first app is a no-op ([`openFirstApp` has a case just for that situation to ensure it does nothing][2]). As a result, `webclient_started` is never triggered, `_onWebClientStarted` is never called, `odoo.isReady` is never set, and the tour never runs. Fix by updating `openFirstApp` to return *whether* it opened an application, and in `show_application` the last fallback if even opening the first application failed is to just declare the web client ready. While at it, rewrite `show_application` using ES6 facilities and flatten and linearize it using guards. This means the code pretty much tracks the process described above, with one step added: 5. otherwise complete the webclient's startup [0]: https://github.com/odoo/odoo/blob/1eb474243b55f1b9e10c70d199bbe022e68b51d0/addons/web/static/src/js/chrome/action_manager.js#L174 [1]: https://github.com/odoo/odoo/blob/d1c56ec7c435c5baba8604feccc6116e4c25ca96/addons/web/static/src/js/chrome/web_client.js#L77-L107 [2]: https://github.com/odoo/odoo/blob/e24ab17d38fb049404f04112990e8b2fe1dd7727/addons/web/static/src/js/chrome/apps_menu.js#L44-L46 closes odoo/odoo#69962 Signed-off-by: Xavier Morel (xmo) <xmo@odoo.com>
2019-10-21[FIX] web: web_client o_content is scrollable, not action managerLucas Perais (lpe)
Go on a kanban view with a scroll bar scroll all the way down Open a record in form view Use the breadcrumb to go back to the kanban Before this commit, the kanban was re-opened but the position were we were before opening the record was lost This was due to 40dd121938552d3f88289d2e5fcd1d57a0dd01bb which refactors the dom, puting the action manager on top of controllers After this commit, when re-opening the kanban, we end up at the same position we left it at OPW 2074077 closes odoo/odoo#39120 X-original-commit: c0d48878c452b256859f067186567c126d8de27e Signed-off-by: Lucas Perais (lpe) <lpe@odoo.com>
2019-05-20[IMP] base,web: Improve webclient startupVincent Schippefilt
Today, some resources that varies very infrequentely are requested on every page load: the menus, the translations and the qweb templates After this commit, there will be 2 improvements that will make the loading of the webclient faster: 1. cache almost static resources forever when loading the /web/ page, the user session will contain the cache key to be used to fetch these resources. As the content of the resource itself it used to compute the hash, the request can be put in cache by the browser forever (for a year). The up side is that in general less requests are needed to load the web client The down side is that the load time and number of queries of /web page has increased to include what is needed to compute the hash of translations, menus and qweb templates 2. trigger the loading of the menus before the download (and startup) of the JS and CSS assets: The menus contains the definition of the action, wich is the first thing needed to load a page in odoo. Starting the loading of the menu much earlier means that when they are not yet in the browser cache (see point 1), the browser does not need to wait for the entire assets to be downloaded and parsed before starting the 'load_menu' request, but instead start it immediately and hold onto a promise to be used instead of the rpc 'load_menu'. Because the request is done before anything else is loaded, including JQuery, it is made in vanilla JS. Co-authored-by: Julien Mougenot <jum@odoo.com>
2019-05-13[IMP] base: Contextualize the multi companyYannick Tivisse
Purpose ======= Allow the user to select the allowed companies for which he wants to see records on top of selecting his current company. It is confusing for users to see the records from the company he is connected to and the records of the children companies. Instead of using the hierarchy of companies to access records across companies, the user can now select (from his set of allowed companies) the companies for which he wants to access records. /!\ This means that the user will interact with records from company A when in company B. Example: a SO has been created and confirmed in A. When in B, I create the invoice from it. Specifications ============== 1/ Deprecate the parent/children hierarchy on the res.company model. The fields are kept on the res.company model to ensure the retro-compatibility, but won't be used accross the standard code anymore. The only functional usage for this mechanism was to allow to see records from several companies by creating a virtual parent company, which will be possible with the new mechanism. 2/ By default, a user will only see the records of the company he is connected to (or records without a company). (It is still editable by the user if needed). For that, put this information in the user context, to allow having different configurations on different browser tabs. Instead of having domains like ['|', ('company_id', '=', False), ('company_id', 'child_of', user.company_id.id)] you'll have something like ['|', ('company_id', '=', False), ('company_id', 'in', company_ids)] Note that the 'company_ids' is a value that is passed in the evaluation context on the record rule, as we already have user, or time. company_ids is a list of the ids of all the enabled companies in the user's context. 3/ Out of the generic improvements brought by this task, this will illustrate issues that could exist since several versions. For example, it should not be possible to create a scrap order for the company A with a package of the company B, or it should not be possible to create an invoice on the company A with payment terms from the company B. Before the version 12.0, it was easy to encounter this kind of issues as the admin was the SUPERUSER_ID. A positive side effect of the fact that the SUPERUSER_ID has become an inactive user was to make it more difficult to introduce mismatch on the records, but haven't solved the issue, as it was still possible to do it with parent companies configuration. Some of these issues have been fixed in this commit, but all the business flows should be re-tested to check if an ir.rule should be introduced (eg: a multi company rule for stock.quand.package), if the company of a record is correctly transfered to another record created from the first record (eg: From a SO, create an invoice and a payment, the company of the sales order should be transfered on the invoice and the payment, even if the company of the sales order is A and I'm logged into the company B with the company A enabled. 4/ Currently, if I click on a button on a notification email (example 'View Task'), I face a traceback if I'm not logged into the company of the record. Now, if you click on a button and if you have access to the record, the correct company will be automatically set. 5/ If I display a kanban view with several records from several companies (and an image), all the images should be displayed. 6/ Currently if you copy paste an url, this will crash if you're not in the correct company. This won't be fixed because it's quite impossible to do it in a clean way. This task brings a workaround. Copy/Paste -> Traceback -> Log into the correct company, re-copy/paste -> Ok. 7/ 2 property methods have been added on the environment to retrieve the company on which the user is logged in and the companies the user enabled, on a specific tab. That way, when creating a record, instead of doing default=lambda self: self.env.user.company_id do default=lambda self: self.env.company_id On the other hand, to retrieve the enabled companies, do companies = self.env.company_ids 8/ Modify the Company Switcher widget to allow to log into another company WITHOUT writing on the res.users (and thus bringing cache invalidation issues and so on). Also allow to enable several companies and see records from several companies, and independantly of the other browser's tabs. 9/ When focusing on a tab, save the current company configuration on the local storage. That way, when doing 'CTRL+T' or a middle click, the context is propagated to the new tab. 10/ Improve the error message in case of multi company access errors. Now, when the user is in debug mode, display the related names of the records and the name of the user who brings the issue. 11/ Remove the context erasing when writing on a res.users This is probably coming from the migration to new API of the base module. The context was not propagated at this moment, which was a common mistake at that time. When migrating the module, probably by using the 'black box' method, as the context was not propagated, it was erased on the new version. This is now an issue because the context (i.e. the enabled companies) was erased when writing on a res.users, leading to tracebacks. See: https://github.com/odoo/odoo/commit/7eab8e26d3d46c53f4be924d6a34e80a66e74960#diff-4c2e738ee8f64f11806c889ea097b5e7R624 12/ Fix the crash manager on redirect warnings. The issue is the following - Create an invoice on a company without a configured CoA. - Set a partner - On the onchange_partner_id, a redirect warning is raised to propose you to configure a CoA - Click on 'Go to the configuration panel' - A generic warning says something like 'Do you want to discard your changes?' - Click on yes, the page refreshes, but not on the redirect action. Now, set correctly the action on the hash, and reload instead. The breadcrumb is lost for example, but you reach the correct action at least. 13/ Introduce a res.group to enable/disable the multi company per tab feature. 14/ To help the users to know which tab is in which company, add the possibility to have a favicon per company. When creating a company, the classical 'O' icon is colored by default in a random color. 15/ Remove the company switcher on the frontend. This was mainly there to allow a user to swicth to the company linked to the website. This behavior is now transparent to the user. If the website A is activated, then the company set on the context is the company of the website. 16/ Deprecated the _company_default_get method on the res.company model. Remove the method _get_company on the res.users model. 17/ Add 'allowed_company_ids' and 'current_company_id' on the pyeval context. You can now use those variables on domains in the views to access directly to the activated company.ies on the current tab. TaskID: 1960971 closes odoo/odoo#32341 Signed-off-by: Yannick Tivisse (yti) <yti@odoo.com>
2019-03-06[REF] web: adapt code after jQuery updateVincent Schippefilt
Part of task 1896658 Co-authored-by: Aaron Bohy <aab@odoo.com> Co-authored-by: Christophe Matthieu <chm@odoo.com> Co-authored-by: Mathieu Duckerts-Antoine <dam@odoo.com> Co-authored-by: David Monjoie <dmo@odoo.com> Co-authored-by: Martin Geubelle <mge@odoo.com> Co-authored-by: svs-odoo <svs@odoo.com> Co-authored-by: Vincent Schippefilt <vsc@odoo.com>
2018-10-17[FIX] web: fix menu app button when menu_id can't be inferredDavid Monjoie
There used to be no processing done at all when loading the client from an url missing a menu_id and from which the menu could not be inferred from the action_id. This resulted in the app name button in the menu being empty but still present and not bound to any action. Clicking on it triggered a traceback. This commit stops ignoring the case when the menu cannot be inferred from the action and hides the entire menu and submenus for this particular action. They will be restored when entering an action from which a proper menu can be inferred. closes odoo/odoo#27791
2018-09-17[IMP] web: new navbar in communityAlexandre Kühn
The navbar in community now looks more like the navbar in enterprise. Here is a sum-up of the changes in community: - The navbar in community is now in blue, instead of black. - No more app list that almost fills the whole navbar: there is now an "Apps Menu" in the left-most side of the navbar. - No more sidebar for the menus inside an app: those menus are now located in the middle part of the navbar. The navbar in community does not support mobile (< 768px width), but it should still somewhat usable on most mobile devices. As for the website navbar, it has been unchanged and should still support mobile layout. Task-ID 1878649
2018-09-12[FIX] web: remove race condition at webclient startupAaron Bohy
Before this rev., there was a race condition making some tours randomly fail on runbot, when the following steps occurred in that order: - load webclient - as soon as the menu is ready and visible, click on a root menu which thus leads to a doAction - in the meantime, an RPC is done by the webclient to retrieve the (optional) default action of the user (if there is no state in the url, which is the case for tours in general) - when that RPC returns, this action (if any), or the action of the first menu is executed, thus leading to a second doAction - the ActionManager using a DropPrevious, the first doAction is dropped and thus the action linked to the clicked menu is never shown, making the tour fail This rev. uses the state of the ActionManager's DropPrevious to prevent the default action from being executed if another action is already being executed, thus removing that race condition. Note that this fix is temporary, as the community webclient is currently being refactored.
2018-09-11[FIX] web: remove display none timeoutChristophe Monniez
Since 6dc37ee461c9 a d-none class was added to hide the menus in the navbar during the start of the navbar. A timeout was set to mimic the old behavior and let enought time to bind events on menus. When the project app was installed alongside with all other apps on the runbot, there was not enough place in the navbar. This resulted in a race condition at the begining of the project tour. With this commit, the d-none class is immediately removed and then the menu are started (binded to events) before the tour has the hand to continue its next step.
2018-07-27[REF] web, *: share and adapt code for auto "more" buttons for navbarsqsm-odoo
* portal, web_tour, website, base Before this commit, there were 3 different implementations for the same feature: the "more" button in the community navbar, the "+" button for the website menu and the "+" button in the enterprise navbar. As those implementation were now broken with BS4, it was a good time to share the code of those 3 features.
2018-04-26[FIX] web: fix a race condition in web clientGéry Debongnie
Here is an interesting scenario, involving the reconciliation tour again (because it is our only tour that does async stuff before changing url): - web client starts normally - tour reconciliation starts, perform an rpc to find some id - web client fetches users default action, it is empty, so clicks on first menu item to load initial action, which is discuss. this will make the web client load the action with datamanager (it should be the action manager's job!). - reconciliation tour rpc completes, it changes the url, this will do a do_action - the load_action rpc from the web client completes, it will then perform a do_action, which will drop the action initiated by the tour - tour fails. The issue here is that the on_menu_action method from the web client is not really safe, from a concurrency point of view: it performs some asynchronous work, and then unilateraly decides to do a doAction. With this commit, we simply add the do_action request to the action manager, which uses internally a "dropprevious" system. This means that it will always use the last action, just as expected.
2018-04-18[MERGE] forward port branch saas-11.2 up to fed775bc0c2Christophe Simonis
2018-04-17[FIX] web: display shortcuts in communityVincent Schippefilt
before this fix, hitting the ALT key did not show the shortcuts on the buttons after this fix, the events of the web_client are extending those of abstract_web_clients where the keyboard navigation is hooked up, so the shortcuts are visible
2018-04-17[FIX] web: fix issue with initial action in web clientGéry Debongnie
Here is a scenario that could happen before this commit: 1. web client is started 2. it binds a callback on hashchange 3. it performs some async work (read initial action for user) 4. the user (or more likely, a tour) changes the url 5. the hashchange handler is called, and it starts a new action 6. the async work for the web client is over, it then executes the default action and/or clicks on the first menu 7. we are now in the default action state, instead of the desired action state (the one from the new url) With this fix, we simply do nothing when there was an hashchange before the initial action was done.
2018-03-21[MERGE] forward port branch saas-11.2 up to 500e3f49705Christophe Simonis
2018-03-20[MERGE] forward port branch 11.0 up to 2835d299792Christophe Simonis
2018-03-19[FIX] web: pick correct menu item on hashchangeAlexandre Kühn
Before this commit, we had the following issue: 1. install CRM and Sales 2. Sales > Customers > (open any form) 3. Click on browser's "back" button We are redirected to the contact kanban view in CRM instead of Sales. This is due to the fact that both menu items share the same action. When the user uses the browser's "back" button (AKA. it triggers an hashchange event), the web_client opens the first menu_item that matches the action. This commit fixes the issue by allowing us to open an action by providing a menu ID: 1. If it matches the action, then it opens this menu instead of the first match. 2. If we do not provide any menuID, or this menuID does not match with the action, it falls back to the first menu matching this action. Fixes #23639
2018-03-19[FIX] web: set correct menu_id on menu actionAlexandre Kühn
Before this commit, the menu_id displayed in the url was incorrect when we click on a menu item for the first time. This is due to the fact that the web_client was mistakenly using the previous menu_id as the action's menu_id: the JS widget menu is not up-to-date with the value of the current menuID, and the web client was relying on its internal state instead of the server's response. With this commit, the web client uses the server's reponse to register the correct menuID that has been clicked.
2018-03-10[IMP] web: restore scroll positionAaron Bohy
This rev. improves the way the scroll position is restored when coming back to a view (e.g. open a kanban view, scroll, click on a record to open it in a form view, go back to kanban using the breadcrumbs): - generalize the scroll position handling from web_enterprise to web to make it available in the community webclient as well - also restore left scroll position, not only top (especially useful for grouped Kanban views with a lot of columns) - handle the case where the scrolling area is a sub element of the view (e.g. the grouped Kanban view in mobile). Task 34037 Co-authored-by: Mohammed Shekha <msh@openerp.com> Co-authored-by: Ankit Sathvara <asa@odoo.com>
2018-02-20[FIX] web: WebClient: reload company logo after editionAaron Bohy
This commit only concerns the community webclient. The user can edit the company data by clicking on the company logo displayed in the submenu (left bar). When it does, the logo's url must be updated to force the logo to be reloaded. The last part doesn't work since the new views, as it uses an hook of the form view (called when it is saved) that doesn't exist anymore. This rev. adapts the code so that the logo is reloaded when the edit menu dialog is closed. It also ensures that the logo is properly reloaded by specifying the timestamp in the img url as a query string parameter instead of an hash param, since changing the hash doesn't seem to be enough to fool the browser's cache anymore.
2018-02-19[FIX] web: WebClient: edit company dataAaron Bohy
Before this rev., a traceback was raised when the user tried to edit the company data, by clicking on the company logo in the submenu (community edition only). This was due to code not being converted after the ActionManager refactoring of 7b6056a0. Also ensures that the logo is properly reloaded by specifying the timestamp in the img url as a query string parameter instead of an hash param, since changing the hash doesn't seem to be enough to fool the browser's cache anymore.
2018-01-19[FIX] web: WebClient: notify the ActionManager it's in the DOMMohammed Shekha
Before this rev., on_attach_callback of the ActionManager wasn't called at init, because the WebClient didn't use the append function of dom_utils.
2018-01-16[REF] web,*: ActionManager/ViewManager refactoringAaron Bohy
This rev. is the first part (out of 3) of the refactoring of the ActionManager and ViewManager layer of the webclient. The main changes are: - there is no ViewManager anymore, its work is now handled by the ActionManager itself, but isolated in a specific file ; this eases a lot of things, as the breadcrumbs handling for example. - the ActionManager code is converted to the new coding principles and guidelines ; mainly, children widgets communicate with it by triggering events up, and not by function calls anymore. - the ActionManager layer is now testable, and a lot of tests have already been written. - the code in other addons has been adapted consequently. What's coming next: - introduce the 'AbstractAction' Widget, and make client actions and view controllers inherit from it ; this widget will implement a common API that could be used uniformly by the ActionManager (e.g. restore(), canBeLeft(), renderButtons(), getTitle()...). - move the ControlPanel handling from the ActionManager to the AbstractAction.
2017-10-18[FIX] web,*: replace core.debug by config.debugKhoi Nguyen
2017-04-11[REF] web, *: simplify our RPC system (in JS)Géry Debongnie
The RPC system was not completely satisfactory, we decided to prepare the future and do it properly. This commit introduces the new rpc system, which replace the previous new one. We now simply have a method, this._rpc, which takes a dictionary of parameters. The idea is that depending on the parameters, it is able to add correct default value when necessary. For situations where we don't have the this._rpc method, we can use the rpc.query method, which takes the same arguments, but directly calls ajax.rpc instead of triggering up some events.
2017-04-11[REF] *: use _rpc method for all rpcsGéry Debongnie
The _rpc method is now the preferred method to do a rpc, so we need to update all calls.
2017-04-11[REF] web,*: remove 'web.model' and 'web.dataModelGéry Debongnie
Use this.rpc instead of Model object, with web.ajax if necessary. nb: EventDispatcherMixin include now the custom_events managment instead of widget
2017-04-11[REF] web, *: redesign all JS viewsGéry Debongnie
This commit introduce a full redesign of all JS views. We started basically from scratch. The goal was to unify all the various views under a common framework, to make them testable, to make then usable in different conditions (in studio, or in the frontend), and to make our lives easier. Some important points are: - we introduced new coding guidelines (camelCase, 80 chars width, ...) - we have a brand new testing framework (still QUnit based) - kanban view moved to the web addon - calendar view (formerly web_calender) moved to web as well - the tree view was removed - all new code should be documented We hope that this code is the start of a new era for the Odoo web client, we want to have a high quality codebase, well documented, well tested, well designed. Work done by the framework team: mostly aab, ged, chm, dmo, qsm