Commit 285c7a0e3e9e29a03f1af15bd7ee5f25efdb36ef

Authored by Brad Shuttleworth
1 parent 13b327a0

re-add transition-effects (aka transition action triggers)


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@5925 c91229c3-7414-0410-bfa2-8a42b809f60b
plugins/ktcore/KTWorkflowTriggers.inc.php
... ... @@ -477,7 +477,7 @@ class CopyActionTrigger extends KTWorkflowTrigger {
477 477  
478 478 $qsFrag = array();
479 479 foreach ($args as $k => $v) {
480   - if ($k == 'action') { $v = 'editTrigger'; } // horrible hack - we really need iframe embedding.
  480 + if ($k == 'action') { $v = 'editactiontrigger'; } // horrible hack - we really need iframe embedding.
481 481 $qsFrag[] = sprintf("%s=%s",urlencode($k), urlencode($v));
482 482 }
483 483 $qs = implode('&',$qsFrag);
... ...
plugins/ktcore/admin/workflowsv2.php
... ... @@ -1379,6 +1379,223 @@ class KTWorkflowAdminV2 extends KTAdminDispatcher {
1379 1379 ));
1380 1380 return $oTemplate->render();
1381 1381 }
  1382 +
  1383 +
  1384 + function form_addtransitionaction() {
  1385 + $oForm = new KTForm;
  1386 + $oForm->setOptions(array(
  1387 + 'identifier' => 'ktcore.admin.workflow.addaction',
  1388 + 'label' => _kt("Add New Transition Action"),
  1389 + 'action' => 'addactiontrigger',
  1390 + 'cancel_action' => 'managetransitionactions',
  1391 + 'fail_action' => 'managetransitionactions',
  1392 + 'submit_label' => _kt("Add Action"),
  1393 + 'context' => $this,
  1394 + ));
  1395 +
  1396 + $oTriggerSingleton =& KTWorkflowTriggerRegistry::getSingleton();
  1397 + $aTriggerList = $oTriggerSingleton->listWorkflowTriggers();
  1398 + $vocab = array();
  1399 + foreach ($aTriggerList as $ns => $aTriggerInfo) {
  1400 + $aInfo = $aTriggerInfo; // i am lazy.
  1401 + //var_dump($aInfo);
  1402 + $actions = array();
  1403 + if ($aInfo['guard']) {
  1404 + $actions[] = _kt('Guard');
  1405 + }
  1406 + if ($aInfo['action']) {
  1407 + $actions[] = _kt('Action');
  1408 + } else {
  1409 + continue;
  1410 + }
  1411 + $sActStr = implode(', ', $actions);
  1412 + $vocab[$ns] = sprintf(_kt("%s (%s)"), $aInfo['name'], $sActStr);
  1413 + }
  1414 +
  1415 + $oForm->setWidgets(array(
  1416 + array('ktcore.widgets.selection', array(
  1417 + 'label' => _kt("Action/Effect Type"),
  1418 + 'name' => 'action_name',
  1419 + 'vocab' => $vocab,
  1420 + 'simple_select' => false,
  1421 + 'required' => true,
  1422 + )),
  1423 + ));
  1424 +
  1425 + $oForm->setValidators(array(
  1426 + array('ktcore.validators.string', array(
  1427 + 'test' => 'action_name',
  1428 + 'output' => 'action_name',
  1429 + )),
  1430 + ));
  1431 + return $oForm;
  1432 + }
  1433 +
  1434 + function do_transitionactions() {
  1435 + $oTemplate = $this->oValidator->validateTemplate('ktcore/workflow/admin/transition_effects_overview');
  1436 + $this->oPage->setBreadcrumbDetails(_kt("Transition Effects"));
  1437 +
  1438 + $aTransitions = KTWorkflowTransition::getByWorkflow($this->oWorkflow);
  1439 +
  1440 + $oTemplate->setData(array(
  1441 + 'context' => $this,
  1442 + 'transitions' => $aTransitions,
  1443 + ));
  1444 + return $oTemplate->render();
  1445 + }
  1446 +
  1447 +
  1448 + // helper
  1449 + function describeTransitionActions($oTransition) {
  1450 + $actions = KTWorkflowUtil::getActionTriggersForTransition($oTransition);
  1451 +
  1452 + if (empty($actions)) {
  1453 + return '—';
  1454 + }
  1455 +
  1456 + $action_text = array();
  1457 + foreach ($actions as $oAction) {
  1458 + $action_text[] = $oAction->getConfigDescription();
  1459 + }
  1460 +
  1461 + return implode('. ', $action_text);
  1462 + }
  1463 +
  1464 +
  1465 + function do_managetransitionactions() {
  1466 + $oTemplate = $this->oValidator->validateTemplate('ktcore/workflow/admin/transition_actions_edit');
  1467 + $this->oPage->setBreadcrumbDetails(_kt("Actions"));
  1468 +
  1469 + $actions = KTWorkflowUtil::getActionTriggersForTransition($this->oTransition);
  1470 + $add_form = $this->form_addtransitionaction();
  1471 +
  1472 + $oTemplate->setData(array(
  1473 + 'context' => $this,
  1474 + 'add_form' => $add_form,
  1475 + 'aActionTriggers' => $actions,
  1476 + ));
  1477 + return $oTemplate->render();
  1478 + }
  1479 +
  1480 + function do_addactiontrigger() {
  1481 + $oForm = $this->form_addtransitionaction();
  1482 + $res = $oForm->validate();
  1483 + $data = $res['results'];
  1484 + $errors = $res['errors'];
  1485 +
  1486 + if (!empty($errors)) {
  1487 + return $oForm->handleError();
  1488 + }
  1489 +
  1490 + $KTWFTriggerReg =& KTWorkflowTriggerRegistry::getSingleton();
  1491 +
  1492 + $this->startTransaction();
  1493 +
  1494 + $oTrigger = $KTWFTriggerReg->getWorkflowTrigger(KTUtil::arrayGet($data, 'action_name'));
  1495 + if (PEAR::isError($oTrigger)) {
  1496 + return $oForm->handleError(_kt('Unable to add trigger.'));
  1497 + }
  1498 +
  1499 + $oTriggerConfig = KTWorkflowTriggerInstance::createFromArray(array(
  1500 + 'transitionid' => KTUtil::getId($this->oTransition),
  1501 + 'namespace' => KTUtil::arrayGet($data, 'action_name'),
  1502 + 'config' => array(),
  1503 + ));
  1504 +
  1505 + if (PEAR::isError($oTriggerConfig)) {
  1506 + return $oForm->handleError(_kt('Unable to add trigger.') . $oTriggerConfig->getMessage());
  1507 + }
  1508 +
  1509 + // now, if the trigger is editable...
  1510 + $oTrigger->loadConfig($oTriggerConfig);
  1511 + if ($oTrigger->bIsConfigurable) {
  1512 + $this->successRedirectTo('editactiontrigger', _kt("New action added. This action requires configuration: please specify this below."), array('fTriggerInstanceId' => $oTriggerConfig->getId()));
  1513 + } else {
  1514 + $this->successRedirectTo('managetransitionactions', _kt("New restriction added."));
  1515 + }
  1516 + exit(0);
  1517 + }
  1518 +
  1519 +
  1520 + function do_editactiontrigger() {
  1521 + $this->oPage->setBreadcrumbDetails(_kt('editing restriction'));
  1522 + $oTriggerInstance =& KTWorkflowTriggerInstance::get($_REQUEST['fTriggerInstanceId']);
  1523 + if (PEAR::isError($oTriggerInstance)) {
  1524 + return $this->errorRedirectTo('managetransitionactions', _kt('Unable to load trigger.'));
  1525 + }
  1526 +
  1527 + // grab the transition ns from the request.
  1528 + $KTWFTriggerReg =& KTWorkflowTriggerRegistry::getSingleton();
  1529 +
  1530 + $this->startTransaction();
  1531 +
  1532 + $oTrigger = $KTWFTriggerReg->getWorkflowTrigger($oTriggerInstance->getNamespace());
  1533 + if (PEAR::isError($oTrigger)) {
  1534 + $this->errorRedirectTo('managetransitionactions', _kt('Unable to add trigger.'), 'fWorkflowId=' . $oWorkflow->getId() . '&fTransitionId=' . $oTransition->getId());
  1535 + exit(0);
  1536 + }
  1537 + $oTrigger->loadConfig($oTriggerInstance);
  1538 +
  1539 + return $oTrigger->displayConfiguration($this->meldPersistQuery(array('fTriggerInstanceId' => $oTriggerInstance->getId()), 'saveactiontrigger', true));
  1540 + }
  1541 +
  1542 + // }}}
  1543 +
  1544 + function do_saveactiontrigger() {
  1545 + $oTriggerInstance =& KTWorkflowTriggerInstance::get($_REQUEST['fTriggerInstanceId']);
  1546 + if (PEAR::isError($oTriggerInstance)) {
  1547 + $this->errorRedirectTo('managetransitionactions', _kt('Unable to load trigger.'));
  1548 + exit(0);
  1549 + }
  1550 +
  1551 + $KTWFTriggerReg =& KTWorkflowTriggerRegistry::getSingleton();
  1552 +
  1553 + $this->startTransaction();
  1554 +
  1555 + $oTrigger = $KTWFTriggerReg->getWorkflowTrigger($oTriggerInstance->getNamespace());
  1556 + if (PEAR::isError($oTrigger)) {
  1557 + $this->errorRedirectTo('managetransitionactions', _kt('Unable to load trigger.'));
  1558 + exit(0);
  1559 + }
  1560 + $oTrigger->loadConfig($oTriggerInstance);
  1561 +
  1562 + $res = $oTrigger->saveConfiguration();
  1563 + if (PEAR::isError($res)) {
  1564 + $this->errorRedirectTo('managetransitionactions', _kt('Unable to save trigger: ') . $res->getMessage());
  1565 + exit(0);
  1566 + }
  1567 +
  1568 + $this->successRedirectTo('managetransitionactions', _kt('Trigger saved.'));
  1569 + exit(0);
  1570 + }
  1571 +
  1572 + function do_deleteactiontrigger() {
  1573 + $oTriggerInstance =& KTWorkflowTriggerInstance::get($_REQUEST['fTriggerInstanceId']);
  1574 + if (PEAR::isError($oTriggerInstance)) {
  1575 + return $this->errorRedirectTo('managetransitionactions', _kt('Unable to load trigger.'));
  1576 + }
  1577 +
  1578 + // grab the transition ns from the request.
  1579 + $KTWFTriggerReg =& KTWorkflowTriggerRegistry::getSingleton();
  1580 + $this->startTransaction();
  1581 +
  1582 + $oTrigger = $KTWFTriggerReg->getWorkflowTrigger($oTriggerInstance->getNamespace());
  1583 + if (PEAR::isError($oTrigger)) {
  1584 + $this->errorRedirectTo('managetransitionactions', _kt('Unable to load trigger.'));
  1585 + exit(0);
  1586 + }
  1587 + $oTrigger->loadConfig($oTriggerInstance);
  1588 +
  1589 + $res = $oTriggerInstance->delete();
  1590 + if (PEAR::isError($res)) {
  1591 + $this->errorRedirectTo('managetransitionactions', _kt('Unable to delete trigger: ') . $res->getMessage(), 'fWorkflowId=' . $oWorkflow->getId() . '&fTransitionId=' . $oTransition->getId());
  1592 + exit(0);
  1593 + }
  1594 +
  1595 + $this->successRedirectTo('managetransitionactions', _kt('Trigger deleted.'));
  1596 + exit(0);
  1597 + }
  1598 +
