Commit b3ca2bf43b615c85d134e9662a48ef4fbaf5d22b
1 parent
be99ef2c
- forms should respect old values better
- checkout should use new ui code - fix for KTS-945: download choice on checkout. git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@5832 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
3 changed files
with
69 additions
and
25 deletions
lib/widgets/forms.inc.php
| ... | ... | @@ -93,8 +93,12 @@ class KTForm { |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | // FIXME process extra arguments more intelligently |
| 96 | + $default_args = array(); | |
| 97 | + if (!is_null($this->_context)) { | |
| 98 | + $default_args = $this->_context->meldPersistQuery("","",true); | |
| 99 | + } | |
| 96 | 100 | $this->_extraargs = KTUtil::arrayGet($aOptions, |
| 97 | - 'extraargs', array()); | |
| 101 | + 'extraargs', $default_args); | |
| 98 | 102 | $this->_extraargs['postReceived'] = 1; |
| 99 | 103 | } |
| 100 | 104 | |
| ... | ... | @@ -228,7 +232,7 @@ class KTForm { |
| 228 | 232 | $widget->wrapName('data'); |
| 229 | 233 | if ($bUseOld) { |
| 230 | 234 | $widget->setDefault(KTUtil::arrayGet($aOldData, $widget->getBasename(), |
| 231 | - $widget->getDefault())); | |
| 235 | + $widget->getDefault(), false)); | |
| 232 | 236 | $widget->setErrors(KTUtil::arrayGet($aErrors, $widget->getBasename())); |
| 233 | 237 | } |
| 234 | 238 | } | ... | ... |
plugins/ktcore/KTDocumentActions.php
| ... | ... | @@ -35,6 +35,8 @@ require_once(KT_LIB_DIR . "/browse/DocumentCollection.inc.php"); |
| 35 | 35 | require_once(KT_LIB_DIR . "/browse/BrowseColumns.inc.php"); |
| 36 | 36 | require_once(KT_LIB_DIR . "/browse/PartialQuery.inc.php"); |
| 37 | 37 | |
| 38 | +require_once(KT_LIB_DIR . "/widgets/forms.inc.php"); | |
| 39 | + | |
| 38 | 40 | // {{{ KTDocumentDetailsAction |
| 39 | 41 | class KTDocumentDetailsAction extends KTDocumentAction { |
| 40 | 42 | var $sName = 'ktcore.actions.document.displaydetails'; |
| ... | ... | @@ -268,27 +270,69 @@ class KTDocumentCheckOutAction extends KTDocumentAction { |
| 268 | 270 | return true; |
| 269 | 271 | } |
| 270 | 272 | |
| 273 | + function form_checkout() { | |
| 274 | + $oForm = new KTForm; | |
| 275 | + $oForm->setOptions(array( | |
| 276 | + 'label' => _kt("Checkout"), | |
| 277 | + 'action' => 'checkout', | |
| 278 | + 'fail_action' => 'main', | |
| 279 | + 'cancel_url' => KTBrowseUtil::getUrlForDocument($this->oDocument), | |
| 280 | + 'submit_label' => _kt("Checkout document"), | |
| 281 | + 'context' => &$this, | |
| 282 | + )); | |
| 283 | + $oForm->setWidgets(array( | |
| 284 | + array('ktcore.widgets.reason', array( | |
| 285 | + 'label' => _kt("Reason"), | |
| 286 | + '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 <strong>250</strong> characters."), | |
| 287 | + 'name' => 'reason', | |
| 288 | + )), | |
| 289 | + array('ktcore.widgets.boolean', array( | |
| 290 | + 'label' => _kt("Download File"), | |
| 291 | + 'description' => _kt("Indicate whether you would like to download this file as part of the checkout."), | |
| 292 | + 'name' => 'download_file', | |
| 293 | + 'value' => true, | |
| 294 | + )), | |
| 295 | + )); | |
| 296 | + $oForm->setValidators(array( | |
| 297 | + array('ktcore.validators.string', array( | |
| 298 | + 'test' => 'reason', | |
| 299 | + 'max_length' => 250, | |
| 300 | + 'output' => 'reason', | |
| 301 | + )), | |
| 302 | + array('ktcore.validators.boolean', array( | |
| 303 | + 'test' => 'download_file', | |
| 304 | + 'output' => 'download_file', | |
| 305 | + )), | |
| 306 | + )); | |
| 307 | + | |
| 308 | + return $oForm; | |
| 309 | + } | |
| 310 | + | |
| 271 | 311 | function do_main() { |
| 272 | 312 | $this->oPage->setBreadcrumbDetails(_kt("checkout")); |
| 273 | 313 | $oTemplate =& $this->oValidator->validateTemplate('ktcore/action/checkout'); |
| 274 | - $checkout_fields = array(); | |
| 275 | - $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); | |
| 314 | + | |
| 315 | + $oForm = $this->form_checkout(); | |
| 276 | 316 | |
| 277 | 317 | $oTemplate->setData(array( |
| 278 | 318 | 'context' => &$this, |
| 279 | - 'checkout_fields' => $checkout_fields, | |
| 319 | + 'form' => $oForm, | |
| 280 | 320 | )); |
| 281 | 321 | return $oTemplate->render(); |
| 282 | 322 | } |
| 283 | 323 | |
| 284 | 324 | function do_checkout() { |
| 285 | - $aErrorOptions = array( | |
| 286 | - 'redirect_to' => array('','fDocumentId=' . $this->oDocument->getId()), | |
| 287 | - 'message' => _kt("You must provide a reason"), | |
| 288 | - ); | |
| 289 | - | |
| 325 | + | |
| 326 | + $oForm = $this->form_checkout(); | |
| 327 | + $res = $oForm->validate(); | |
| 328 | + if (!empty($res['errors'])) { | |
| 329 | + return $oForm->handleError(); | |
| 330 | + } | |
| 331 | + | |
| 332 | + $data = $res['results']; | |
| 333 | + | |
| 290 | 334 | $oTemplate =& $this->oValidator->validateTemplate('ktcore/action/checkout_final'); |
| 291 | - $sReason = $this->oValidator->validateString(KTUtil::arrayGet($_REQUEST, 'reason'), $aErrorOptions); | |
| 335 | + $sReason = $data['reason']; | |
| 292 | 336 | |
| 293 | 337 | $this->startTransaction(); |
| 294 | 338 | $res = KTDocumentUtil::checkout($this->oDocument, $sReason, $this->oUser); |
| ... | ... | @@ -296,7 +340,16 @@ class KTDocumentCheckOutAction extends KTDocumentAction { |
| 296 | 340 | return $this->errorRedirectToMain(sprintf(_kt('Failed to check out the document: %s'), $res->getMessage())); |
| 297 | 341 | } |
| 298 | 342 | |
| 343 | + | |
| 344 | + | |
| 299 | 345 | $this->commitTransaction(); |
| 346 | + | |
| 347 | + if (!$data['download_file']) { | |
| 348 | + $this->addInfoMessage(_kt("Document checked out.")); | |
| 349 | + redirect(KTBrowseUtil::getUrlForDocument($this->oDocument)); | |
| 350 | + exit(0); | |
| 351 | + } | |
| 352 | + | |
| 300 | 353 | $oTemplate->setData(array( |
| 301 | 354 | 'context' => &$this, |
| 302 | 355 | 'reason' => $sReason, | ... | ... |
templates/ktcore/action/checkout.smarty
| ... | ... | @@ -3,17 +3,4 @@ exclusive use. This ensures that you can edit the document without |
| 3 | 3 | anyone else changing the document and placing it into the document |
| 4 | 4 | management system.{/i18n}</p> |
| 5 | 5 | |
| 6 | -{assign var=iDocumentId value=$context->oDocument->getId()} | |
| 7 | - | |
| 8 | -<form method="POST" action="{$smarty.server.PHP_SELF}"> | |
| 9 | -<fieldset><legend>{i18n}Checkout{/i18n}</legend> | |
| 10 | -<input type="hidden" name="action" value="checkout" /> | |
| 11 | -<input type="hidden" name="fDocumentId" value="{$iDocumentId}" /> | |
| 12 | -{foreach from=$checkout_fields item=oWidget } | |
| 13 | - {$oWidget->render()} | |
| 14 | -{/foreach} | |
| 15 | -<div class="form_actions"> | |
| 16 | -<input type="submit" name="submit" value="{i18n}Checkout{/i18n}" /> | |
| 17 | -</div> | |
| 18 | -</fieldset> | |
| 19 | -</form> | |
| 6 | +{$form->render()} | ... | ... |