diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 6c5a01fd0e..d43c9a6cb8 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -1783,6 +1783,7 @@ phutil_register_library_map(array( 'PhabricatorBadgesDAO' => 'applications/badges/storage/PhabricatorBadgesDAO.php', 'PhabricatorBadgesDefaultEditCapability' => 'applications/badges/capability/PhabricatorBadgesDefaultEditCapability.php', 'PhabricatorBadgesEditController' => 'applications/badges/controller/PhabricatorBadgesEditController.php', + 'PhabricatorBadgesEditEngine' => 'applications/badges/editor/PhabricatorBadgesEditEngine.php', 'PhabricatorBadgesEditRecipientsController' => 'applications/badges/controller/PhabricatorBadgesEditRecipientsController.php', 'PhabricatorBadgesEditor' => 'applications/badges/editor/PhabricatorBadgesEditor.php', 'PhabricatorBadgesIconSet' => 'applications/badges/icon/PhabricatorBadgesIconSet.php', @@ -5945,7 +5946,8 @@ phutil_register_library_map(array( 'PhabricatorBadgesCreateCapability' => 'PhabricatorPolicyCapability', 'PhabricatorBadgesDAO' => 'PhabricatorLiskDAO', 'PhabricatorBadgesDefaultEditCapability' => 'PhabricatorPolicyCapability', - 'PhabricatorBadgesEditController' => 'PhabricatorBadgesController', + 'PhabricatorBadgesEditController' => 'PhabricatorPasteController', + 'PhabricatorBadgesEditEngine' => 'PhabricatorEditEngine', 'PhabricatorBadgesEditRecipientsController' => 'PhabricatorBadgesController', 'PhabricatorBadgesEditor' => 'PhabricatorApplicationTransactionEditor', 'PhabricatorBadgesIconSet' => 'PhabricatorIconSet', diff --git a/src/applications/badges/controller/PhabricatorBadgesEditController.php b/src/applications/badges/controller/PhabricatorBadgesEditController.php index b1a4fb1030..aef92a983e 100644 --- a/src/applications/badges/controller/PhabricatorBadgesEditController.php +++ b/src/applications/badges/controller/PhabricatorBadgesEditController.php @@ -1,186 +1,11 @@ getViewer(); - $id = $request->getURIData('id'); - - if ($id) { - $badge = id(new PhabricatorBadgesQuery()) - ->setViewer($viewer) - ->withIDs(array($id)) - ->requireCapabilities( - array( - PhabricatorPolicyCapability::CAN_VIEW, - PhabricatorPolicyCapability::CAN_EDIT, - )) - ->executeOne(); - if (!$badge) { - return new Aphront404Response(); - } - $is_new = false; - } else { - $this->requireApplicationCapability( - PhabricatorBadgesCreateCapability::CAPABILITY); - - $badge = PhabricatorBadgesBadge::initializeNewBadge($viewer); - $is_new = true; - } - - if ($is_new) { - $title = pht('Create Badge'); - $button_text = pht('Create Badge'); - $cancel_uri = $this->getApplicationURI(); - } else { - $title = pht( - 'Edit %s', - $badge->getName()); - $button_text = pht('Save Changes'); - $cancel_uri = $this->getApplicationURI('view/'.$id.'/'); - } - - $e_name = true; - $v_name = $badge->getName(); - $v_icon = $badge->getIcon(); - $v_flav = $badge->getFlavor(); - $v_desc = $badge->getDescription(); - $v_qual = $badge->getQuality(); - $v_edit = $badge->getEditPolicy(); - - $validation_exception = null; - if ($request->isFormPost()) { - $v_name = $request->getStr('name'); - $v_flav = $request->getStr('flavor'); - $v_desc = $request->getStr('description'); - $v_icon = $request->getStr('icon'); - $v_qual = $request->getStr('quality'); - - $v_view = $request->getStr('viewPolicy'); - $v_edit = $request->getStr('editPolicy'); - - $type_name = PhabricatorBadgesTransaction::TYPE_NAME; - $type_flav = PhabricatorBadgesTransaction::TYPE_FLAVOR; - $type_desc = PhabricatorBadgesTransaction::TYPE_DESCRIPTION; - $type_icon = PhabricatorBadgesTransaction::TYPE_ICON; - $type_qual = PhabricatorBadgesTransaction::TYPE_QUALITY; - - $type_edit = PhabricatorTransactions::TYPE_EDIT_POLICY; - - $xactions = array(); - - $xactions[] = id(new PhabricatorBadgesTransaction()) - ->setTransactionType($type_name) - ->setNewValue($v_name); - - $xactions[] = id(new PhabricatorBadgesTransaction()) - ->setTransactionType($type_flav) - ->setNewValue($v_flav); - - $xactions[] = id(new PhabricatorBadgesTransaction()) - ->setTransactionType($type_desc) - ->setNewValue($v_desc); - - $xactions[] = id(new PhabricatorBadgesTransaction()) - ->setTransactionType($type_icon) - ->setNewValue($v_icon); - - $xactions[] = id(new PhabricatorBadgesTransaction()) - ->setTransactionType($type_qual) - ->setNewValue($v_qual); - - $xactions[] = id(new PhabricatorBadgesTransaction()) - ->setTransactionType($type_edit) - ->setNewValue($v_edit); - - $editor = id(new PhabricatorBadgesEditor()) - ->setActor($viewer) - ->setContentSourceFromRequest($request) - ->setContinueOnNoEffect(true); - - try { - $editor->applyTransactions($badge, $xactions); - $return_uri = $this->getApplicationURI('view/'.$badge->getID().'/'); - return id(new AphrontRedirectResponse())->setURI($return_uri); - - } catch (PhabricatorApplicationTransactionValidationException $ex) { - $validation_exception = $ex; - - $e_name = $ex->getShortMessage($type_name); - } - } - - $policies = id(new PhabricatorPolicyQuery()) - ->setViewer($viewer) - ->setObject($badge) - ->execute(); - - $form = id(new AphrontFormView()) - ->setUser($viewer) - ->appendChild( - id(new AphrontFormTextControl()) - ->setName('name') - ->setLabel(pht('Name')) - ->setValue($v_name) - ->setError($e_name)) - ->appendChild( - id(new AphrontFormTextControl()) - ->setName('flavor') - ->setLabel(pht('Flavor Text')) - ->setValue($v_flav)) - ->appendChild( - id(new PHUIFormIconSetControl()) - ->setLabel(pht('Icon')) - ->setName('icon') - ->setIconSet(new PhabricatorBadgesIconSet()) - ->setValue($v_icon)) - ->appendChild( - id(new AphrontFormSelectControl()) - ->setName('quality') - ->setLabel(pht('Quality')) - ->setValue($v_qual) - ->setOptions($badge->getQualityNameMap())) - ->appendChild( - id(new PhabricatorRemarkupControl()) - ->setUser($viewer) - ->setName('description') - ->setLabel(pht('Description')) - ->setValue($v_desc)) - ->appendChild( - id(new AphrontFormPolicyControl()) - ->setName('editPolicy') - ->setPolicyObject($badge) - ->setCapability(PhabricatorPolicyCapability::CAN_EDIT) - ->setValue($v_edit) - ->setPolicies($policies)) - ->appendChild( - id(new AphrontFormSubmitControl()) - ->setValue($button_text) - ->addCancelButton($cancel_uri)); - - $crumbs = $this->buildApplicationCrumbs(); - if ($is_new) { - $crumbs->addTextCrumb(pht('Create Badge')); - } else { - $crumbs->addTextCrumb( - $badge->getName(), - '/badges/view/'.$badge->getID().'/'); - $crumbs->addTextCrumb(pht('Edit')); - } - - $box = id(new PHUIObjectBoxView()) - ->setValidationException($validation_exception) - ->setHeaderText($title) - ->appendChild($form); - - return $this->newPage() - ->setTitle($title) - ->setCrumbs($crumbs) - ->appendChild( - array( - $box, - )); + return id(new PhabricatorBadgesEditEngine()) + ->setController($this) + ->buildResponse(); } } diff --git a/src/applications/badges/editor/PhabricatorBadgesEditEngine.php b/src/applications/badges/editor/PhabricatorBadgesEditEngine.php new file mode 100644 index 0000000000..49a8e85022 --- /dev/null +++ b/src/applications/badges/editor/PhabricatorBadgesEditEngine.php @@ -0,0 +1,98 @@ +getViewer()); + } + + protected function newObjectQuery() { + return new PhabricatorBadgesQuery(); + } + + protected function getObjectCreateTitleText($object) { + return pht('Create New Badge'); + } + + protected function getObjectEditTitleText($object) { + return pht('Edit %s', $object->getName()); + } + + protected function getObjectEditShortText($object) { + return $object->getName(); + } + + protected function getObjectCreateShortText() { + return pht('Create Badge'); + } + + protected function getCommentViewHeaderText($object) { + return pht('Add Comment'); + } + + protected function getCommentViewButtonText($object) { + return pht('Submit'); + } + + protected function getObjectViewURI($object) { + return $object->getViewURI(); + } + + protected function buildCustomEditFields($object) { + + return array( + id(new PhabricatorTextEditField()) + ->setKey('name') + ->setLabel(pht('Name')) + ->setDescription(pht('Badge name.')) + ->setTransactionType(PhabricatorBadgesTransaction::TYPE_NAME) + ->setValue($object->getName()), + id(new PhabricatorTextEditField()) + ->setKey('flavor') + ->setLabel(pht('Flavor text')) + ->setDescription(pht('Short description of the badge.')) + ->setValue($object->getFlavor()) + ->setTransactionType(PhabricatorBadgesTransaction::TYPE_FLAVOR), + id(new PhabricatorIconSetEditField()) + ->setKey('icon') + ->setLabel(pht('Icon')) + ->setIconSet(new PhabricatorBadgesIconSet()) + ->setTransactionType(PhabricatorBadgesTransaction::TYPE_ICON) + ->setConduitDescription(pht('Change the badge icon.')) + ->setConduitTypeDescription(pht('New badge icon.')) + ->setValue($object->getIcon()), + id(new PhabricatorSelectEditField()) + ->setKey('quality') + ->setLabel(pht('Quality')) + ->setValue($object->getQuality()) + ->setTransactionType(PhabricatorBadgesTransaction::TYPE_QUALITY) + ->setOptions($object->getQualityNameMap()), + id(new PhabricatorRemarkupEditField()) + ->setKey('description') + ->setLabel(pht('Description')) + ->setDescription(pht('Badge long description.')) + ->setTransactionType(PhabricatorBadgesTransaction::TYPE_DESCRIPTION) + ->setValue($object->getDescription()), + ); + } + +} diff --git a/src/applications/badges/storage/PhabricatorBadgesBadge.php b/src/applications/badges/storage/PhabricatorBadgesBadge.php index f6ff495a6e..29cccb9f44 100644 --- a/src/applications/badges/storage/PhabricatorBadgesBadge.php +++ b/src/applications/badges/storage/PhabricatorBadgesBadge.php @@ -111,6 +111,10 @@ final class PhabricatorBadgesBadge extends PhabricatorBadgesDAO return $this->assertAttached($this->recipientPHIDs); } + public function getViewURI() { + return '/badges/view/'.$this->getID().'/'; + } + public function save() { if (!$this->getMailKey()) { $this->setMailKey(Filesystem::readRandomCharacters(20));