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

Adding ChatRoomAddForm

This commit is contained in:
Tim Düsterhus 2012-02-04 21:57:39 +01:00
parent cb64177639
commit ed5daa1e0a
6 changed files with 255 additions and 2 deletions

View File

@ -0,0 +1,77 @@
{include file='header'}
<header class="wcf-mainHeading">
<img src="{@RELATIVE_WCF_DIR}icon/{$action}1.svg" alt="" />
<hgroup>
<h1>{lang}wcf.acp.chat.room.{$action}{/lang}</h1>
</hgroup>
</header>
{if $errorField}
<p class="wcf-error">{lang}wcf.global.form.error{/lang}</p>
{/if}
{if $success|isset}
<p class="wcf-success">{lang}wcf.global.form.{$action}.success{/lang}</p>
{/if}
<div class="wcf-contentHeader">
<nav>
<ul class="wcf-largeButtons">
<li><a href="{link controller='ChatRoomList'}{/link}" title="{lang}wcf.acp.menu.link.chat.room.list{/lang}" class="wcf-button"><img src="{@RELATIVE_WCF_DIR}icon/chat1.svg" alt="" /> <span>{lang}wcf.acp.menu.link.chat.room.list{/lang}</span></a></li>
</ul>
</nav>
</div>
<form method="post" action="{if $action == 'add'}{link controller='ChatRoomAdd'}{/link}{else}{link controller='ChatRoomEdit'}{/link}{/if}">
<div class="wcf-border wcf-content">
<fieldset>
<legend>{lang}wcf.acp.chat.room.data{/lang}</legend>
<dl{if $errorField == 'title'} class="wcf-formError"{/if}>
<dt><label for="title">{lang}wcf.acp.chat.room.title{/lang}</label></dt>
<dd>
<input type="text" id="title" name="title" value="{$title}" autofocus="autofocus" class="long" />
{if $errorField == 'title'}
<small class="wcf-innerError">
{if $errorType == 'empty'}
{lang}wcf.global.form.error.empty{/lang}
{else}
{lang}wcf.acp.chat.room.title.error.{@$errorType}{/lang}
{/if}
</small>
{/if}
</dd>
</dl>
{include file='multipleLanguageInputJavascript' elementIdentifier='title'}
<dl{if $errorField == 'topic'} class="wcf-formError"{/if}>
<dt><label for="topic">{lang}wcf.acp.chat.room.topic{/lang}</label></dt>
<dd>
<input type="text" id="topic" name="topic" value="{$topic}" class="long" />
{if $errorField == 'topic'}
<small class="wcf-innerError">
{if $errorType == 'empty'}
{lang}wcf.global.form.error.empty{/lang}
{else}
{lang}wcf.acp.chat.room.topic.error.{@$errorType}{/lang}
{/if}
</small>
{/if}
</dd>
</dl>
{include file='multipleLanguageInputJavascript' elementIdentifier='topic'}
</fieldset>
</div>
<div class="wcf-formSubmit">
<input type="reset" value="{lang}wcf.global.button.reset{/lang}" accesskey="r" />
<input type="submit" value="{lang}wcf.global.button.submit{/lang}" accesskey="s" />
{@SID_INPUT_TAG}
{if $roomID|isset}<input type="hidden" name="id" value="{@$roomID}" />{/if}
</div>
</form>
{include file='footer'}

View File

