Commit fcb0f51a8cc3a8fc7a75d4d3050ae2b9a4605663
1 parent
e2e28b3b
Use the new action infrastructure to populate the document actions
git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@3562 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
1 changed file
with
15 additions
and
155 deletions
presentation/lookAndFeel/knowledgeTree/documentmanagement/viewUI.inc
| @@ -519,168 +519,28 @@ function displayButton($sAction, $sQueryString, $sImageName, $sDisabledText = "" | @@ -519,168 +519,28 @@ function displayButton($sAction, $sQueryString, $sImageName, $sDisabledText = "" | ||
| 519 | } | 519 | } |
| 520 | } | 520 | } |
| 521 | 521 | ||
| 522 | -function displayViewButton($oDocument, $bEdit) { | ||
| 523 | - $sQueryString = "fDocumentID=" . $oDocument->getID(); | ||
| 524 | - $sViewAlert = _("This will download a copy of the document and is not the same as Checking Out a document. Changes to this downloaded file will not be managed in the DMS."); | ||
| 525 | - $sJS = "onClick=\"alert('$sViewAlert '); return true;\""; | ||
| 526 | - return displayButton("downloadDocument", $sQueryString, "view", $sDisabledText, $sJS); | ||
| 527 | - | ||
| 528 | -} | ||
| 529 | - | ||
| 530 | -function displayCheckInOutButton($oDocument, $bEdit) { | ||
| 531 | - | ||
| 532 | - $sQueryString = "fDocumentID=" . $oDocument->getID(); | ||
| 533 | - // display the check in button if the document is checked out and you checked the document out | ||
| 534 | - if ($oDocument->getIsCheckedOut()) { | ||
| 535 | - $sAction = "checkInDocument"; | ||
| 536 | - $sImageName = "checkin"; | ||
| 537 | - if ($oDocument->getCheckedOutUserID() <> $_SESSION["userID"]) { | ||
| 538 | - $oUser = User::get($oDocument->getCheckedOutUserID()); | ||
| 539 | - $sDisabledText = sprintf(_("The document can only be checked back in by %s"), $oUser->getName()); | ||
| 540 | - } | ||
| 541 | - // otherwise display the check out button | ||
| 542 | - } else { | ||
| 543 | - $sAction = "checkOutDocument"; | ||
| 544 | - $sImageName = "checkout"; | ||
| 545 | - // #3481 if the document is published don't allow checkout | ||
| 546 | - if (DocumentCollaboration::documentIsPublished($oDocument->getID())) { | ||
| 547 | - $sDisabledText = _("This document has been published and cannot be checked out"); | ||
| 548 | - } | ||
| 549 | - } | ||
| 550 | - if (!$bEdit) { | ||
| 551 | - $sDisabledText = _("You do not have write access to this document"); | ||
| 552 | - } | ||
| 553 | - return displayButton($sAction, $sQueryString, $sImageName, $sDisabledText); | ||
| 554 | -} | ||
| 555 | - | ||
| 556 | -function displayEmailButton($oDocument) { | ||
| 557 | - global $default; | ||
| 558 | - return displayButton("emailDocument", "fDocumentID=" . $oDocument->getID(), "email"); | ||
| 559 | -} | ||
| 560 | - | ||
| 561 | -function displayDeleteButton($oDocument, $bEdit) { | ||
| 562 | - if ($bEdit) { | ||
| 563 | - $sQueryString = "fDocumentIDs[]=" . $oDocument->getID(); | ||
| 564 | - $sQueryString .= "&fReturnDocumentID=" . $oDocument->getID(); | ||
| 565 | - if ($oDocument->getIsCheckedOut()) { | ||
| 566 | - $sDisabledText = _("This document can't be deleted because its checked out"); | ||
| 567 | - } | ||
| 568 | - } else { | ||
| 569 | - $sDisabledText = _("You do not have write access to this document"); | ||
| 570 | - } | ||
| 571 | - return displayButton("deleteDocument", $sQueryString, "delete", $sDisabledText); | ||
| 572 | -} | ||
| 573 | - | ||
| 574 | -function displayHistoryButton($oDocument) { | ||
| 575 | - global $default; | ||
| 576 | - return displayButton("viewHistory", "fDocumentID=" . $oDocument->getID(), "history"); | ||
| 577 | -} | ||
| 578 | -function displayMoveButton($oDocument, $bEdit) { | ||
| 579 | - if ($bEdit) { | ||
| 580 | - $sQueryString = "fFolderID=" . $oDocument->getFolderID() . "&fDocumentIDs[]=" . $oDocument->getID(); | ||
| 581 | - // documents in collaboration and checked out documents can't be moved | ||
| 582 | - if ($oDocument->getIsCheckedOut()) { | ||
| 583 | - $sDisabledText = _("The document is checked out and cannot be moved."); | ||
| 584 | - } | ||
| 585 | - if (DocumentCollaboration::documentCollaborationStarted($oDocument->getID()) && | ||
| 586 | - !DocumentCollaboration::documentCollaborationDone($oDocument->getID())) { | ||
| 587 | - $sDisabledText = _("The document is in collaboration and cannot be moved."); | ||
| 588 | - } | ||
| 589 | - } else { | ||
| 590 | - $sDisabledText = _("You do not have write access to this document"); | ||
| 591 | - } | ||
| 592 | - return displayButton("moveDocument", $sQueryString, "move", $sDisabledText); | ||
| 593 | -} | 522 | +/** |
| 523 | + * Displays document action buttons | ||
| 524 | + */ | ||
| 594 | 525 | ||
| 595 | -function displaySubscriptionButton($oDocument) { | ||
| 596 | - // display the unsubscribe button if the user is subscribed to the document | ||
| 597 | - if (Subscription::exists($_SESSION["userID"], $oDocument->getID(), SubscriptionConstants::subscriptionType("DocumentSubscription"))) { | ||
| 598 | - $sAction = "removeSubscription"; | ||
| 599 | - $sImageName = "unsubscribe"; | ||
| 600 | - // otherwise display the subscribe button | ||
| 601 | - } else { | ||
| 602 | - $sAction = "addSubscription"; | ||
| 603 | - $sImageName = "subscribe"; | ||
| 604 | - } | ||
| 605 | - return displayButton($sAction, "fDocumentID=" . $oDocument->getID(), $sImageName); | ||
| 606 | -} | 526 | +function displayActionButtons($oDocument, $bEdit) { |
| 527 | + require_once(KT_LIB_DIR . '/actions/documentaction.inc.php'); | ||
| 528 | + $oTemplating =& KTTemplating::getSingleton(); | ||
| 529 | + $oTemplate = $oTemplating->loadTemplate('ktcore/document_action'); | ||
| 607 | 530 | ||
| 608 | -function displayDiscussionButton($oDocument, $bEdit) { | ||
| 609 | - global $default; | ||
| 610 | - return displayButton("viewDiscussion", "fDocumentID=" . $oDocument->getID() . "&fForDiscussion=1", "discussion"); | ||
| 611 | -} | ||
| 612 | - | ||
| 613 | -function displayArchiveButton($oDocument, $bEdit) { | ||
| 614 | - // only display the archive button for available documents | ||
| 615 | - // if the document is not checked out | ||
| 616 | - // and if the document is not in collaboration | ||
| 617 | - if ($bEdit) { | ||
| 618 | - if (!$oDocument->getIsCheckedOut()) { | ||
| 619 | - if ($oDocument->hasCollaboration() && | ||
| 620 | - DocumentCollaboration::documentCollaborationStarted($oDocument->getID()) && | ||
| 621 | - !DocumentCollaboration::documentCollaborationDone($oDocument->getID())) { | ||
| 622 | - $sDisabledText = _("This document is in collaboration and cannot be archived"); | ||
| 623 | - } | ||
| 624 | - } else { | ||
| 625 | - $sDisabledText = _("This document is checked out and cannot be archived."); | ||
| 626 | - } | ||
| 627 | - } else { | ||
| 628 | - $sDisabledText = _("You do not have write access to this document"); | ||
| 629 | - } | ||
| 630 | - return displayButton("archiveDocument", "fDocumentID=" . $oDocument->getID(), "archive", $sDisabledText); | ||
| 631 | -} | 531 | + $sToRender = ""; |
| 632 | 532 | ||
| 633 | -function displayDependantDocumentButton($oDocument, $bEdit) { | ||
| 634 | - global $default; | ||
| 635 | - return displayButton("createDependantDocument", "fDocumentID=" . $oDocument->getID(), "dependentdoc"); | ||
| 636 | -} | 533 | + // XXX: Anonymous/Guest interaction |
| 534 | + $oUser =& User::get($_SESSION["userID"]); | ||
| 637 | 535 | ||
| 638 | -function displayPublishButton($oDocument, $bEdit) { | ||
| 639 | - // only display the publish button for unpublished documents | ||
| 640 | - if (!DocumentCollaboration::documentIsPublished($oDocument->getID()) && | ||
| 641 | - !DocumentCollaboration::documentIsPendingWebPublishing($oDocument->getID())) { | ||
| 642 | - // if there is collaboration | ||
| 643 | - if ($oDocument->hasCollaboration()) { | ||
| 644 | - // only display publish button if collaboration is complete and you're the last user in the collaboration process (or a sysadmin) | ||
| 645 | - if (DocumentCollaboration::documentCollaborationDone($oDocument->getID())) { | ||
| 646 | - if ( !($_SESSION["userID"] == DocumentCollaboration::getLastCollaboratorID($oDocument->getID())) && !Permission::userIsSystemAdministrator() ) { | ||
| 647 | - $sDisabledText = _("You are not the last collaborator and hence cannot publish this document"); | ||
| 648 | - } | ||
| 649 | - } else { | ||
| 650 | - $sDisabledText = _("You cannot publish this document until collaboration is complete"); | ||
| 651 | - } | ||
| 652 | - } else { | ||
| 653 | - // no collaboration, check the user permissions | ||
| 654 | - if ( !($_SESSION["userID"] == $oDocument->getCreatorID()) && !Permission::userIsSystemAdministrator() ) { | ||
| 655 | - $sDisabledText = _("You do not have permission to publish this document."); | ||
| 656 | - } | 536 | + foreach (KTDocumentActionUtil::getDocumentActionsForDocument($oDocument, $oUser) as $oAction) { |
| 537 | + $aInfo = $oAction->getInfo(); | ||
| 538 | + if (is_null($aInfo)) { | ||
| 539 | + continue; | ||
| 657 | } | 540 | } |
| 658 | - } else { | ||
| 659 | - if (DocumentCollaboration::documentIsPublished($oDocument->getID())) { | ||
| 660 | - $sDisabledText = _("This document is already published."); | ||
| 661 | - } else if (DocumentCollaboration::documentIsPendingWebPublishing($oDocument->getID())) { | ||
| 662 | - $sDisabledText = _("This document has been marked as pending publishing and the web publisher has been notified."); | ||
| 663 | - } | 541 | + $sToRender .= $oTemplate->render($aInfo); |
| 664 | } | 542 | } |
| 665 | - return displayButton("viewDocument", "fDocumentID=" . $oDocument->getID() . "&fForPublish=1", "publish", $sDisabledText); | ||
| 666 | -} | ||
| 667 | 543 | ||
| 668 | -/** | ||
| 669 | - * Displays document action buttons | ||
| 670 | - */ | ||
| 671 | -function displayActionButtons($oDocument, $bEdit) { | ||
| 672 | - $sToRender .= displayViewButton($oDocument, $bEdit); | ||
| 673 | - $sToRender .= displayEmailButton($oDocument); | ||
| 674 | - $sToRender .= displayCheckInOutButton($oDocument, $bEdit); | ||
| 675 | - $sToRender .= displayDeleteButton($oDocument, $bEdit); | ||
| 676 | - $sToRender .= displayHistoryButton($oDocument); | ||
| 677 | - $sToRender .= displayMoveButton($oDocument, $bEdit); | ||
| 678 | - $sToRender .= displaySubscriptionButton($oDocument); | ||
| 679 | - $sToRender .= displayDiscussionButton($oDocument, $bEdit); | ||
| 680 | - $sToRender .= displayArchiveButton($oDocument, $bEdit); | ||
| 681 | - $sToRender .= displayDependantDocumentButton($oDocument, $bEdit); | ||
| 682 | - $sToRender .= displayPublishButton($oDocument, $bEdit); | ||
| 683 | - | ||
| 684 | return $sToRender; | 544 | return $sToRender; |
| 685 | } | 545 | } |
| 686 | 546 |