diff options
author | Michael Wood <michael.g.wood@intel.com> | 2015-05-18 20:08:28 +0100 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2015-05-29 11:59:45 +0100 |
commit | 2de01a68eb6a9ca74384957c674928944c235269 (patch) | |
tree | 7dbe5a8a2a169dac697bed032263c624e9c2be7e /bitbake/lib/toaster/toastergui/static/js/table.js | |
parent | a0ea663b83ecf5f286844420b071101feefc3d22 (diff) | |
download | poky-2de01a68eb6a9ca74384957c674928944c235269.tar.gz |
bitbake: toaster: Port layerdetails to ToasterTables
This ports the layerdetails page to using ToasterTables
Also some whitespace and strict clean ups in the existing layerdetails
js and html template.
(Bitbake rev: 8ce35f81631e31539aeb82f8a85abbb3312e5097)
Signed-off-by: Michael Wood <michael.g.wood@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/toaster/toastergui/static/js/table.js')
-rw-r--r-- | bitbake/lib/toaster/toastergui/static/js/table.js | 77 |
1 files changed, 48 insertions, 29 deletions
diff --git a/bitbake/lib/toaster/toastergui/static/js/table.js b/bitbake/lib/toaster/toastergui/static/js/table.js index 97370fd020..2e35e3871c 100644 --- a/bitbake/lib/toaster/toastergui/static/js/table.js +++ b/bitbake/lib/toaster/toastergui/static/js/table.js | |||
@@ -64,10 +64,12 @@ function tableInit(ctx){ | |||
64 | 64 | ||
65 | function updateTable(tableData) { | 65 | function updateTable(tableData) { |
66 | var tableBody = table.children("tbody"); | 66 | var tableBody = table.children("tbody"); |
67 | var paginationBtns = $('#pagination-'+ctx.tableName); | 67 | var pagination = $('#pagination-'+ctx.tableName); |
68 | var paginationBtns = pagination.children('ul'); | ||
69 | var tableContainer = $("#table-container-"+ctx.tableName); | ||
68 | 70 | ||
71 | tableContainer.css("visibility", "hidden"); | ||
69 | /* To avoid page re-layout flicker when paging set fixed height */ | 72 | /* To avoid page re-layout flicker when paging set fixed height */ |
70 | table.css("visibility", "hidden"); | ||
71 | table.css("padding-bottom", table.height()); | 73 | table.css("padding-bottom", table.height()); |
72 | 74 | ||
73 | /* Reset table components */ | 75 | /* Reset table components */ |
@@ -83,19 +85,30 @@ function tableInit(ctx){ | |||
83 | tableTotal = tableData.total; | 85 | tableTotal = tableData.total; |
84 | 86 | ||
85 | if (tableData.total === 0){ | 87 | if (tableData.total === 0){ |
86 | $("#table-container-"+ctx.tableName).hide(); | 88 | tableContainer.hide(); |
87 | $("#new-search-input-"+ctx.tableName).val(tableParams.search); | 89 | /* If we were searching show the new search bar and return */ |
88 | $("#no-results-"+ctx.tableName).show(); | 90 | if (tableParams.search){ |
91 | $("#new-search-input-"+ctx.tableName).val(tableParams.search); | ||
92 | $("#no-results-"+ctx.tableName).show(); | ||
93 | } | ||
94 | table.trigger("table-done", [tableData.total, tableParams]); | ||
95 | |||
89 | return; | 96 | return; |
97 | |||
98 | /* We don't want to clutter the place with the table chrome if there | ||
99 | * are only a few results */ | ||
100 | } else if (tableData.total <= 10 && | ||
101 | !tableParams.filter && | ||
102 | !tableParams.search){ | ||
103 | $("#table-chrome-"+ctx.tableName).hide(); | ||
104 | pagination.hide(); | ||
90 | } else { | 105 | } else { |
91 | $("#table-container-"+ctx.tableName).show(); | 106 | tableContainer.show(); |
92 | $("#no-results-"+ctx.tableName).hide(); | 107 | $("#no-results-"+ctx.tableName).hide(); |
93 | } | 108 | } |
94 | 109 | ||
95 | |||
96 | setupTableChrome(tableData); | 110 | setupTableChrome(tableData); |
97 | 111 | ||
98 | |||
99 | /* Add table data rows */ | 112 | /* Add table data rows */ |
100 | for (var i in tableData.rows){ | 113 | for (var i in tableData.rows){ |
101 | var row = $("<tr></tr>"); | 114 | var row = $("<tr></tr>"); |
@@ -137,26 +150,31 @@ function tableInit(ctx){ | |||
137 | var end = tableParams.page + 2; | 150 | var end = tableParams.page + 2; |
138 | var numPages = Math.ceil(tableData.total/tableParams.limit); | 151 | var numPages = Math.ceil(tableData.total/tableParams.limit); |
139 | 152 | ||
140 | if (tableParams.page < 3) | 153 | if (numPages > 1){ |
141 | end = 5; | 154 | if (tableParams.page < 3) |
155 | end = 5; | ||
142 | 156 | ||
143 | for (var page_i=1; page_i <= numPages; page_i++){ | 157 | for (var page_i=1; page_i <= numPages; page_i++){ |
144 | if (page_i >= start && page_i <= end){ | 158 | if (page_i >= start && page_i <= end){ |
145 | var btn = $('<li><a href="#" class="page">'+page_i+'</a></li>'); | 159 | var btn = $('<li><a href="#" class="page">'+page_i+'</a></li>'); |
146 | 160 | ||
147 | if (page_i === tableParams.page){ | 161 | if (page_i === tableParams.page){ |
148 | btn.addClass("active"); | 162 | btn.addClass("active"); |
149 | } | 163 | } |
150 | 164 | ||
151 | /* Add the click handler */ | 165 | /* Add the click handler */ |
152 | btn.click(pageButtonClicked); | 166 | btn.click(pageButtonClicked); |
153 | paginationBtns.append(btn); | 167 | paginationBtns.append(btn); |
168 | } | ||
154 | } | 169 | } |
155 | } | 170 | } |
156 | table.css("padding-bottom", 0); | 171 | |
157 | loadColumnsPreference(); | 172 | loadColumnsPreference(); |
158 | 173 | ||
159 | $("table").css("visibility", "visible"); | 174 | table.css("padding-bottom", 0); |
175 | tableContainer.css("visibility", "visible"); | ||
176 | |||
177 | table.trigger("table-done", [tableData.total, tableParams]); | ||
160 | } | 178 | } |
161 | 179 | ||
162 | function setupTableChrome(tableData){ | 180 | function setupTableChrome(tableData){ |
@@ -374,9 +392,9 @@ function tableInit(ctx){ | |||
374 | data: params, | 392 | data: params, |
375 | headers: { 'X-CSRFToken' : $.cookie('csrftoken')}, | 393 | headers: { 'X-CSRFToken' : $.cookie('csrftoken')}, |
376 | success: function (filterData) { | 394 | success: function (filterData) { |
377 | var filterActionRadios = $('#filter-actions'); | 395 | var filterActionRadios = $('#filter-actions-'+ctx.tableName); |
378 | 396 | ||
379 | $('#filter-modal-title').text(filterData.title); | 397 | $('#filter-modal-title-'+ctx.tableName).text(filterData.title); |
380 | 398 | ||
381 | filterActionRadios.text(""); | 399 | filterActionRadios.text(""); |
382 | 400 | ||
@@ -404,7 +422,7 @@ function tableInit(ctx){ | |||
404 | filterActionRadios.append(action); | 422 | filterActionRadios.append(action); |
405 | } | 423 | } |
406 | 424 | ||
407 | $('#filter-modal').modal('show'); | 425 | $('#filter-modal-'+ctx.tableName).modal('show'); |
408 | } | 426 | } |
409 | }); | 427 | }); |
410 | } | 428 | } |
@@ -417,17 +435,18 @@ function tableInit(ctx){ | |||
417 | e.stopPropagation(); | 435 | e.stopPropagation(); |
418 | }); | 436 | }); |
419 | 437 | ||
420 | $(".pagesize").val(tableParams.limit); | 438 | $(".pagesize-"+ctx.tableName).val(tableParams.limit); |
421 | 439 | ||
422 | /* page size selector */ | 440 | /* page size selector */ |
423 | $(".pagesize").change(function(){ | 441 | $(".pagesize-"+ctx.tableName).change(function(e){ |
424 | tableParams.limit = Number(this.value); | 442 | tableParams.limit = Number(this.value); |
425 | if ((tableParams.page * tableParams.limit) > tableTotal) | 443 | if ((tableParams.page * tableParams.limit) > tableTotal) |
426 | tableParams.page = 1; | 444 | tableParams.page = 1; |
427 | 445 | ||
428 | loadData(tableParams); | 446 | loadData(tableParams); |
429 | /* sync the other selectors on the page */ | 447 | /* sync the other selectors on the page */ |
430 | $(".pagesize").val(this.value); | 448 | $(".pagesize-"+ctx.tableName).val(this.value); |
449 | e.preventDefault(); | ||
431 | }); | 450 | }); |
432 | 451 | ||
433 | $("#search-submit-"+ctx.tableName).click(function(e){ | 452 | $("#search-submit-"+ctx.tableName).click(function(e){ |
@@ -463,12 +482,12 @@ function tableInit(ctx){ | |||
463 | e.preventDefault(); | 482 | e.preventDefault(); |
464 | }); | 483 | }); |
465 | 484 | ||
466 | $("#clear-filter-btn").click(function(){ | 485 | $("#clear-filter-btn-"+ctx.tableName).click(function(){ |
467 | tableParams.filter = null; | 486 | tableParams.filter = null; |
468 | loadData(tableParams); | 487 | loadData(tableParams); |
469 | }); | 488 | }); |
470 | 489 | ||
471 | $("#filter-modal-form").submit(function(e){ | 490 | $("#filter-modal-form-"+ctx.tableName).submit(function(e){ |
472 | e.preventDefault(); | 491 | e.preventDefault(); |
473 | 492 | ||
474 | tableParams.filter = $(this).find("input[type='radio']:checked").val(); | 493 | tableParams.filter = $(this).find("input[type='radio']:checked").val(); |