From 2adc9d50321d58fa7f33a0231a5594d338a3ffa4 Mon Sep 17 00:00:00 2001 From: Jigar Patel Date: Tue, 9 May 2017 15:02:17 +0530 Subject: [IMP] account: Add a new boolean_favorite widget Purpose ======= Projects and soon sales teams have a manual "favorite" button that calls a toggle_favorite method It should actually be a widget on a boolean field Specifications ============== Develop a favorite widget for kanban view that allows to toggle a boolean field Probably update boolean field to allow inverse method on it Functionally nothing changed. --- addons/web/static/src/js/fields/basic_fields.js | 53 +++++++++++++++++++++++++ 1 file changed, 53 insertions(+) (limited to 'addons/web/static/src/js/fields/basic_fields.js') diff --git a/addons/web/static/src/js/fields/basic_fields.js b/addons/web/static/src/js/fields/basic_fields.js index 2de5a73802d..2d18a0ddb56 100644 --- a/addons/web/static/src/js/fields/basic_fields.js +++ b/addons/web/static/src/js/fields/basic_fields.js @@ -1449,6 +1449,58 @@ var StateSelectionWidget = AbstractField.extend({ }, }); +var FavoriteWidget = AbstractField.extend({ + className: 'o_favorite', + events: { + 'click': '_setFavorite' + }, + supportedFieldTypes: ['boolean'], + + //-------------------------------------------------------------------------- + // Public + //-------------------------------------------------------------------------- + + /** + * A boolean field is always set since false is a valid value. + * + * @override + */ + isSet: function () { + return true; + }, + + //-------------------------------------------------------------------------- + // Private + //-------------------------------------------------------------------------- + + /** + * Render favorite icon based on state + * + * @override + * @private + */ + _render: function () { + var template = this.attrs.nolabel ? '' : ' %s'; + this.$el.empty().append(_.str.sprintf(template, this.value ? 'fa-star' : 'fa-star-o', this.value ? _t('Remove from Favorites') : _t('Add to Favorites'))); + }, + + //-------------------------------------------------------------------------- + // Handlers + //-------------------------------------------------------------------------- + + /** + * Toggle favorite state + * + * @private + * @param {MouseEvent} event + */ + _setFavorite: function (event) { + event.preventDefault(); + event.stopPropagation(); + this._setValue(!this.value); + }, +}); + var LabelSelection = AbstractField.extend({ supportedFieldTypes: ['selection'], @@ -2350,6 +2402,7 @@ return { AttachmentImage: AttachmentImage, LabelSelection: LabelSelection, StateSelectionWidget: StateSelectionWidget, + FavoriteWidget: FavoriteWidget, PriorityWidget: PriorityWidget, StatInfo: StatInfo, UrlWidget: UrlWidget, -- cgit v1.2.3