1
0
mirror of https://github.com/wbbaddons/Tims-Chat.git synced 2024-10-31 14:10:08 +00:00

Made rooms sortable

This commit is contained in:
Tim Düsterhus 2012-03-03 21:36:52 +01:00
parent b68f4087eb
commit 86544d5ae8
3 changed files with 101 additions and 74 deletions

View File

@ -1,18 +1,19 @@
{include file='header'}
<script type="text/javascript">
//<![CDATA[
$(function() {
new WCF.Action.Delete('\\wcf\\data\\chat\\room\\ChatRoomAction', $('.chatRoomRow'));
new WCF.Sortable.List('chatRoomList', '\\wcf\\data\\chat\\room\\ChatRoomAction');
});
//]]>
</script>
<header class="wcf-mainHeading wcf-container">
<img src="{@$__wcf->getPath('wcf')}icon/chat1.svg" alt="" class="wcf-containerIcon" />
<hgroup class="wcf-containerContent">
<h1>{lang}wcf.acp.chat.room.list{/lang}</h1>
</hgroup>
<script type="text/javascript">
//<![CDATA[
$(function() {
new WCF.Action.Delete('wcf\\data\\chat\\room\\ChatRoomAction', $('.chatRoomRow'), $('.wcf-content .wcf-badge'));
});
//]]>
</script>
</header>
<div class="wcf-contentHeader">
@ -27,69 +28,31 @@
{/if}
</div>
{hascontent}
<div class="wcf-border wcf-boxTitle">
<hgroup>
<h1>{lang}wcf.acp.chat.room.list{/lang} <span class="wcf-badge" title="{lang}wcf.acp.chat.room.list.count{/lang}">{#$items}</span></h1>
</hgroup>
<table>
<thead>
<tr>
<th class="columnID columnChatRoomID" colspan="2">{lang}wcf.global.objectID{/lang}</th>
<th class="columnTitle columnChatRoomTitle">{lang}wcf.acp.chat.room.title{/lang}</th>
{event name='headColumns'}
</tr>
</thead>
<tbody>
{content}
{foreach from=$objects item=chatRoom}
<tr class="chatRoomRow">
<td class="columnIcon">
{if $__wcf->session->getPermission('admin.content.chat.canEditRoom')}
<a href="{link controller='ChatRoomEdit' id=$chatRoom->roomID}{/link}"><img src="{@$__wcf->getPath('wcf')}icon/edit1.svg" alt="" title="{lang}wcf.global.button.edit{/lang}" class="balloonTooltip" /></a>
{else}
<img src="{@$__wcf->getPath('wcf')}icon/edit1D.svg" alt="" title="{lang}wcf.global.button.edit{/lang}" />
{/if}
{if $__wcf->session->getPermission('admin.content.chat.canDeleteRoom')}
<img src="{@$__wcf->getPath('wcf')}icon/delete1.svg" alt="" title="{lang}wcf.global.button.delete{/lang}" class="deleteButton balloonTooltip" data-object-id="{@$chatRoom->roomID}" data-confirm-message="{lang}wcf.acp.bbcode.delete.sure{/lang}" />
{else}
<img src="{@$__wcf->getPath('wcf')}icon/delete1D.svg" alt="" title="{lang}wcf.global.button.delete{/lang}" />
{/if}
{event name='buttons'}
</td>
<td class="columnID"><p>{@$chatRoom->roomID}</p></td>
<td class="columnTitle columnChatRoomTitle"><p>{if $__wcf->session->getPermission('admin.content.chat.canEditRoom')}<a href="{link controller='ChatRoomEdit' id=$chatRoom->roomID}{/link}">{$chatRoom->title|language}</a>{else}{$chatRoom->title|language}{/if}</p></td>
{event name='columns'}
</tr>
{/foreach}
{/content}
</tbody>
</table>
</div>
<div class="wcf-contentFooter">
{@$pagesLinks}
{if $__wcf->session->getPermission('admin.content.chat.canAddRoom')}
<nav>
<ul class="wcf-largeButtons">
<li><a href="{link controller='ChatRoomAdd'}{/link}" title="{lang}wcf.acp.chat.room.add{/lang}" class="wcf-button"><img src="{@$__wcf->getPath('wcf')}icon/add1.svg" alt="" /> <span>{lang}wcf.acp.chat.room.add{/lang}</span></a></li>
</ul>
</nav>
{/if}
</div>
{hascontentelse}
<div class="wcf-border wcf-content">
<div>
<p class="wcf-warning">{lang}wcf.acp.chat.room.noneAvailable{/lang}</p>
</div>
</div>
{/hascontent}
<section id="chatRoomList" class="wcf-border wcf-sortableListContainer">
{hascontent}
<ol class="wcf-sortableList" data-object-id="0">
{content}
{foreach from=$objects item=chatRoom}
<li class="wcf-sortableNode chatRoomRow" data-object-id="{@$chatRoom->roomID}">
<span class="wcf-sortableNodeLabel">
<a href="{link controller='ChatRoomEdit' id=$chatRoom->roomID}{/link}">{$chatRoom->title|language}</a>
<span class="wcf-sortableButtonContainer">
{if $__wcf->session->getPermission('admin.content.chat.canEditRoom')}
<a href="{link controller='ChatRoomEdit' id=$chatRoom->roomID}{/link}"><img src="{@$__wcf->getPath('wcf')}icon/edit1.svg" alt="" title="{lang}wcf.global.button.edit{/lang}" class="balloonTooltip" /></a>
{/if}
{if $__wcf->session->getPermission('admin.content.chat.canDeleteRoom')}
<img src="{@$__wcf->getPath('wcf')}icon/delete1.svg" alt="" title="{lang}wcf.global.button.delete{/lang}" class="jsDeleteButton jsTooltip" data-object-id="{@$chatRoom->roomID}" data-confirm-message="{lang}wcf.acp.bbcode.delete.sure{/lang}" />
{/if}
</span>
</span>
</li>
{/foreach}
{/content}
</ol>
{hascontentelse}
<p class="wcf-warning">{lang}wcf.acp.chat.room.noneAvailable{/lang}</p>
{/hascontent}
</section>
{include file='footer'}

View File

@ -117,7 +117,7 @@ public function save() {
}
\wcf\system\acl\ACLHandler::getInstance()->save($roomID, $this->objectTypeID);
\wcf\system\chat\permissions\ChatPermissionHandler::clearCache();
\wcf\system\chat\permission\ChatPermissionHandler::clearCache();
$this->saved();

View File

@ -1,5 +1,6 @@
<?php
namespace wcf\data\chat\room;
use \wcf\system\WCF;
/**
* Executes chatroom-related actions.
@ -25,4 +26,67 @@ class ChatRoomAction extends \wcf\data\AbstractDatabaseObjectAction {
* @see \wcf\data\AbstractDatabaseObjectAction::$permissionsUpdate
*/
protected $permissionsUpdate = array('admin.content.chat.canEditRoom');
/**
* Fixes create to append new boards.
*/
public function create() {
$room = parent::create();
WCF::getDB()->beginTransaction();
$sql = "SELECT max(position) as max
FROM wcf".WCF_N."_chat_room";
$stmt = WCF::getDB()->prepareStatement($sql);
$stmt->execute();
$row = $stmt->fetchArray();
$sql = "UPDATE wcf".WCF_N."_chat_room
SET position = ".($row['max'] + 1)."
WHERE roomID = ?";
$stmt = WCF::getDB()->prepareStatement($sql);
$stmt->execute(array($room->roomID));
WCF::getDB()->commitTransaction();
return $room;
}
/**
* Validates parameters to update sorting.
*/
public function validateUpdatePosition() {
// validate permissions
if (is_array($this->permissionsUpdate) && count($this->permissionsUpdate)) {
try {
WCF::getSession()->checkPermissions($this->permissionsUpdate);
}
catch (\wcf\system\exception\PermissionDeniedException $e) {
throw new ValidateActionException('Insufficient permissions');
}
}
else {
throw new ValidateActionException('Insufficient permissions');
}
if (!isset($this->parameters['data']['structure'])) {
throw new ValidateActionException('Missing parameter structure');
}
}
/**
* Updates sorting.
*/
public function updatePosition() {
$roomList = new \wcf\data\chat\room\ChatRoomList();
$roomList->sqlOrderBy = "chat_room.position";
$roomList->sqlLimit = 0;
$roomList->readObjects();
$i = 0;
WCF::getDB()->beginTransaction();
foreach ($this->parameters['data']['structure'][0] as $roomID) {
$editor = new ChatRoomEditor($roomList->search($roomID));
$editor->update(array('position' => $i++));
}
WCF::getDB()->commitTransaction();
}
}