Commit b83bc18929e206dd5a9d582cedf299f15b242e55

Authored by bshuttle
1 parent 8d88cb6c

finish up with document fieldset editing.


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@5922 c91229c3-7414-0410-bfa2-8a42b809f60b
lib/dispatcher.inc.php
@@ -180,6 +180,27 @@ class KTDispatcher { @@ -180,6 +180,27 @@ class KTDispatcher {
180 } 180 }
181 $this->redirectTo($event, $sQuery); 181 $this->redirectTo($event, $sQuery);
182 } 182 }
  183 +
  184 + function errorRedirectToParent($error_message) {
  185 + if ($this->bTransactionStarted) {
  186 + $this->rollbackTransaction();
  187 + }
  188 +
  189 + $_SESSION['KTErrorMessage'][] = $error_message;
  190 + redirect($this->sParentUrl);
  191 + exit(0);
  192 + }
  193 +
  194 + function successRedirectToParent($info_message) {
  195 + if ($this->bTransactionStarted) {
  196 + $this->commitTransaction();
  197 + }
  198 + if (!empty($info_message)) {
  199 + $_SESSION['KTInfoMessage'][] = $info_message;
  200 + }
  201 + redirect($this->sParentUrl);
  202 + exit(0);
  203 + }
183 204
184 function redirectTo($event, $sQuery = "") { 205 function redirectTo($event, $sQuery = "") {
185 // meld persistant options 206 // meld persistant options
lib/widgets/forms.inc.php
@@ -212,6 +212,11 @@ class KTForm { @@ -212,6 +212,11 @@ class KTForm {
212 return $this->renderContaining($sWidgets . ' ' . $sButtons); 212 return $this->renderContaining($sWidgets . ' ' . $sButtons);
213 } 213 }
214 214
  215 + function renderPage($sTitle) {
  216 + $pageval = $this->render();
  217 + return sprintf('<h2>%s</h2> %s', $sTitle, $pageval);
  218 + }
  219 +
215 function renderWidgets() { 220 function renderWidgets() {
216 if (empty($this->_widgets)) { 221 if (empty($this->_widgets)) {
217 return '&nbsp;'; 222 return '&nbsp;';
plugins/ktcore/KTValidators.php
@@ -22,7 +22,9 @@ class KTStringValidator extends KTValidator { @@ -22,7 +22,9 @@ class KTStringValidator extends KTValidator {
22 $this->sMinLengthWarning = KTUtil::arrayGet($aOptions, 'min_length_warning', 22 $this->sMinLengthWarning = KTUtil::arrayGet($aOptions, 'min_length_warning',
23 sprintf(_kt('You must provide a value which is at least %d characters long.'), $this->iMinLength)); 23 sprintf(_kt('You must provide a value which is at least %d characters long.'), $this->iMinLength));
24 $this->sMaxLengthWarning = KTUtil::arrayGet($aOptions, 'max_length_warning', 24 $this->sMaxLengthWarning = KTUtil::arrayGet($aOptions, 'max_length_warning',
25 - sprintf(_kt('You must provide a value which is at most %d characters long.'), $this->iMaxLength)); 25 + sprintf(_kt('You must provide a value which is at most %d characters long.'), $this->iMaxLength));
  26 +
  27 + $this->bTrim = KTUtil::arrayGet($aOptions, 'trim', true, false);
26 } 28 }
27 29
28 function validate($data) { 30 function validate($data) {
@@ -33,6 +35,10 @@ class KTStringValidator extends KTValidator { @@ -33,6 +35,10 @@ class KTStringValidator extends KTValidator {
33 // otherwise, its ok. 35 // otherwise, its ok.
34 $val = KTUtil::arrayGet($data, $this->sInputVariable); 36 $val = KTUtil::arrayGet($data, $this->sInputVariable);
35 37
  38 + if ($this->bTrim) {
  39 + $val = trim($val);
  40 + }
  41 +
36 $l = strlen($val); 42 $l = strlen($val);
37 if ($l < $this->iMinLength) { 43 if ($l < $this->iMinLength) {
38 $errors[$this->sBasename] = $this->sMinLengthWarning; 44 $errors[$this->sBasename] = $this->sMinLengthWarning;
plugins/ktcore/admin/documentFieldsv2.php
@@ -267,6 +267,129 @@ class KTDocumentFieldDispatcher extends KTAdminDispatcher { @@ -267,6 +267,129 @@ class KTDocumentFieldDispatcher extends KTAdminDispatcher {
267 )); 267 ));
268 return $oTemplate->render(); 268 return $oTemplate->render();
269 } 269 }
  270 +
  271 + function do_delete() {
  272 + $this->startTransaction();
  273 + $res = $this->oFieldset->delete();
  274 + $this->oValidator->notErrorFalse($res, array(
  275 + 'redirect_to' => array('main', ''),
  276 + 'message' => _kt('Could not delete fieldset'),
  277 + ));
  278 + $this->successRedirectToMain(_kt('Fieldset deleted'));
  279 + }
  280 +
  281 + function form_edit() {
  282 + $oForm = new KTForm;
  283 + $oForm->setOptions(array(
  284 + 'identifier' => 'ktcore.fieldsets.edit',
  285 + 'label' => _kt("Change Fieldset Details"),
  286 + 'submit_label' => _kt('Update Fieldset'),
  287 + 'cancel_action' => 'edit',
  288 + 'fail_action' => 'editfieldset',
  289 + 'action' => 'savefieldset',
  290 + 'context' => $this,
  291 + ));
  292 +
  293 +
  294 + // construct the widget set.
  295 + // we use a slight variation here, because "type" is only present in certain circumstances.
  296 + $widgets = array(
  297 + array('ktcore.widgets.string',array(
  298 + 'label' => _kt("Fieldset Name"),
  299 + 'name' => 'name',
  300 + 'required' => true,
  301 + 'description' => _kt("Each fieldset needs a unique name."),
  302 + 'value' => $this->oFieldset->getName(),
  303 + )),
  304 + array('ktcore.widgets.text',array(
  305 + 'label' => _kt("Description"),
  306 + 'name' => 'description',
  307 + 'required' => true,
  308 + 'description' => _kt("In order to ensure that the data that users enter is useful, it is essential that you provide a good example."),
  309 + 'value' => $this->oFieldset->getDescription(),
  310 + )),
  311 + );
  312 +
  313 + $widgets[] = array('ktcore.widgets.boolean',array(
  314 + 'label' => _kt("Generic"),
  315 + 'name' => 'generic',
  316 + 'description' => _kt("A generic fieldset is one that is available for every document by default. These fieldsets will be available for users to edit and add for every document in the document management system."),
  317 + 'value' => $this->oFieldset->getIsGeneric(),
  318 + ));
  319 +
  320 + $oForm->setWidgets($widgets);
  321 +
  322 + // similarly, we construct validators here.
  323 + $validators = array(
  324 + array('ktcore.validators.string', array(
  325 + 'test' => 'name',
  326 + 'output' => 'name',
  327 + )),
  328 + array('ktcore.validators.string', array(
  329 + 'test' => 'description',
  330 + 'output' => 'description',
  331 + )),
  332 + array('ktcore.validators.boolean', array(
  333 + 'test' => 'generic',
  334 + 'output' => 'generic',
  335 + )),
  336 + );
  337 +
  338 + $oForm->setValidators($validators);
  339 +
  340 + return $oForm;
  341 + }
  342 +
  343 + function do_editfieldset() {
  344 + $oForm = $this->form_edit();
  345 + return $oForm->renderPage(_kt("Edit Fieldset"));
  346 + }
  347 +
  348 + function do_savefieldset() {
  349 + $oForm = $this->form_edit();
  350 + $res = $oForm->validate();
  351 +
  352 + $data = $res['results'];
  353 + $errors = $res['errors'];
  354 + $extra_errors = array();
  355 + if ($data['name'] != $this->oFieldset->getName()) {
  356 + $oOldFieldset = KTFieldset::getByName($data['name']);
  357 + if (!PEAR::isError($oOldFieldset)) {
  358 + $extra_errors['name'][] = _kt("A fieldset with that name already exists.");
  359 + }
  360 + }
  361 +
  362 + if (!empty($errors) || !empty($extra_errors)) {
  363 + return $oForm->handleError(null, $extra_errors);
  364 + }
  365 +
  366 + $this->startTransaction();
  367 +
  368 + $this->oFieldset->setName($data['name']);
  369 + $this->oFieldset->setDescription($data['description']);
  370 + $bGeneric = $data['generic'];
  371 + if ($bGeneric != $this->oFieldset->getIsGeneric() && $bGeneric == true) {
  372 + // delink it from all doctypes.
  373 + $aTypes = $oFieldset->getAssociatedTypes();
  374 + foreach ($aTypes as $oType) {
  375 + $res = KTMetadataUtil::removeSetsFromDocumentType($oType, $oFieldset->getId());
  376 + if (PEAR::isError($res)) {
  377 + $this->errorRedirectTo('edit', _kt('Could not save fieldset changes'));
  378 + exit(0);
  379 + }
  380 + }
  381 + }
  382 +
  383 + $this->oFieldset->setIsGeneric($data['generic']);
  384 +
  385 + $res = $this->oFieldset->update();
  386 + if (PEAR::isError($res)) {
  387 + $this->errorRedirectTo('edit', _kt('Could not save fieldset changes'));
  388 + exit(0);
  389 + }
  390 +
  391 + return $this->successRedirectTo('edit', _kt("Fieldset details updated."));
  392 + }
270 } 393 }
271 394
272 ?> 395 ?>
plugins/ktcore/admin/fieldsets/basic.inc.php
@@ -512,31 +512,6 @@ class BasicFieldsetManagementDispatcher extends KTAdminDispatcher { @@ -512,31 +512,6 @@ class BasicFieldsetManagementDispatcher extends KTAdminDispatcher {
512 } 512 }
513 // }}} 513 // }}}
514 514
515 - // {{{ do_removeFields  
516 - function do_removeFields() {  
517 - $oFieldset =& KTFieldset::get($_REQUEST['fFieldsetId']);  
518 - foreach ($_REQUEST['fields'] as $iFieldId) {  
519 - $oField =& DocumentField::get($iFieldId);  
520 - $oField->delete();  
521 - }  
522 - $this->successRedirectTo('edit', _kt('Fields removed'), 'fFieldsetId=' . $oFieldset->getId());  
523 - exit(0);  
524 - }  
525 - // }}}  
526 -  
527 - // {{{ do_delete  
528 - function do_delete() {  
529 - $oFieldset =& $this->oValidator->validateFieldset($_REQUEST['fFieldsetId']);  
530 - $res = $oFieldset->delete();  
531 - $this->oValidator->notErrorFalse($res, array(  
532 - 'redirect_to' => array('main', ''),  
533 - 'message' => _kt('Could not delete fieldset'),  
534 - ));  
535 - $this->successRedirectToMain(_kt('Fieldset deleted'));  
536 - }  
537 - // }}}  
538 -  
539 -  
540 // {{{ TREE 515 // {{{ TREE
541 // create and display the tree editing form. 516 // create and display the tree editing form.
542 function do_managetree() { 517 function do_managetree() {
@@ -772,6 +747,15 @@ class BasicFieldsetManagementDispatcher extends KTAdminDispatcher { @@ -772,6 +747,15 @@ class BasicFieldsetManagementDispatcher extends KTAdminDispatcher {
772 return $actionStr; 747 return $actionStr;
773 } 748 }
774 749
  750 + function do_deletefield() {
  751 + $res = $this->oField->delete();
  752 + if (PEAR::isError($res)) {
  753 + $this->errorRedirectToParent(sprintf(_kt("Unable to delete field: %s"), $res->getMessage()));
  754 + }
  755 +
  756 + $this->successRedirectToParent(_kt("Field deleted."));
  757 + }
  758 +
775 } 759 }
776 760
777 ?> 761 ?>
templates/ktcore/metadata/admin/basic_overview.smarty
@@ -9,8 +9,8 @@ of related information.{/i18n}&lt;/p&gt; @@ -9,8 +9,8 @@ of related information.{/i18n}&lt;/p&gt;
9 <thead> 9 <thead>
10 <tr> 10 <tr>
11 <th>{i18n}Field Name{/i18n}</th> 11 <th>{i18n}Field Name{/i18n}</th>
12 - <th>{i18n}Edit{/i18n}</th>  
13 - <th>{i18n}Delete{/i18n}</th> 12 + <th class="centered">{i18n}Edit{/i18n}</th>
  13 + <th class="centered">{i18n}Delete{/i18n}</th>
14 <th>{i18n}Type Description{/i18n}</th> 14 <th>{i18n}Type Description{/i18n}</th>
15 </tr> 15 </tr>
16 </thead> 16 </thead>
@@ -20,9 +20,12 @@ of related information.{/i18n}&lt;/p&gt; @@ -20,9 +20,12 @@ of related information.{/i18n}&lt;/p&gt;
20 <td class="title"> 20 <td class="title">
21 {$oField->getName()|escape} 21 {$oField->getName()|escape}
22 </td> 22 </td>
23 - <td> 23 + <td class="centered">
24 <a href="{addQS context=$context}fieldset_action=managefield&fFieldId={$oField->getId()}{/addQS}" class="ktAction ktEdit">{i18n}edit{/i18n}</a> 24 <a href="{addQS context=$context}fieldset_action=managefield&fFieldId={$oField->getId()}{/addQS}" class="ktAction ktEdit">{i18n}edit{/i18n}</a>
25 </td> 25 </td>
  26 + <td class="centered">
  27 + <a href="{addQS context=$context}fieldset_action=deletefield&fFieldId={$oField->getId()}{/addQS}" class="ktAction ktDelete">{i18n}delete{/i18n}</a>
  28 + </td>
26 <td> 29 <td>
27 <span class="descriptiveText">{$oField->getTypeDescription()}</span> 30 <span class="descriptiveText">{$oField->getTypeDescription()}</span>
28 </td> 31 </td>