From b3ca2bf43b615c85d134e9662a48ef4fbaf5d22b Mon Sep 17 00:00:00 2001
From: bshuttle
Date: Wed, 16 Aug 2006 12:11:27 +0000
Subject: [PATCH] - forms should respect old values better - checkout should use new ui code - fix for KTS-945: download choice on checkout.
---
lib/widgets/forms.inc.php | 8 ++++++--
plugins/ktcore/KTDocumentActions.php | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------
templates/ktcore/action/checkout.smarty | 15 +--------------
3 files changed, 69 insertions(+), 25 deletions(-)
diff --git a/lib/widgets/forms.inc.php b/lib/widgets/forms.inc.php
index bdc4fbe..a0a5a22 100644
--- a/lib/widgets/forms.inc.php
+++ b/lib/widgets/forms.inc.php
@@ -93,8 +93,12 @@ class KTForm {
}
// FIXME process extra arguments more intelligently
+ $default_args = array();
+ if (!is_null($this->_context)) {
+ $default_args = $this->_context->meldPersistQuery("","",true);
+ }
$this->_extraargs = KTUtil::arrayGet($aOptions,
- 'extraargs', array());
+ 'extraargs', $default_args);
$this->_extraargs['postReceived'] = 1;
}
@@ -228,7 +232,7 @@ class KTForm {
$widget->wrapName('data');
if ($bUseOld) {
$widget->setDefault(KTUtil::arrayGet($aOldData, $widget->getBasename(),
- $widget->getDefault()));
+ $widget->getDefault(), false));
$widget->setErrors(KTUtil::arrayGet($aErrors, $widget->getBasename()));
}
}
diff --git a/plugins/ktcore/KTDocumentActions.php b/plugins/ktcore/KTDocumentActions.php
index 8179133..e57ccb7 100644
--- a/plugins/ktcore/KTDocumentActions.php
+++ b/plugins/ktcore/KTDocumentActions.php
@@ -35,6 +35,8 @@ require_once(KT_LIB_DIR . "/browse/DocumentCollection.inc.php");
require_once(KT_LIB_DIR . "/browse/BrowseColumns.inc.php");
require_once(KT_LIB_DIR . "/browse/PartialQuery.inc.php");
+require_once(KT_LIB_DIR . "/widgets/forms.inc.php");
+
// {{{ KTDocumentDetailsAction
class KTDocumentDetailsAction extends KTDocumentAction {
var $sName = 'ktcore.actions.document.displaydetails';
@@ -268,27 +270,69 @@ class KTDocumentCheckOutAction extends KTDocumentAction {
return true;
}
+ function form_checkout() {
+ $oForm = new KTForm;
+ $oForm->setOptions(array(
+ 'label' => _kt("Checkout"),
+ 'action' => 'checkout',
+ 'fail_action' => 'main',
+ 'cancel_url' => KTBrowseUtil::getUrlForDocument($this->oDocument),
+ 'submit_label' => _kt("Checkout document"),
+ 'context' => &$this,
+ ));
+ $oForm->setWidgets(array(
+ array('ktcore.widgets.reason', array(
+ 'label' => _kt("Reason"),
+ 'description' => _kt("Please specify why you are checking out this document. It will assist other users in understanding why you have locked this file. Please bear in mind that you can use a maximum of 250 characters."),
+ 'name' => 'reason',
+ )),
+ array('ktcore.widgets.boolean', array(
+ 'label' => _kt("Download File"),
+ 'description' => _kt("Indicate whether you would like to download this file as part of the checkout."),
+ 'name' => 'download_file',
+ 'value' => true,
+ )),
+ ));
+ $oForm->setValidators(array(
+ array('ktcore.validators.string', array(
+ 'test' => 'reason',
+ 'max_length' => 250,
+ 'output' => 'reason',
+ )),
+ array('ktcore.validators.boolean', array(
+ 'test' => 'download_file',
+ 'output' => 'download_file',
+ )),
+ ));
+
+ return $oForm;
+ }
+
function do_main() {
$this->oPage->setBreadcrumbDetails(_kt("checkout"));
$oTemplate =& $this->oValidator->validateTemplate('ktcore/action/checkout');
- $checkout_fields = array();
- $checkout_fields[] = new KTStringWidget(_kt('Reason'), _kt('The reason for the checkout of this document for historical purposes, and to inform those who wish to check out this document.'), 'reason', "", $this->oPage, true);
+
+ $oForm = $this->form_checkout();
$oTemplate->setData(array(
'context' => &$this,
- 'checkout_fields' => $checkout_fields,
+ 'form' => $oForm,
));
return $oTemplate->render();
}
function do_checkout() {
- $aErrorOptions = array(
- 'redirect_to' => array('','fDocumentId=' . $this->oDocument->getId()),
- 'message' => _kt("You must provide a reason"),
- );
-
+
+ $oForm = $this->form_checkout();
+ $res = $oForm->validate();
+ if (!empty($res['errors'])) {
+ return $oForm->handleError();
+ }
+
+ $data = $res['results'];
+
$oTemplate =& $this->oValidator->validateTemplate('ktcore/action/checkout_final');
- $sReason = $this->oValidator->validateString(KTUtil::arrayGet($_REQUEST, 'reason'), $aErrorOptions);
+ $sReason = $data['reason'];
$this->startTransaction();
$res = KTDocumentUtil::checkout($this->oDocument, $sReason, $this->oUser);
@@ -296,7 +340,16 @@ class KTDocumentCheckOutAction extends KTDocumentAction {
return $this->errorRedirectToMain(sprintf(_kt('Failed to check out the document: %s'), $res->getMessage()));
}
+
+
$this->commitTransaction();
+
+ if (!$data['download_file']) {
+ $this->addInfoMessage(_kt("Document checked out."));
+ redirect(KTBrowseUtil::getUrlForDocument($this->oDocument));
+ exit(0);
+ }
+
$oTemplate->setData(array(
'context' => &$this,
'reason' => $sReason,
diff --git a/templates/ktcore/action/checkout.smarty b/templates/ktcore/action/checkout.smarty
index 3adee3e..0402732 100644
--- a/templates/ktcore/action/checkout.smarty
+++ b/templates/ktcore/action/checkout.smarty
@@ -3,17 +3,4 @@ exclusive use. This ensures that you can edit the document without
anyone else changing the document and placing it into the document
management system.{/i18n}
-{assign var=iDocumentId value=$context->oDocument->getId()}
-
-
+{$form->render()}
--
libgit2 0.21.4