summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/toaster/toastergui/static/js/base.js
diff options
context:
space:
mode:
Diffstat (limited to 'bitbake/lib/toaster/toastergui/static/js/base.js')
-rw-r--r--bitbake/lib/toaster/toastergui/static/js/base.js229
1 files changed, 0 insertions, 229 deletions
diff --git a/bitbake/lib/toaster/toastergui/static/js/base.js b/bitbake/lib/toaster/toastergui/static/js/base.js
deleted file mode 100644
index ed22a4ebc1..0000000000
--- a/bitbake/lib/toaster/toastergui/static/js/base.js
+++ /dev/null
@@ -1,229 +0,0 @@
1'use strict';
2
3function basePageInit(ctx) {
4
5 var newBuildButton = $("#new-build-button");
6 var newBuildTargetInput;
7 var newBuildTargetBuildBtn;
8 var projectNameForm = $("#project-name-change-form");
9 var projectNameContainer = $("#project-name-container");
10 var projectName = $("#project-name");
11 var projectNameFormToggle = $("#project-change-form-toggle");
12 var projectNameChangeCancel = $("#project-name-change-cancel");
13
14 /* initially the current project is used unless overridden by the new build
15 * button in top right nav
16 */
17 var selectedProject = libtoaster.ctx;
18
19 var selectedTarget;
20
21 var newBuildProjectInput = $("#new-build-button #project-name-input");
22 var newBuildProjectSaveBtn = $("#new-build-button #save-project-button");
23
24 /* Project name change functionality */
25 projectNameFormToggle.click(function(e){
26 e.preventDefault();
27 projectNameContainer.hide();
28 projectNameForm.fadeIn();
29 });
30
31 projectNameChangeCancel.click(function(e){
32 e.preventDefault();
33 projectNameForm.hide();
34 projectNameContainer.fadeIn();
35 });
36
37 $("#project-name-change-btn").click(function(e){
38 var newProjectName = $("#project-name-change-input").val();
39
40 libtoaster.editCurrentProject({ projectName: newProjectName }, function (){
41 projectName.html(newProjectName);
42 libtoaster.ctx.projectName = newProjectName;
43 projectNameChangeCancel.click();
44 });
45 });
46
47 _checkProjectBuildable();
48
49 $("#project-topbar .nav li a").each(function(){
50 if (window.location.pathname === $(this).attr('href'))
51 $(this).parent().addClass('active');
52 else
53 $(this).parent().removeClass('active');
54 });
55
56 if ($(".total-builds").length !== 0){
57 libtoaster.getProjectInfo(libtoaster.ctx.projectPageUrl, function(prjInfo){
58 if (prjInfo.completedbuilds)
59 $(".total-builds").text(prjInfo.completedbuilds.length);
60 });
61 }
62
63 /* Hide the button if we're on the project,newproject or importlyaer page
64 * or if there are no projects yet defined
65 * only show if there isn't already a build-target-input already
66 */
67 if (ctx.numProjects > 0 &&
68 ctx.currentUrl.search('newproject') < 0 &&
69 $(".build-target-input").length === 1) {
70
71 newBuildTargetInput = $("#new-build-button .build-target-input");
72 newBuildTargetBuildBtn = $("#new-build-button").find(".build-button");
73
74 _setupNewBuildButton();
75 newBuildButton.show();
76 } else if ($(".build-target-input").length > 0) {
77 newBuildTargetInput = $("#project-topbar .build-target-input");
78 newBuildTargetBuildBtn = $("#project-topbar .build-button");
79 } else {
80 return;
81 }
82
83 /* Hide the change project icon when there is only one project */
84 if (ctx.numProjects === 1) {
85 $('#project .icon-pencil').hide();
86 }
87
88 /* If we have a project setup the typeahead */
89 if (selectedProject.recipesTypeAheadUrl){
90 libtoaster.makeTypeahead(newBuildTargetInput, selectedProject.recipesTypeAheadUrl, { format: "json" }, function (item) {
91 selectedTarget = item;
92 newBuildTargetBuildBtn.removeAttr("disabled");
93 });
94 }
95
96 newBuildTargetInput.on('input', function () {
97 if ($(this).val().length === 0) {
98 newBuildTargetBuildBtn.attr("disabled", "disabled");
99 } else {
100 newBuildTargetBuildBtn.removeAttr("disabled");
101 }
102 });
103
104 newBuildTargetBuildBtn.click(function (e) {
105 e.preventDefault();
106
107 if (!newBuildTargetInput.val()) {
108 return;
109 }
110
111 /* We use the value of the input field so as to maintain any command also
112 * added e.g. core-image-minimal:clean
113 */
114 selectedTarget = { name: newBuildTargetInput.val() };
115
116 /* Fire off the build */
117 libtoaster.startABuild(selectedProject.projectBuildsUrl,
118 selectedProject.projectId, selectedTarget.name, function(){
119 window.location.replace(selectedProject.projectBuildsUrl);
120 }, null);
121 });
122
123 function _checkProjectBuildable() {
124 if (selectedProject.projectId === undefined || selectedProject.projectIsDefault) {
125 return;
126 }
127
128 libtoaster.getProjectInfo(selectedProject.projectPageUrl,
129 function (data) {
130 if (data.machine === null || data.machine.name === undefined || data.layers.length === 0) {
131 /* we can't build anything without a machine and some layers */
132 $("#new-build-button #targets-form").hide();
133 $("#new-build-button .alert").show();
134 } else {
135 $("#new-build-button #targets-form").show();
136 $("#new-build-button .alert").hide();
137
138 /* we can build this project; enable input fields */
139 newBuildTargetInput.removeAttr("disabled");
140 }
141 }, null);
142 }
143
144 /* Setup New build button in the top nav bar */
145 function _setupNewBuildButton() {
146
147 /* If we don't have a current project then present the set project
148 * form.
149 */
150 if (selectedProject.projectId === undefined || selectedProject.projectIsDefault) {
151 $('#change-project-form').show();
152 $('#project .icon-pencil').hide();
153 }
154
155 libtoaster.makeTypeahead(newBuildProjectInput, selectedProject.projectsTypeAheadUrl, { format : "json" }, function (item) {
156 /* successfully selected a project */
157 newBuildProjectSaveBtn.removeAttr("disabled");
158 selectedProject = item;
159 });
160
161 /* Any typing in the input apart from enter key is going to invalidate
162 * the value that has been set by selecting a suggestion from the typeahead
163 */
164 newBuildProjectInput.on('input', function (event) {
165 if (event.keyCode === 13) {
166 return;
167 }
168 newBuildProjectSaveBtn.attr("disabled", "disabled");
169 });
170
171
172 newBuildProjectSaveBtn.click(function () {
173 selectedProject.projectId = selectedProject.id;
174 /* Update the typeahead project_id paramater */
175 _checkProjectBuildable();
176
177 newBuildTargetInput.removeAttr("disabled");
178
179 /* We've got a new project so now we need to update the
180 * target urls. We can get this from the new project's info
181 */
182 $.getJSON(selectedProject.projectPageUrl, { format: "json" },
183 function(projectInfo){
184 /* Update the typeahead to use the new selectedProject */
185 selectedProject = projectInfo;
186
187 libtoaster.makeTypeahead(newBuildTargetInput, selectedProject.recipesTypeAheadUrl, { format: "json" }, function (item) {
188 /* successfully selected a target */
189 selectedTarget = item;
190 newBuildTargetBuildBtn.removeAttr("disabled");
191 });
192
193 });
194 newBuildTargetInput.val("");
195
196 /* set up new form aspect */
197 $("#new-build-button #project a").text(selectedProject.name).attr('href', selectedProject.projectPageUrl);
198 $("#new-build-button .alert a").attr('href', selectedProject.projectPageUrl);
199 $("#project .icon-pencil").show();
200
201 $("#change-project-form").slideUp({ 'complete' : function () {
202 $("#new-build-button #project").show();
203 }});
204 });
205
206 $('#new-build-button #project .icon-pencil').click(function () {
207 newBuildProjectSaveBtn.attr("disabled", "disabled");
208 newBuildProjectInput.val($("#new-build-button #project a").text());
209 $("#cancel-change-project").show();
210 $(this).parent().hide();
211 $("#change-project-form").slideDown();
212 });
213
214 $("#new-build-button #cancel-change-project").click(function () {
215 $("#change-project-form").hide(function () {
216 $('#new-build-button #project').show();
217 });
218
219 newBuildProjectInput.val("");
220 newBuildProjectSaveBtn.attr("disabled", "disabled");
221 });
222
223 /* Keep the dropdown open even unless we click outside the dropdown area */
224 $(".new-build").click (function (event) {
225 event.stopPropagation();
226 });
227 };
228
229}