1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-19 12:00:55 +01:00

Make dialogs a little easier to use

Summary:
  - Dialog pages currently have no titles or crumbs, and look shoddy. Add titles and crumbs.
  - Dialog titles aren't always great for crumbs, add an optional "short title" for crumbs.
  - `AphrontDialogResponse` is pure boilerplate. Allow controllers to just return a `DialogView` instead and get the same effect.
  - Building dialogs requires a bit of boilerplate, and we generally construct them with no explicit `"action"`, which has some issues with T4593. Provide a convenience method to set the viewer and get a reasonable, explict submit URI.

Test Plan:
  - Viewed dialog on its own.
  - Viewed dialog as a dialog.

{F132353}

Reviewers: btrahan, chad

Reviewed By: chad

Subscribers: epriestley

Differential Revision: https://secure.phabricator.com/D8577
This commit is contained in:
epriestley 2014-03-21 14:40:05 -07:00
parent 03c6bf0d09
commit d8713f6f0b
3 changed files with 57 additions and 19 deletions

View file

@ -36,8 +36,7 @@ final class PhabricatorAuthTerminateSessionController
$panel_uri = '/settings/panel/sessions/'; $panel_uri = '/settings/panel/sessions/';
if (!$sessions) { if (!$sessions) {
$dialog = id(new AphrontDialogView()) return $this->newDialog()
->setUser($viewer)
->setTitle(pht('No Matching Sessions')) ->setTitle(pht('No Matching Sessions'))
->appendParagraph( ->appendParagraph(
pht('There are no matching sessions to terminate.')) pht('There are no matching sessions to terminate.'))
@ -46,8 +45,6 @@ final class PhabricatorAuthTerminateSessionController
'(You can not terminate your current login session. To '. '(You can not terminate your current login session. To '.
'terminate it, log out.)')) 'terminate it, log out.)'))
->addCancelButton($panel_uri); ->addCancelButton($panel_uri);
return id(new AphrontDialogResponse())->setDialog($dialog);
} }
if ($request->isDialogFormPost()) { if ($request->isDialogFormPost()) {
@ -59,24 +56,24 @@ final class PhabricatorAuthTerminateSessionController
if ($is_all) { if ($is_all) {
$title = pht('Terminate Sessions?'); $title = pht('Terminate Sessions?');
$short = pht('Terminate Sessions');
$body = pht( $body = pht(
'Really terminate all sessions? (Your current login session will '. 'Really terminate all sessions? (Your current login session will '.
'not be terminated.)'); 'not be terminated.)');
} else { } else {
$title = pht('Terminate Session?'); $title = pht('Terminate Session?');
$short = pht('Terminate Session');
$body = pht( $body = pht(
'Really terminate session %s?', 'Really terminate session %s?',
phutil_tag('strong', array(), substr($session->getSessionKey(), 0, 6))); phutil_tag('strong', array(), substr($session->getSessionKey(), 0, 6)));
} }
$dialog = id(new AphrontDialogView()) return $this->newDialog()
->setUser($viewer)
->setTitle($title) ->setTitle($title)
->setShortTitle($short)
->appendParagraph($body) ->appendParagraph($body)
->addSubmitButton(pht('Terminate')) ->addSubmitButton(pht('Terminate'))
->addCancelButton($panel_uri); ->addCancelButton($panel_uri);
return id(new AphrontDialogResponse())->setDialog($dialog);
} }

View file

@ -258,6 +258,11 @@ abstract class PhabricatorController extends AphrontController {
} }
public function didProcessRequest($response) { public function didProcessRequest($response) {
// If a bare DialogView is returned, wrap it in a DialogResponse.
if ($response instanceof AphrontDialogView) {
$response = id(new AphrontDialogResponse())->setDialog($response);
}
$request = $this->getRequest(); $request = $this->getRequest();
$response->setRequest($request); $response->setRequest($request);
@ -278,17 +283,28 @@ abstract class PhabricatorController extends AphrontController {
if ($response instanceof AphrontDialogResponse) { if ($response instanceof AphrontDialogResponse) {
if (!$request->isAjax()) { if (!$request->isAjax()) {
$view = new PhabricatorStandardPageView(); $dialog = $response->getDialog();
$view->setRequest($request);
$view->setController($this); $title = $dialog->getTitle();
$view->appendChild(phutil_tag( $short = $dialog->getShortTitle();
'div',
array('style' => 'padding: 2em 0;'), $crumbs = $this->buildApplicationCrumbs();
$response->buildResponseString())); $crumbs->addTextCrumb(coalesce($short, $title));
$page_response = new AphrontWebpageResponse();
$page_response->setContent($view->render()); $page_content = array(
$page_response->setHTTPResponseCode($response->getHTTPResponseCode()); $crumbs,
return $page_response; $response->buildResponseString(),
);
$view = id(new PhabricatorStandardPageView())
->setRequest($request)
->setController($this)
->setTitle($title)
->appendChild($page_content);
$response = id(new AphrontWebpageResponse())
->setContent($view->render())
->setHTTPResponseCode($response->getHTTPResponseCode());
} else { } else {
$response->getDialog()->setIsStandalone(true); $response->getDialog()->setIsStandalone(true);
@ -306,6 +322,7 @@ abstract class PhabricatorController extends AphrontController {
)); ));
} }
} }
return $response; return $response;
} }
@ -448,4 +465,18 @@ abstract class PhabricatorController extends AphrontController {
} }
/**
* Create a new @{class:AphrontDialogView} with defaults filled in.
*
* @return AphrontDialogView New dialog.
*/
protected function newDialog() {
$submit_uri = new PhutilURI($this->getRequest()->getRequestURI());
$submit_uri = $submit_uri->getPath();
return id(new AphrontDialogView())
->setUser($this->getRequest()->getUser())
->setSubmitURI($submit_uri);
}
} }

View file

@ -3,6 +3,7 @@
final class AphrontDialogView extends AphrontView { final class AphrontDialogView extends AphrontView {
private $title; private $title;
private $shortTitle;
private $submitButton; private $submitButton;
private $cancelURI; private $cancelURI;
private $cancelText = 'Cancel'; private $cancelText = 'Cancel';
@ -51,6 +52,15 @@ final class AphrontDialogView extends AphrontView {
return $this->title; return $this->title;
} }
public function setShortTitle($short_title) {
$this->shortTitle = $short_title;
return $this;
}
public function getShortTitle() {
return $this->shortTitle;
}
public function addSubmitButton($text = null) { public function addSubmitButton($text = null) {
if (!$text) { if (!$text) {
$text = pht('Okay'); $text = pht('Okay');