1382 1599 }
1383 1600  
1384 1601 ?>
... ...
templates/ktcore/workflow/admin/effects_overview.smarty
... ... @@ -5,3 +5,8 @@ varies other actions to occur. For example, you can attach a "Move" action to a
5 5 which will cause any document moving through that workflow to be moved to a particular folder.
6 6 Or you can specify that when a document reaches the "Pending Review" state, users
7 7 with the role "Reviewer" on that document are informed.</p>
  8 +
  9 +<ul class="descriptiveText">
  10 + <li><a href="{addQS context=$context}action=transitionactions{/addQS}">Transition Effects</a></li>
  11 + <li><a href="{addQS context=$context}action=statenotifications{/addQS}">Notifications</a></li>
  12 +</ul>
... ...
templates/ktcore/workflow/admin/transition_actions_edit.smarty 0 → 100644
  1 +<h2>{i18n}Transition Effects{/i18n}</h2>
  2 +
  3 +{$add_form->render()}
  4 +
  5 +<br />
  6 +
  7 +{if empty($aActionTriggers)}
  8 + <div class="ktInfo"><p>{i18n}This transition has no actions associated with it..{/i18n}</p></div>
  9 +{else}
  10 +
  11 +<table class="kt_collection narrow" cellspacing="0">
  12 + <thead>
  13 + <tr>
  14 + <th>{i18n}Action{/i18n}</th>
  15 + <th>{i18n}Edit{/i18n}</th>
  16 + <th>{i18n}Delete{/i18n}</th>
  17 + <th>{i18n}Configuration{/i18n}</th>
  18 + </tr>
  19 + </thead>
  20 + <tbody>
  21 + {foreach from=$aActionTriggers item=oTrigger}
  22 + <tr>
  23 + <td>{$oTrigger->getName()}</td>
  24 + <td>{if $oTrigger->bIsConfigurable}<a class="ktAction ktEdit" href="{addQS context=$context}action=editactiontrigger&fTriggerInstanceId={$oTrigger->getConfigId()}{/addQS}">edit</a>{else}&mdash;{/if}</td>
  25 + <td><a class="ktAction ktDelete" href="{addQS context=$context}action=deleteactiontrigger&fTriggerInstanceId={$oTrigger->getConfigId()}{/addQS}">delete</a></td>
  26 + <td>{$oTrigger->getConfigDescription()}</td>
  27 + </tr>
  28 + {/foreach}
  29 + </tbody>
  30 + </table>
  31 +
  32 + {/if}
... ...
templates/ktcore/workflow/admin/transition_effects_overview.smarty 0 → 100644
  1 +<h2>Transition Actions Overview</h2>
  2 +
  3 +<p class="descriptiveText important">Please note that the plugins that are installed
  4 +will affect the available options</p>
  5 +
  6 +<table class="kt_collection narrow" cellspacing="0">
  7 + <thead>
  8 + <th>Transition</th>
  9 + <th>Edit</th>
  10 + <th>Effects</th>
  11 + </thead>
  12 +
  13 + <tbody>
  14 + {foreach from=$transitions item=oTransition}
  15 + {assign value=$oTransition->getId() var=transition_id}
  16 + <tr>
  17 + <td>{$oTransition->getName()}</td>
  18 + <td class="centered"><a href="{addQS context=$context}action=managetransitionactions&fTransitionId={$transition_id}{/addQS}" class="ktAction ktEdit"></a></td>
  19 + <td><span class="descriptiveText">{$context->describeTransitionActions($oTransition)}</span></td>
  20 + </tr>
  21 + {/foreach}
  22 + </tbody>
  23 +</table>
... ...