/**
* Provides the ability to remove application groups.
+ *
+ * @param string redirectURL
*/
WCF.ACP.Application.Group.Delete = Class.extend({
+ /**
+ * redirect URL
+ * @var string
+ */
+ _redirectURL: '',
+
/**
* Initializes the WCF.ACP.Application.Group.Delete class.
+ *
+ * @param string redirectURL
*/
- init: function() {
+ init: function(redirectURL) {
+ this._redirectURL = redirectURL || '';
+
$('.jsDeleteApplicationGroup').click($.proxy(this._click, this));
},
},
success: $.proxy(function(data, textStatus, jqXHR) {
var $notification = new WCF.System.Notification(WCF.Language.get('wcf.acp.application.group.delete.success'));
- $notification.show(function() {
- window.location.reload();
- });
+ $notification.show($.proxy(function() {
+ if (this._redirectURL) {
+ window.location = this._redirectURL;
+ }
+ else {
+ window.location.reload();
+ }
+ }, this));
}, this)
});
}
-{include file='header' pageTitle='wcf.acp.application.group.add'}
+{include file='header' pageTitle='wcf.acp.application.group.'|concat:$action}
+
+<script type="text/javascript">
+ //<![CDATA[
+ $(function() {
+ new WCF.ACP.Application.Group.Delete('{link controller='ApplicationManagement'}{/link}');
+
+ WCF.Language.addObject({
+ 'wcf.acp.application.group.delete.success': '{lang}wcf.acp.application.group.delete.success{/lang}'
+ });
+ });
+ //]]>
+</script>
<header class="boxHeadline">
<hgroup>
- <h1>{lang}wcf.acp.application.group.add{/lang}</h1>
+ <h1>{lang}wcf.acp.application.group.{$action}{/lang}</h1>
</hgroup>
</header>
<div class="contentNavigation">
<nav>
<ul>
+ {if $action == 'edit'}<li><a class="button jsDeleteApplicationGroup" data-confirm-message="{lang}wcf.acp.application.group.delete.confirmMessage{/lang}" data-group-id="{@$applicationGroup->groupID}"><img src="{@RELATIVE_WCF_DIR}icon/delete.svg" class="icon24" /> <span>{lang}wcf.acp.application.group.delete{/lang}</span></a></li>{/if}
<li><a href="{link controller='ApplicationManagement'}{/link}" class="button"><img src="{@RELATIVE_WCF_DIR}icon/list.svg" alt="" /> <span>{lang}wcf.acp.application.management{/lang}</span></a></li>
</ul>
</nav>
</div>
<div class="container containerPadding marginTop">
- <form method="post" action="{link controller='ApplicationGroupAdd'}{/link}">
+ <form method="post" action="{if $action == 'add'}{link controller='ApplicationGroupAdd'}{/link}{else}{link controller='ApplicationGroupEdit' id=$applicationGroup->groupID}{/link}{/if}">
<fieldset>
<legend>{lang}wcf.acp.application.group.data{/lang}</legend>
<dl{if $errorField == 'groupName'} class="formError"{/if}>
<dt><label for="groupName">{lang}wcf.acp.application.group.groupName{/lang}</label></dt>
<dd>
- <input type="text" name="groupName" id="groupName" value="{$groupName}" class="long" />
+ <input type="text" name="groupName" id="groupName" value="{$groupName}" class="long" required="required" />
{if $errorField == 'groupName'}
<small class="innerError">
{if $errorType == 'empty'}
<div class="contentNavigation">
<nav>
<ul>
- <li><a href="{link controller='ApplicationGroupEdit' id=$applicationGroup->groupID}{/link}" class="button"><img src="{@RELATIVE_WCF_DIR}icon/edit.svg" class="icon24" /> <span>{lang}wcf.acp.application.group.edit{/lang}</span></a></li>
<li><a class="button jsDeleteApplicationGroup" data-confirm-message="{lang}wcf.acp.application.group.delete.confirmMessage{/lang}" data-group-id="{@$applicationGroup->groupID}"><img src="{@RELATIVE_WCF_DIR}icon/delete.svg" class="icon24" /> <span>{lang}wcf.acp.application.group.delete{/lang}</span></a></li>
+ <li><a href="{link controller='ApplicationGroupEdit' id=$applicationGroup->groupID}{/link}" class="button"><img src="{@RELATIVE_WCF_DIR}icon/edit.svg" class="icon24" /> <span>{lang}wcf.acp.application.group.edit{/lang}</span></a></li>
</ul>
</nav>
</div>
parent::validate();
// validate group name
- if (empty($this->groupName)) {
- throw new UserInputException('groupName');
- }
- else {
- // check for duplicates
- $sql = "SELECT COUNT(*) AS count
- FROM wcf".WCF_N."_application_group
- WHERE groupName = ?";
- $statement = WCF::getDB()->prepareStatement($sql);
- $statement->execute(array($this->groupName));
- $row = $statement->fetchArray();
- if ($row['count']) {
- throw new UserInputException('groupName', 'notUnique');
- }
- }
+ $this->validateGroupName();
// validate application package ids
if (empty($this->applications)) {
}
}
+ /**
+ * Validates group name.
+ */
+ protected function validateGroupName() {
+ if (empty($this->groupName)) {
+ throw new UserInputException('groupName');
+ }
+ else {
+ // check for duplicates
+ $sql = "SELECT COUNT(*) AS count
+ FROM wcf".WCF_N."_application_group
+ WHERE groupName = ?";
+ $statement = WCF::getDB()->prepareStatement($sql);
+ $statement->execute(array($this->groupName));
+ $row = $statement->fetchArray();
+ if ($row['count']) {
+ throw new UserInputException('groupName', 'notUnique');
+ }
+ }
+ }
+
/**
* @see wcf\form\IForm::save()
*/
--- /dev/null
+<?php
+namespace wcf\acp\form;
+use wcf\data\application\group\ApplicationGroup;
+use wcf\data\application\group\ApplicationGroupAction;
+use wcf\data\application\ViewableApplicationList;
+use wcf\system\exception\IllegalLinkException;
+use wcf\system\exception\UserInputException;
+use wcf\system\WCF;
+
+/**
+ * Shows the application group edit form.
+ *
+ * @author Alexander Ebert
+ * @copyright 2001-2012 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package com.woltlab.wcf
+ * @subpackage acp.form
+ * @category Community Framework
+ */
+class ApplicationGroupEditForm extends ApplicationGroupAddForm {
+ /**
+ * application group object
+ * @var wcf\data\application\group\ApplicationGroup
+ */
+ public $applicationGroup = null;
+
+ /**
+ * groupd id
+ * @var integer
+ */
+ public $groupID = 0;
+
+ /**
+ * @see wcf\page\IPage::readParameters()
+ */
+ public function readParameters() {
+ if (isset($_REQUEST['id'])) $this->groupID = intval($_REQUEST['id']);
+ $this->applicationGroup = new ApplicationGroup($this->groupID);
+ if (!$this->applicationGroup->groupID) {
+ throw new IllegalLinkException();
+ }
+
+ parent::readParameters();
+ }
+
+ /**
+ * Reads the list of available applications.
+ */
+ protected function readAvailableApplications() {
+ $applicationList = new ViewableApplicationList();
+ $applicationList->getConditionBuilder()->add("(application.groupID = ? OR application.groupID IS NULL)", array($this->applicationGroup->groupID));
+ $applicationList->sqlLimit = 0;
+ $applicationList->readObjects();
+
+ $this->availableApplications = $applicationList->getObjects();
+ foreach ($this->availableApplications as $application) {
+ if ($application->groupID == $this->applicationGroup->groupID) {
+ $this->applications[] = $application->packageID;
+ }
+ }
+ }
+
+ /**
+ * @see wcf\acp\form\ApplicationGroupAddForm::validateGroupName()
+ */
+ protected function validateGroupName() {
+ if (empty($this->groupName)) {
+ throw new UserInputException('groupName');
+ }
+ else {
+ // check for duplicates
+ $sql = "SELECT COUNT(*) AS count
+ FROM wcf".WCF_N."_application_group
+ WHERE groupName = ?
+ AND groupID <> ?";
+ $statement = WCF::getDB()->prepareStatement($sql);
+ $statement->execute(array(
+ $this->groupName,
+ $this->applicationGroup->groupID
+ ));
+ $row = $statement->fetchArray();
+ if ($row['count']) {
+ throw new UserInputException('groupName', 'notUnique');
+ }
+ }
+ }
+
+ /**
+ * @see wcf\page\IPage::readData()
+ */
+ public function readData() {
+ parent::readData();
+
+ if (empty($_POST)) {
+ $this->groupName = $this->applicationGroup->groupName;
+ }
+ }
+
+ /**
+ * @see wcf\form\IForm::save()
+ */
+ public function save() {
+ ACPForm::save();
+
+ // save group
+ $this->objectAction = new ApplicationGroupAction(array($this->applicationGroup), 'update', array(
+ 'applications' => $this->applications,
+ 'data' => array(
+ 'groupName' => $this->groupName
+ )
+ ));
+ $this->objectAction->executeAction();
+ $this->saved();
+
+ // show success.
+ WCF::getTPL()->assign(array(
+ 'success' => true
+ ));
+ }
+
+ /**
+ * @see wcf\page\IPage::assignVariables()
+ */
+ public function assignVariables() {
+ parent::assignVariables();
+
+ WCF::getTPL()->assign(array(
+ 'action' => 'edit',
+ 'applicationGroup' => $this->applicationGroup,
+ 'groupID' => $this->groupID
+ ));
+ }
+}
}
/**
- * @see wcf\data\AbstractDatabaseObjectAction::delete()
+ * @see wcf\data\AbstractDatabaseObjectAction::update()
*/
- public function delete() {
- $groupIDs = array();
- foreach ($this->objects as $applicationGroup) {
- $groupIDs[] = $applicationGroup->groupID;
+ public function update() {
+ parent::update();
+
+ // read list of currently associated applications
+ $applicationGroup = current($this->objects);
+ $applicationList = new ApplicationList();
+ $applicationList->getConditionBuilder()->add("application.groupID = ?", array($applicationGroup->groupID));
+ $applicationList->sqlLimit = 0;
+ $applicationList->readObjects();
+
+ $updateApplications = $removeApplications = array();
+ foreach ($applicationList as $application) {
+ $index = array_search($application->packageID, $this->parameters['applications']);
+ if ($index === false) {
+ $removeApplications[] = $application;
+ }
+ else {
+ // already existing
+ $updateApplications[] = $application;
+ unset($this->parameters['applications'][$index]);
+ }
+ }
+
+ if (!empty($this->parameters['applications'])) {
+ $applicationList = new ApplicationList();
+ $applicationList->getConditionBuilder()->add("application.packageID IN (?)", $this->parameters['applications']);
+ $applicationList->sqlLimit = 0;
+ $applicationList->readObjects();
+ $updateApplications = array_merge($updateApplications, $applicationList->getObjects());
+ }
+
+ // rebuild current group
+ $applicationAction = new ApplicationAction($updateApplications, 'group', array('groupID' => $applicationGroup->groupID));
+ $applicationAction->executeAction();
+
+ // remove applications from group
+ if (!empty($removeApplications)) {
+ $applicationAction = new ApplicationAction($removeApplications, 'ungroup');
+ $applicationAction->executeAction();
}
- // read all applications associated by affected groups
+ $this->clearCache();
+ }
+
+ /**
+ * @see wcf\data\AbstractDatabaseObjectAction::delete()
+ */
+ public function delete() {
+ // read all associated applications
+ $applicationGroup = current($this->objects);
$applicationList = new ApplicationList();
- $applicationList->getConditionBuilder()->add("application.groupID IN (?)", array($groupIDs));
+ $applicationList->getConditionBuilder()->add("application.groupID = ?", array($applicationGroup->groupID));
$applicationList->sqlLimit = 0;
$applicationList->readObjects();
$applicationAction = new ApplicationAction($applicationList->getObjects(), 'ungroup');
$applicationAction->executeAction();
+ $this->clearCache();
+
+ return parent::delete();
+ }
+
+ /**
+ * Clears WCF cache.
+ */
+ protected function clearCache() {
// delete language cache and compiled templates
LanguageFactory::getInstance()->deleteLanguageCache();
// delete WCF cache
CacheHandler::getInstance()->clear(WCF_DIR.'cache', '*.php');
CacheHandler::getInstance()->clear(WCF_DIR.'cache/templateListener', '*.php');
-
- return parent::delete();
}
}