From cf7775ceca1f31236ffb8476c27ee9a1af59436e Mon Sep 17 00:00:00 2001 From: Marc Delisle Date: Fri, 1 Aug 2014 08:30:19 -0400 Subject: [PATCH] Fix variables scope Signed-off-by: Marc Delisle --- js/server_privileges.js | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/js/server_privileges.js b/js/server_privileges.js index 7df0ee9159..082716238b 100644 --- a/js/server_privileges.js +++ b/js/server_privileges.js @@ -47,29 +47,35 @@ function appendNewUser(new_user_string, new_user_initial, new_user_initial_strin //Append the newly retrieved user to the table now //Calculate the index for the new row var $curr_last_row = $("#usersForm").find('tbody').find('tr:last'); + var curr_shown_initial; + var is_show_all; + var $insert_position; + var dummy_tr_inserted; + var $tbody; + if ($curr_last_row.length) { // at least one tr exists inside the tbody var $curr_first_row = $("#usersForm").find('tbody').find('tr:first'); var first_row_initial = $curr_first_row.find('label').html().substr(0, 1).toUpperCase(); - var curr_shown_initial = $curr_last_row.find('label').html().substr(0, 1).toUpperCase(); + curr_shown_initial = $curr_last_row.find('label').html().substr(0, 1).toUpperCase(); var curr_last_row_index_string = $curr_last_row.find('input:checkbox').attr('id').match(/\d+/)[0]; var curr_last_row_index = parseFloat(curr_last_row_index_string); var new_last_row_index = curr_last_row_index + 1; - var is_show_all = (first_row_initial != curr_shown_initial) ? true : false; - var $insert_position = $curr_last_row; - var dummy_tr_inserted = false; + is_show_all = (first_row_initial != curr_shown_initial) ? true : false; + $insert_position = $curr_last_row; + dummy_tr_inserted = false; } else { // no tr exists inside the tbody - var $tbody = $("#usersForm").find('tbody'); + $tbody = $("#usersForm").find('tbody'); // append a dummy tr $tbody.append(''); - var dummy_tr_inserted = true; - var $insert_position = $tbody.find('tr:first'); - var is_show_all = true; + dummy_tr_inserted = true; + $insert_position = $tbody.find('tr:first'); + is_show_all = true; //todo: the case when the new user's initial does not match // the currently selected initial - var curr_shown_initial = ''; - var new_last_row_index = 0; + curr_shown_initial = ''; + new_last_row_index = 0; } var new_last_row_id = 'checkbox_sel_users_' + new_last_row_index;