3 final class LegalpadDocumentManageController
extends LegalpadController
{
5 public function handleRequest(AphrontRequest
$request) {
6 $viewer = $request->getViewer();
7 $id = $request->getURIData('id');
9 // NOTE: We require CAN_EDIT to view this page.
11 $document = id(new LegalpadDocumentQuery())
14 ->needDocumentBodies(true)
15 ->needContributors(true)
16 ->requireCapabilities(
18 PhabricatorPolicyCapability
::CAN_VIEW
,
19 PhabricatorPolicyCapability
::CAN_EDIT
,
23 return new Aphront404Response();
26 $subscribers = PhabricatorSubscribersQuery
::loadSubscribersForPHID(
27 $document->getPHID());
29 $document_body = $document->getDocumentBody();
31 $engine = id(new PhabricatorMarkupEngine())
35 LegalpadDocumentBody
::MARKUP_FIELD_TEXT
);
36 $timeline = $this->buildTransactionTimeline(
38 new LegalpadTransactionQuery(),
40 $timeline->setQuoteRef($document->getMonogram());
42 $title = $document_body->getTitle();
44 $header = id(new PHUIHeaderView())
47 ->setPolicyObject($document)
48 ->setHeaderIcon('fa-gavel');
50 $curtain = $this->buildCurtainView($document);
51 $properties = $this->buildPropertyView($document, $engine);
52 $document_view = $this->buildDocumentView($document, $engine);
54 $comment_form = $this->buildCommentView($document, $timeline);
56 $crumbs = $this->buildApplicationCrumbs();
57 $crumbs->addTextCrumb(
58 $document->getMonogram(),
59 '/'.$document->getMonogram());
60 $crumbs->addTextCrumb(pht('Manage'));
61 $crumbs->setBorder(true);
64 $view = id(new PHUITwoColumnView())
66 ->setCurtain($curtain)
67 ->setMainColumn(array(
74 return $this->newPage()
77 ->setPageObjectPHIDs(array($document->getPHID()))
81 private function buildDocumentView(
82 LegalpadDocument
$document,
83 PhabricatorMarkupEngine
$engine) {
85 $viewer = $this->getViewer();
87 $view = id(new PHUIPropertyListView())
89 $document_body = $document->getDocumentBody();
90 $document_text = $engine->getOutput(
91 $document_body, LegalpadDocumentBody
::MARKUP_FIELD_TEXT
);
94 if (strlen($document->getPreamble())) {
95 $preamble_text = new PHUIRemarkupView($viewer, $document->getPreamble());
96 $view->addTextContent($preamble_text);
97 $view->addSectionHeader('');
98 $view->addTextContent($document_text);
100 $view->addTextContent($document_text);
103 return id(new PHUIObjectBoxView())
104 ->setHeaderText(pht('DOCUMENT'))
105 ->addPropertyList($view)
106 ->setBackground(PHUIObjectBoxView
::BLUE_PROPERTY
);
109 private function buildCurtainView(LegalpadDocument
$document) {
110 $viewer = $this->getViewer();
112 $curtain = $this->newCurtainView($document);
114 $can_edit = PhabricatorPolicyFilter
::hasCapability(
117 PhabricatorPolicyCapability
::CAN_EDIT
);
119 $doc_id = $document->getID();
122 id(new PhabricatorActionView())
123 ->setIcon('fa-pencil-square')
124 ->setName(pht('View/Sign Document'))
125 ->setHref('/'.$document->getMonogram()));
128 id(new PhabricatorActionView())
129 ->setIcon('fa-pencil')
130 ->setName(pht('Edit Document'))
131 ->setHref($this->getApplicationURI('/edit/'.$doc_id.'/'))
132 ->setDisabled(!$can_edit)
133 ->setWorkflow(!$can_edit));
136 id(new PhabricatorActionView())
137 ->setIcon('fa-terminal')
138 ->setName(pht('View Signatures'))
139 ->setHref($this->getApplicationURI('/signatures/'.$doc_id.'/')));
144 private function buildPropertyView(
145 LegalpadDocument
$document,
146 PhabricatorMarkupEngine
$engine) {
148 $viewer = $this->getViewer();
150 $properties = id(new PHUIPropertyListView())
153 $properties->addProperty(
154 pht('Signature Type'),
155 $document->getSignatureTypeName());
157 $properties->addProperty(
159 phabricator_datetime($document->getDateModified(), $viewer));
161 $properties->addProperty(
163 $viewer->renderHandle($document->getDocumentBody()->getCreatorPHID()));
165 $properties->addProperty(
167 $document->getVersions());
169 if ($document->getContributors()) {
170 $properties->addProperty(
173 ->renderHandleList($document->getContributors())
174 ->setAsInline(true));
177 return id(new PHUIObjectBoxView())
178 ->setHeaderText(pht('Properties'))
179 ->addPropertyList($properties)
180 ->setBackground(PHUIObjectBoxView
::BLUE_PROPERTY
);
183 private function buildCommentView(LegalpadDocument
$document, $timeline) {
184 $viewer = $this->getViewer();
185 $box = id(new LegalpadDocumentEditEngine())
187 ->buildEditEngineCommentView($document)
188 ->setTransactionTimeline($timeline);