@ -0,0 +1,152 @@
<?php
namespace wcf\acp\form;
use \wcf\system\exception\UserInputException;
use \wcf\system\language\I18nHandler;
use \wcf\system\package\PackageDependencyHandler;
use \wcf\system\WCF;
/**
* Shows the chatroom add form.
*
* @author Tim Düsterhus
* @copyright 2010-2012 Tim Düsterhus
* @license Creative Commons Attribution-NonCommercial-ShareAlike <http://creativecommons.org/licenses/by-nc-sa/3.0/legalcode>
* @package timwolla.wcf.chat
* @subpackage acp.form
*/
class ChatRoomAddForm extends ACPForm {
/**
* @see wcf\acp\form\ACPForm::$activeMenuItem
*/
public $activeMenuItem = 'wcf.acp.menu.link.chat.room.add';
/**
* @see wcf\page\AbstractPage::$neededPermissions
*/
public $neededPermissions = array('admin.content.chat.canAddRoom');
/**
* Title of the room
*
* @var string
*/
public $title = '';
/**
* Topic of the room
*
* @var string
*/
public $topic = '';
/**
* @see wcf\page\IPage::readParameters()
*/
public function readParameters() {
parent::readParameters();
I18nHandler::getInstance()->register('title');
I18nHandler::getInstance()->register('topic');
}
/**
* @see wcf\form\IForm::readFormParameters()
*/
public function readFormParameters() {
parent::readFormParameters();
I18nHandler::getInstance()->readValues();
if (I18nHandler::getInstance()->isPlainValue('title')) $this->title = I18nHandler::getInstance()->getValue('title');
if (I18nHandler::getInstance()->isPlainValue('topic')) $this->topic = I18nHandler::getInstance()->getValue('topic');
}
/**
* @see wcf\form\IForm::validate()
*/
public function validate() {
parent::validate();
// validate title
try {
if (!I18nHandler::getInstance()->validateValue('title')) {
throw new UserInputException('title');
}
}
catch (UserInputException $e) {
$this->errorType[$e->getField()] = $e->getType();
}
// validate topic
try {
if (!I18nHandler::getInstance()->validateValue('topic')) {
throw new UserInputException('topic');
}
}
catch (UserInputException $e) {
$this->errorType[$e->getField()] = $e->getType();
}
}
/**
* @see wcf\form\IForm::save()
*/
public function save() {
parent::save();
// save room
$chatRoomAction = new \wcf\data\chat\room\ChatRoomAction(array(), 'create', array('data' => array(
'title' => $this->title,
'topic' => $this->topic
)));
$chatRoomAction->executeAction();
$returnValues = $chatRoomAction->getReturnValues();
$chatRoomEditor = new \wcf\data\chat\room\ChatRoomEditor($returnValues['returnValues']);
$roomID = $returnValues['returnValues']->roomID;
if (!I18nHandler::getInstance()->isPlainValue('title')) {
I18nHandler::getInstance()->save('title', 'wcf.chat.room.title.room'.$roomID, 'wcf.chat.room', PackageDependencyHandler::getPackageID('timwolla.wcf.chat'));
// update title
$chatRoomEditor->update(array(
'title' => 'wcf.chat.room.title.room'.$roomID
));
}
if (!I18nHandler::getInstance()->isPlainValue('topic')) {
I18nHandler::getInstance()->save('title', 'wcf.chat.room.topic.room'.$roomID, 'wcf.chat.room', PackageDependencyHandler::getPackageID('timwolla.wcf.chat'));
// update topic
$chatRoomEditor->update(array(
'title' => 'wcf.chat.room.topic.room'.$roomID
));
}
$this->saved();
// reset values
$this->topic = $this->title = '';
I18nHandler::getInstance()->disableAssignValueVariables();
// show success
WCF::getTPL()->assign(array(
'success' => true
));
}
/**
* @see wcf\page\IPage::assignVariables()
*/
public function assignVariables() {
parent::assignVariables();
I18nHandler::getInstance()->assignVariables();
WCF::getTPL()->assign(array(
'action' => 'add',
'title' => $this->title,
'topic' => $this->topic
));
}
}

View File

@ -1,5 +1,6 @@
<?php
namespace wcf\data\chat\room;
use \wcf\system\WCF;
/**
* Provides functions to edit chat rooms.
@ -23,4 +24,24 @@ public static function resetCache() {
ChatRoom::getCache();
\wcf\system\cache\CacheHandler::getInstance()->clearResource('chatrooms');
}
/**
* @see \wcf\data\DatabaseObjectEditor::deleteAll()
*/
public static function deleteAll(array $objectIDs = array()) {
parent::deleteAll($objectIDs);
$packageID = \wcf\system\package\PackageDependencyHandler::getPackageID('timwolla.wcf.chat');
$sql = "DELETE FROM wcf".WCF_N."_language_item
WHERE languageItem = ? AND packageID = ?";
$statement = WCF::getDB()->prepareStatement($sql);
WCF::getDB()->beginTransaction();
foreach ($objectIDs as $objectID) {
$statement->execute(array('wcf.chat.room.title.room'.$objectID, $packageID));
$statement->execute(array('wcf.chat.room.topic.room'.$objectID, $packageID));
}
WCF::getDB()->commitTransaction();
return count($objectIDs);
}
}

View File

@ -21,7 +21,7 @@ CREATE TABLE wcf1_chat_message (
DROP TABLE IF EXISTS wcf1_chat_room;
CREATE TABLE wcf1_chat_room (
roomID int(10) NOT NULL AUTO_INCREMENT,
title varchar(25) NOT NULL,
title varchar(255) NOT NULL,
topic varchar(255) NOT NULL,
position int(10) NOT NULL DEFAULT 0,
permanent tinyint(1) NOT NULL DEFAULT 1,

View File

@ -63,6 +63,9 @@
<item name="wcf.chat.message.2"><![CDATA[hat den Chat verlassen.]]></item>
</category>
<!-- I18N Values -->
<category name="wcf.chat.room" />
<category name="wcf.header">
<item name="wcf.header.menu.chat"><![CDATA[Chat]]></item>
</category>

View File

@ -5,7 +5,7 @@
<packagedescription><![CDATA[Chat for WoltLab Community Framework™]]></packagedescription>
<standalone>0</standalone>
<isunique>1</isunique>
<version>3.0.0 Alpha 5</version>
<version>3.0.0 Alpha 6</version>
<date>2011-11-26</date>
<plugin>com.woltlab.wcf.bbcode</plugin> <!-- TODO: Correct me -->
</packageinformation>