|
1 | 1 | {#
|
2 | 2 |
|
3 |
| -OPNsense® is Copyright © 2014 – 2015 by Deciso B.V. |
| 3 | +OPNsense® is Copyright © 2014 – 2024 by Deciso B.V. |
4 | 4 | All rights reserved.
|
5 | 5 |
|
6 | 6 | Redistribution and use in source and binary forms, with or without modification,
|
@@ -30,115 +30,75 @@ POSSIBILITY OF SUCH DAMAGE.
|
30 | 30 | <script>
|
31 | 31 |
|
32 | 32 | $( document ).ready(function() {
|
33 |
| - /** |
34 |
| - * update zone list |
35 |
| - */ |
36 |
| - function updateZones() { |
37 |
| - ajaxGet("/api/captiveportal/session/zones/", {}, function(data, status) { |
38 |
| - if (status == "success") { |
39 |
| - $('#cp-zones').html(""); |
40 |
| - $.each(data, function(key, value) { |
41 |
| - $('#cp-zones').append($("<option></option>").attr("value", key).text(value)); |
42 |
| - }); |
43 |
| - $('.selectpicker').selectpicker('refresh'); |
44 |
| - // link on change event |
45 |
| - $('#cp-zones').on('change', function(){ |
46 |
| - loadSessions(); |
47 |
| - }); |
48 |
| - // initial load sessions |
49 |
| - loadSessions(); |
50 |
| - } |
51 |
| - }); |
52 |
| - } |
53 |
| - |
54 |
| - /** |
55 |
| - * load sessions for selected zone, hook events |
56 |
| - */ |
57 |
| - function loadSessions() { |
58 |
| - var zoneid = $('#cp-zones').find("option:selected").val(); |
59 |
| - var gridopt = { |
60 |
| - ajax: false, |
61 |
| - selection: true, |
62 |
| - multiSelect: true, |
63 |
| - formatters: { |
64 |
| - "commands": function (column, row) { |
65 |
| - return '<button type="button" class="btn btn-xs btn-default command-disconnect bootgrid-tooltip" title="{{ lang._('Disconnect') }}" data-row-id="' + row.sessionId + '"><span class="fa fa-trash-o fa-fw"></span></button>'; |
66 |
| - } |
67 |
| - } |
68 |
| - }; |
69 |
| - if ($("#grid-clients").hasClass('bootgrid-table')) { |
70 |
| - $("#grid-clients").bootgrid('clear'); |
71 |
| - } else { |
72 |
| - let grid_clients = $("#grid-clients").bootgrid(gridopt).on("loaded.rs.jquery.bootgrid", function(){ |
73 |
| - // hook disconnect button |
74 |
| - grid_clients.find(".command-disconnect").on("click", function(e) { |
75 |
| - var zoneid = $('#cp-zones').find("option:selected").val(); |
76 |
| - var sessionId=$(this).data("row-id"); |
77 |
| - stdDialogConfirm('{{ lang._('Confirm disconnect') }}', |
78 |
| - '{{ lang._('Do you want to disconnect the selected client?') }}', |
79 |
| - '{{ lang._('Yes') }}', '{{ lang._('Cancel') }}', function () { |
80 |
| - ajaxCall("/api/captiveportal/session/disconnect/" + zoneid + '/', |
81 |
| - {'sessionId': sessionId}, function(data,status){ |
82 |
| - // reload grid after delete |
83 |
| - loadSessions(); |
84 |
| - }); |
85 |
| - }); |
86 |
| - }); |
87 |
| - $(this).find(".bootgrid-tooltip").each(function (index) { |
88 |
| - $(this).tooltip(); |
89 |
| - }); |
| 33 | + ajaxGet("/api/captiveportal/session/zones/", {}, function(data, status) { |
| 34 | + if (status == "success") { |
| 35 | + $('#zone-selection').empty(); |
| 36 | + $.each(data, function(key, value) { |
| 37 | + $('#zone-selection').append($("<option></option>").attr("value", key).text(value)); |
90 | 38 | });
|
| 39 | + $('.selectpicker').selectpicker('refresh'); |
91 | 40 | }
|
92 |
| - ajaxGet("/api/captiveportal/session/list/"+zoneid+"/", {}, function(data, status) { |
93 |
| - if (status == "success") { |
94 |
| - // format records (our bootgrid doesn't like null and expects moment for datetime) |
95 |
| - let table = []; |
96 |
| - for (var i = 0; i < data.length; i++) { |
97 |
| - let record = {}; |
98 |
| - $.each(data[i], function(key, value) { |
99 |
| - record[key] = value !== null ? value : ""; |
| 41 | + }); |
| 42 | + |
| 43 | + $("#zone-selection").on("changed.bs.select", function (e) { |
| 44 | + $("#grid-clients").bootgrid('reload'); |
| 45 | + }); |
| 46 | + $("#grid-clients").UIBootgrid({ |
| 47 | + search:'/api/captiveportal/session/search/', |
| 48 | + datakey: 'sessionId', |
| 49 | + commands: { |
| 50 | + disconnect: { |
| 51 | + title: "{{ lang._('Disconnect') }}", |
| 52 | + method: function() { |
| 53 | + let sessid = $(this).data("row-id") !== undefined ? $(this).data("row-id") : ''; |
| 54 | + stdDialogConfirm( |
| 55 | + "{{ lang._('Confirm disconnect') }}", |
| 56 | + "{{ lang._('Do you want to disconnect the selected client?') }}", |
| 57 | + "{{ lang._('Yes') }}", |
| 58 | + "{{ lang._('Cancel') }}", |
| 59 | + function () { |
| 60 | + ajaxCall("/api/captiveportal/session/disconnect",{'sessionId': sessid}, function(data,status){ |
| 61 | + $("#grid-clients").bootgrid('reload'); |
| 62 | + }); |
100 | 63 | });
|
101 |
| - table.push(record); |
102 |
| - } |
103 |
| - $("#grid-clients").bootgrid('append', table); |
104 |
| - // hide actionBar on mobile |
105 |
| - $('.actionBar').addClass('hidden-xs hidden-sm'); |
| 64 | + }, |
| 65 | + classname: 'fa fa-trash-o fa-fw', |
| 66 | + sequence: 1, |
| 67 | + } |
| 68 | + }, |
| 69 | + options: { |
| 70 | + selection: false, |
| 71 | + multiSelect: false, |
| 72 | + useRequestHandlerOnGet: true, |
| 73 | + requestHandler: function(request) { |
| 74 | + request['selected_zones'] = $("#zone-selection").val(); |
| 75 | + return request; |
106 | 76 | }
|
107 |
| - }); |
108 |
| - } |
| 77 | + } |
| 78 | + }); |
109 | 79 |
|
110 |
| - // init with first selected zone |
111 |
| - updateZones(); |
| 80 | + $("#zone-selection-wrapper").detach().prependTo('#grid-clients-header > .row > .actionBar > .actions'); |
112 | 81 | });
|
113 | 82 | </script>
|
114 | 83 |
|
115 |
| -<div class="content-box"> |
116 |
| - <div class="content-box-main"> |
117 |
| - <div class="table-responsive"> |
118 |
| - <div class="col-sm-12"> |
119 |
| - <div class="pull-right"> |
120 |
| - <select id="cp-zones" class="selectpicker" data-width="200px"></select> |
121 |
| - <hr/> |
122 |
| - </div> |
123 |
| - </div> |
124 |
| - <div> |
125 |
| - <table id="grid-clients" class="table table-condensed table-hover table-striped table-responsive"> |
126 |
| - <thead> |
127 |
| - <tr> |
128 |
| - <th data-column-id="sessionId" data-type="string" data-identifier="true" data-visible="false">{{ lang._('Session') }}</th> |
129 |
| - <th data-column-id="userName" data-type="string">{{ lang._('Username') }}</th> |
130 |
| - <th data-column-id="macAddress" data-type="string" data-css-class="hidden-xs hidden-sm" data-header-css-class="hidden-xs hidden-sm">{{ lang._('MAC address') }}</th> |
131 |
| - <th data-column-id="ipAddress" data-type="string" data-css-class="hidden-xs hidden-sm" data-header-css-class="hidden-xs hidden-sm">{{ lang._('IP address') }}</th> |
132 |
| - <th data-column-id="startTime" data-type="datetime">{{ lang._('Connected since') }}</th> |
133 |
| - <th data-column-id="commands" data-searchable="false" data-width="7em" data-formatter="commands" data-sortable="false">{{ lang._('Commands') }}</th> |
134 |
| - </tr> |
135 |
| - </thead> |
136 |
| - <tbody> |
137 |
| - </tbody> |
138 |
| - <tfoot> |
139 |
| - </tfoot> |
140 |
| - </table> |
141 |
| - </div> |
142 |
| - </div> |
| 84 | +<ul class="nav nav-tabs" data-tabs="tabs" id="maintabs"></ul> |
| 85 | +<div class="tab-content content-box col-xs-12 __mb"> |
| 86 | + <div class="btn-group" id="zone-selection-wrapper"> |
| 87 | + <select class="selectpicker" multiple="multiple" data-live-search="true" id="zone-selection" data-width="auto" title="{{ lang._('All Zones') }}"> |
| 88 | + </select> |
143 | 89 | </div>
|
| 90 | + <table id="grid-clients" class="table table-condensed table-hover table-striped table-responsive"> |
| 91 | + <thead> |
| 92 | + <tr> |
| 93 | + <th data-column-id="sessionId" data-type="string" data-identifier="true" data-visible="false">{{ lang._('Session') }}</th> |
| 94 | + <th data-column-id="userName" data-type="string">{{ lang._('Username') }}</th> |
| 95 | + <th data-column-id="macAddress" data-type="string" data-css-class="hidden-xs hidden-sm" data-header-css-class="hidden-xs hidden-sm">{{ lang._('MAC address') }}</th> |
| 96 | + <th data-column-id="ipAddress" data-type="string" data-css-class="hidden-xs hidden-sm" data-header-css-class="hidden-xs hidden-sm">{{ lang._('IP address') }}</th> |
| 97 | + <th data-column-id="startTime" data-type="datetime">{{ lang._('Connected since') }}</th> |
| 98 | + <th data-column-id="commands" data-searchable="false" data-width="7em" data-formatter="commands" data-sortable="false">{{ lang._('Commands') }}</th> |
| 99 | + </tr> |
| 100 | + </thead> |
| 101 | + <tbody> |
| 102 | + </tbody> |
| 103 | + </table> |
144 | 104 | </div>
|
0 commit comments