Commit 355c3fe81bc6e220cc4780bbac557223d7d50f01

Authored by Brad Shuttleworth
1 parent b4b411bb

fix for KTS-949 : Workflow viewlet


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@5947 c91229c3-7414-0410-bfa2-8a42b809f60b
plugins/ktcore/KTCorePlugin.php
... ... @@ -67,6 +67,10 @@ class KTCorePlugin extends KTPlugin {
67 67 $this->registerAction('documentaction', 'KTDocumentAssistAction', 'ktcore.actions.document.assist', 'KTAssist.php');
68 68 // $this->registerAction('folderaction', 'KTDocumentAssistAction', 'ktcore.actions.folder.assist', 'KTAssist.php');
69 69  
  70 + // Viewlets
  71 + $this->registerAction('documentviewlet', 'KTWorkflowViewlet', 'ktcore.viewlets.document.workflow', 'KTDocumentViewlets.php');
  72 +
  73 +
70 74 $this->registerNotificationHandler('KTAssistNotification', 'ktcore/assist', 'KTAssist.php');
71 75 $this->registerNotificationHandler("KTSubscriptionNotification", "ktcore/subscriptions", KT_LIB_DIR . '/dashboard/Notification.inc.php');
72 76 $this->registerNotificationHandler("KTWorkflowNotification", "ktcore/workflow", KT_LIB_DIR . '/dashboard/Notification.inc.php');
... ...
plugins/ktcore/KTDocumentActions.php
... ... @@ -1303,6 +1303,10 @@ class KTDocumentWorkflowAction extends KTDocumentAction {
1303 1303  
1304 1304 var $sHelpPage = 'ktcore/user/workflow.html';
1305 1305  
  1306 + function predispatch() {
  1307 + $this->persistParams(array("fTransitionId"));
  1308 + }
  1309 +
1306 1310 function getDisplayName() {
1307 1311 return _kt('Workflow');
1308 1312 }
... ... @@ -1392,6 +1396,75 @@ class KTDocumentWorkflowAction extends KTDocumentAction {
1392 1396 array('fDocumentId' => $oDocument->getId()));
1393 1397 }
1394 1398 }
  1399 +
  1400 + function form_quicktransition() {
  1401 +
  1402 + $oForm = new KTForm;
  1403 + $oForm->setOptions(array(
  1404 + 'identifier' => 'ktcore.workflow.quicktransition',
  1405 + 'label' => _kt("Perform Quick Transition"),
  1406 + 'submit_label' => _kt("Perform Transition"),
  1407 + 'context' => $this,
  1408 + 'action' => 'performquicktransition',
  1409 + 'fail_action' => 'quicktransition',
  1410 + 'cancel_url' => KTBrowseUtil::getUrlForDocument($this->oDocument),
  1411 + ));
  1412 + $oForm->setWidgets(array(
  1413 + array('ktcore.widgets.reason', array(
  1414 + 'label' => _kt("Reason"),
  1415 + 'description' => _kt("Specify your reason for performing this action."),
  1416 + 'important_description' => _kt("Please bear in mind that you can use a maximum of <strong>250</strong> characters."),
  1417 + 'name' => 'reason',
  1418 + )),
  1419 + ));
  1420 + $oForm->setValidators(array(
  1421 + array('ktcore.validators.string', array(
  1422 + 'test' => 'reason',
  1423 + 'max_length' => 250,
  1424 + 'output' => 'reason',
  1425 + )),
  1426 + ));
  1427 +
  1428 + return $oForm;
  1429 + }
  1430 +
  1431 + function do_quicktransition() {
  1432 + // make sure this gets through.
  1433 + $this->persistParams(array('fTransitionId'));
  1434 +
  1435 + $transition_id = $_REQUEST['fTransitionId'];
  1436 + $oTransition = KTWorkflowTransition::get($transition_id);
  1437 +
  1438 + $oForm = $this->form_quicktransition();
  1439 + return $oForm->renderPage(sprintf(_kt("Perform Transition: %s"), $oTransition->getName()));
  1440 + }
  1441 +
  1442 + function do_performquicktransition() {
  1443 + $oForm = $this->form_quicktransition();
  1444 + $res = $oForm->validate();
  1445 +
  1446 + if (!empty($res['errors'])) {
  1447 + return $oForm->handleError();
  1448 + }
  1449 +
  1450 + $this->startTransaction();
  1451 +
  1452 + $data = $res['results'];
  1453 + $oTransition = KTWorkflowTransition::get($_REQUEST['fTransitionId']);
  1454 +
  1455 + $res = KTWorkflowUtil::performTransitionOnDocument($oTransition, $this->oDocument, $this->oUser, $data['reason']);
  1456 +
  1457 + if(!Permission::userHasDocumentReadPermission($this->oDocument)) {
  1458 + $this->commitTransaction();
  1459 + $_SESSION['KTInfoMessage'][] = _kt('Transition performed') . '. ' . _kt('You no longer have permission to view this document');
  1460 + controllerRedirect('browse', sprintf('fFolderId=%d', $this->oDocument->getFolderId()));
  1461 + } else {
  1462 + $this->commitTransaction();
  1463 + $_SESSION['KTInfoMessage'][] = _kt('Transition performed');
  1464 + controllerRedirect('viewDocument', sprintf('fDocumentId=%d', $this->oDocument->getId()));
  1465 + }
  1466 + }
  1467 +
