diff options
Diffstat (limited to 'bitbake/lib/toaster/toastergui/static/js')
-rw-r--r-- | bitbake/lib/toaster/toastergui/static/js/base.js | 125 |
1 files changed, 125 insertions, 0 deletions
diff --git a/bitbake/lib/toaster/toastergui/static/js/base.js b/bitbake/lib/toaster/toastergui/static/js/base.js new file mode 100644 index 0000000000..864130def9 --- /dev/null +++ b/bitbake/lib/toaster/toastergui/static/js/base.js | |||
@@ -0,0 +1,125 @@ | |||
1 | |||
2 | |||
3 | function basePageInit (ctx) { | ||
4 | |||
5 | var newBuildButton = $("#new-build-button"); | ||
6 | /* Hide the button if we're on the project,newproject or importlyaer page */ | ||
7 | if (ctx.currentUrl.search('newproject|project/\\d/$|importlayer/$') > 0){ | ||
8 | newBuildButton.hide(); | ||
9 | return; | ||
10 | } | ||
11 | |||
12 | |||
13 | newBuildButton.show().removeAttr("disabled"); | ||
14 | |||
15 | _checkProjectBuildable() | ||
16 | _setupNewBuildButton(); | ||
17 | |||
18 | |||
19 | function _checkProjectBuildable(){ | ||
20 | libtoaster.getProjectInfo(ctx.projectInfoUrl, ctx.projectId, | ||
21 | function(data){ | ||
22 | if (data.machine.name == undefined || data.layers.length == 0) { | ||
23 | /* we can't build anything with out a machine and some layers */ | ||
24 | $("#new-build-button #targets-form").hide(); | ||
25 | $("#new-build-button .alert").show(); | ||
26 | } else { | ||
27 | $("#new-build-button #targets-form").show(); | ||
28 | $("#new-build-button .alert").hide(); | ||
29 | } | ||
30 | }, null); | ||
31 | } | ||
32 | |||
33 | function _setupNewBuildButton() { | ||
34 | /* Setup New build button */ | ||
35 | var newBuildProjectInput = $("#new-build-button #project-name-input"); | ||
36 | var newBuildTargetBuildBtn = $("#new-build-button #build-button"); | ||
37 | var newBuildTargetInput = $("#new-build-button #build-target-input"); | ||
38 | var newBuildProjectSaveBtn = $("#new-build-button #save-project-button"); | ||
39 | var selectedTarget; | ||
40 | var selectedProject; | ||
41 | |||
42 | /* If we don't have a current project then present the set project | ||
43 | * form. | ||
44 | */ | ||
45 | if (ctx.projectId == undefined) { | ||
46 | $('#change-project-form').show(); | ||
47 | $('#project .icon-pencil').hide(); | ||
48 | } | ||
49 | |||
50 | libtoaster.makeTypeahead(newBuildTargetInput, ctx.xhrDataTypeaheadUrl, { type : "targets", project_id: ctx.projectId }, function(item){ | ||
51 | /* successfully selected a target */ | ||
52 | selectedTarget = item; | ||
53 | }); | ||
54 | |||
55 | |||
56 | libtoaster.makeTypeahead(newBuildProjectInput, ctx.xhrDataTypeaheadUrl, { type : "projects" }, function(item){ | ||
57 | /* successfully selected a project */ | ||
58 | newBuildProjectSaveBtn.removeAttr("disabled"); | ||
59 | selectedProject = item; | ||
60 | }); | ||
61 | |||
62 | /* Any typing in the input apart from enter key is going to invalidate | ||
63 | * the value that has been set by selecting a suggestion from the typeahead | ||
64 | */ | ||
65 | newBuildProjectInput.keyup(function(event) { | ||
66 | if (event.keyCode == 13) | ||
67 | return; | ||
68 | newBuildProjectSaveBtn.attr("disabled", "disabled"); | ||
69 | }); | ||
70 | |||
71 | newBuildTargetInput.keyup(function() { | ||
72 | if ($(this).val().length == 0) | ||
73 | newBuildTargetBuildBtn.attr("disabled", "disabled"); | ||
74 | else | ||
75 | newBuildTargetBuildBtn.removeAttr("disabled"); | ||
76 | }); | ||
77 | |||
78 | newBuildTargetBuildBtn.click(function() { | ||
79 | if (!newBuildTargetInput.val()) | ||
80 | return; | ||
81 | |||
82 | /* fire and forget */ | ||
83 | libtoaster.startABuild(ctx.projectBuildUrl, ctx.projectId, selectedTarget.name, null, null); | ||
84 | window.location.replace(ctx.projectPageUrl+ctx.projectId); | ||
85 | }); | ||
86 | |||
87 | newBuildProjectSaveBtn.click(function() { | ||
88 | ctx.projectId = selectedProject.id | ||
89 | /* Update the typeahead project_id paramater */ | ||
90 | _checkProjectBuildable(); | ||
91 | newBuildTargetInput.data('typeahead').options.xhrParams.project_id = ctx.projectId; | ||
92 | newBuildTargetInput.val(""); | ||
93 | |||
94 | $("#new-build-button #project a").text(selectedProject.name).attr('href', ctx.projectPageUrl+ctx.projectId); | ||
95 | $("#new-build-button .alert a").attr('href', ctx.projectPageUrl+ctx.projectId); | ||
96 | |||
97 | |||
98 | $("#change-project-form").slideUp({ 'complete' : function() { | ||
99 | $("#new-build-button #project").show(); | ||
100 | }}); | ||
101 | }); | ||
102 | |||
103 | $('#new-build-button #project .icon-pencil').click(function() { | ||
104 | newBuildProjectSaveBtn.attr("disabled", "disabled"); | ||
105 | newBuildProjectInput.val($("#new-build-button #project a").text()); | ||
106 | $(this).parent().hide(); | ||
107 | $("#change-project-form").slideDown(); | ||
108 | }); | ||
109 | |||
110 | $("#new-build-button #cancel-change-project").click(function() { | ||
111 | $("#change-project-form").hide(function(){ | ||
112 | $('#new-build-button #project').show(); | ||
113 | }); | ||
114 | |||
115 | newBuildProjectInput.val(""); | ||
116 | newBuildProjectSaveBtn.attr("disabled", "disabled"); | ||
117 | }); | ||
118 | |||
119 | /* Keep the dropdown open even unless we click outside the dropdown area */ | ||
120 | $(".new-build").click (function(event) { | ||
121 | event.stopPropagation(); | ||
122 | }); | ||
123 | }; | ||
124 | |||
125 | } | ||