Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[webui] refactor requests table code to allow it to be used by other …
…parts of app
- Loading branch information
Showing
5 changed files
with
52 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
src/api/app/assets/javascripts/webui/application/requests_table.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
$( document ).ready(function() { | ||
$('.requests-datatable').each(function(index){ | ||
// 1. Create DataTable | ||
var url = $(this).data('source'); | ||
var dataTableId = $(this).attr('id'); | ||
var options = { | ||
order: [[0,'desc']], | ||
info: false, | ||
columnDefs: [ | ||
// We only allow ordering for created, requester and priority. | ||
// Columns: created, source, target, requester, type, priority. | ||
{ orderable: false, targets: [1,2,4,6,] } | ||
], | ||
paging: 25, | ||
pageLength: 25, | ||
pagingType: "full_numbers", | ||
processing: true, | ||
serverSide: true, | ||
ajax: { | ||
url: url, | ||
data: { dataTableId: dataTableId } | ||
} | ||
}; | ||
var table = $(this).dataTable(options); | ||
|
||
// 2. Reload button | ||
var reload_button = $('.result_reload[data-table=' + dataTableId + ']') | ||
var loading_spinner = $(reload_button).siblings('.result_spinner'); | ||
|
||
reload_button.click(function(){ | ||
reload_button.hide(); | ||
loading_spinner.show(); | ||
|
||
table.api().ajax.reload(function(){ | ||
reload_button.show(); | ||
loading_spinner.hide(); | ||
}, false); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,7 @@ | ||
$( document ).ready(function() { | ||
var url = $('.requests-datatable').first().data('source'); | ||
var options = { | ||
order: [[0,'desc']], | ||
info: false, | ||
columnDefs: [ | ||
// We only allow ordering for created, requester and priority. | ||
// Columns: created, source, target, requester, type, priority. | ||
{ orderable: false, targets: [1,2,4,6,] } | ||
], | ||
paging: 25, | ||
pageLength: 25, | ||
pagingType: "full_numbers", | ||
processing: true, | ||
serverSide: true, | ||
ajax: { | ||
url: url, | ||
data: { dataTableId: null } | ||
} | ||
}; | ||
|
||
options.ajax.data.dataTableId = 'requests_in_table'; | ||
$('#requests_in_table').dataTable(options); | ||
|
||
options.ajax.data.dataTableId = 'requests_out_table'; | ||
$('#requests_out_table').dataTable(options); | ||
|
||
options.ajax.data.dataTableId = 'requests_declined_table'; | ||
$('#requests_declined_table').dataTable(options); | ||
|
||
options.ajax.data.dataTableId = 'all_requests_table'; | ||
$('#all_requests_table').dataTable(options); | ||
|
||
options.ajax.data.dataTableId = 'reviews_in_table'; | ||
$('#reviews_in_table').dataTable(options); | ||
|
||
$('.result_reload').click(function() { | ||
var that = this; | ||
$(this).hide(); | ||
$(this).siblings('.result_spinner').show(); | ||
var table = $(this).data('table'); | ||
|
||
$('#' + table).DataTable().ajax.reload(function(){ | ||
$(that).show(); | ||
$(that).siblings('.result_spinner').hide(); | ||
}, false); | ||
}); | ||
|
||
$('#requests li a').click(function (event) { | ||
$(this).parent().parent().find('.result_reload').hide(); | ||
$(this).siblings('.result_reload').show(); | ||
}); | ||
// Show reload button when tab is changed | ||
$('#requests li a').click(function (event) { | ||
$(this).parent().parent().find('.result_reload').hide(); | ||
$(this).siblings('.result_reload').show(); | ||
}); | ||
}); |
2 changes: 1 addition & 1 deletion
2
.../app/views/webui/user/_requests.html.haml → ...ws/webui/shared/_requests_table.html.haml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters