~ubuntu-branches/ubuntu/vivid/phpmyadmin/vivid

« back to all changes in this revision

Viewing changes to js/server_privileges.js

  • Committer: Package Import Robot
  • Author(s): Michal Čihař
  • Date: 2014-08-11 11:14:26 UTC
  • mfrom: (1.2.61)
  • Revision ID: package-import@ubuntu.com-20140811111426-uimdbe8nyzrvpddo
Tags: 4:4.2.7-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
45
45
 
46
46
    //Calculate the index for the new row
47
47
    var $curr_last_row = $("#usersForm").find('tbody').find('tr:last');
48
 
    var $curr_first_row = $("#usersForm").find('tbody').find('tr:first');
49
 
    var first_row_initial = $curr_first_row.find('label').html().substr(0, 1).toUpperCase();
50
 
    var curr_shown_initial = $curr_last_row.find('label').html().substr(0, 1).toUpperCase();
51
 
    var curr_last_row_index_string = $curr_last_row.find('input:checkbox').attr('id').match(/\d+/)[0];
52
 
    var curr_last_row_index = parseFloat(curr_last_row_index_string);
53
 
    var new_last_row_index = curr_last_row_index + 1;
 
48
    if ($curr_last_row.length) {
 
49
        // at least one tr exists inside the tbody
 
50
        var $curr_first_row = $("#usersForm").find('tbody').find('tr:first');
 
51
        var first_row_initial = $curr_first_row.find('label').html().substr(0, 1).toUpperCase();
 
52
        var curr_shown_initial = $curr_last_row.find('label').html().substr(0, 1).toUpperCase();
 
53
        var curr_last_row_index_string = $curr_last_row.find('input:checkbox').attr('id').match(/\d+/)[0];
 
54
        var curr_last_row_index = parseFloat(curr_last_row_index_string);
 
55
        var new_last_row_index = curr_last_row_index + 1;
 
56
        var is_show_all = (first_row_initial != curr_shown_initial) ? true : false;
 
57
        var $insert_position = $curr_last_row;
 
58
        var dummy_tr_inserted = false;
 
59
    } else {
 
60
        // no tr exists inside the tbody
 
61
        var $tbody = $("#usersForm").find('tbody');
 
62
        // append a dummy tr
 
63
        $tbody.append('<tr></tr>');
 
64
        var dummy_tr_inserted = true;
 
65
        var $insert_position = $tbody.find('tr:first');
 
66
        var is_show_all = true;
 
67
        //todo: the case when the new user's initial does not match
 
68
        //      the currently selected initial
 
69
        var curr_shown_initial = '';
 
70
        var new_last_row_index = 0;
 
71
    }
54
72
    var new_last_row_id = 'checkbox_sel_users_' + new_last_row_index;
55
 
    var is_show_all = (first_row_initial != curr_shown_initial) ? true : false;
56
73
 
57
74
    //Append to the table and set the id/names correctly
58
75
    if ((curr_shown_initial == new_user_initial) || is_show_all) {
59
76
        $(new_user_string)
60
 
        .insertAfter($curr_last_row)
 
77
        .insertAfter($insert_position)
61
78
        .find('input:checkbox')
62
79
        .attr('id', new_last_row_id)
63
80
        .val(function () {
70
87
        .end();
71
88
    }
72
89
 
 
90
    if (dummy_tr_inserted) {
 
91
        // remove the dummy tr
 
92
        $tbody.find('tr:first').remove();
 
93
    }
 
94
 
73
95
    //Let us sort the table alphabetically
74
96
    $("#usersForm").find('tbody').PMA_sort_table('label');
75
97