3 final class LegalpadDocumentEditEngine
4 extends PhabricatorEditEngine
{
6 const ENGINECONST
= 'legalpad.document';
8 public function getEngineName() {
9 return pht('Legalpad');
12 public function getEngineApplicationClass() {
13 return 'PhabricatorLegalpadApplication';
16 public function getSummaryHeader() {
17 return pht('Configure Legalpad Forms');
20 public function getSummaryText() {
21 return pht('Configure creation and editing documents in Legalpad.');
24 public function isEngineConfigurable() {
28 protected function newEditableObject() {
29 $viewer = $this->getViewer();
31 $document = LegalpadDocument
::initializeNewDocument($viewer);
32 $body = id(new LegalpadDocumentBody())
33 ->setCreatorPHID($viewer->getPHID());
34 $document->attachDocumentBody($body);
35 $document->setDocumentBodyPHID(PhabricatorPHIDConstants
::PHID_VOID
);
40 protected function newObjectQuery() {
41 return id(new LegalpadDocumentQuery())
42 ->needDocumentBodies(true);
45 protected function getObjectCreateTitleText($object) {
46 return pht('Create New Document');
49 protected function getObjectEditTitleText($object) {
50 $body = $object->getDocumentBody();
51 $title = $body->getTitle();
52 return pht('Edit Document: %s', $title);
55 protected function getObjectEditShortText($object) {
56 $body = $object->getDocumentBody();
57 return $body->getTitle();
60 protected function getObjectCreateShortText() {
61 return pht('Create Document');
64 protected function getObjectName() {
65 return pht('Document');
68 protected function getObjectCreateCancelURI($object) {
69 return $this->getApplication()->getApplicationURI('/');
72 protected function getEditorURI() {
73 return $this->getApplication()->getApplicationURI('edit/');
76 protected function getObjectViewURI($object) {
77 $id = $object->getID();
78 return $this->getApplication()->getApplicationURI('view/'.$id.'/');
82 protected function getCreateNewObjectPolicy() {
83 return $this->getApplication()->getPolicy(
84 LegalpadCreateDocumentsCapability
::CAPABILITY
);
87 protected function buildCustomEditFields($object) {
88 $viewer = $this->getViewer();
90 $body = $object->getDocumentBody();
91 $document_body = $body->getText();
93 $is_create = $this->getIsCreate();
94 $is_admin = $viewer->getIsAdmin();
98 id(new PhabricatorTextEditField())
100 ->setLabel(pht('Title'))
101 ->setDescription(pht('Document Title.'))
102 ->setConduitTypeDescription(pht('New document title.'))
103 ->setValue($object->getTitle())
104 ->setIsRequired(true)
105 ->setTransactionType(
106 LegalpadDocumentTitleTransaction
::TRANSACTIONTYPE
);
110 id(new PhabricatorSelectEditField())
111 ->setKey('signatureType')
112 ->setLabel(pht('Who Should Sign?'))
113 ->setDescription(pht('Type of signature required'))
114 ->setConduitTypeDescription(pht('New document signature type.'))
115 ->setValue($object->getSignatureType())
116 ->setOptions(LegalpadDocument
::getSignatureTypeMap())
117 ->setTransactionType(
118 LegalpadDocumentSignatureTypeTransaction
::TRANSACTIONTYPE
);
119 $show_require = true;
121 $fields[] = id(new PhabricatorStaticEditField())
122 ->setLabel(pht('Who Should Sign?'))
123 ->setValue($object->getSignatureTypeName());
124 $individual = LegalpadDocument
::SIGNATURE_TYPE_INDIVIDUAL
;
125 $show_require = $object->getSignatureType() == $individual;
128 if ($show_require && $is_admin) {
130 id(new PhabricatorBoolEditField())
131 ->setKey('requireSignature')
133 pht('No Signature Required'),
134 pht('Signature Required to Log In'))
135 ->setAsCheckbox(true)
136 ->setTransactionType(
137 LegalpadDocumentRequireSignatureTransaction
::TRANSACTIONTYPE
)
138 ->setDescription(pht('Marks this document as required signing.'))
139 ->setConduitDescription(
140 pht('Marks this document as required signing.'))
141 ->setValue($object->getRequireSignature());
145 id(new PhabricatorRemarkupEditField())
147 ->setLabel(pht('Preamble'))
148 ->setDescription(pht('The preamble of the document.'))
149 ->setConduitTypeDescription(pht('New document preamble.'))
150 ->setValue($object->getPreamble())
151 ->setTransactionType(
152 LegalpadDocumentPreambleTransaction
::TRANSACTIONTYPE
);
155 id(new PhabricatorRemarkupEditField())
157 ->setLabel(pht('Document Body'))
158 ->setDescription(pht('The body of text of the document.'))
159 ->setConduitTypeDescription(pht('New document body.'))
160 ->setValue($document_body)
161 ->setIsRequired(true)
162 ->setTransactionType(
163 LegalpadDocumentTextTransaction
::TRANSACTIONTYPE
);