From 4c2be6b2c572a833a1f3185c6a36743417331cd7 Mon Sep 17 00:00:00 2001 From: Pierre Goiffon Date: Mon, 8 Oct 2018 18:29:45 +0200 Subject: [PATCH] =?UTF-8?q?N=C2=B0931=20AttributeTagSet=20widget=20js=20wr?= =?UTF-8?q?apper=20:=20partial=20values=20can=20now=20be=20added=20with=20?= =?UTF-8?q?just=20a=20click?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- js/jquery.itop-set-widget.js | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/js/jquery.itop-set-widget.js b/js/jquery.itop-set-widget.js index b9e31c000..24a0e90be 100644 --- a/js/jquery.itop-set-widget.js +++ b/js/jquery.itop-set-widget.js @@ -66,6 +66,7 @@ $.widget('itop.set_widget', PARENT_CSS_CLASS: "attribute-set", ITEM_CSS_CLASS: "attribute-set-item", + ITEM_PARTIAL_CSS_CLASS: "partial-code", POSSIBLE_VAL_KEY: 'possible_values', PARTIAL_VAL_KEY: "partial_values", @@ -176,6 +177,11 @@ $.widget('itop.set_widget', setWidget.enable(); } }); + + console.debug("bindEvents", setWidget.selectizeWidget); + setWidget.selectizeWidget.$control.on('click', '.attribute-set-item.partial-code', function () { + setWidget._onTagPartialClick(setWidget, this); + }) }, refresh: function () { @@ -246,7 +252,7 @@ $.widget('itop.set_widget', $item.addClass(setWidget.ITEM_CSS_CLASS + '-' + setItemCode); // no escape as codes are already pretty restrictive if (setWidget._isCodeInPartialValues(setItemCode)) { - inputWidget.getItem(setItemCode).addClass("partial-code"); + inputWidget.getItem(setItemCode).addClass(setWidget.ITEM_PARTIAL_CSS_CLASS); } }); }, @@ -258,7 +264,7 @@ $.widget('itop.set_widget', this.setItemsCodesStatus[setItemCode] = this.STATUS_ADDED; if (this._isCodeInPartialValues(setItemCode)) { - this.partialValues = this.partialValues.filter(item => (item !== setItemCode)); + this._partialCodeRemove(setItemCode); } else { if (this.originalValue.indexOf(setItemCode) !== -1) { // do not add if was present initially and removed @@ -286,6 +292,24 @@ $.widget('itop.set_widget', this.refresh(); }, + _onTagPartialClick: function (setWidget, inputWidgetItemNode) { + if (setWidget.options.isDebug) { + console.debug("onTagPartialClick", setWidget, inputWidgetItemNode); + } + if (setWidget.selectizeWidget.isDisabled) { + return; + } + + var partialCodeClicked = $(inputWidgetItemNode).data("value"); + this._onTagAdd(partialCodeClicked, $(inputWidgetItemNode), setWidget.selectizeWidget); + + $(inputWidgetItemNode).removeClass(setWidget.ITEM_PARTIAL_CSS_CLASS); + }, + + _partialCodeRemove: function (setItemCode) { + this.partialValues = this.partialValues.filter(item => (item !== setItemCode)); + }, + _isCodeInPartialValues: function (setItemCode) { return (this.partialValues.indexOf(setItemCode) >= 0); }