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
This commit is contained in:
		| @@ -5,11 +5,23 @@ abstract class PhabricatorCalendarController extends PhabricatorController { | |||||||
|   protected function buildApplicationCrumbs() { |   protected function buildApplicationCrumbs() { | ||||||
|     $crumbs = parent::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( |     $crumbs->addAction( | ||||||
|       id(new PHUIListItemView()) |       id(new PHUIListItemView()) | ||||||
|         ->setName(pht('Create Event')) |         ->setName(pht('Create Event')) | ||||||
|         ->setHref($this->getApplicationURI().'event/create/') |         ->setHref($this->getApplicationURI().'event/create/') | ||||||
|         ->setIcon('fa-plus-square')); |         ->setIcon('fa-plus-square') | ||||||
|  |         ->setDropdownMenu($actions)); | ||||||
|  |  | ||||||
|     return $crumbs; |     return $crumbs; | ||||||
|   } |   } | ||||||
|   | |||||||
| @@ -29,7 +29,10 @@ final class PhabricatorCalendarEventEditController | |||||||
|     $uri_query = $request->getStr('query'); |     $uri_query = $request->getStr('query'); | ||||||
|  |  | ||||||
|     if ($this->isCreate()) { |     if ($this->isCreate()) { | ||||||
|       $event = PhabricatorCalendarEvent::initializeNewCalendarEvent($viewer); |       $mode = $request->getStr('mode'); | ||||||
|  |       $event = PhabricatorCalendarEvent::initializeNewCalendarEvent( | ||||||
|  |         $viewer, | ||||||
|  |         $mode); | ||||||
|  |  | ||||||
|       $create_start_year = $request->getInt('year'); |       $create_start_year = $request->getInt('year'); | ||||||
|       $create_start_month = $request->getInt('month'); |       $create_start_month = $request->getInt('month'); | ||||||
|   | |||||||
| @@ -28,18 +28,26 @@ final class PhabricatorCalendarEvent extends PhabricatorCalendarDAO | |||||||
|   private $invitees = self::ATTACHABLE; |   private $invitees = self::ATTACHABLE; | ||||||
|   private $appliedViewer; |   private $appliedViewer; | ||||||
|  |  | ||||||
|   public static function initializeNewCalendarEvent(PhabricatorUser $actor) { |   public static function initializeNewCalendarEvent( | ||||||
|  |     PhabricatorUser $actor, | ||||||
|  |     $mode) { | ||||||
|     $app = id(new PhabricatorApplicationQuery()) |     $app = id(new PhabricatorApplicationQuery()) | ||||||
|       ->setViewer($actor) |       ->setViewer($actor) | ||||||
|       ->withClasses(array('PhabricatorCalendarApplication')) |       ->withClasses(array('PhabricatorCalendarApplication')) | ||||||
|       ->executeOne(); |       ->executeOne(); | ||||||
|  |  | ||||||
|  |     if ($mode == 'public') { | ||||||
|  |       $view_policy = PhabricatorPolicies::getMostOpenPolicy(); | ||||||
|  |     } else { | ||||||
|  |       $view_policy = $actor->getPHID(); | ||||||
|  |     } | ||||||
|  |  | ||||||
|     return id(new PhabricatorCalendarEvent()) |     return id(new PhabricatorCalendarEvent()) | ||||||
|       ->setUserPHID($actor->getPHID()) |       ->setUserPHID($actor->getPHID()) | ||||||
|       ->setIsCancelled(0) |       ->setIsCancelled(0) | ||||||
|       ->setIsAllDay(0) |       ->setIsAllDay(0) | ||||||
|       ->setIcon(self::DEFAULT_ICON) |       ->setIcon(self::DEFAULT_ICON) | ||||||
|       ->setViewPolicy($actor->getPHID()) |       ->setViewPolicy($view_policy) | ||||||
|       ->setEditPolicy($actor->getPHID()) |       ->setEditPolicy($actor->getPHID()) | ||||||
|       ->attachInvitees(array()) |       ->attachInvitees(array()) | ||||||
|       ->applyViewerTimezone($actor); |       ->applyViewerTimezone($actor); | ||||||
|   | |||||||
| @@ -84,6 +84,7 @@ final class PHUICrumbsView extends AphrontView { | |||||||
|             'class' => implode(' ', $action_classes), |             'class' => implode(' ', $action_classes), | ||||||
|             'sigil' => implode(' ', $action_sigils), |             'sigil' => implode(' ', $action_sigils), | ||||||
|             'style' => $action->getStyle(), |             'style' => $action->getStyle(), | ||||||
|  |             'meta' => $action->getMetadata(), | ||||||
|           ), |           ), | ||||||
|           array( |           array( | ||||||
|             $icon, |             $icon, | ||||||
|   | |||||||
| @@ -29,6 +29,18 @@ final class PHUIListItemView extends AphrontTagView { | |||||||
|   private $aural; |   private $aural; | ||||||
|   private $profileImage; |   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) { |   public function setAural($aural) { | ||||||
|     $this->aural = $aural; |     $this->aural = $aural; | ||||||
|     return $this; |     return $this; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 lkassianik
					lkassianik