summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/toaster
diff options
context:
space:
mode:
Diffstat (limited to 'bitbake/lib/toaster')
-rw-r--r--bitbake/lib/toaster/toastergui/static/js/projecttopbar.js81
1 files changed, 81 insertions, 0 deletions
diff --git a/bitbake/lib/toaster/toastergui/static/js/projecttopbar.js b/bitbake/lib/toaster/toastergui/static/js/projecttopbar.js
new file mode 100644
index 0000000000..b6ad380c19
--- /dev/null
+++ b/bitbake/lib/toaster/toastergui/static/js/projecttopbar.js
@@ -0,0 +1,81 @@
1'use strict';
2
3function projectTopBarInit(ctx) {
4
5 var projectNameForm = $("#project-name-change-form");
6 var projectNameContainer = $("#project-name-container");
7 var projectName = $("#project-name");
8 var projectNameFormToggle = $("#project-change-form-toggle");
9 var projectNameChangeCancel = $("#project-name-change-cancel");
10 var newBuildTargetInput = $("#build-input");
11 var newBuildTargetBuildBtn = $("#build-button");
12 var selectedTarget;
13
14 /* Project name change functionality */
15 projectNameFormToggle.click(function(e){
16 e.preventDefault();
17 projectNameContainer.hide();
18 projectNameForm.fadeIn();
19 });
20
21 projectNameChangeCancel.click(function(e){
22 e.preventDefault();
23 projectNameForm.hide();
24 projectNameContainer.fadeIn();
25 });
26
27 $("#project-name-change-btn").click(function(){
28 var newProjectName = $("#project-name-change-input").val();
29
30 libtoaster.editCurrentProject({ projectName: newProjectName }, function (){
31 projectName.html(newProjectName);
32 libtoaster.ctx.projectName = newProjectName;
33 projectNameChangeCancel.click();
34 });
35 });
36
37 /* Nav bar activate state switcher */
38 $("#project-topbar .nav li a").each(function(){
39 if (window.location.pathname === $(this).attr('href'))
40 $(this).parent().addClass('active');
41 else
42 $(this).parent().removeClass('active');
43 });
44
45 /* Recipe build input functionality */
46 if (ctx.numProjectLayers > 0 && ctx.machine){
47 newBuildTargetInput.removeAttr("disabled");
48 }
49
50 libtoaster.makeTypeahead(newBuildTargetInput,
51 libtoaster.ctx.recipesTypeAheadUrl, {}, function (item) {
52 selectedTarget = item;
53 newBuildTargetBuildBtn.removeAttr("disabled");
54 });
55
56 newBuildTargetInput.on('input', function () {
57 if ($(this).val().length === 0) {
58 newBuildTargetBuildBtn.attr("disabled", "disabled");
59 } else {
60 newBuildTargetBuildBtn.removeAttr("disabled");
61 }
62 });
63
64 newBuildTargetBuildBtn.click(function (e) {
65 e.preventDefault();
66 if (!newBuildTargetInput.val()) {
67 return;
68 }
69 /* We use the value of the input field so as to maintain any command also
70 * added e.g. core-image-minimal:clean and because we can build targets
71 * that toaster doesn't yet know about
72 */
73 selectedTarget = { name: newBuildTargetInput.val() };
74
75 /* Fire off the build */
76 libtoaster.startABuild(libtoaster.ctx.projectBuildsUrl,
77 null, selectedTarget.name, function(){
78 window.location.replace(libtoaster.ctx.projectBuildsUrl);
79 }, null);
80 });
81}