From 8b878f2f3cb37144c36fcedb4d6a69e9abb2f283 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Sun, 21 Apr 2013 18:27:55 +0200 Subject: [PATCH] Use AjaxProxy for roomlist refresh --- file/js/be.bastelstu.Chat.litcoffee | 15 +++-- file/lib/data/room/RoomAction.class.php | 34 ++++++++++ file/lib/page/RoomListPage.class.php | 85 ------------------------- 3 files changed, 43 insertions(+), 91 deletions(-) delete mode 100644 file/lib/page/RoomListPage.class.php diff --git a/file/js/be.bastelstu.Chat.litcoffee b/file/js/be.bastelstu.Chat.litcoffee index 0031ee1..c764ec7 100644 --- a/file/js/be.bastelstu.Chat.litcoffee +++ b/file/js/be.bastelstu.Chat.litcoffee @@ -611,15 +611,18 @@ Updates the room list. console.log 'Refreshing the roomlist' $('#toggleRooms .ajaxLoad').show() - $.ajax $('#toggleRooms a').data('refreshUrl'), - dataType: 'json' - type: 'POST' - success: (data, textStatus, jqXHR) => + proxy = new WCF.Action.Proxy + autoSend: true + data: + actionName: 'getRoomList' + className: 'chat\\data\\room\\RoomAction' + showLoadingOverlay: false + success: (data) => $('#timsChatRoomList li').remove() $('#toggleRooms .ajaxLoad').hide() - $('#toggleRooms .badge').text data.length + $('#toggleRooms .badge').text data.returnValues.length - for room in data + for room in data.returnValues li = $ '
  • ' li.addClass 'activeMenuItem' if room.active $("""#{room.title}""").addClass('timsChatRoom').appendTo li diff --git a/file/lib/data/room/RoomAction.class.php b/file/lib/data/room/RoomAction.class.php index c711fee..4df07d6 100644 --- a/file/lib/data/room/RoomAction.class.php +++ b/file/lib/data/room/RoomAction.class.php @@ -118,4 +118,38 @@ public function updatePosition() { } WCF::getDB()->commitTransaction(); } + + /** + * Validates parameters and permissions. + */ + public function validateGetRoomList() { + if (!CHAT_ACTIVE) throw new \wcf\system\exception\IllegalLinkException(); + } + + /** + * Returns the available rooms. + */ + public function getRoomList() { + $rooms = Room::getCache(); + + $roomID = \chat\util\ChatUtil::readUserData('roomID'); + if (!isset($rooms[$roomID])) throw new \wcf\system\exception\IllegalLinkException(); + $activeRoom = $rooms[$roomID]; + + $result = array(); + foreach ($rooms as $room) { + if (!$room->canEnter()) continue; + + $result[] = array( + 'title' => (string) $room, + 'link' => \wcf\system\request\LinkHandler::getInstance()->getLink('Chat', array( + 'application' => 'chat', + 'object' => $room + )), + 'active' => $room->roomID == $activeRoom->roomID + ); + } + + return $result; + } } diff --git a/file/lib/page/RoomListPage.class.php b/file/lib/page/RoomListPage.class.php deleted file mode 100644 index 7e53879..0000000 --- a/file/lib/page/RoomListPage.class.php +++ /dev/null @@ -1,85 +0,0 @@ - - * @package be.bastelstu.chat - * @subpackage page - */ -class RoomListPage extends \wcf\page\AbstractPage { - /** - * @see wcf\page\AbstractPage::$loginRequired - */ - public $loginRequired = true; - - /** - * @see \wcf\page\AbstractPage::$neededModules - */ - public $neededModules = array('CHAT_ACTIVE'); - - /** - * @see \wcf\page\AbstractPage::$neededPermissions - */ - public $neededPermissions = array(); - - /** - * the room the user current is in - * @var \chat\data\room\Room - */ - public $room = null; - - /** - * all rooms in the current installation - * @var array<\chat\data\room\Room> - */ - public $rooms = array(); - - /** - * @see \wcf\page\AbstractPage::$useTemplate - */ - public $useTemplate = false; - - /** - * @see \wcf\page\IPage::readData() - */ - public function readData() { - parent::readData(); - - $this->rooms = data\room\Room::getCache(); - - $roomID = \chat\util\ChatUtil::readUserData('roomID'); - if (!isset($this->rooms[$roomID])) throw new IllegalLinkException(); - $this->room = $this->rooms[$roomID]; - } - - /** - * @see \wcf\page\IPage::show() - */ - public function show() { - parent::show(); - - @header('Content-type: application/json'); - $json = array(); - foreach ($this->rooms as $room) { - if (!$room->canEnter()) continue; - - $json[] = array( - 'title' => WCF::getLanguage()->get($room->title), - 'link' => \wcf\system\request\LinkHandler::getInstance()->getLink('Chat', array( - 'application' => 'chat', - 'object' => $room - )), - 'active' => $room->roomID == $this->room->roomID - ); - } - echo \wcf\util\JSON::encode($json); - exit; - } -}