summaryrefslogtreecommitdiffstats
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
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>
-rw-r--r--bitbake/lib/toaster/toastergui/static/js/newcustomimage_modal.js37
-rw-r--r--bitbake/lib/toaster/toastergui/templates/newcustomimage_modal.html7
2 files changed, 35 insertions, 9 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}
diff --git a/bitbake/lib/toaster/toastergui/templates/newcustomimage_modal.html b/bitbake/lib/toaster/toastergui/templates/newcustomimage_modal.html
index 93cf9d7e02..fed489fad9 100644
--- a/bitbake/lib/toaster/toastergui/templates/newcustomimage_modal.html
+++ b/bitbake/lib/toaster/toastergui/templates/newcustomimage_modal.html
@@ -22,12 +22,11 @@
22 <span class="help-block span8">Image names must be unique. They should not contain spaces or capital letters, and the only allowed special character is dash (-).<p></p> 22 <span class="help-block span8">Image names must be unique. They should not contain spaces or capital letters, and the only allowed special character is dash (-).<p></p>
23 </span></div> 23 </span></div>
24 <div class="control-group controls"> 24 <div class="control-group controls">
25 <input type="text" class="huge span5" placeholder="Type the name, something like 'core-image-myimage'"> 25 <input type="text" class="huge span5" placeholder="Type the name, something like 'core-image-myimage'" required>
26 <span class="help-block" style="display:none">Image names cannot contain spaces or capital letters. The only allowed special character is dash (-)</span> 26 <span class="help-block error" id="invalid-name-help" style="display:none"></span>
27 <span class="help-block" style="display: none">An image with this name already exists. Image names must be unique: try a different one.</span>
28 </div> 27 </div>
29 </div> 28 </div>
30 <div class="modal-footer"> 29 <div class="modal-footer">
31 <a href="#" id="create-new-custom-image-btn" class="btn btn-primary btn-large" data-original-title="" title="">Create custom image</a> 30 <button id="create-new-custom-image-btn" class="btn btn-primary btn-large" data-original-title="" title="" disabled>Create custom image</button>
32 </div> 31 </div>
33</div> 32</div>