diff options
| author | Géry Debongnie <ged@odoo.com> | 2017-05-29 11:22:26 +0200 |
|---|---|---|
| committer | Géry Debongnie <ged@odoo.com> | 2017-05-29 12:12:45 +0200 |
| commit | bbf724e4012e983d56bea27b66caa204294ebda6 (patch) | |
| tree | 43117d5e2859f401b63061241e7053f2fdb5790b /addons/web/static/src | |
| parent | cad943d035c200cce4a7e5a428d2883bf2452b9d (diff) | |
[FIX] web: properly support password attribute for fields
With the new views, the special attribute password was no longer
supported. We simply reintroduce in this commit proper support to
display password fields with *.
Note: we may want to display passwords with a static number of *, but
this requires some thoughts on the usability of the change. We simply
reintroduce the previous behaviour here.
Diffstat (limited to 'addons/web/static/src')
| -rw-r--r-- | addons/web/static/src/js/fields/basic_fields.js | 3 | ||||
| -rw-r--r-- | addons/web/static/src/js/fields/field_utils.js | 14 | ||||
| -rw-r--r-- | addons/web/static/src/js/views/list/list_renderer.js | 1 |
3 files changed, 16 insertions, 2 deletions
diff --git a/addons/web/static/src/js/fields/basic_fields.js b/addons/web/static/src/js/fields/basic_fields.js index 3f279eeeec7..cdaed1d7b4f 100644 --- a/addons/web/static/src/js/fields/basic_fields.js +++ b/addons/web/static/src/js/fields/basic_fields.js @@ -165,6 +165,7 @@ var InputField = DebouncedField.extend({ */ init: function () { this._super.apply(this, arguments); + this.nodeOptions.isPassword = 'password' in this.attrs; if (this.mode === 'edit') { this.tagName = 'input'; } @@ -222,7 +223,7 @@ var InputField = DebouncedField.extend({ this.$input = $input || $("<input/>"); this.$input.addClass('o_input'); this.$input.attr({ - type: 'text', + type: this.nodeOptions.isPassword ? 'password' : 'text', placeholder: this.attrs.placeholder || "", }); this.$input.val(this._formatValue(this.value)); diff --git a/addons/web/static/src/js/fields/field_utils.js b/addons/web/static/src/js/fields/field_utils.js index 0606af0d662..75403c288e5 100644 --- a/addons/web/static/src/js/fields/field_utils.js +++ b/addons/web/static/src/js/fields/field_utils.js @@ -56,10 +56,15 @@ function formatBoolean(value) { * a description of the field (note: this parameter is ignored) * @param {Object} [options] additional options * @param {boolean} [options.escape=false] if true, escapes the formatted value + * @param {boolean} [options.isPassword=false] if true, returns '********' + * instead of the formatted value * @returns {string} */ function formatChar(value, field, options) { value = typeof value === 'string' ? value : ''; + if (options && options.isPassword) { + return _.str.repeat('*', value ? value.length : 0); + } if (options && options.escape) { value = _.escape(value); } @@ -177,9 +182,16 @@ function formatFloatTime(value) { * return an empty string. * * @param {integer|false} value + * @param {Object} [field] + * a description of the field (note: this parameter is ignored) + * @param {Object} [options] additional options + * @param {boolean} [options.isPassword=false] if true, returns '********' * @returns {string} */ -function formatInteger(value) { +function formatInteger(value, field, options) { + if (options && options.isPassword) { + return _.str.repeat('*', String(value).length); + } if (!value && value !== 0) { // previously, it returned 'false'. I don't know why. But for the Pivot // view, I want to display the concept of 'no value' with an empty diff --git a/addons/web/static/src/js/views/list/list_renderer.js b/addons/web/static/src/js/views/list/list_renderer.js index 059e2aeccad..e589c0d430a 100644 --- a/addons/web/static/src/js/views/list/list_renderer.js +++ b/addons/web/static/src/js/views/list/list_renderer.js @@ -254,6 +254,7 @@ var ListRenderer = BasicRenderer.extend({ var formattedValue = field_utils.format[field.type](value, field, { data: record.data, escape: true, + isPassword: 'password' in node.attrs, }); return $td.html(formattedValue); }, |
