From 50240eda03e14130d6ada8c01a1a1459583c2f4c Mon Sep 17 00:00:00 2001 From: lkassianik Date: Wed, 27 May 2015 11:11:11 -0700 Subject: [PATCH] Create button should be a dropdown with public and private options Summary: Ref T8026, Create button should be a dropdown with public and private options Test Plan: Create both a public and private event. Confirm view policies apply correctly. Reviewers: #blessed_reviewers, epriestley Reviewed By: #blessed_reviewers, epriestley Subscribers: Korvin, epriestley Maniphest Tasks: T8026 Differential Revision: https://secure.phabricator.com/D13033 --- .../controller/PhabricatorCalendarController.php | 14 +++++++++++++- .../PhabricatorCalendarEventEditController.php | 5 ++++- .../calendar/storage/PhabricatorCalendarEvent.php | 12 ++++++++++-- src/view/phui/PHUICrumbsView.php | 1 + src/view/phui/PHUIListItemView.php | 12 ++++++++++++ 5 files changed, 40 insertions(+), 4 deletions(-) diff --git a/src/applications/calendar/controller/PhabricatorCalendarController.php b/src/applications/calendar/controller/PhabricatorCalendarController.php index 08af8971ea..2e088ecf49 100644 --- a/src/applications/calendar/controller/PhabricatorCalendarController.php +++ b/src/applications/calendar/controller/PhabricatorCalendarController.php @@ -5,11 +5,23 @@ abstract class PhabricatorCalendarController extends PhabricatorController { protected function buildApplicationCrumbs() { $crumbs = parent::buildApplicationCrumbs(); + $actions = id(new PhabricatorActionListView()) + ->setUser($this->getViewer()) + ->addAction( + id(new PhabricatorActionView()) + ->setName(pht('Create Private Event')) + ->setHref('/calendar/event/create/?mode=private')) + ->addAction( + id(new PhabricatorActionView()) + ->setName(pht('Create Public Event')) + ->setHref('/calendar/event/create/?mode=public')); + $crumbs->addAction( id(new PHUIListItemView()) ->setName(pht('Create Event')) ->setHref($this->getApplicationURI().'event/create/') - ->setIcon('fa-plus-square')); + ->setIcon('fa-plus-square') + ->setDropdownMenu($actions)); return $crumbs; } diff --git a/src/applications/calendar/controller/PhabricatorCalendarEventEditController.php b/src/applications/calendar/controller/PhabricatorCalendarEventEditController.php index cc19f7273f..109aa692bd 100644 --- a/src/applications/calendar/controller/PhabricatorCalendarEventEditController.php +++ b/src/applications/calendar/controller/PhabricatorCalendarEventEditController.php @@ -29,7 +29,10 @@ final class PhabricatorCalendarEventEditController $uri_query = $request->getStr('query'); if ($this->isCreate()) { - $event = PhabricatorCalendarEvent::initializeNewCalendarEvent($viewer); + $mode = $request->getStr('mode'); + $event = PhabricatorCalendarEvent::initializeNewCalendarEvent( + $viewer, + $mode); $create_start_year = $request->getInt('year'); $create_start_month = $request->getInt('month'); diff --git a/src/applications/calendar/storage/PhabricatorCalendarEvent.php b/src/applications/calendar/storage/PhabricatorCalendarEvent.php index 3055e5e4e6..cd829369d8 100644 --- a/src/applications/calendar/storage/PhabricatorCalendarEvent.php +++ b/src/applications/calendar/storage/PhabricatorCalendarEvent.php @@ -28,18 +28,26 @@ final class PhabricatorCalendarEvent extends PhabricatorCalendarDAO private $invitees = self::ATTACHABLE; private $appliedViewer; - public static function initializeNewCalendarEvent(PhabricatorUser $actor) { + public static function initializeNewCalendarEvent( + PhabricatorUser $actor, + $mode) { $app = id(new PhabricatorApplicationQuery()) ->setViewer($actor) ->withClasses(array('PhabricatorCalendarApplication')) ->executeOne(); + if ($mode == 'public') { + $view_policy = PhabricatorPolicies::getMostOpenPolicy(); + } else { + $view_policy = $actor->getPHID(); + } + return id(new PhabricatorCalendarEvent()) ->setUserPHID($actor->getPHID()) ->setIsCancelled(0) ->setIsAllDay(0) ->setIcon(self::DEFAULT_ICON) - ->setViewPolicy($actor->getPHID()) + ->setViewPolicy($view_policy) ->setEditPolicy($actor->getPHID()) ->attachInvitees(array()) ->applyViewerTimezone($actor); diff --git a/src/view/phui/PHUICrumbsView.php b/src/view/phui/PHUICrumbsView.php index 95d78a268c..11ec90fafe 100644 --- a/src/view/phui/PHUICrumbsView.php +++ b/src/view/phui/PHUICrumbsView.php @@ -84,6 +84,7 @@ final class PHUICrumbsView extends AphrontView { 'class' => implode(' ', $action_classes), 'sigil' => implode(' ', $action_sigils), 'style' => $action->getStyle(), + 'meta' => $action->getMetadata(), ), array( $icon, diff --git a/src/view/phui/PHUIListItemView.php b/src/view/phui/PHUIListItemView.php index 79eb6c0f44..e2e347306f 100644 --- a/src/view/phui/PHUIListItemView.php +++ b/src/view/phui/PHUIListItemView.php @@ -29,6 +29,18 @@ final class PHUIListItemView extends AphrontTagView { private $aural; private $profileImage; + public function setDropdownMenu(PhabricatorActionListView $actions) { + Javelin::initBehavior('phui-dropdown-menu'); + + $this->addSigil('phui-dropdown-menu'); + $this->setMetadata( + array( + 'items' => $actions, + )); + + return $this; + } + public function setAural($aural) { $this->aural = $aural; return $this;