Return-Path: Received: by yocto-www.yoctoproject.org (Postfix, from userid 118) id 294D3E006D2; Mon, 9 May 2016 08:27:40 -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=-2.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 X-Spam-HAM-Report: * -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low * trust * [74.125.82.50 listed in list.dnswl.org] * -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% * [score: 0.0000] * 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily * valid * -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature Received: from mail-wm0-f50.google.com (mail-wm0-f50.google.com [74.125.82.50]) by yocto-www.yoctoproject.org (Postfix) with ESMTP id 62854E004F1 for ; Mon, 9 May 2016 08:27:37 -0700 (PDT) Received: by mail-wm0-f50.google.com with SMTP id n129so142846210wmn.1 for ; Mon, 09 May 2016 08:27:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=FeeAyazQGi+HNXEMK48RO5wRSu6aGt81mgdUvw8cFLo=; b=pvZxFa6RoYt1AA7AN5B1ROYKgq3arEm1PJRotKdLPDLwAgpgOiuGL4lQL2Jssnzchj UGUN5XFA4SUyDuOVGURqv0yLRRwOxWGc53TCwwTcmnP0UIUNk7ELavLA8qOW5YSXC8S0 WuNbXT8tq6bY1JUN/BFPOc1uusXv9hO4ediI6V/FKq4v9+8rEF0GpzYqZRmRY/QkU3zl DLd6imI7/WX/STE4poHPsdd6UI9D4kSYBKYv1PWSyA/vCCmMtn+z0htwTGtkScHFOwMW 1xYBh24CbPc2fuVAYRqw8GKPIJgFV7AgF1EX3nJCLDDoFakJSGsiXhWDlsNerJoQjr4z 67Wg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=FeeAyazQGi+HNXEMK48RO5wRSu6aGt81mgdUvw8cFLo=; b=RmlLJiiDPr+HzaJvB+dOBnc7Q0iJuEPaYZFTRktdyM2s++CR+qtJRfRiY8T2mBcG0O stiKIT+jO96EiWbdx/7fiQnpbJARcm4pnJykfKsAjUXi66hNVfTHnDTRjPbO4C8bf12a k0lhzhoVn1Jo9MbWCHrXgHrqsveavP2aIF9rqXzqgQw7XvGfj/kBxPZHXuLToB+O+vfs +K0vWebXM43uWjZMm3xtMatP3yPfydUILA2iP38PoNSsIIeY1h+CDh5d/X3ng1EOqGOk vIpFI7Soyo5yM26AFRg/rzZXITHkyI9+CYFJ6DZqMEaDbs67u1ViY6kkeOnNlcXOUFpS mjEQ== X-Gm-Message-State: AOPr4FUQXZruSF4WaudEd/OHpAibbTIUZVhPTsp/FIfw8E5+MjsxKhngYnHpEjNDZQDyTwYa X-Received: by 10.28.111.14 with SMTP id k14mr12111817wmc.32.1462807656474; Mon, 09 May 2016 08:27:36 -0700 (PDT) Received: from orion.home (host109-151-244-175.range109-151.btcentralplus.com. [109.151.244.175]) by smtp.gmail.com with ESMTPSA id b15sm25192732wmd.1.2016.05.09.08.27.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 09 May 2016 08:27:36 -0700 (PDT) From: Michael Wood To: toaster@yoctoproject.org Date: Mon, 9 May 2016 16:27:27 +0100 Message-Id: <1462807651-16627-2-git-send-email-michael.g.wood@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1462807651-16627-1-git-send-email-michael.g.wood@intel.com> References: <1462807651-16627-1-git-send-email-michael.g.wood@intel.com> Subject: [PATCH 1/5] toaster: projectNameValidation API added 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: Mon, 09 May 2016 15:27:40 -0000 From: Sujith H The projectNameValidation API would help users to validate if a project name exists or not. This API is added to libtoaster. [YOCTO #7005] Signed-off-by: Sujith H --- .../lib/toaster/toastergui/static/js/libtoaster.js | 62 ++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/bitbake/lib/toaster/toastergui/static/js/libtoaster.js b/bitbake/lib/toaster/toastergui/static/js/libtoaster.js index 43930a2..0d1486b 100644 --- a/bitbake/lib/toaster/toastergui/static/js/libtoaster.js +++ b/bitbake/lib/toaster/toastergui/static/js/libtoaster.js @@ -374,6 +374,67 @@ var libtoaster = (function (){ }); } + /* Validate project names. Use unique project names + + All arguments accepted by this function are JQeury objects. + + For example if the HTML element has "hint-error-project-name", then + it is passed to this function as $("#hint-error-project-name"). + + Arg1 - projectName : This is a string object. In the HTML, project name will be entered here. + Arg2 - hintEerror : This is a jquery object which will accept span which throws error for + duplicate project + Arg3 - ctrlGrpValidateProjectName : This object holds the div with class "control-group" + Arg4 - enableOrDisableBtn : This object will help the API to enable or disable the form. + For example in the new project the create project button will be hidden if the + duplicate project exist. Similarly in the projecttopbar the save button will be + disabled if the project name already exist. + + Return - This function doesn't return anything. It sets/unsets the behavior of the elements. + */ + + function _makeProjectNameValidation(projectName, hintError, + ctrlGrpValidateProjectName, enableOrDisableBtn ) { + + function checkProjectName(projectName){ + $.ajax({ + type: "GET", + url: libtoaster.ctx.projectsTypeAheadUrl, + data: { 'search' : projectName }, + headers: { 'X-CSRFToken' : $.cookie('csrftoken')}, + success: function(data){ + if (data.results.length > 0 && + data.results[0].name === projectName) { + // This project name exists hence show the error and disable + // the save button + ctrlGrpValidateProjectName.addClass('control-group error'); + hintError.show(); + enableOrDisableBtn.attr('disabled', 'disabled'); + } else { + ctrlGrpValidateProjectName.removeClass('control-group error'); + hintError.hide(); + enableOrDisableBtn.removeAttr('disabled'); + } + }, + error: function (data) { + console.log(data); + }, + }); + } + + /* The moment user types project name remove the error */ + projectName.on("input", function() { + var projectName = $(this).val(); + checkProjectName(projectName) + }); + + /* Validate new project name */ + projectName.on("blur", function(){ + var projectName = $(this).val(); + checkProjectName(projectName) + }); + } + return { reload_params : reload_params, @@ -390,6 +451,7 @@ var libtoaster = (function (){ makeLayerAddRmAlertMsg : _makeLayerAddRmAlertMsg, showChangeNotification : _showChangeNotification, createCustomRecipe: _createCustomRecipe, + makeProjectNameValidation: _makeProjectNameValidation, }; })(); -- 2.7.4