summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/toaster/toastergui/static/js
diff options
context:
space:
mode:
authorMichael Wood <michael.g.wood@intel.com>2016-02-02 17:46:31 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2016-02-10 13:29:21 +0000
commit0fee829932fe0263bdc0b61cd3546743e726a2d7 (patch)
tree439220a7d6e6a4ffac7055fc05b7c40979ed79e9 /bitbake/lib/toaster/toastergui/static/js
parentcb6d290d0b93e0f6673d315075152fcef8a4b416 (diff)
downloadpoky-0fee829932fe0263bdc0b61cd3546743e726a2d7.tar.gz
bitbake: toaster: newcustomimage_modal add frontend name validation
Add front end handling of validation response from create new CustomImageRecipe api. (Bitbake rev: eff66b502df8e001cd0abc25bcbd742687169619) Signed-off-by: Michael Wood <michael.g.wood@intel.com> Signed-off-by: brian avery <avery.brian@gmail.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/toaster/toastergui/static/js')
-rw-r--r--bitbake/lib/toaster/toastergui/static/js/newcustomimage_modal.js37
1 files changed, 32 insertions, 5 deletions
diff --git a/bitbake/lib/toaster/toastergui/static/js/newcustomimage_modal.js b/bitbake/lib/toaster/toastergui/static/js/newcustomimage_modal.js
index 16e42b3d27..0b9d31aa6c 100644
--- a/bitbake/lib/toaster/toastergui/static/js/newcustomimage_modal.js
+++ b/bitbake/lib/toaster/toastergui/static/js/newcustomimage_modal.js
@@ -5,24 +5,51 @@ function newCustomImageModalInit(){
5 5
6 var newCustomImgBtn = $("#create-new-custom-image-btn"); 6 var newCustomImgBtn = $("#create-new-custom-image-btn");
7 var imgCustomModal = $("#new-custom-image-modal"); 7 var imgCustomModal = $("#new-custom-image-modal");
8 var invalidNameHelp = $("#invalid-name-help");
9 var nameInput = imgCustomModal.find('input');
10
11 var invalidMsg = "Image names cannot contain spaces or capital letters. The only allowed special character is dash (-).";
8 12
9 newCustomImgBtn.click(function(e){ 13 newCustomImgBtn.click(function(e){
10 e.preventDefault(); 14 e.preventDefault();
11 15
12 var name = imgCustomModal.find('input').val();
13 var baseRecipeId = imgCustomModal.data('recipe'); 16 var baseRecipeId = imgCustomModal.data('recipe');
14 17
15 if (name.length > 0) { 18 if (nameInput.val().length > 0) {
16 imgCustomModal.modal('hide'); 19 libtoaster.createCustomRecipe(nameInput.val(), baseRecipeId,
17 libtoaster.createCustomRecipe(name, baseRecipeId, function(ret) { 20 function(ret) {
18 if (ret.error !== "ok") { 21 if (ret.error !== "ok") {
19 console.warn(ret.error); 22 console.warn(ret.error);
23 if (ret.error === "invalid-name") {
24 showError(invalidMsg);
25 } else if (ret.error === "already-exists") {
26 showError("An image with this name already exists. Image names must be unique.");
27 }
20 } else { 28 } else {
29 imgCustomModal.modal('hide');
21 window.location.replace(ret.url + '?notify=new'); 30 window.location.replace(ret.url + '?notify=new');
22 } 31 }
23 }); 32 });
33 }
34 });
35
36 function showError(text){
37 invalidNameHelp.text(text);
38 invalidNameHelp.show();
39 }
40
41 nameInput.on('keyup', function(){
42 if (nameInput.val().length === 0){
43 newCustomImgBtn.prop("disabled", true);
44 return
45 }
46
47 if (nameInput.val().search(/[^a-z|0-9|-]/) != -1){
48 showError(invalidMsg);
49 newCustomImgBtn.prop("disabled", true);
24 } else { 50 } else {
25 console.warn("TODO No name supplied"); 51 invalidNameHelp.hide();
52 newCustomImgBtn.prop("disabled", false);
26 } 53 }
27 }); 54 });
28} 55}