##// END OF EJS Templates
admin: fixed search in user admin page
marcink -
r1090:276bfa3c default
parent child Browse files
Show More
@@ -1,140 +1,142 b''
1 1 ## -*- coding: utf-8 -*-
2 2 <%inherit file="/base/base.html"/>
3 3
4 4 <%def name="title()">
5 5 ${_('Users administration')}
6 6 %if c.rhodecode_name:
7 7 &middot; ${h.branding(c.rhodecode_name)}
8 8 %endif
9 9 </%def>
10 10
11 11 <%def name="breadcrumbs_links()">
12 12 <input class="q_filter_box" id="q_filter" size="15" type="text" name="filter" placeholder="${_('quick filter...')}" value=""/>
13 13 ${h.link_to(_('Admin'),h.url('admin_home'))} &raquo; <span id="user_count">0</span>
14 14 </%def>
15 15
16 16 <%def name="menu_bar_nav()">
17 17 ${self.menu_items(active='admin')}
18 18 </%def>
19 19
20 20 <%def name="main()">
21 21 <div class="box">
22 22
23 23 <div class="title">
24 24 ${self.breadcrumbs()}
25 25 <ul class="links">
26 26 <li>
27 27 <a href="${h.url('new_user')}" class="btn btn-small btn-success">${_(u'Add User')}</a>
28 28 </li>
29 29 </ul>
30 30 </div>
31 31
32 32 <div id="repos_list_wrap">
33 33 <table id="user_list_table" class="display"></table>
34 34 </div>
35 35 </div>
36 36
37 37 <script>
38 38 $(document).ready(function() {
39 39
40 40 var get_datatable_count = function(){
41 41 var datatable = $('#user_list_table').dataTable();
42 42 var api = datatable.api();
43 43 var total = api.page.info().recordsDisplay;
44 44 var active = datatable.fnGetFilteredData();
45 45 var _text = _gettext("{0} active out of {1} users").format(active, total);
46 46 $('#user_count').text(_text);
47 47 };
48 48
49 49 // custom filter that filters by username OR email
50 50 $.fn.dataTable.ext.search.push(
51 51 function( settings, data, dataIndex ) {
52 52 var query = $('#q_filter').val();
53 var username = data[1];
54 var email = data[2];
55 var first_name = data[3];
56 var last_name = data[4];
53
54 var username = data[0];
55 var email = data[1];
56 var first_name = data[2];
57 var last_name = data[3];
57 58
58 59 var query_str = username + " " +
59 60 email + " " +
60 61 first_name + " " +
61 62 last_name;
62 if((query_str).indexOf(query) !== -1){
63
64 if ((query_str).indexOf(query) !== -1) {
63 65 return true;
64 66 }
65 67 return false;
66 68 }
67 69 );
68 70 // filtered data plugin
69 71 $.fn.dataTableExt.oApi.fnGetFilteredData = function ( oSettings ) {
70 72 var res = [];
71 73 for ( var i=0, iLen=oSettings.fnRecordsDisplay() ; i<iLen ; i++ ) {
72 74 var record = oSettings.aoData[i]._aData;
73 75 if(record['active_raw']){
74 76 res.push(record);
75 77 }
76 78 }
77 79 return res.length;
78 80 };
79 81
80 82 // user list
81 83 $('#user_list_table').DataTable({
82 84 data: ${c.data|n},
83 85 dom: 'rtp',
84 86 pageLength: ${c.visual.admin_grid_items},
85 87 order: [[ 1, "asc" ]],
86 88 columns: [
87 89 { data: {"_": "username",
88 90 "sort": "username_raw"}, title: "${_('Username')}", className: "td-user" },
89 91 { data: {"_": "email",
90 92 "sort": "email"}, title: "${_('Email')}", className: "td-email" },
91 93 { data: {"_": "first_name",
92 94 "sort": "first_name"}, title: "${_('First Name')}", className: "td-user" },
93 95 { data: {"_": "last_name",
94 96 "sort": "last_name"}, title: "${_('Last Name')}", className: "td-user" },
95 97 { data: {"_": "last_login",
96 98 "sort": "last_login_raw",
97 99 "type": Number}, title: "${_('Last login')}", className: "td-time" },
98 100 { data: {"_": "active",
99 101 "sort": "active_raw"}, title: "${_('Active')}", className: "td-active" },
100 102 { data: {"_": "admin",
101 103 "sort": "admin_raw"}, title: "${_('Admin')}", className: "td-admin" },
102 104 { data: {"_": "extern_type",
103 105 "sort": "extern_type"}, title: "${_('Authentication type')}", className: "td-type" },
104 106 { data: {"_": "action",
105 107 "sort": "action"}, title: "${_('Action')}", className: "td-action" }
106 108 ],
107 109 language: {
108 110 paginate: DEFAULT_GRID_PAGINATION,
109 111 emptyTable: _gettext("No users available yet.")
110 112 },
111 113 "initComplete": function( settings, json ) {
112 114 get_datatable_count();
113 115 },
114 116 "createdRow": function ( row, data, index ) {
115 117 if (!data['active_raw']){
116 118 $(row).addClass('closed')
117 119 }
118 120 }
119 121 });
120 122
121 123 // update the counter when doing search
122 124 $('#user_list_table').on( 'search.dt', function (e,settings) {
123 125 get_datatable_count();
124 126 });
125 127
126 128 // filter, filter both grids
127 129 $('#q_filter').on( 'keyup', function () {
128 130 var user_api = $('#user_list_table').dataTable().api();
129 131 user_api
130 132 .draw();
131 133 });
132 134
133 135 // refilter table if page load via back button
134 136 $("#q_filter").trigger('keyup');
135 137
136 138 });
137 139
138 140 </script>
139 141
140 142 </%def>
General Comments 0
You need to be logged in to leave comments. Login now