Return-Path: Received: by yocto-www.yoctoproject.org (Postfix, from userid 118) id C0C90E00B8C; Wed, 30 Mar 2016 02:11:04 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on yocto-www.yoctoproject.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 X-Spam-HAM-Report: * -5.0 RCVD_IN_DNSWL_HI RBL: Sender listed at http://www.dnswl.org/, high * trust * [192.55.52.115 listed in list.dnswl.org] * -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% * [score: 0.0000] Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by yocto-www.yoctoproject.org (Postfix) with ESMTP id 7AC17E00852 for ; Wed, 30 Mar 2016 02:11:00 -0700 (PDT) Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga103.fm.intel.com with ESMTP; 30 Mar 2016 02:11:00 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.24,415,1455004800"; d="scan'208";a="677886567" Received: from meskola-mobl3.ger.corp.intel.com (HELO lp.ger.corp.intel.com) ([10.252.26.30]) by FMSMGA003.fm.intel.com with ESMTP; 30 Mar 2016 02:10:59 -0700 From: Elliot Smith To: toaster@yoctoproject.org Date: Wed, 30 Mar 2016 10:10:25 +0100 Message-Id: <1459329025-8619-1-git-send-email-elliot.smith@intel.com> X-Mailer: git-send-email 1.9.3 Subject: [PATCH] toaster: disable/enable "Add layer" button according to input's content X-BeenThere: toaster@yoctoproject.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Web based interface for BitBake List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 30 Mar 2016 09:11:04 -0000 In the import layer page, the "Add layer" button in the layer dependencies section doesn't accurately reflect whether the layer name in the corresponding input can be added. A partial or empty layer name can leave the button active, such that when it is clicked, a previously-selected layer can be accidentally added. Fix by keeping track of the items currently available in the typeahead, only activating the "Add layer" button when the input matches the name of one of those items. [YOCTO #8511] Signed-off-by: Elliot Smith --- .../toaster/toastergui/static/js/importlayer.js | 30 +++++++++++++++++++++- .../lib/toaster/toastergui/static/js/libtoaster.js | 5 ++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/bitbake/lib/toaster/toastergui/static/js/importlayer.js b/bitbake/lib/toaster/toastergui/static/js/importlayer.js index c68f366..5a59799 100644 --- a/bitbake/lib/toaster/toastergui/static/js/importlayer.js +++ b/bitbake/lib/toaster/toastergui/static/js/importlayer.js @@ -18,10 +18,38 @@ function importLayerPageInit (ctx) { libtoaster.makeTypeahead(layerDepInput, libtoaster.ctx.layersTypeAheadUrl, { include_added: "true" }, function(item){ currentLayerDepSelection = item; + }); + + // choices available in the typeahead + var layerDepsChoices = {}; + + // when the typeahead choices change, store an array of the available layer + // choices locally, to use for enabling/disabling the "Add layer" button + layerDepInput.on("typeahead-choices-change", function (event, data) { + layerDepsChoices = {}; - layerDepBtn.removeAttr("disabled"); + if (data.choices) { + data.choices.forEach(function (item) { + layerDepsChoices[item.name] = item; + }); + } }); + // disable the "Add layer" button when the layer input typeahead is empty + // or not in the typeahead choices + layerDepInput.on("input change", function () { + // get the choices from the typeahead + var choice = layerDepsChoices[$(this).val()]; + + if (choice) { + layerDepBtn.removeAttr("disabled"); + currentLayerDepSelection = choice; + } + else { + layerDepBtn.attr("disabled", "disabled"); + currentLayerDepSelection = undefined; + } + }); /* We automatically add "openembedded-core" layer for convenience as a * dependency as pretty much all layers depend on this one diff --git a/bitbake/lib/toaster/toastergui/static/js/libtoaster.js b/bitbake/lib/toaster/toastergui/static/js/libtoaster.js index b6b49b6..0e81f67 100644 --- a/bitbake/lib/toaster/toastergui/static/js/libtoaster.js +++ b/bitbake/lib/toaster/toastergui/static/js/libtoaster.js @@ -21,6 +21,9 @@ var libtoaster = (function (){ var xhrReq; jQElement.typeahead({ + // each time the typeahead's choices change, a + // "typeahead-choices-change" event is fired with an object + // containing the available choices in a "choices" property source: function(query, process){ xhrParams.search = query; @@ -36,6 +39,8 @@ var libtoaster = (function (){ xhrReq = null; + jQElement.trigger("typeahead-choices-change", {choices: data.results}); + return process(data.results); }); }, -- 1.9.3 --------------------------------------------------------------------- Intel Corporation (UK) Limited Registered No. 1134945 (England) Registered Office: Pipers Way, Swindon SN3 1RJ VAT No: 860 2173 47 This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.