2013-07-03 11:15:45 -07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class LegalpadDocumentEditController extends LegalpadController {
|
|
|
|
|
2015-02-12 15:22:56 -08:00
|
|
|
public function handleRequest(AphrontRequest $request) {
|
2013-07-03 11:15:45 -07:00
|
|
|
$user = $request->getUser();
|
|
|
|
|
2015-02-12 15:22:56 -08:00
|
|
|
$id = $request->getURIData('id');
|
|
|
|
if (!$id) {
|
2013-07-03 11:15:45 -07:00
|
|
|
$is_create = true;
|
|
|
|
|
2014-06-29 12:43:13 -07:00
|
|
|
$this->requireApplicationCapability(
|
2014-07-25 08:20:39 +10:00
|
|
|
LegalpadCreateDocumentsCapability::CAPABILITY);
|
2014-06-29 12:43:13 -07:00
|
|
|
|
2014-01-30 11:47:42 -08:00
|
|
|
$document = LegalpadDocument::initializeNewDocument($user);
|
2013-07-03 11:15:45 -07:00
|
|
|
$body = id(new LegalpadDocumentBody())
|
|
|
|
->setCreatorPHID($user->getPHID());
|
|
|
|
$document->attachDocumentBody($body);
|
|
|
|
$document->setDocumentBodyPHID(PhabricatorPHIDConstants::PHID_VOID);
|
|
|
|
} else {
|
|
|
|
$is_create = false;
|
|
|
|
|
|
|
|
$document = id(new LegalpadDocumentQuery())
|
|
|
|
->setViewer($user)
|
|
|
|
->needDocumentBodies(true)
|
|
|
|
->requireCapabilities(
|
|
|
|
array(
|
|
|
|
PhabricatorPolicyCapability::CAN_VIEW,
|
|
|
|
PhabricatorPolicyCapability::CAN_EDIT,
|
|
|
|
))
|
2015-02-12 15:22:56 -08:00
|
|
|
->withIDs(array($id))
|
2013-07-03 11:15:45 -07:00
|
|
|
->executeOne();
|
|
|
|
if (!$document) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$e_title = true;
|
|
|
|
$e_text = true;
|
2014-07-04 08:04:28 -07:00
|
|
|
|
|
|
|
$title = $document->getDocumentBody()->getTitle();
|
|
|
|
$text = $document->getDocumentBody()->getText();
|
|
|
|
$v_signature_type = $document->getSignatureType();
|
2014-07-04 09:41:27 -07:00
|
|
|
$v_preamble = $document->getPreamble();
|
2015-02-12 15:22:56 -08:00
|
|
|
$v_require_signature = $document->getRequireSignature();
|
2014-07-04 08:04:28 -07:00
|
|
|
|
2013-07-03 11:15:45 -07:00
|
|
|
$errors = array();
|
|
|
|
$can_view = null;
|
|
|
|
$can_edit = null;
|
|
|
|
if ($request->isFormPost()) {
|
|
|
|
|
|
|
|
$xactions = array();
|
|
|
|
|
|
|
|
$title = $request->getStr('title');
|
|
|
|
if (!strlen($title)) {
|
|
|
|
$e_title = pht('Required');
|
|
|
|
$errors[] = pht('The document title may not be blank.');
|
|
|
|
} else {
|
|
|
|
$xactions[] = id(new LegalpadTransaction())
|
2015-06-08 09:54:53 +10:00
|
|
|
->setTransactionType(LegalpadTransaction::TYPE_TITLE)
|
2013-07-03 11:15:45 -07:00
|
|
|
->setNewValue($title);
|
|
|
|
}
|
|
|
|
|
|
|
|
$text = $request->getStr('text');
|
|
|
|
if (!strlen($text)) {
|
|
|
|
$e_text = pht('Required');
|
|
|
|
$errors[] = pht('The document may not be blank.');
|
|
|
|
} else {
|
|
|
|
$xactions[] = id(new LegalpadTransaction())
|
2015-06-08 09:54:53 +10:00
|
|
|
->setTransactionType(LegalpadTransaction::TYPE_TEXT)
|
2013-07-03 11:15:45 -07:00
|
|
|
->setNewValue($text);
|
|
|
|
}
|
|
|
|
|
|
|
|
$can_view = $request->getStr('can_view');
|
|
|
|
$xactions[] = id(new LegalpadTransaction())
|
|
|
|
->setTransactionType(PhabricatorTransactions::TYPE_VIEW_POLICY)
|
|
|
|
->setNewValue($can_view);
|
|
|
|
$can_edit = $request->getStr('can_edit');
|
|
|
|
$xactions[] = id(new LegalpadTransaction())
|
|
|
|
->setTransactionType(PhabricatorTransactions::TYPE_EDIT_POLICY)
|
|
|
|
->setNewValue($can_edit);
|
|
|
|
|
2014-07-04 08:04:28 -07:00
|
|
|
if ($is_create) {
|
|
|
|
$v_signature_type = $request->getStr('signatureType');
|
|
|
|
$xactions[] = id(new LegalpadTransaction())
|
2015-06-08 09:54:53 +10:00
|
|
|
->setTransactionType(LegalpadTransaction::TYPE_SIGNATURE_TYPE)
|
2014-07-04 08:04:28 -07:00
|
|
|
->setNewValue($v_signature_type);
|
|
|
|
}
|
|
|
|
|
2014-07-04 09:41:27 -07:00
|
|
|
$v_preamble = $request->getStr('preamble');
|
|
|
|
$xactions[] = id(new LegalpadTransaction())
|
2015-06-08 09:54:53 +10:00
|
|
|
->setTransactionType(LegalpadTransaction::TYPE_PREAMBLE)
|
2014-07-04 09:41:27 -07:00
|
|
|
->setNewValue($v_preamble);
|
|
|
|
|
2015-02-12 15:22:56 -08:00
|
|
|
$v_require_signature = $request->getBool('requireSignature', 0);
|
|
|
|
if ($v_require_signature) {
|
|
|
|
if (!$user->getIsAdmin()) {
|
|
|
|
$errors[] = pht('Only admins may require signature.');
|
|
|
|
}
|
2015-02-17 11:45:20 -08:00
|
|
|
$individual = LegalpadDocument::SIGNATURE_TYPE_INDIVIDUAL;
|
|
|
|
if ($v_signature_type != $individual) {
|
2015-02-12 15:22:56 -08:00
|
|
|
$errors[] = pht(
|
|
|
|
'Only documents with signature type "individual" may require '.
|
|
|
|
'signing to use Phabricator.');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($user->getIsAdmin()) {
|
|
|
|
$xactions[] = id(new LegalpadTransaction())
|
2015-06-08 09:54:53 +10:00
|
|
|
->setTransactionType(LegalpadTransaction::TYPE_REQUIRE_SIGNATURE)
|
2015-02-12 15:22:56 -08:00
|
|
|
->setNewValue($v_require_signature);
|
|
|
|
}
|
|
|
|
|
2013-07-03 11:15:45 -07:00
|
|
|
if (!$errors) {
|
|
|
|
$editor = id(new LegalpadDocumentEditor())
|
|
|
|
->setContentSourceFromRequest($request)
|
|
|
|
->setContinueOnNoEffect(true)
|
|
|
|
->setActor($user);
|
|
|
|
|
|
|
|
$xactions = $editor->applyTransactions($document, $xactions);
|
|
|
|
|
|
|
|
return id(new AphrontRedirectResponse())
|
|
|
|
->setURI($this->getApplicationURI('view/'.$document->getID()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($errors) {
|
|
|
|
// set these to what was specified in the form on post
|
|
|
|
$document->setViewPolicy($can_view);
|
|
|
|
$document->setEditPolicy($can_edit);
|
|
|
|
}
|
|
|
|
|
|
|
|
$form = id(new AphrontFormView())
|
|
|
|
->setUser($user)
|
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormTextControl())
|
2013-07-08 17:05:33 -07:00
|
|
|
->setID('document-title')
|
2013-07-03 11:15:45 -07:00
|
|
|
->setLabel(pht('Title'))
|
|
|
|
->setError($e_title)
|
|
|
|
->setValue($title)
|
2014-07-04 08:04:28 -07:00
|
|
|
->setName('title'));
|
|
|
|
|
|
|
|
if ($is_create) {
|
|
|
|
$form->appendChild(
|
|
|
|
id(new AphrontFormSelectControl())
|
|
|
|
->setLabel(pht('Who Should Sign?'))
|
|
|
|
->setName(pht('signatureType'))
|
|
|
|
->setValue($v_signature_type)
|
|
|
|
->setOptions(LegalpadDocument::getSignatureTypeMap()));
|
2015-02-12 15:22:56 -08:00
|
|
|
$show_require = true;
|
2015-02-17 11:45:20 -08:00
|
|
|
$caption = pht('Applies only to documents individuals sign.');
|
2014-07-04 08:04:28 -07:00
|
|
|
} else {
|
|
|
|
$form->appendChild(
|
|
|
|
id(new AphrontFormMarkupControl())
|
|
|
|
->setLabel(pht('Who Should Sign?'))
|
|
|
|
->setValue($document->getSignatureTypeName()));
|
2015-02-12 15:22:56 -08:00
|
|
|
$individual = LegalpadDocument::SIGNATURE_TYPE_INDIVIDUAL;
|
|
|
|
$show_require = $document->getSignatureType() == $individual;
|
2015-02-17 11:45:20 -08:00
|
|
|
$caption = null;
|
2015-02-12 15:22:56 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($show_require) {
|
|
|
|
$form
|
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormCheckboxControl())
|
|
|
|
->setDisabled(!$user->getIsAdmin())
|
|
|
|
->setLabel(pht('Require Signature'))
|
|
|
|
->addCheckbox(
|
|
|
|
'requireSignature',
|
|
|
|
'requireSignature',
|
2015-05-22 17:27:56 +10:00
|
|
|
pht('Should signing this document be required to use Phabricator?'),
|
2015-02-17 11:45:20 -08:00
|
|
|
$v_require_signature)
|
|
|
|
->setCaption($caption));
|
2014-07-04 08:04:28 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
$form
|
2014-07-04 09:41:27 -07:00
|
|
|
->appendChild(
|
|
|
|
id(new PhabricatorRemarkupControl())
|
2014-11-24 15:25:25 -08:00
|
|
|
->setUser($user)
|
|
|
|
->setID('preamble')
|
|
|
|
->setLabel(pht('Preamble'))
|
|
|
|
->setValue($v_preamble)
|
|
|
|
->setName('preamble')
|
|
|
|
->setCaption(
|
|
|
|
pht('Optional help text for users signing this document.')))
|
2013-07-03 11:15:45 -07:00
|
|
|
->appendChild(
|
|
|
|
id(new PhabricatorRemarkupControl())
|
2014-11-24 15:25:25 -08:00
|
|
|
->setUser($user)
|
|
|
|
->setID('document-text')
|
|
|
|
->setLabel(pht('Document Body'))
|
|
|
|
->setError($e_text)
|
|
|
|
->setValue($text)
|
|
|
|
->setHeight(AphrontFormTextAreaControl::HEIGHT_VERY_TALL)
|
|
|
|
->setName('text'));
|
2013-07-03 11:15:45 -07:00
|
|
|
|
|
|
|
$policies = id(new PhabricatorPolicyQuery())
|
|
|
|
->setViewer($user)
|
|
|
|
->setObject($document)
|
|
|
|
->execute();
|
|
|
|
|
|
|
|
$form
|
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormPolicyControl())
|
|
|
|
->setUser($user)
|
|
|
|
->setCapability(PhabricatorPolicyCapability::CAN_VIEW)
|
|
|
|
->setPolicyObject($document)
|
|
|
|
->setPolicies($policies)
|
|
|
|
->setName('can_view'))
|
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormPolicyControl())
|
|
|
|
->setUser($user)
|
|
|
|
->setCapability(PhabricatorPolicyCapability::CAN_EDIT)
|
|
|
|
->setPolicyObject($document)
|
|
|
|
->setPolicies($policies)
|
|
|
|
->setName('can_edit'));
|
|
|
|
|
2014-01-16 14:36:57 -08:00
|
|
|
$crumbs = $this->buildApplicationCrumbs($this->buildSideNav());
|
2013-07-03 11:15:45 -07:00
|
|
|
$submit = new AphrontFormSubmitControl();
|
|
|
|
if ($is_create) {
|
|
|
|
$submit->setValue(pht('Create Document'));
|
2014-06-29 12:43:13 -07:00
|
|
|
$submit->addCancelButton($this->getApplicationURI());
|
2013-07-03 11:15:45 -07:00
|
|
|
$title = pht('Create Document');
|
|
|
|
$short = pht('Create');
|
|
|
|
} else {
|
2015-01-08 16:11:53 -08:00
|
|
|
$submit->setValue(pht('Save Document'));
|
2013-07-03 11:15:45 -07:00
|
|
|
$submit->addCancelButton(
|
|
|
|
$this->getApplicationURI('view/'.$document->getID()));
|
2014-06-29 12:43:13 -07:00
|
|
|
$title = pht('Edit Document');
|
|
|
|
$short = pht('Edit');
|
2014-06-28 16:37:15 -07:00
|
|
|
|
2014-01-16 14:36:57 -08:00
|
|
|
$crumbs->addTextCrumb(
|
|
|
|
$document->getMonogram(),
|
|
|
|
$this->getApplicationURI('view/'.$document->getID()));
|
2013-07-03 11:15:45 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
$form
|
|
|
|
->appendChild($submit);
|
|
|
|
|
2013-09-25 11:23:29 -07:00
|
|
|
$form_box = id(new PHUIObjectBoxView())
|
2013-08-26 11:53:11 -07:00
|
|
|
->setHeaderText($title)
|
2014-01-10 09:17:37 -08:00
|
|
|
->setFormErrors($errors)
|
2013-08-26 11:53:11 -07:00
|
|
|
->setForm($form);
|
|
|
|
|
2013-12-18 17:47:34 -08:00
|
|
|
$crumbs->addTextCrumb($short);
|
2013-07-03 11:15:45 -07:00
|
|
|
|
2013-08-05 10:47:26 -07:00
|
|
|
$preview = id(new PHUIRemarkupPreviewPanel())
|
|
|
|
->setHeader(pht('Document Preview'))
|
|
|
|
->setPreviewURI($this->getApplicationURI('document/preview/'))
|
[Redesign] Move basefont to Lato, remove Source Sans Pro
Summary: Working towards a more unified look and feel. This brings in Lato as a complete base font over Helvetica Neue, as well as removing Source Sans Pro from DocumentView and Conpherence. Design-wise Lato provides the nice readability at larger font sizes that Source Sans Pro did, with the ability to scale down to tables and UI widgets with ease. This gives us one font instead of two, and now Object descriptions and Timeline posts all can benefit from a consistent, readable font.
Test Plan:
Test main UI, smaller elements like tables, menus, DocumentViews, Previews, Conpherence.
{F498135}
{F498136}
Reviewers: btrahan, epriestley
Reviewed By: epriestley
Subscribers: epriestley, Korvin
Differential Revision: https://secure.phabricator.com/D13276
2015-06-13 20:32:45 +01:00
|
|
|
->setControlID('document-text');
|
2013-07-08 17:05:33 -07:00
|
|
|
|
2013-07-03 11:15:45 -07:00
|
|
|
return $this->buildApplicationPage(
|
|
|
|
array(
|
|
|
|
$crumbs,
|
2013-08-26 11:53:11 -07:00
|
|
|
$form_box,
|
2014-10-08 00:01:04 +11:00
|
|
|
$preview,
|
2013-07-03 11:15:45 -07:00
|
|
|
),
|
|
|
|
array(
|
|
|
|
'title' => $title,
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|