Files
poky/bitbake/lib/toaster/toastergui/static/js/base.js
Michael Wood 5da543c7b5 bitbake: toaster: Fix build button current project race
Make sure the current project value is set before we check to see if the
project is buildable. Also update the blacklist url patterns where we
aren't displaying the button.

[YOCTO #7739]

(Bitbake rev: e169ed5cf190af62586f3e1c6ed6db6120406e05)

Signed-off-by: Michael Wood <michael.g.wood@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2015-05-29 11:59:43 +01:00

139 lines
4.6 KiB
JavaScript

function basePageInit (ctx) {
var newBuildButton = $("#new-build-button");
/* Hide the button if we're on the project,newproject or importlyaer page
* or if there are no projects yet defined
*/
if (ctx.numProjects == 0 || ctx.currentUrl.search('newproject|project/\\d$|importlayer$') > 0){
newBuildButton.hide();
return;
}
var currentProjectId = libtoaster.ctx.projectId;
/* Hide the change project icon when there is only one project */
if (ctx.numProjects == 1){
$('#project .icon-pencil').hide();
}
newBuildButton.show().removeAttr("disabled");
_checkProjectBuildable()
_setupNewBuildButton();
function _checkProjectBuildable(){
if (currentProjectId == undefined)
return;
libtoaster.getProjectInfo(ctx.projectInfoUrl, currentProjectId,
function(data){
if (data.machine.name == undefined || data.layers.length == 0) {
/* we can't build anything with out a machine and some layers */
$("#new-build-button #targets-form").hide();
$("#new-build-button .alert").show();
} else {
$("#new-build-button #targets-form").show();
$("#new-build-button .alert").hide();
}
}, null);
}
function _setupNewBuildButton() {
/* Setup New build button */
var newBuildProjectInput = $("#new-build-button #project-name-input");
var newBuildTargetBuildBtn = $("#new-build-button #build-button");
var newBuildTargetInput = $("#new-build-button #build-target-input");
var newBuildProjectSaveBtn = $("#new-build-button #save-project-button");
var selectedTarget;
var selectedProject;
/* If we don't have a current project then present the set project
* form.
*/
if (currentProjectId == undefined) {
$('#change-project-form').show();
$('#project .icon-pencil').hide();
}
libtoaster.makeTypeahead(newBuildTargetInput, { type : "targets", project_id: currentProjectId }, function(item){
/* successfully selected a target */
selectedTarget = item;
});
libtoaster.makeTypeahead(newBuildProjectInput, { type : "projects" }, function(item){
/* successfully selected a project */
newBuildProjectSaveBtn.removeAttr("disabled");
selectedProject = item;
});
/* Any typing in the input apart from enter key is going to invalidate
* the value that has been set by selecting a suggestion from the typeahead
*/
newBuildProjectInput.on('input', function(event) {
if (event.keyCode == 13)
return;
newBuildProjectSaveBtn.attr("disabled", "disabled");
});
newBuildTargetInput.on('input', function() {
if ($(this).val().length == 0)
newBuildTargetBuildBtn.attr("disabled", "disabled");
else
newBuildTargetBuildBtn.removeAttr("disabled");
});
newBuildTargetBuildBtn.click(function() {
if (!newBuildTargetInput.val())
return;
if (!selectedTarget)
selectedTarget = { name: newBuildTargetInput.val() };
/* fire and forget */
libtoaster.startABuild(ctx.projectBuildUrl, currentProjectId, selectedTarget.name, null, null);
window.location.replace(ctx.projectBasePageUrl+currentProjectId);
});
newBuildProjectSaveBtn.click(function() {
currentProjectId = selectedProject.id
/* Update the typeahead project_id paramater */
_checkProjectBuildable();
newBuildTargetInput.data('typeahead').options.xhrParams.project_id = currentProjectId;
newBuildTargetInput.val("");
$("#new-build-button #project a").text(selectedProject.name).attr('href', ctx.projectBasePageUrl+currentProjectId);
$("#new-build-button .alert a").attr('href', ctx.projectBasePageUrl+currentProjectId);
$("#change-project-form").slideUp({ 'complete' : function() {
$("#new-build-button #project").show();
}});
});
$('#new-build-button #project .icon-pencil').click(function() {
newBuildProjectSaveBtn.attr("disabled", "disabled");
newBuildProjectInput.val($("#new-build-button #project a").text());
$(this).parent().hide();
$("#change-project-form").slideDown();
});
$("#new-build-button #cancel-change-project").click(function() {
$("#change-project-form").hide(function(){
$('#new-build-button #project').show();
});
newBuildProjectInput.val("");
newBuildProjectSaveBtn.attr("disabled", "disabled");
});
/* Keep the dropdown open even unless we click outside the dropdown area */
$(".new-build").click (function(event) {
event.stopPropagation();
});
};
}