mirror of
https://we.phorge.it/source/phorge.git
synced 2025-03-16 06:14:57 +01:00
Use AphrontDialog for New/Move Phame Posts
Summary: Moves New Post and Move Post to be separate Controllers with Dialogs. Ref T9897 Test Plan: Move a post to a new blog, see message and see post. Click New Post, get dialog, pick blog, edit new post. Reviewers: epriestley Reviewed By: epriestley Subscribers: Korvin Maniphest Tasks: T9897 Differential Revision: https://secure.phabricator.com/D14698
This commit is contained in:
parent
468f785845
commit
afacdbd814
6 changed files with 110 additions and 73 deletions
|
@ -3338,6 +3338,7 @@ phutil_register_library_map(array(
|
|||
'PhamePostListController' => 'applications/phame/controller/post/PhamePostListController.php',
|
||||
'PhamePostListView' => 'applications/phame/view/PhamePostListView.php',
|
||||
'PhamePostMailReceiver' => 'applications/phame/mail/PhamePostMailReceiver.php',
|
||||
'PhamePostMoveController' => 'applications/phame/controller/post/PhamePostMoveController.php',
|
||||
'PhamePostNewController' => 'applications/phame/controller/post/PhamePostNewController.php',
|
||||
'PhamePostNotLiveController' => 'applications/phame/controller/post/PhamePostNotLiveController.php',
|
||||
'PhamePostPreviewController' => 'applications/phame/controller/post/PhamePostPreviewController.php',
|
||||
|
@ -7687,6 +7688,7 @@ phutil_register_library_map(array(
|
|||
'PhamePostListController' => 'PhamePostController',
|
||||
'PhamePostListView' => 'AphrontTagView',
|
||||
'PhamePostMailReceiver' => 'PhabricatorObjectMailReceiver',
|
||||
'PhamePostMoveController' => 'PhamePostController',
|
||||
'PhamePostNewController' => 'PhamePostController',
|
||||
'PhamePostNotLiveController' => 'PhamePostController',
|
||||
'PhamePostPreviewController' => 'PhamePostController',
|
||||
|
|
|
@ -54,7 +54,7 @@ final class PhabricatorPhameApplication extends PhabricatorApplication {
|
|||
'preview/' => 'PhabricatorMarkupPreviewController',
|
||||
'framed/(?P<id>\d+)/' => 'PhamePostFramedController',
|
||||
'new/' => 'PhamePostNewController',
|
||||
'move/(?P<id>\d+)/' => 'PhamePostNewController',
|
||||
'move/(?P<id>\d+)/' => 'PhamePostMoveController',
|
||||
'comment/(?P<id>[1-9]\d*)/' => 'PhamePostCommentController',
|
||||
),
|
||||
'blog/' => array(
|
||||
|
|
|
@ -84,6 +84,13 @@ final class PhameHomeController extends PhamePostController {
|
|||
$can_create = $this->hasApplicationCapability(
|
||||
PhameBlogCreateCapability::CAPABILITY);
|
||||
|
||||
$crumbs->addAction(
|
||||
id(new PHUIListItemView())
|
||||
->setName(pht('New Post'))
|
||||
->setHref($this->getApplicationURI('/post/new/'))
|
||||
->setIcon('fa-plus-square')
|
||||
->setWorkflow(true));
|
||||
|
||||
$crumbs->addAction(
|
||||
id(new PHUIListItemView())
|
||||
->setName(pht('New Blog'))
|
||||
|
|
|
@ -0,0 +1,78 @@
|
|||
<?php
|
||||
|
||||
final class PhamePostMoveController extends PhamePostController {
|
||||
|
||||
public function handleRequest(AphrontRequest $request) {
|
||||
$viewer = $request->getViewer();
|
||||
$id = $request->getURIData('id');
|
||||
|
||||
$post = id(new PhamePostQuery())
|
||||
->setViewer($viewer)
|
||||
->withIDs(array($id))
|
||||
->requireCapabilities(
|
||||
array(
|
||||
PhabricatorPolicyCapability::CAN_EDIT,
|
||||
PhabricatorPolicyCapability::CAN_VIEW,
|
||||
))
|
||||
->executeOne();
|
||||
|
||||
if (!$post) {
|
||||
return new Aphront404Response();
|
||||
}
|
||||
|
||||
$view_uri = '/post/view/'.$post->getID().'/';
|
||||
$view_uri = $this->getApplicationURI($view_uri);
|
||||
|
||||
if ($request->isFormPost()) {
|
||||
$blog = id(new PhameBlogQuery())
|
||||
->setViewer($viewer)
|
||||
->withIDs(array($request->getInt('blog')))
|
||||
->requireCapabilities(
|
||||
array(
|
||||
PhabricatorPolicyCapability::CAN_EDIT,
|
||||
))
|
||||
->executeOne();
|
||||
|
||||
if ($blog) {
|
||||
$post->setBlogPHID($blog->getPHID());
|
||||
$post->save();
|
||||
|
||||
return id(new AphrontRedirectResponse())
|
||||
->setURI($view_uri.'?moved=1');
|
||||
}
|
||||
}
|
||||
|
||||
$blogs = id(new PhameBlogQuery())
|
||||
->setViewer($viewer)
|
||||
->requireCapabilities(
|
||||
array(
|
||||
PhabricatorPolicyCapability::CAN_EDIT,
|
||||
))
|
||||
->execute();
|
||||
|
||||
$options = mpull($blogs, 'getName', 'getID');
|
||||
asort($options);
|
||||
|
||||
$selected_value = null;
|
||||
if ($post && $post->getBlog()) {
|
||||
$selected_value = $post->getBlog()->getID();
|
||||
}
|
||||
|
||||
$form = id(new PHUIFormLayoutView())
|
||||
->setUser($viewer)
|
||||
->appendChild(
|
||||
id(new AphrontFormSelectControl())
|
||||
->setLabel(pht('Blog'))
|
||||
->setName('blog')
|
||||
->setOptions($options)
|
||||
->setValue($selected_value));
|
||||
|
||||
return $this->newDialog()
|
||||
->setTitle(pht('Move Post'))
|
||||
->appendChild($form)
|
||||
->addSubmitButton(pht('Move Post'))
|
||||
->addCancelButton($view_uri);
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -4,12 +4,10 @@ final class PhamePostNewController extends PhamePostController {
|
|||
|
||||
public function handleRequest(AphrontRequest $request) {
|
||||
$viewer = $request->getViewer();
|
||||
$id = $request->getURIData('id');
|
||||
$id = $request->getInt('blog');
|
||||
|
||||
$post = null;
|
||||
$view_uri = null;
|
||||
if ($id) {
|
||||
$post = id(new PhamePostQuery())
|
||||
$blog = id(new PhameBlogQuery())
|
||||
->setViewer($viewer)
|
||||
->withIDs(array($id))
|
||||
->requireCapabilities(
|
||||
|
@ -17,35 +15,14 @@ final class PhamePostNewController extends PhamePostController {
|
|||
PhabricatorPolicyCapability::CAN_EDIT,
|
||||
))
|
||||
->executeOne();
|
||||
if (!$post) {
|
||||
if (!$blog) {
|
||||
return new Aphront404Response();
|
||||
}
|
||||
|
||||
$view_uri = '/post/view/'.$post->getID().'/';
|
||||
$view_uri = '/post/edit/?blog='.$blog->getID();
|
||||
$view_uri = $this->getApplicationURI($view_uri);
|
||||
|
||||
if ($request->isFormPost()) {
|
||||
$blog = id(new PhameBlogQuery())
|
||||
->setViewer($viewer)
|
||||
->withIDs(array($request->getInt('blog')))
|
||||
->requireCapabilities(
|
||||
array(
|
||||
PhabricatorPolicyCapability::CAN_EDIT,
|
||||
))
|
||||
->executeOne();
|
||||
|
||||
if ($blog) {
|
||||
$post->setBlogPHID($blog->getPHID());
|
||||
$post->save();
|
||||
|
||||
return id(new AphrontRedirectResponse())->setURI($view_uri);
|
||||
}
|
||||
}
|
||||
|
||||
$title = pht('Move Post');
|
||||
} else {
|
||||
$title = pht('Create Post');
|
||||
$view_uri = $this->getApplicationURI('/post/new');
|
||||
return id(new AphrontRedirectResponse())->setURI($view_uri);
|
||||
}
|
||||
|
||||
$blogs = id(new PhameBlogQuery())
|
||||
|
@ -56,13 +33,8 @@ final class PhamePostNewController extends PhamePostController {
|
|||
))
|
||||
->execute();
|
||||
|
||||
$crumbs = $this->buildApplicationCrumbs();
|
||||
$crumbs->addTextCrumb($title, $view_uri);
|
||||
|
||||
$notification = null;
|
||||
$form_box = null;
|
||||
if (!$blogs) {
|
||||
$notification = id(new PHUIInfoView())
|
||||
$form = id(new PHUIInfoView())
|
||||
->setSeverity(PHUIInfoView::SEVERITY_NODATA)
|
||||
->appendChild(
|
||||
pht('You do not have permission to post to any blogs. Create a blog '.
|
||||
|
@ -72,48 +44,19 @@ final class PhamePostNewController extends PhamePostController {
|
|||
$options = mpull($blogs, 'getName', 'getID');
|
||||
asort($options);
|
||||
|
||||
$selected_value = null;
|
||||
if ($post && $post->getBlog()) {
|
||||
$selected_value = $post->getBlog()->getID();
|
||||
}
|
||||
|
||||
$form = id(new AphrontFormView())
|
||||
$form = id(new PHUIFormLayoutView())
|
||||
->setUser($viewer)
|
||||
->appendChild(
|
||||
id(new AphrontFormSelectControl())
|
||||
->setLabel(pht('Blog'))
|
||||
->setName('blog')
|
||||
->setOptions($options)
|
||||
->setValue($selected_value));
|
||||
|
||||
if ($post) {
|
||||
$form
|
||||
->appendChild(
|
||||
id(new AphrontFormSubmitControl())
|
||||
->setValue(pht('Move Post'))
|
||||
->addCancelButton($view_uri));
|
||||
} else {
|
||||
$form
|
||||
->setAction($this->getApplicationURI('post/edit/'))
|
||||
->setMethod('GET')
|
||||
->appendChild(
|
||||
id(new AphrontFormSubmitControl())
|
||||
->setValue(pht('Continue')));
|
||||
}
|
||||
|
||||
$form_box = id(new PHUIObjectBoxView())
|
||||
->setHeaderText($title)
|
||||
->setForm($form);
|
||||
->setOptions($options));
|
||||
}
|
||||
|
||||
return $this->newPage()
|
||||
->setTitle($title)
|
||||
->setCrumbs($crumbs)
|
||||
->appendChild(
|
||||
array(
|
||||
$notification,
|
||||
$form_box,
|
||||
));
|
||||
return $this->newDialog()
|
||||
->setTitle(pht('New Post'))
|
||||
->appendChild($form)
|
||||
->addSubmitButton(pht('Continue'));
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ final class PhamePostViewController extends PhamePostController {
|
|||
|
||||
public function handleRequest(AphrontRequest $request) {
|
||||
$viewer = $request->getViewer();
|
||||
$moved = $request->getStr('moved');
|
||||
|
||||
$post = id(new PhamePostQuery())
|
||||
->setViewer($viewer)
|
||||
|
@ -57,6 +58,13 @@ final class PhamePostViewController extends PhamePostController {
|
|||
$document = id(new PHUIDocumentViewPro())
|
||||
->setHeader($header);
|
||||
|
||||
if ($moved) {
|
||||
$document->appendChild(
|
||||
id(new PHUIInfoView())
|
||||
->setSeverity(PHUIInfoView::SEVERITY_NOTICE)
|
||||
->appendChild(pht('Post moved successfully.')));
|
||||
}
|
||||
|
||||
if ($post->isDraft()) {
|
||||
$document->appendChild(
|
||||
id(new PHUIInfoView())
|
||||
|
@ -169,8 +177,7 @@ final class PhamePostViewController extends PhamePostController {
|
|||
->setIcon('fa-pencil')
|
||||
->setHref($this->getApplicationURI('post/edit/'.$id.'/'))
|
||||
->setName(pht('Edit Post'))
|
||||
->setDisabled(!$can_edit)
|
||||
->setWorkflow(!$can_edit));
|
||||
->setDisabled(!$can_edit));
|
||||
|
||||
$actions->addAction(
|
||||
id(new PhabricatorActionView())
|
||||
|
@ -178,7 +185,7 @@ final class PhamePostViewController extends PhamePostController {
|
|||
->setHref($this->getApplicationURI('post/move/'.$id.'/'))
|
||||
->setName(pht('Move Post'))
|
||||
->setDisabled(!$can_edit)
|
||||
->setWorkflow(!$can_edit));
|
||||
->setWorkflow(true));
|
||||
|
||||
$actions->addAction(
|
||||
id(new PhabricatorActionView())
|
||||
|
|
Loading…
Add table
Reference in a new issue