From 1cf5cb757f9318ef6379c67d8d8818140d2d1dd3 Mon Sep 17 00:00:00 2001 From: nbm Date: Mon, 20 Feb 2006 10:16:13 +0000 Subject: [PATCH] Hook up Brad's document renaming code into a document action. --- plugins/ktcore/KTCorePlugin.php | 1 + plugins/ktcore/document/Rename.php | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ templates/ktcore/action/rename.smarty | 22 ++++++++++++++++++++++ 3 files changed, 103 insertions(+), 0 deletions(-) create mode 100644 plugins/ktcore/document/Rename.php create mode 100644 templates/ktcore/action/rename.smarty diff --git a/plugins/ktcore/KTCorePlugin.php b/plugins/ktcore/KTCorePlugin.php index 3d83e6e..0097793 100644 --- a/plugins/ktcore/KTCorePlugin.php +++ b/plugins/ktcore/KTCorePlugin.php @@ -17,6 +17,7 @@ class KTCorePlugin extends KTPlugin { $this->registerAction('documentaction', 'KTDocumentDeleteAction', 'ktcore.actions.document.delete', 'KTDocumentActions.php'); $this->registerAction('documentaction', 'KTDocumentMoveAction', 'ktcore.actions.document.move', 'KTDocumentActions.php'); $this->registerAction('documentaction', 'KTDocumentCopyAction', 'ktcore.actions.document.copy', 'KTDocumentActions.php'); + $this->registerAction('documentaction', 'KTDocumentRenameAction', 'ktcore.actions.document.rename', 'document/Rename.php'); $this->registerAction('documentaction', 'KTDocumentTransactionHistoryAction', 'ktcore.actions.document.transactionhistory', 'KTDocumentActions.php'); $this->registerAction('documentaction', 'KTDocumentVersionHistoryAction', 'ktcore.actions.document.versionhistory', 'KTDocumentActions.php'); $this->registerAction('documentaction', 'KTDocumentArchiveAction', 'ktcore.actions.document.archive', 'KTDocumentActions.php'); diff --git a/plugins/ktcore/document/Rename.php b/plugins/ktcore/document/Rename.php new file mode 100644 index 0000000..5c552a8 --- /dev/null +++ b/plugins/ktcore/document/Rename.php @@ -0,0 +1,80 @@ +oDocument->getIsCheckedOut()) { + return null; + } + return parent::getInfo(); + } + + function check() { + $res = parent::check(); + if ($res !== true) { + return $res; + } + if ($this->oDocument->getIsCheckedOut()) { + $_SESSION["KTErrorMessage"][]= _("This document can't be renamed because it is checked out"); + controllerRedirect('viewDocument', 'fDocumentId=' . $this->oDocument->getId()); + exit(0); + } + return true; + } + + function do_main() { + $this->oPage->setBreadcrumbDetails("rename"); + $oTemplate =& $this->oValidator->validateTemplate('ktcore/action/rename'); + $fields = array(); + $fields[] = new KTStringWidget(_('New file name'), _('The name to which the current file should be renamed.'), 'filename', "", $this->oPage, true); + + $oTemplate->setData(array( + 'context' => &$this, + 'fields' => $fields, + )); + return $oTemplate->render(); + } + + function do_rename() { + global $default; + $sFilename = KTUtil::arrayGet($_REQUEST, 'filename'); + $aOptions = array( + 'redirect_to' => array('', sprintf('fDocumentId=%d', $this->oDocument->getId())), + 'message' => "No filename given", + ); + $this->oValidator->validateString($sFilename, $aOptions); + + $res = KTDocumentUtil::rename($this->oDocument, $sFilename, $this->oUser); + if (PEAR::isError($res)) { + $_SESSION['KTErrorMessage'][] = $res->getMessage(); + controllerRedirect('viewDocument',sprintf('fDocumentId=%d', $this->oDocument->getId())); + } else { + $_SESSION['KTInfoMessage'][] = sprintf(_('Document "%s" renamed.'),$this->oDocument->getName()); + } + + controllerRedirect('viewDocument', sprintf('fDocumentId=%d', $this->oDocument->getId())); + exit(0); + } +} +// }}} + +?> diff --git a/templates/ktcore/action/rename.smarty b/templates/ktcore/action/rename.smarty new file mode 100644 index 0000000..bbb932c --- /dev/null +++ b/templates/ktcore/action/rename.smarty @@ -0,0 +1,22 @@ +

{i18n}This page allows you to rename the file +name (not the document title) for a document.{/i18n}

+ +{assign var=iDocumentId value=$context->oDocument->getId()} +{capture assign=link}{"viewDocument"|generateControllerUrl:"fDocumentId=$iDocumentId"}{/capture} +

{i18n arg_link=$link}If you do not intend to +rename this document, you should cancel the +deletion.{/i18n}

+ +
+
{i18n}Rename{/i18n} + + +{foreach from=$fields item=oWidget } + {$oWidget->render()} +{/foreach} +
+ + +
+
+
-- libgit2 0.21.4