summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/toaster/toastergui/static/js/newcustomimage_modal.js
diff options
context:
space:
mode:
Diffstat (limited to 'bitbake/lib/toaster/toastergui/static/js/newcustomimage_modal.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}