Commit 6c6894cff45276ce16b56c4c32c10cda544d7562

Authored by bshuttle
1 parent 1d512242

improve unit management (KTS-490)


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@5007 c91229c3-7414-0410-bfa2-8a42b809f60b
plugins/ktcore/admin/unitManagement.php
... ... @@ -59,9 +59,11 @@ class KTUnitAdminDispatcher extends KTAdminDispatcher {
59 59  
60 60 $aOptions = array(
61 61 'redirect_to' => array('addUnit'),
62   - 'message' => 'No name given',
  62 + 'message' => _('No name given'),
63 63 );
64 64 $sName = $this->oValidator->validateString($_REQUEST['unit_name'], $aOptions);
  65 + $aOptions['message'] = _('A unit with that name already exists.');
  66 + $sName = $this->oValidator->validateDuplicateName('Unit', _('Unit'), $sName, $aOptions);
65 67  
66 68 $iFolderId = KTUtil::arrayGet($_REQUEST, 'fFolderId', 1);
67 69 $_REQUEST['fFolderId'] = $iFolderId;
... ... @@ -104,6 +106,11 @@ class KTUnitAdminDispatcher extends KTAdminDispatcher {
104 106 $add_fields = array();
105 107 $add_fields[] = new KTStaticTextWidget(_('Unit Name'),_('A short name for the unit. e.g. <strong>Accounting</strong>.'), 'unit_name', $sName, $this->oPage, true);
106 108  
  109 + $isValid = true;
  110 + if (KTFolderUtil::exists($oFolder, $sName)) {
  111 + $isValid = false; // can't add a unit folder with the same name.
  112 + }
  113 +
107 114 $oTemplating =& KTTemplating::getSingleton();
108 115 $oTemplate = $oTemplating->loadTemplate("ktcore/principals/addunit2");
109 116 $aTemplateData = array(
... ... @@ -113,6 +120,7 @@ class KTUnitAdminDispatcher extends KTAdminDispatcher {
113 120 "collection_breadcrumbs" => $aBreadcrumbs,
114 121 "folder" => $oFolder,
115 122 "name" => $sName,
  123 + "is_valid" => $isValid,
116 124 );
117 125 return $oTemplate->render($aTemplateData);
118 126 }
... ... @@ -120,18 +128,20 @@ class KTUnitAdminDispatcher extends KTAdminDispatcher {
120 128 function do_createUnit() {
121 129 $aOptions = array(
122 130 'redirect_to' => array('main'),
123   - 'message' => 'Invalid folder chosen',
  131 + 'message' => _('Invalid folder chosen'),
124 132 );
125 133 $oParentFolder = $this->oValidator->validateFolder($_REQUEST['fFolderId'], $aOptions);
126 134 $aOptions = array(
127 135 'redirect_to' => array('addUnit', sprintf('fFolderId=%d', $oParentFolder->getId())),
128   - 'message' => 'No name given',
  136 + 'message' => _('No name given'),
129 137 );
130 138 $sName = $this->oValidator->validateString($_REQUEST['unit_name'], $aOptions);
  139 + $aOptions['message'] = _('A unit with that name already exists.');
  140 + $sName = $this->oValidator->validateDuplicateName('Unit', _('Unit'), $sName, $aOptions);
131 141  
132 142 $oFolder = KTFolderUtil::add($oParentFolder, $sName, $this->oUser);
133 143 $aOptions = array(
134   - 'redirect_to' => array('addUnit', sprintf('fFolderId=%d', $oParentFolder->getId())),
  144 + 'redirect_to' => array('addUnit2', sprintf('fFolderId=%d&unit_name=%s', $oParentFolder->getId(), $sName)),
135 145 'defaultmessage' => 'Error creating folder',
136 146 );
137 147 $this->oValidator->notError($oFolder, $aOptions);
... ...
templates/ktcore/principals/addunit2.smarty
... ... @@ -32,7 +32,12 @@ to browse to the folder you wish to create the unit folder into.{/i18n}&lt;/p&gt;
32 32 </div>
33 33  
34 34 <div class="form_actions">
  35 + {if $is_valid}
35 36 <input type="submit" value="{i18n}create unit{/i18n}" />
  37 + {else}
  38 + <p class="descriptiveText">{i18n}A folder with this name already exists in this location. Please select
  39 + another folder before creating the unit.{/i18n}</p>
  40 + {/if}
36 41 <input type="submit" name="kt_cancel[]" value="{i18n}Cancel{/i18n}" />
37 42 </div>
38 43 </fieldset>
... ...