diff options
Diffstat (limited to 'bitbake/lib/toaster/toastergui/static/js/customrecipe.js')
-rw-r--r-- | bitbake/lib/toaster/toastergui/static/js/customrecipe.js | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/bitbake/lib/toaster/toastergui/static/js/customrecipe.js b/bitbake/lib/toaster/toastergui/static/js/customrecipe.js new file mode 100644 index 0000000000..4f6b304dd6 --- /dev/null +++ b/bitbake/lib/toaster/toastergui/static/js/customrecipe.js | |||
@@ -0,0 +1,50 @@ | |||
1 | "use strict"; | ||
2 | |||
3 | function customRecipePageInit(ctx) { | ||
4 | |||
5 | var urlParams = libtoaster.parseUrlParams(); | ||
6 | |||
7 | (function notificationRequest(){ | ||
8 | if (urlParams.hasOwnProperty('notify') && urlParams.notify === 'new'){ | ||
9 | $("#image-created-notification").show(); | ||
10 | } | ||
11 | })(); | ||
12 | |||
13 | $("#recipeselection").on('table-done', function(e, total, tableParams){ | ||
14 | /* Table is done so now setup the click handler for the package buttons */ | ||
15 | $(".add-rm-package-btn").click(function(e){ | ||
16 | e.preventDefault(); | ||
17 | addRemovePackage($(this), tableParams); | ||
18 | }); | ||
19 | }); | ||
20 | |||
21 | function addRemovePackage(pkgBtn, tableParams){ | ||
22 | var pkgBtnData = pkgBtn.data(); | ||
23 | var method; | ||
24 | var buttonToShow; | ||
25 | |||
26 | if (pkgBtnData.directive == 'add') { | ||
27 | method = 'PUT'; | ||
28 | buttonToShow = '#package-rm-btn-' + pkgBtnData.package; | ||
29 | } else if (pkgBtnData.directive == 'remove') { | ||
30 | method = 'DELETE'; | ||
31 | buttonToShow = '#package-add-btn-' + pkgBtnData.package; | ||
32 | } else { | ||
33 | throw("Unknown package directive: should be add or remove"); | ||
34 | } | ||
35 | |||
36 | $.ajax({ | ||
37 | type: method, | ||
38 | url: pkgBtnData.packageUrl, | ||
39 | headers: { 'X-CSRFToken' : $.cookie('csrftoken')}, | ||
40 | success: function(data){ | ||
41 | /* Invalidate the Add | Rm package table's current cache */ | ||
42 | tableParams.nocache = true; | ||
43 | $.get(ctx.tableApiUrl, tableParams); | ||
44 | /* Swap the buttons around */ | ||
45 | pkgBtn.hide(); | ||
46 | $(buttonToShow).show(); | ||
47 | } | ||
48 | }); | ||
49 | } | ||
50 | } | ||