<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header(#{system.online.list.title})" />
</head>
<body class="gray-bg">
<div class="container-div">
	<div class="row">
		<div class="col-sm-12 search-collapse">
			<form id="online-form">
				<div class="select-list">
					<ul>
						<li>
							<label th:text="#{system.online.list.query.ipaddr}"></label><input type="text" name="ipaddr"/>
						</li>
						<li>
							<label th:text="#{system.online.list.query.loginName}"></label><input type="text" name="loginName"/>
						</li>
						<li>
							<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;<span th:text="#{btn.search}"></span></a>
							<a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;<span th:text="#{btn.reset}"></span></a>
						</li>
					</ul>
				</div>
			</form>
		</div>

		<div class="btn-group-sm" id="toolbar" role="group">
			<a class="btn btn-danger multiple disabled" onclick="javascript:batchForceLogout()" shiro:hasPermission="monitor:online:batchForceLogout">
				<i class="fa fa-sign-out"></i> <span th:text="#{btn.forceLogout}"></span>
			</a>
		</div>

		<div class="col-sm-12 select-table table-striped">
			<table id="bootstrap-table"></table>
		</div>
	</div>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: bootstrap-table-export-js" />
<script th:inline="javascript">
	var forceFlag = [[${@permission.hasPermi('monitor:online:forceLogout')}]];
	var prefix = ctx + "monitor/online";

	$(function() {
		var options = {
			uniqueId: "sessionId",
			url: prefix + "/list",
			exportUrl: prefix + "/export",
			sortName: "lastAccessTime",
			sortOrder: "desc",
			showExport: true,
			escape: true,
			columns: [{
				checkbox: true
			},
				{
					title: i18n("system.online.table.serialNumber"),
					formatter: function (value, row, index) {
						return $.table.serialNumber(index);
					}
				},
				{
					field: 'sessionId',
					title: i18n("system.online.table.sessionId"),
					formatter: function(value, row, index) {
						return $.table.tooltip(value);
					}
				},
				{
					field: 'loginName',
					title: i18n("system.online.table.loginName"),
					sortable: true
				},
				{
					field: 'deptName',
					title: i18n("system.online.table.deptName")
				},
				{
					field: 'ipaddr',
					title: i18n("system.online.table.ipaddr")
				},
				{
					field: 'loginLocation',
					title: i18n("system.online.table.loginLocation")
				},
				{
					field: 'browser',
					title: i18n("system.online.table.browser")
				},
				{
					field: 'os',
					title: i18n("system.online.table.os")
				},
				{
					field: 'status',
					title: i18n("system.online.table.status"),
					align: 'center',
					formatter: function(value, row, index) {
						if (value == 'on_line') {
							return '<span class="badge badge-primary">' + i18n("system.online.status.online") + '</span>';
						} else if (value == 'off_line') {
							return '<span class="badge badge-danger">' + i18n("system.online.status.offline") + '</span>';
						}
					}
				},
				{
					field: 'startTimestamp',
					title: i18n("system.online.table.startTimestamp"),
					sortable: true
				},
				{
					field: 'lastAccessTime',
					title: i18n("system.online.table.lastAccessTime"),
					sortable: true
				},
				{
					title: i18n("system.online.table.operation"),
					align: 'center',
					formatter: function(value, row, index) {
						var msg = '<a class="btn btn-danger btn-xs ' + forceFlag + '" href="javascript:void(0)" onclick="forceLogout(\'' + row.sessionId + '\')"><i class="fa fa-sign-out"></i>' + i18n("btn.forceLogout") + '</a> ';
						return msg;
					}
				}]
		};
		$.table.init(options);
	});

	// 单条强退
	function forceLogout(sessionId) {
		$.modal.confirm(i18n("system.online.msg.confirmForceLogout"), function() {
			var data = { "ids": sessionId };
			$.operate.post(prefix + "/batchForceLogout", data);
		})
	}

	// 批量强退
	function batchForceLogout() {
		var rows = $.table.selectColumns("sessionId");
		if (rows.length == 0) {
			$.modal.alertWarning(i18n("system.online.msg.selectUser"));
			return;
		}
		$.modal.confirm(i18n("system.online.msg.confirmBatchForceLogout", rows.length), function() {
			var url = prefix + "/batchForceLogout";
			var data = { "ids": rows.join() };
			$.operate.post(url, data);
		});
	}
</script>
</body>
</html>