1395 1468 }
1396 1469 // }}}
1397 1470  
... ...
plugins/ktcore/KTDocumentViewlets.php 0 โ†’ 100644
  1 +<?php
  2 +
  3 +/**
  4 + *
  5 + * The contents of this file are subject to the KnowledgeTree Public
  6 + * License Version 1.1 ("License"); You may not use this file except in
  7 + * compliance with the License. You may obtain a copy of the License at
  8 + * http://www.ktdms.com/KPL
  9 + *
  10 + * Software distributed under the License is distributed on an "AS IS"
  11 + * basis,
  12 + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  13 + * for the specific language governing rights and limitations under the
  14 + * License.
  15 + *
  16 + * The Original Code is: KnowledgeTree Open Source
  17 + *
  18 + * The Initial Developer of the Original Code is The Jam Warehouse Software
  19 + * (Pty) Ltd, trading as KnowledgeTree.
  20 + * Portions created by The Jam Warehouse Software (Pty) Ltd are Copyright
  21 + * (C) 2006 The Jam Warehouse Software (Pty) Ltd;
  22 + * All Rights Reserved.
  23 + *
  24 + */
  25 +
  26 +require_once(KT_LIB_DIR . "/actions/documentviewlet.inc.php");
  27 +require_once(KT_LIB_DIR . "/workflow/workflowutil.inc.php");
  28 +
  29 +// {{{ KTDocumentDetailsAction
  30 +class KTWorkflowViewlet extends KTDocumentViewlet {
  31 + var $sName = 'ktcore.viewlets.document.workflow';
  32 +
  33 + function display_viewlet() {
  34 + $oKTTemplating =& KTTemplating::getSingleton();
  35 + $oTemplate =& $oKTTemplating->loadTemplate("ktcore/document/viewlets/workflow");
  36 + if (is_null($oTemplate)) { return ""; }
  37 +
  38 + $oWorkflowState = KTWorkflowState::get($this->oDocument->getWorkflowStateId());
  39 + if (PEAR::isError($oWorkflowState)) {
  40 + return "";
  41 + }
  42 +
  43 + $aDisplayTransitions = array();
  44 + $aTransitions = KTWorkflowUtil::getTransitionsForDocumentUser($this->oDocument, $this->oUser);
  45 + if (empty($aTransitions)) {
  46 + return "";
  47 + }
  48 +
  49 + foreach ($aTransitions as $oTransition) {
  50 + $aDisplayTransitions[] = array(
  51 + 'url' => KTUtil::ktLink('action.php', 'ktcore.actions.document.workflow', array("fDocumentId" => $this->oDocument->getId(), "action" => "quicktransition", "fTransitionId" => $oTransition->getId())),
  52 + 'name' => $oTransition->getName(),
  53 + );
  54 + }
  55 +
  56 + $oTemplate->setData(array(
  57 + 'context' => $this,
  58 + 'transitions' => $aDisplayTransitions,
  59 + 'state_name' => $oWorkflowState->getName(),
  60 + ));
  61 + return $oTemplate->render();
  62 + }
  63 +}
  64 +// }}}
  65 +
  66 +
  67 +
  68 +?>
... ...
templates/ktcore/document/view.smarty
... ... @@ -40,12 +40,12 @@ these tasks, use the Request Assistance action.{/i18n}
40 40 {$oFieldset->render($document_data)}
41 41 {/foreach}
42 42  
43   -{if !empty($viewlets)}
  43 +{if !empty($viewlet_data)}
44 44  
45 45 <!-- Document "Views" -->
46 46 <div id="document-views">
47 47  
48   -{$sviewlet_data}
  48 +{$viewlet_data}
49 49  
50 50 </div>
51 51 {/if}
... ...
templates/ktcore/document/viewlets/download.smarty 0 โ†’ 100644
  1 +<div class="viewlet download">
  2 + Download the file! Yay!
  3 +</div>
... ...
templates/ktcore/document/viewlets/workflow.smarty 0 โ†’ 100644
  1 +<div class="viewlet">
  2 + <h3>Available Transitions</h3>
  3 + <p class="descriptiveText">{i18n arg_name=$state_name}The document is currently in state "#name#"{/i18n}</p>
  4 + <ul>
  5 + {foreach from=$transitions item=info}
  6 + <li><a href="{$info.url}">{$info.name}</a></li>
  7 + {/foreach}
  8 + </ul>
  9 +</div>
... ...