summaryrefslogtreecommitdiff
path: root/addons/web/static/tests/fields/basic_fields_tests.js
AgeCommit message (Collapse)Author
2017-07-07[ADD] web: Add new widget to toogle a boolean with a sliderAnkit Sathvara
Purpose ======= Currently, it's not possible to activate a boolean on a non-editable list view without adding 2 buttons linked to a python method. These buttons aren't aligned and the result is not pretty. This commit adds a new widget that allows to toggle a boolean record by record by clicking on the slider.
2017-06-29[FIX] web: prevent dirty state after testGéry Debongnie
The test changed in this commit had a big issue: it did not properly destroy the second form view that it created. Because of that, it was still alive and could interact with other tests, such as the barcode tests. This is what happened: 1. var form was assigned to a form view 2. form was destroyed 3. in a try catch, form was reassigned to the result of createView, but the evaluation of createView crashed (after creating a form view), so the assignation was not done, and the var form was still pointing to the first form view 4. form.destroy is called, which did nothing for the second form view. There is no easy way to get the reference to the form view created by createView without changing some other code, so we simply remove the second part of the test, which was not particularly important.
2017-06-28[FIX] web: FieldText: keep editing the textarea after enterMartin Geubelle
In the editable list, when pressing enter, the cursor goes to the next line and the current row is saved. This should not be the case for a textarea (i.e. in the FieldText widget). In this particular case, we just want to continue editing the textarea.
2017-06-27[FIX] web: MonetaryField: rerender with currencyAaron Bohy
The MonetaryField can be rendered with or without a currency. The currency can change during the lifecyle of the widget (e.g. currency field in the view, whose value is set by an onchange). More precisely, the widget can be instantiated without currency, then a change on another field can trigger an onchange which sets the currency, and our monetary widget is re-rendered with a currency. Before this rev., this wasn't supported in edit mode because the $el's root node was different if there were a currency or not (it was an input if there were no currency, and a div containing an input and a span otherwise). This root node being rendered only once (at the creation of the widget), the widget wasn't re-rendered correctly if the currency was suddenly set or unset. This fix makes the widget behave uniformly whether or not there is a currency, so now it is always a div containing an input (and optionally a span if there is a currency).
2017-06-23[FIX] web: update filename correctly in binary fieldsDavid Monjoie
The update_field event is not used anymore so it needs to trigger a field_changed instead.
2017-06-22[FIX] web: set 0 as default value for numeric fieldsMartin Geubelle
When creating a new record, the numeric field default value should be 0 in order to avoid manually setting mandatory fields to 0. This behaviour has been removed with the new views but one wants to restore it. The `mockRead` function has also been adapted in this commit because the server returns 0 for unset numeric fields.
2017-06-16[FIX] web: FieldWidgets: use correct format/parse functionsAaron Bohy
Field widgets must format and parse values according to the widget type, not to the field type. For example, if a monetary field is inserted in a form view with widget="float", the field's value must be formatted with the float formatter, not the montetary one. This wasn't the case before this rev.
2017-06-09[FIX] web: adapt tests to 3741603495532e218b66f3cfa0272e4536f1cf2cqsm-odoo
The datepicker is now forced to be in the <body/>, so the tests had to search it in there.
2017-05-19[FIX] web: DebounceField: do nothing after widget destructionAaron Bohy
DebounceFields debounce the function that notify field changes to their environment (using _.debounce). It may happen that this function is called once the field widget is destroyed (e.g. type something in a char field and quickly click on Save, the function is called directly by _commitChanges, but the debounced call is still pending). It may be a problem if the subsequent code does something like this.getSession().some_key, as if the widget is destroyed, it has no parent that can provide it the session, and thus it crashes. Also rename attribute _debouncedStarted into _isDirty as it makes much more sense.
2017-05-17[FIX] web: MonetaryField: read currency_field in optionsAaron Bohy
In the xml definition of views, a 'currency_field' can be specified in the node options: <field name="amount" widget='monetary' options="{'currency_field': 'currency_id'}"/> It indicates which field the monetary widget has to use to determine the currency to display. Before this rev., the widget didn't look for the 'currency_field' in the options, but directly in the node attrs, so this simply didn't work. This was for example the case on the crm.lead kanban and form views.
2017-05-17[FIX] web: properly escape field values when necessaryAaron Bohy
This rev. removes some html injections issues: - in char and text field widgets - in phone field widget in mobile - in list views (when no widget is instantiated)
2017-05-15[FIX] web: datepicker did not select correct date after initial renderChristophe Matthieu
2017-05-15[FIX] web: display a translation alert when saving the form viewChristophe Matthieu
In the form view, when the user saves a record (with a multilang instance), an alert is displayed to display all modified translatable fields.
2017-05-12[FIX] web: keep focus on checkboxes after rerenderingDavid Monjoie
Previously, when a checkbox was re-rendered, it was losing focus since it was removed and re-created. Now, if the checkbox itself is the origin point of the re-rendering, we give the focus to the newly re-rendered checkbox, resulting in a seamless experience just as if the checkbox was never removed and re-rendered.
2017-05-10[FIX] web: toggle checkboxes when clicked in editable list viewDavid Monjoie
Previously, the checkbox was not checked when it was clicked in editable list view, it only opened the row but did not check the checkbox.
2017-05-08[FIX] web: display empty input fields properlyGéry Debongnie
Before this commit, it was not possible to see the difference between an unset float field (with a 'false' value) and a set field (for ex, with value 0) This was due to the fact that the formatFloat/formatMonetary functions format false values as the number 0, unlike many other formatting functions.
2017-05-08[FIX] web: FieldMonetary: don't loose focus after editionAaron Bohy
... in x2many editable list views. Field widgets can detect that they are at the origin of a field_changed event, so that they don't re-render themselves when they are being edited. This didn't work for fields inside x2many list views. This wasn't a big problem for most of the fields, because the cursor position was automatically reset after a re-rendering, but it wasn't working for monetary fields that empty their $el before each re-rendering. This rev. fixes the issue by making the field widgets inside x2many list able to detect that they are the origin of a change, and thus removes the now useless code that restore the cursor position.
2017-05-07[REF] web: optimize basic model (improve perfs for most views)Géry Debongnie
The 'get' method in the basic model is called very often (too often, but that is another issue). For a large list with many columns, it can be quickly be called more than 10k times. In that function, we had to protect our integrity by performing a deep clone with $.extend, so noone else can be allowed to change something in our internal structure. This is good in theory, but not so good in practice, as $.extend is a really expensive operation. Also, we try to have the smallest external API by deleting useless keys. But instead of keeping a blacklist of private keys, it is simpler to have a whitelist of public keys. So, what we do is to explicitely construct the object returned by key, since we know the types of every values involved. This is more explicit, and at the same time, much faster. Also, we propagate the options for elements of type list. This is why I had to change the isFieldSet method. In a benchmark I just ran, loading and rendering a large list (200 rows, 7 columns) went from about 2.7s to 0.7s. We still do way too much work, but at least it is much faster...
2017-05-05[FIX] web: DebouncedField: notify changes only when changedAaron Bohy
Before this rev., if you opened a form view with, e.g. a float field, that is unset, and then click on edit, then save, it actually saved the new value for the float field (being 0), whereas it shouldn't do any RPC as nothing changed. This is because the former code couldn't detect if the value "0" in the input is there because the field is still unset or if the user simply set it to 0.
2017-05-04[FIX] web: add translate button for char and text fieldsChristophe Matthieu
The button allowing the user to translate fields (existing in previous versions) was not present.
2017-05-04[REF] web, *: restore views designqsm-odoo
Since the new views merge, a lot of design elements were broken. This was particularly impacting the fields in the editable list view; indeed the editable list view is not using an inline form view anymore so the fields in the list were not properly styled as the LESS was still defined assuming the form view environment (for example the invalid fields were red for o2m fields in form view but not in editable list view even though they got the right CSS class). This commit refactor the LESS following these rules: - No more division of non-layout and layout rules. Dividing LESS rules in x_layout.less and x.less was a mistake. Many rules can be considered to be layout and not layout at the same time, developers always have to switch from one file part to the other, many CSS selectors (and rules!) are duplicated for nothing, ... - Field style is extracted from x_view.less and put in the new fields.less file. As before, the fields_extra.less will contain the rules specific to community so that the enterprise repo can override those by replacing the whole file. - Many classes have been renamed so that o_form_x_y becomes o_x_y as many classes can now be applied outside of form view. These classes should not be used in templates anyway. The commit also changes the DOM of fields so that it is more minimalist (no useless parent div, etc). Input elements are not automatically styled anymore, they have to get the o_input class explicitely. This allows to fix lots of small style bugs of previous versions (required monetary field had not the proper style, readonly m2m tags appeared as editable, ...). This also improves the LESS code. The editable list view should also completely stop flickering on chrome and firefox. The commit also removes the orange outline on list view dirty cells. The commit also removes deprecated static xml, LESS and other code. Notice there are still styles to restore/fix and LESS to improve.
2017-05-04[ADD] web: add Qunit test case for graph widget's tooltipDeepak Geriani
2017-05-02[FIX] web: fix missing idForLabel on some widgetsDavid Monjoie
Widgets which manipulates their dom in _renderEdit were left out from the previous implementation since this processing was done only once when the widget is rendered the first time. If the widget regenerates a new input upon reset for example, then it would lack the idForLabel.
2017-04-28[REF] web: restore editable list views behaviorsqsm-odoo
Since the new views, the editable list view lost some behaviors. These behaviors were indeed implemented in the form controller/renderer but as the new editable list view does not use an inline form view, these behaviors had to be implemented in the basic controller/renderer. For this to work, the list editable renderer had to be changed as it was doing work that should be done by the controller. The problem is even more complex because the x2m fields are using a list renderer but not a list controller. So moving code from the renderer to the controller obviously broke the x2m fields. Right now, the problem is solved by catching renderer events and forwarding new ones to the form controller (which handles the x2m specifically). The initial goal of this commit was to share the validation of records on save. Indeed, the fields were marked as invalid in the form view but not in the list view. Also, before the new views, the editable list view had different behaviors if they were used for a x2m field or not. As these behaviors are making sense, this commit tries to restore them. Basically, what we want is: - When a record is saved (form view save or list view line leaving), the invalid fields are marked (in red), the names of the related fields are notified to the user and the record is not left. - When a record is discarded (form view discard or list view discard), the user is asked to confirm if the record is dirty before making the record readonly. - When a record is discarded, if the record is a new one, then the record should be abandoned (removed as if never existed). In the form view this induces to go back in the history and in the list view, to remove a row. - For x2m fields, the notification of invalid fields is not triggered but the user is instead asked if he wants to discard the changes made to the row (indeed, this replaces the list "Discard" button, as non existent for x2m lists). - ... Saving, discarding, marking the fields as invalid and other behaviors are thus now shared behavior of basic views. The management of the dirty flag has also been moved to the model as it was handle by the controller for the form view but by the renderer for the list view. Now this flag is directly managed in the basic model (the model can have changes thanks to the `_changes` property but not be dirty (this is the case for creations)). This change however created a problem. The view manager is currently keeping asking if there are changes to discard at each action which might lead to leave a dirty record (appswitcher / url change / ...). It however did not discard anything as leaving if the user is ok with it will lead to an implicit discard. However, as the view manager might ask for this discard multiple times by second, the controller was marking the record as not dirty the first time but without discarding the changes. This is more complex to do now, as the dirty state is part of the model and that the renderer should match the model data. To solve this problem, the view manager now actually discard changes explicitely when asked to. Even though this had been optimized to not cause any rerender in some cases where it is not needed, this could cause some performance decreasing. However, this makes some cases more logical (opening the app switcher on a dirty form view then going back to the form view by hitting the "go back" button left the form view untouched although the user asked to discard it). This solution will be improved with the view manager refactoring. This commit is also making use of the `commitChanges` system which had been implemented for HTML fields. Indeed, these fields cannot know about all of their changes, so when hitting the save button, we asked those fields to commit their value. Using this system is a great way to make the `isValid` method of x2m fields synchronous. Indeed, before this commit, the method was sometimes asking the user if he wants to discard an invalid line before save. That case can be handled by the x2m `commitChanges` method: we consider that saving the lines of x2m is an operation that has to be done before considering the save, so we ask all the x2m fields to do so at that time. Also, the system was broken since a recent commit: we indeed protected the changes - save order with a mutex but unfortunately, the `commitChanges` method was part of the save and the changes it triggered were not able to be considered because of this mutex. This had not been detected by tests as there is not current way to test html fields.
2017-04-28[FIX] web: prevent record creation in M2O with option {'no_create': True}Christophe Matthieu
before this fix, if you enter a random string and exit focus you'll be prompted to create it.
2017-04-27[FIX] web: BasicField: use `getSession`Martin Geubelle
`session` is not an field widget attribute anymore. One should use `getSession` instead. This commit also introduces tests for the `binary` field.
2017-04-24[FIX] hr_holidays,web: proper use of toggle_boolean in list viewGéry Debongnie
hr_holiday was the only module that used a widget=toggle_boolean on a button in a list view. That behaviour was implemented as a column widget in the previous list view, and was not reimplemented in the new views. The feature is useful, but this was not done properly: it is better to use a widget on a field (that was the intent) instead of doing a weird hack like it was done. With this commit, we update hr_holidays to use the ToggleBoolean widget, which is supposed to work on every views. Also, we fix the toggleboolean widget (it was not properly rendering tooltips, and changes were not saved in readonly list view). Note that it as the side effect of being better from the point of rpcs: before, the list view had to reload itself. Also, another advantage is that models do not need to implement custom methods (such as toggle_payslip_status) just to toggle a boolean...
2017-04-21[FIX] web: look for nolabel in attributes rather than optionsDavid Monjoie
2017-04-20[FIX] web: allow virtual ids for integer fieldsChristophe Matthieu
Before this change, the redering throw an exception when we try to open a form view with a virtual id. eg: recurrent event in calendar
2017-04-20[FIX] web: JournalDashboardGraph: empty $el at rerenderingAaron Bohy
The '_render' function of field widgets can be called several times in the widget's life cycle (each time its value changes). The JournalDashboardGraph appends a new 'svg' to its the $el at each rendering, so it must empty its $el at the beginning of each rendering. Before this fix, several graphs were displayed in the same kanban card in the Sales dashboard when, e.g., the user changed the color of the card.
2017-04-20[FIX] web: AceEditor tests: don't try to remove libsAaron Bohy
... to clean up once the test is finished, because it doesn't work. The previous solution to clean up only deleted ace and require from window, but doing this didn't force a reload of the libs for a potential second test using ace (because the scripts were still in the page). Trying to remove the scripts from the page doesn't work either because the loadJS function uses an internal cache to prevent from loading twice the same lib. So if we want to have more than one test on ace, we can't clean up the libs.
2017-04-19[FIX] web: use correct timezone for date fieldsChristophe Matthieu
before this commit when toggling allday flag in calendar form view, it was possible to have one day error. The input datetime is wrong when the user don't use the datepicker widget (insert date by keypress instead of click on datepicker) sometimes, the value could be null (crash because try to clone false)
2017-04-19[REF] web, *: implement modifiers behaviorsqsm-odoo
* account, mail, sale Since the views refactoring, modifiers were not properly handled anymore (readonly/required not recomputed, use of readonly/required of "python field" instead of "view field", ...). This commit tries to implement a system which allows to handle the modifiers (re)computation the same way for all the basic views. For this to work, many specialized renderers behaviors have been moved to the basic renderer so that more mechanisms are shared (especially by the form renderer and the list editable renderer). The list editable renderer is hugely impacted by this commit. Here is a list of key changes: - The basic renderer now has a `_renderFieldWidget` function which is used without modification by the form and the list renderers. - Modifiers have to be registered thanks to the basic renderer `_registerModifiersData` function (this is done automatically for fields by the `_renderFieldWidget` function for example). - All instantiated widgets are accessible, organized by record, and ordered in a special basic renderer variable. - The code which resets the widgets of the form view and the code which updates the row of a list editable view is now shared in the basic renderer and now also automatically updates the DOM according to the reevaluated modifiers. - The last point has an huge impact on list editable renderer: all the widgets have to be instantiated when editing a row (even readonly and invisible ones) as they can be switched to editable/visible during edition (after a modifiers update). - `replace_element` and `readonly` options of `AbstractField` are useless: widgets are now always replacing the list editable cells in edition and the `readonly` widget mechanism is replaced by the notion of 'focusable' widgets. (see `AbstractField.getFocusableElement`) - The 'tab' navigation mechanism is impacted by the previous point, some code sharing have been done in basic renderer for this too. - `AbstractField` does not care anymore of the 'required' status, this is the view responsability to check that a required field has a set value on save. - Some list editable bug fixing (e.g. it was possible to edit multiple rows at the same time, it was not possible to navigate towards the previous field, crash on o2m add an item click, ...) - The mockserver now properly simulates server modifiers computation. - ... Note: list editable style may be worse than before this commit but a CSS update is coming in a few days.
2017-04-18[FIX] web: date_picker empty input fieldPierre Masereel
When you try to empty a date or datetime field, you get a traceback saying that 'clone' and 'isSame' are not functions. This error occurs when you empty the field because the value is 'false' and you cannot call 'clone' or 'isSame' on false. To fix this, we ensure that value is not false before calling these methods on it. This bug has been introduced in rev: https://github.com/odoo/odoo/commit/c32724eae06c987e74a0600f1669696e499edc33
2017-04-13[FIX] web: calendar timezone with user configurationChristophe Matthieu
The client must receive the tzOffset to apply this on all hours. To use the date picker we must change the date to apply the change in the user's tzOffset, without this change the result is wrong. For datetime widget we must change like it to avoid max stack error. The server send the tzOffset, if it's undefined, by default the client use the browser time offset. Every test are change to use tzOffset. A test is added in calendar to use the click by position for the fullcalendar lib. This test create and drag and drop an event to check timezone error and error when we use default value in the context. Use formating date like 2026-04-04T08:00:00Z instead of 2026-04-04 08:00:00 is important for phantomjs, because it's crash without information if the formating is not the standard format. For the parsing, when the client receive a server date the date is utc formating but when it's parsed from the client is in the user's timezone
2017-04-11[REF] account, web, web_diagram: rename static test folderGéry Debongnie
For consistency, every static test folder should be named 'tests', with a s.