[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class LegalpadDocumentEditController extends LegalpadController { 4 5 private $id; 6 7 public function willProcessRequest(array $data) { 8 $this->id = idx($data, 'id'); 9 } 10 11 public function processRequest() { 12 $request = $this->getRequest(); 13 $user = $request->getUser(); 14 15 if (!$this->id) { 16 $is_create = true; 17 18 $this->requireApplicationCapability( 19 LegalpadCreateDocumentsCapability::CAPABILITY); 20 21 $document = LegalpadDocument::initializeNewDocument($user); 22 $body = id(new LegalpadDocumentBody()) 23 ->setCreatorPHID($user->getPHID()); 24 $document->attachDocumentBody($body); 25 $document->setDocumentBodyPHID(PhabricatorPHIDConstants::PHID_VOID); 26 } else { 27 $is_create = false; 28 29 $document = id(new LegalpadDocumentQuery()) 30 ->setViewer($user) 31 ->needDocumentBodies(true) 32 ->requireCapabilities( 33 array( 34 PhabricatorPolicyCapability::CAN_VIEW, 35 PhabricatorPolicyCapability::CAN_EDIT, 36 )) 37 ->withIDs(array($this->id)) 38 ->executeOne(); 39 if (!$document) { 40 return new Aphront404Response(); 41 } 42 } 43 44 $e_title = true; 45 $e_text = true; 46 47 $title = $document->getDocumentBody()->getTitle(); 48 $text = $document->getDocumentBody()->getText(); 49 $v_signature_type = $document->getSignatureType(); 50 $v_preamble = $document->getPreamble(); 51 52 $errors = array(); 53 $can_view = null; 54 $can_edit = null; 55 if ($request->isFormPost()) { 56 57 $xactions = array(); 58 59 $title = $request->getStr('title'); 60 if (!strlen($title)) { 61 $e_title = pht('Required'); 62 $errors[] = pht('The document title may not be blank.'); 63 } else { 64 $xactions[] = id(new LegalpadTransaction()) 65 ->setTransactionType(LegalpadTransactionType::TYPE_TITLE) 66 ->setNewValue($title); 67 } 68 69 $text = $request->getStr('text'); 70 if (!strlen($text)) { 71 $e_text = pht('Required'); 72 $errors[] = pht('The document may not be blank.'); 73 } else { 74 $xactions[] = id(new LegalpadTransaction()) 75 ->setTransactionType(LegalpadTransactionType::TYPE_TEXT) 76 ->setNewValue($text); 77 } 78 79 $can_view = $request->getStr('can_view'); 80 $xactions[] = id(new LegalpadTransaction()) 81 ->setTransactionType(PhabricatorTransactions::TYPE_VIEW_POLICY) 82 ->setNewValue($can_view); 83 $can_edit = $request->getStr('can_edit'); 84 $xactions[] = id(new LegalpadTransaction()) 85 ->setTransactionType(PhabricatorTransactions::TYPE_EDIT_POLICY) 86 ->setNewValue($can_edit); 87 88 if ($is_create) { 89 $v_signature_type = $request->getStr('signatureType'); 90 $xactions[] = id(new LegalpadTransaction()) 91 ->setTransactionType(LegalpadTransactionType::TYPE_SIGNATURE_TYPE) 92 ->setNewValue($v_signature_type); 93 } 94 95 $v_preamble = $request->getStr('preamble'); 96 $xactions[] = id(new LegalpadTransaction()) 97 ->setTransactionType(LegalpadTransactionType::TYPE_PREAMBLE) 98 ->setNewValue($v_preamble); 99 100 if (!$errors) { 101 $editor = id(new LegalpadDocumentEditor()) 102 ->setContentSourceFromRequest($request) 103 ->setContinueOnNoEffect(true) 104 ->setActor($user); 105 106 $xactions = $editor->applyTransactions($document, $xactions); 107 108 return id(new AphrontRedirectResponse()) 109 ->setURI($this->getApplicationURI('view/'.$document->getID())); 110 } 111 } 112 113 if ($errors) { 114 // set these to what was specified in the form on post 115 $document->setViewPolicy($can_view); 116 $document->setEditPolicy($can_edit); 117 } 118 119 $form = id(new AphrontFormView()) 120 ->setUser($user) 121 ->appendChild( 122 id(new AphrontFormTextControl()) 123 ->setID('document-title') 124 ->setLabel(pht('Title')) 125 ->setError($e_title) 126 ->setValue($title) 127 ->setName('title')); 128 129 if ($is_create) { 130 $form->appendChild( 131 id(new AphrontFormSelectControl()) 132 ->setLabel(pht('Who Should Sign?')) 133 ->setName(pht('signatureType')) 134 ->setValue($v_signature_type) 135 ->setOptions(LegalpadDocument::getSignatureTypeMap())); 136 } else { 137 $form->appendChild( 138 id(new AphrontFormMarkupControl()) 139 ->setLabel(pht('Who Should Sign?')) 140 ->setValue($document->getSignatureTypeName())); 141 } 142 143 $form 144 ->appendChild( 145 id(new PhabricatorRemarkupControl()) 146 ->setUser($user) 147 ->setID('preamble') 148 ->setLabel(pht('Preamble')) 149 ->setValue($v_preamble) 150 ->setName('preamble') 151 ->setCaption( 152 pht('Optional help text for users signing this document.'))) 153 ->appendChild( 154 id(new PhabricatorRemarkupControl()) 155 ->setUser($user) 156 ->setID('document-text') 157 ->setLabel(pht('Document Body')) 158 ->setError($e_text) 159 ->setValue($text) 160 ->setHeight(AphrontFormTextAreaControl::HEIGHT_VERY_TALL) 161 ->setName('text')); 162 163 $policies = id(new PhabricatorPolicyQuery()) 164 ->setViewer($user) 165 ->setObject($document) 166 ->execute(); 167 168 $form 169 ->appendChild( 170 id(new AphrontFormPolicyControl()) 171 ->setUser($user) 172 ->setCapability(PhabricatorPolicyCapability::CAN_VIEW) 173 ->setPolicyObject($document) 174 ->setPolicies($policies) 175 ->setName('can_view')) 176 ->appendChild( 177 id(new AphrontFormPolicyControl()) 178 ->setUser($user) 179 ->setCapability(PhabricatorPolicyCapability::CAN_EDIT) 180 ->setPolicyObject($document) 181 ->setPolicies($policies) 182 ->setName('can_edit')); 183 184 $crumbs = $this->buildApplicationCrumbs($this->buildSideNav()); 185 $submit = new AphrontFormSubmitControl(); 186 if ($is_create) { 187 $submit->setValue(pht('Create Document')); 188 $submit->addCancelButton($this->getApplicationURI()); 189 $title = pht('Create Document'); 190 $short = pht('Create'); 191 } else { 192 $submit->setValue(pht('Edit Document')); 193 $submit->addCancelButton( 194 $this->getApplicationURI('view/'.$document->getID())); 195 $title = pht('Edit Document'); 196 $short = pht('Edit'); 197 198 $crumbs->addTextCrumb( 199 $document->getMonogram(), 200 $this->getApplicationURI('view/'.$document->getID())); 201 } 202 203 $form 204 ->appendChild($submit); 205 206 $form_box = id(new PHUIObjectBoxView()) 207 ->setHeaderText($title) 208 ->setFormErrors($errors) 209 ->setForm($form); 210 211 $crumbs->addTextCrumb($short); 212 213 $preview = id(new PHUIRemarkupPreviewPanel()) 214 ->setHeader(pht('Document Preview')) 215 ->setPreviewURI($this->getApplicationURI('document/preview/')) 216 ->setControlID('document-text') 217 ->setSkin('document'); 218 219 return $this->buildApplicationPage( 220 array( 221 $crumbs, 222 $form_box, 223 $preview, 224 ), 225 array( 226 'title' => $title, 227 )); 228 } 229 230 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |