diff options
| author | Alexandre Kühn <alexkuhn@users.noreply.github.com> | 2017-11-20 10:47:43 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-11-20 10:47:43 +0100 |
| commit | 23e6dd36d7477f13fe42fdcaae890ffb690d05a4 (patch) | |
| tree | e797dc6b2a29d4d106c86dd937761c405399e4f4 /addons/web/static/src/js/fields/relational_fields.js | |
| parent | 7d2666d020215d8d8fe36c32f4a8e049e5d7915c (diff) | |
[IMP] web: hide in kanban tag's color (#20815)
New feature:
- New Transparent tag visual (grey border & text, white bg),
- By default, newly created kanban tags are transparent,
- Tag's colorpicker has now a 'Hide in Kanban' checkbox,
to select the transparent color.
Toggling off 'Hide in Kanban' sets the color of the tag as follow:
- Previous color, if 'Hide in Kanban' was toggled on on the
same formview session.
- Color 1 (dark orange), otherwise.
Diffstat (limited to 'addons/web/static/src/js/fields/relational_fields.js')
| -rw-r--r-- | addons/web/static/src/js/fields/relational_fields.js | 55 |
1 files changed, 38 insertions, 17 deletions
diff --git a/addons/web/static/src/js/fields/relational_fields.js b/addons/web/static/src/js/fields/relational_fields.js index 6f775e789d4..f9ed847cefc 100644 --- a/addons/web/static/src/js/fields/relational_fields.js +++ b/addons/web/static/src/js/fields/relational_fields.js @@ -1703,6 +1703,7 @@ var FormFieldMany2ManyTags = FieldMany2ManyTags.extend({ events: _.extend({}, FieldMany2ManyTags.prototype.events, { 'click .badge': '_onOpenColorPicker', 'mousedown .o_colorpicker a': '_onUpdateColor', + 'mousedown .o_colorpicker .o_hide_in_kanban': '_onUpdateColor', 'focusout .o_colorpicker': '_onCloseColorPicker', }), @@ -1713,43 +1714,63 @@ var FormFieldMany2ManyTags = FieldMany2ManyTags.extend({ /** * @private */ - _onCloseColorPicker: function (){ + _onCloseColorPicker: function () { this.$color_picker.remove(); }, /** * @private - * @param {MouseEvent} event + * @param {MouseEvent} ev */ - _onOpenColorPicker: function (event) { - var tag_id = $(event.currentTarget).data('id'); - var tag = _.findWhere(this.value.data, { res_id: tag_id }); + _onOpenColorPicker: function (ev) { + var tagID = $(ev.currentTarget).data('id'); + var tagColor = $(ev.currentTarget).data('color'); + var tag = _.findWhere(this.value.data, { res_id: tagID }); if (tag && this.colorField in tag.data) { // if there is a color field on the related model this.$color_picker = $(qweb.render('FieldMany2ManyTag.colorpicker', { 'widget': this, - 'tag_id': tag_id, + 'tag_id': tagID, })); - $(event.currentTarget).append(this.$color_picker); + $(ev.currentTarget).append(this.$color_picker); this.$color_picker.dropdown('toggle'); this.$color_picker.attr("tabindex", 1).focus(); + if (!tagColor) { + this.$('.o_checkbox input').prop('checked', true); + } } }, /** + * Update color based on target of ev + * either by clicking on a color item or + * by toggling the 'Hide in Kanban' checkbox. + * * @private - * @param {MouseEvent} event + * @param {MouseEvent} ev */ - _onUpdateColor: function (event) { - event.preventDefault(); - var self = this; - var color = $(event.currentTarget).data('color'); - var id = $(event.currentTarget).data('id'); - var tag = self.$("span.badge[data-id='" + id + "']"); - var current_color = tag.data('color'); + _onUpdateColor: function (ev) { + ev.preventDefault(); + var $target = $(ev.currentTarget); + var color = $target.data('color'); + var id = $target.data('id'); + var tag = this.$("span.badge[data-id='" + id + "']"); + var currentColor = tag.data('color'); + var changes = {}; - if (color === current_color) { return; } + if ($target.is('.o_hide_in_kanban')) { + var $checkbox = $('.o_hide_in_kanban .o_checkbox input'); + $checkbox.prop('checked', !$checkbox.prop('checked')); // toggle checkbox + this.prevColors = this.prevColors ? this.prevColors : {}; + if ($checkbox.is(':checked')) { + this.prevColors[id] = currentColor + } else { + color = this.prevColors[id] ? this.prevColors[id] : 1; + } + } else if ($target.is('[class^="o_tag_color"]')) { // $target.is('o_tag_color_') + if (color === currentColor) { return; } + } - var changes = {}; changes[this.colorField] = color; + this.trigger_up('field_changed', { dataPointID: _.findWhere(this.value.data, {res_id: id}).id, changes: changes, |
