summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/toaster/toastergui/static/js/importlayer.js
diff options
context:
space:
mode:
Diffstat (limited to 'bitbake/lib/toaster/toastergui/static/js/importlayer.js')
-rw-r--r--bitbake/lib/toaster/toastergui/static/js/importlayer.js125
1 files changed, 114 insertions, 11 deletions
diff --git a/bitbake/lib/toaster/toastergui/static/js/importlayer.js b/bitbake/lib/toaster/toastergui/static/js/importlayer.js
index 2f59567133..191b30ffee 100644
--- a/bitbake/lib/toaster/toastergui/static/js/importlayer.js
+++ b/bitbake/lib/toaster/toastergui/static/js/importlayer.js
@@ -10,6 +10,7 @@ function importLayerPageInit (ctx) {
10 var layerDepInput = $("#layer-dependency"); 10 var layerDepInput = $("#layer-dependency");
11 var layerNameCtrl = $("#layer-name-ctrl"); 11 var layerNameCtrl = $("#layer-name-ctrl");
12 var duplicatedLayerName = $("#duplicated-layer-name-hint"); 12 var duplicatedLayerName = $("#duplicated-layer-name-hint");
13 var localDirPath = $("#local-dir-path");
13 14
14 var layerDeps = {}; 15 var layerDeps = {};
15 var layerDepsDeps = {}; 16 var layerDepsDeps = {};
@@ -35,6 +36,9 @@ function importLayerPageInit (ctx) {
35 } 36 }
36 }); 37 });
37 38
39 // Disable local dir repo when page is loaded.
40 $('#local-dir').hide();
41
38 // disable the "Add layer" button when the layer input typeahead is empty 42 // disable the "Add layer" button when the layer input typeahead is empty
39 // or not in the typeahead choices 43 // or not in the typeahead choices
40 layerDepInput.on("input change", function () { 44 layerDepInput.on("input change", function () {
@@ -168,8 +172,16 @@ function importLayerPageInit (ctx) {
168 dir_path: $("#layer-subdir").val(), 172 dir_path: $("#layer-subdir").val(),
169 project_id: libtoaster.ctx.projectId, 173 project_id: libtoaster.ctx.projectId,
170 layer_deps: layerDepsCsv, 174 layer_deps: layerDepsCsv,
175 local_source_dir: $('#local-dir-path').val(),
171 }; 176 };
172 177
178 if ($('input[name=repo]:checked').val() == "git") {
179 layerData.local_source_dir = "";
180 } else {
181 layerData.vcs_url = "";
182 layerData.git_ref = "";
183 }
184
173 $.ajax({ 185 $.ajax({
174 type: "POST", 186 type: "POST",
175 url: ctx.xhrImportLayerUrl, 187 url: ctx.xhrImportLayerUrl,
@@ -208,25 +220,45 @@ function importLayerPageInit (ctx) {
208 function check_form() { 220 function check_form() {
209 var valid = false; 221 var valid = false;
210 var inputs = $("input:required"); 222 var inputs = $("input:required");
223 var inputStr = inputs.val().split("");
211 224
212 for (var i=0; i<inputs.length; i++){ 225 for (var i=0; i<inputs.val().length; i++){
213 if (!(valid = inputs[i].value)){ 226 if (!(valid = inputStr[i])){
214 enable_import_btn(false); 227 enable_import_btn(false);
215 break; 228 break;
216 } 229 }
217 } 230 }
218 231
219 if (valid) 232 if (valid) {
220 enable_import_btn(true); 233 if ($("#local-dir-radio").prop("checked") && localDirPath.val().length > 0) {
234 enable_import_btn(true);
235 }
236 if ($("#git-repo-radio").prop("checked") && vcsURLInput.val().length > 0 && gitRefInput.val().length > 0) {
237 enable_import_btn(true);
238 }
239 }
240
241 if (inputs.val().length == 0)
242 enable_import_btn(false);
221 } 243 }
222 244
223 function layerExistsError(layer){ 245 function layerExistsError(layer){
224 var dupLayerInfo = $("#duplicate-layer-info"); 246 var dupLayerInfo = $("#duplicate-layer-info");
225 dupLayerInfo.find(".dup-layer-name").text(layer.name);
226 dupLayerInfo.find(".dup-layer-link").attr("href", layer.layerdetailurl);
227 dupLayerInfo.find("#dup-layer-vcs-url").text(layer.vcs_url);
228 dupLayerInfo.find("#dup-layer-revision").text(layer.vcs_reference);
229 247
248 if (layer.local_source_dir) {
249 $("#git-layer-dup").hide();
250 $("#local-layer-dup").fadeIn();
251 dupLayerInfo.find(".dup-layer-name").text(layer.name);
252 dupLayerInfo.find(".dup-layer-link").attr("href", layer.layerdetailurl);
253 dupLayerInfo.find("#dup-local-source-dir-name").text(layer.local_source_dir);
254 } else {
255 $("#git-layer-dup").fadeIn();
256 $("#local-layer-dup").hide();
257 dupLayerInfo.find(".dup-layer-name").text(layer.name);
258 dupLayerInfo.find(".dup-layer-link").attr("href", layer.layerdetailurl);
259 dupLayerInfo.find("#dup-layer-vcs-url").text(layer.vcs_url);
260 dupLayerInfo.find("#dup-layer-revision").text(layer.vcs_reference);
261 }
230 $(".fields-apart-from-layer-name").fadeOut(function(){ 262 $(".fields-apart-from-layer-name").fadeOut(function(){
231 263
232 dupLayerInfo.fadeIn(); 264 dupLayerInfo.fadeIn();
@@ -271,10 +303,13 @@ function importLayerPageInit (ctx) {
271 303
272 if ($("#duplicate-layer-info").css("display") != "None"){ 304 if ($("#duplicate-layer-info").css("display") != "None"){
273 $("#duplicate-layer-info").fadeOut(function(){ 305 $("#duplicate-layer-info").fadeOut(function(){
274 $(".fields-apart-from-layer-name").show(); 306 $(".fields-apart-from-layer-name").show();
275 }); 307 radioDisplay();
308 });
276 309
277 } 310 }
311
312 radioDisplay();
278 313
279 /* Don't remove the error class if we're displaying the error for another 314 /* Don't remove the error class if we're displaying the error for another
280 * reason. 315 * reason.
@@ -301,4 +336,72 @@ function importLayerPageInit (ctx) {
301 } 336 }
302 }); 337 });
303 338
339 function radioDisplay() {
340 if ($('input[name=repo]:checked').val() == "local") {
341 $('#git-repo').hide();
342 $('#import-git-layer-and-add-hint').hide();
343 $('#local-dir').fadeIn();
344 $('#import-local-dir-and-add-hint').fadeIn();
345 } else {
346 $('#local-dir').hide();
347 $('#import-local-dir-and-add-hint').hide();
348 $('#git-repo').fadeIn();
349 $('#import-git-layer-and-add-hint').fadeIn();
350 }
351 }
352
353 $('input:radio[name="repo"]').change(function() {
354 radioDisplay();
355 if ($("#local-dir-radio").prop("checked")) {
356 if (localDirPath.val().length > 0) {
357 enable_import_btn(true);
358 } else {
359 enable_import_btn(false);
360 }
361 }
362 if ($("#git-repo-radio").prop("checked")) {
363 if (vcsURLInput.val().length > 0 && gitRefInput.val().length > 0) {
364 enable_import_btn(true);
365 } else {
366 enable_import_btn(false);
367 }
368 }
369 });
370
371 localDirPath.on('input', function(){
372 if ($(this).val().trim().length == 0) {
373 $('#import-and-add-btn').attr("disabled","disabled");
374 $('#local-dir').addClass('has-error');
375 $('#hintError-dir-abs-path').show();
376 $('#hintError-dir-path-starts-with-slash').show();
377 } else {
378 var input = $(this);
379 var reBeginWithSlash = /^\//;
380 var reCheckVariable = /^\$/;
381 var re = /([ <>\\|":\.%\?\*]+)/;
382
383 var invalidDir = re.test(input.val());
384 var invalidSlash = reBeginWithSlash.test(input.val());
385 var invalidVar = reCheckVariable.test(input.val());
386
387 if (!invalidSlash && !invalidVar) {
388 $('#local-dir').addClass('has-error');
389 $('#import-and-add-btn').attr("disabled","disabled");
390 $('#hintError-dir-abs-path').show();
391 $('#hintError-dir-path-starts-with-slash').show();
392 } else if (invalidDir) {
393 $('#local-dir').addClass('has-error');
394 $('#import-and-add-btn').attr("disabled","disabled");
395 $('#hintError-dir-path').show();
396 } else {
397 $('#local-dir').removeClass('has-error');
398 if (layerNameInput.val().length > 0) {
399 $('#import-and-add-btn').removeAttr("disabled");
400 }
401 $('#hintError-dir-abs-path').hide();
402 $('#hintError-dir-path-starts-with-slash').hide();
403 $('#hintError-dir-path').hide();
404 }
405 }
406 });
304} 407}