1
0
mirror of https://github.com/wbbaddons/Tims-Chat.git synced 2024-12-21 21:30:08 +00:00

Automatically refresh room list in room selector

This commit is contained in:
Tim Düsterhus 2014-02-27 19:49:01 +01:00
parent 1f533e255f
commit 2e0651ddd8
4 changed files with 89 additions and 85 deletions

View File

@ -323,27 +323,28 @@ public function removeDeadUsers() {
/**
* Validates permissions.
*/
public function validateGetDashboardRoomList() {
public function validateGetBoxRoomList() {
if (!MODULE_CHAT) throw new \wcf\system\exception\IllegalLinkException();
}
/**
* Returns dashboard roomlist.
*/
public function getDashboardRoomList() {
public function getBoxRoomList() {
$rooms = RoomCache::getInstance()->getRooms();
foreach ($rooms as $key => $room) {
if (!$room->canEnter()) unset($rooms[$key]);
}
$this->readBoolean('showEmptyRooms', true);
\wcf\system\WCF::getTPL()->assign(array(
'rooms' => $rooms,
'onlyList' => true
'showEmptyRooms' => $this->parameters['showEmptyRooms']
));
return array(
'template' => \wcf\system\WCF::getTPL()->fetch('dashboardBoxOnlineList', 'chat')
'template' => \wcf\system\WCF::getTPL()->fetch('boxRoomList', 'chat')
);
}
}

22
template/boxRoomList.tpl Normal file
View File

@ -0,0 +1,22 @@
{foreach from=$rooms item='room'}
{assign var='users' value=$room->getUsers()}
{if $showEmptyRooms || $users|count > 0}
<li>
<div>
<div>
<div class="containerHeadline">
<h3><a href="{link application='chat' controller='Chat' object=$room}{/link}">{$room}</a> <span class="badge">{#$users|count}</span></h3>
<p>{$room->topic|language}</p>
</div>
<ul class="dataList">
{foreach from=$users item='user'}
<li><a href="{link controller='User' object=$user}{/link}" class="userLink" data-user-id="{$user->userID}">{$user}</a></li>
{/foreach}
</ul>
</div>
</div>
</li>
{/if}
{/foreach}

View File

@ -161,29 +161,33 @@
<h1>{lang}chat.general.title{/lang}</h1>
</header>
<div class="container marginTop">
<div id="chatRoomListContainer" class="container marginTop">
<ul class="containerList">
{foreach from=$rooms item='room'}
{assign var='users' value=$room->getUsers()}
<li>
<div>
<div>
<div class="containerHeadline">
<h3><a href="{link application='chat' controller='Chat' object=$room}{/link}">{$room}</a> <span class="badge">{#$users|count}</span></h3>
<p>{$room->topic|language}</p>
</div>
<ul class="dataList">
{foreach from=$users item='user'}
<li><a href="{link controller='User' object=$user}{/link}" class="userLink" data-user-id="{$user->userID}">{$user}</a></li>
{/foreach}
</ul>
</div>
</div>
</li>
{/foreach}
{include application='chat' file='boxRoomList' showEmptyRooms=true}
</ul>
<script data-relocate="true">
//<![CDATA[
(function($, window, undefined) {
proxy = new WCF.Action.Proxy({
data: {
actionName: 'getBoxRoomList',
className: 'chat\\data\\room\\RoomAction',
parameters: {
showEmptyRooms: 1
}
},
showLoadingOverlay: false,
suppressErrors: true,
success: function(data) {
$('#chatRoomListContainer ul').html(data.returnValues.template);
}
});
be.bastelstu.wcf.nodePush.onMessage('be.bastelstu.chat.join', $.proxy(proxy.sendRequest, proxy));
be.bastelstu.wcf.nodePush.onMessage('be.bastelstu.chat.leave', $.proxy(proxy.sendRequest, proxy));
})(jQuery, this);
//]]>
</script>
</div>
{/if}

View File

@ -1,62 +1,39 @@
{capture assign='roomList'}
{foreach from=$rooms item='room'}
{assign var='users' value=$room->getUsers()}
{if $users|count > 0}
<li>
<div>
<div>
<div class="containerHeadline">
<h3><a href="{link application='chat' controller='Chat' object=$room}{/link}">{$room}</a> <span class="badge">{#$users|count}</span></h3>
<p>{$room->topic|language}</p>
</div>
<ul class="dataList">
{foreach from=$users item='user'}
<li><a href="{link controller='User' object=$user}{/link}" class="userLink" data-user-id="{$user->userID}">{$user}</a></li>
{/foreach}
</ul>
</div>
</div>
</li>
{/if}
{/foreach}
{/capture}
{if $onlyList|isset}
{@$roomList}
{else}
<div id="chatDashboardBoxOnlineListContainer" {if !$roomList|trim} style="display: none;"{/if}>
<header class="boxHeadline boxSubHeadline">
<h2>{lang}chat.header.menu.chat{/lang}</h2>
</header>
{capture assign='roomList'}{include application='chat' file='boxRoomList' showEmptyRooms=false}{/capture}
<div class="container marginTop">
<ul class="containerList">
{@$roomList}
</ul>
</div>
<script data-relocate="true">
//<![CDATA[
(function($, window, undefined) {
proxy = new WCF.Action.Proxy({
data: {
actionName: 'getDashboardRoomList',
className: 'chat\\data\\room\\RoomAction'
},
showLoadingOverlay: false,
suppressErrors: true,
success: function(data) {
if (data.returnValues.template) $('#chatDashboardBoxOnlineListContainer').show();
else $('#chatDashboardBoxOnlineListContainer').hide();
$('#chatDashboardBoxOnlineListContainer ul').html(data.returnValues.template);
}
});
be.bastelstu.wcf.nodePush.onMessage('be.bastelstu.chat.join', $.proxy(proxy.sendRequest, proxy));
be.bastelstu.wcf.nodePush.onMessage('be.bastelstu.chat.leave', $.proxy(proxy.sendRequest, proxy));
})(jQuery, this);
//]]>
</script>
<div id="chatDashboardBoxOnlineListContainer"{if !$roomList|trim} style="display: none;"{/if}>
<header class="boxHeadline boxSubHeadline">
<h2>{lang}chat.header.menu.chat{/lang}</h2>
</header>
<div class="container marginTop">
<ul class="containerList">
{@$roomList}
</ul>
</div>
{/if}
<script data-relocate="true">
//<![CDATA[
(function($, window, undefined) {
proxy = new WCF.Action.Proxy({
data: {
actionName: 'getBoxRoomList',
className: 'chat\\data\\room\\RoomAction',
parameters: {
showEmptyRooms: 0
}
},
showLoadingOverlay: false,
suppressErrors: true,
success: function(data) {
if (data.returnValues.template) $('#chatDashboardBoxOnlineListContainer').show();
else $('#chatDashboardBoxOnlineListContainer').hide();
$('#chatDashboardBoxOnlineListContainer ul').html(data.returnValues.template);
}
});
be.bastelstu.wcf.nodePush.onMessage('be.bastelstu.chat.join', $.proxy(proxy.sendRequest, proxy));
be.bastelstu.wcf.nodePush.onMessage('be.bastelstu.chat.leave', $.proxy(proxy.sendRequest, proxy));
})(jQuery, this);
//]]>
</script>
</div>