Fixed #398 Fixed issue with recording length and sort (GRN-83) (#426)

* Fixed issue with recording length and sort

* Made js run on any page with a table element on it

* Scrutinizer fix
This commit is contained in:
farhatahmad
2019-04-10 16:32:28 -04:00
committed by Jesus Federico
parent 95a98f6574
commit 4d648534f7
5 changed files with 25 additions and 27 deletions

View File

@ -15,16 +15,14 @@
// with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
$(document).on('turbolinks:load', function(){
var controller = $("body").data('controller');
var action = $("body").data('action');
if(controller == "rooms" && action == "show" || controller == "rooms" && action == "update"){
// Check if there is a table on this page
if ($("table").length) {
// Choose active header
// (Name, Length or Users)
$('th').each(function(){
if($(this).data("header")){
$(this).on('click', function(){
$(this).on('click', function(){
set_active_header($(this).data("header"));
sort_by($(this).data("header"), $(this).data('order'));
});
@ -80,8 +78,14 @@ $(document).on('turbolinks:load', function(){
// Generalized function for sorting recordings
var sort_recordings = function(recording_list_tbody, order, recording_id){
recording_list_tbody.find('tr').sort(function(a, b){
var a_val = $.trim($(a).find(recording_id).text());
var b_val = $.trim($(b).find(recording_id).text());
var a_val, b_val;
if (recording_id == "#recording-length") {
a_val = $.trim($(a).find(recording_id).data("full-length"));
b_val = $.trim($(b).find(recording_id).data("full-length"));
} else {
a_val = $.trim($(a).find(recording_id).text());
b_val = $.trim($(b).find(recording_id).text());
}
if(order === "asc"){
return a_val.localeCompare(b_val);
@ -89,6 +93,8 @@ $(document).on('turbolinks:load', function(){
else if(order === "desc"){
return b_val.localeCompare(a_val);
}
}).appendTo(recording_list_tbody);
}
}