From 6c6894cff45276ce16b56c4c32c10cda544d7562 Mon Sep 17 00:00:00 2001
From: bshuttle
Date: Mon, 27 Feb 2006 10:09:01 +0000
Subject: [PATCH] improve unit management (KTS-490)
---
plugins/ktcore/admin/unitManagement.php | 18 ++++++++++++++----
templates/ktcore/principals/addunit2.smarty | 5 +++++
2 files changed, 19 insertions(+), 4 deletions(-)
diff --git a/plugins/ktcore/admin/unitManagement.php b/plugins/ktcore/admin/unitManagement.php
index 3adbabc..95b0a14 100755
--- a/plugins/ktcore/admin/unitManagement.php
+++ b/plugins/ktcore/admin/unitManagement.php
@@ -59,9 +59,11 @@ class KTUnitAdminDispatcher extends KTAdminDispatcher {
$aOptions = array(
'redirect_to' => array('addUnit'),
- 'message' => 'No name given',
+ 'message' => _('No name given'),
);
$sName = $this->oValidator->validateString($_REQUEST['unit_name'], $aOptions);
+ $aOptions['message'] = _('A unit with that name already exists.');
+ $sName = $this->oValidator->validateDuplicateName('Unit', _('Unit'), $sName, $aOptions);
$iFolderId = KTUtil::arrayGet($_REQUEST, 'fFolderId', 1);
$_REQUEST['fFolderId'] = $iFolderId;
@@ -104,6 +106,11 @@ class KTUnitAdminDispatcher extends KTAdminDispatcher {
$add_fields = array();
$add_fields[] = new KTStaticTextWidget(_('Unit Name'),_('A short name for the unit. e.g. Accounting.'), 'unit_name', $sName, $this->oPage, true);
+ $isValid = true;
+ if (KTFolderUtil::exists($oFolder, $sName)) {
+ $isValid = false; // can't add a unit folder with the same name.
+ }
+
$oTemplating =& KTTemplating::getSingleton();
$oTemplate = $oTemplating->loadTemplate("ktcore/principals/addunit2");
$aTemplateData = array(
@@ -113,6 +120,7 @@ class KTUnitAdminDispatcher extends KTAdminDispatcher {
"collection_breadcrumbs" => $aBreadcrumbs,
"folder" => $oFolder,
"name" => $sName,
+ "is_valid" => $isValid,
);
return $oTemplate->render($aTemplateData);
}
@@ -120,18 +128,20 @@ class KTUnitAdminDispatcher extends KTAdminDispatcher {
function do_createUnit() {
$aOptions = array(
'redirect_to' => array('main'),
- 'message' => 'Invalid folder chosen',
+ 'message' => _('Invalid folder chosen'),
);
$oParentFolder = $this->oValidator->validateFolder($_REQUEST['fFolderId'], $aOptions);
$aOptions = array(
'redirect_to' => array('addUnit', sprintf('fFolderId=%d', $oParentFolder->getId())),
- 'message' => 'No name given',
+ 'message' => _('No name given'),
);
$sName = $this->oValidator->validateString($_REQUEST['unit_name'], $aOptions);
+ $aOptions['message'] = _('A unit with that name already exists.');
+ $sName = $this->oValidator->validateDuplicateName('Unit', _('Unit'), $sName, $aOptions);
$oFolder = KTFolderUtil::add($oParentFolder, $sName, $this->oUser);
$aOptions = array(
- 'redirect_to' => array('addUnit', sprintf('fFolderId=%d', $oParentFolder->getId())),
+ 'redirect_to' => array('addUnit2', sprintf('fFolderId=%d&unit_name=%s', $oParentFolder->getId(), $sName)),
'defaultmessage' => 'Error creating folder',
);
$this->oValidator->notError($oFolder, $aOptions);
diff --git a/templates/ktcore/principals/addunit2.smarty b/templates/ktcore/principals/addunit2.smarty
index a4fdb06..336cff2 100644
--- a/templates/ktcore/principals/addunit2.smarty
+++ b/templates/ktcore/principals/addunit2.smarty
@@ -32,7 +32,12 @@ to browse to the folder you wish to create the unit folder into.{/i18n}
--
libgit2 0.21.4