Changeset View
Changeset View
Standalone View
Standalone View
src/applications/transactions/editengine/PhabricatorEditEngine.php
| Show First 20 Lines • Show All 1,346 Lines • ▼ Show 20 Lines | final public function hasEditAccessToTransaction($xaction_type) { | ||||
| if (!$field->shouldReadValueFromSubmit()) { | if (!$field->shouldReadValueFromSubmit()) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| return true; | return true; | ||||
| } | } | ||||
| public function newNUXButton($text) { | |||||
| $specs = $this->newCreateActionSpecifications(array()); | |||||
| $head = head($specs); | |||||
| return id(new PHUIButtonView()) | |||||
| ->setTag('a') | |||||
| ->setText($text) | |||||
| ->setHref($head['uri']) | |||||
| ->setDisabled($head['disabled']) | |||||
| ->setWorkflow($head['workflow']) | |||||
| ->setColor(PHUIButtonView::GREEN); | |||||
| } | |||||
| final public function addActionToCrumbs( | final public function addActionToCrumbs( | ||||
| PHUICrumbsView $crumbs, | PHUICrumbsView $crumbs, | ||||
| array $parameters = array()) { | array $parameters = array()) { | ||||
| $viewer = $this->getViewer(); | $viewer = $this->getViewer(); | ||||
| $specs = $this->newCreateActionSpecifications($parameters); | |||||
| $head = head($specs); | |||||
| $menu_uri = $head['uri']; | |||||
| $dropdown = null; | |||||
| if (count($specs) > 1) { | |||||
| $menu_icon = 'fa-caret-square-o-down'; | |||||
| $menu_name = $this->getObjectCreateShortText(); | |||||
| $workflow = false; | |||||
| $disabled = false; | |||||
| $dropdown = id(new PhabricatorActionListView()) | |||||
| ->setUser($viewer); | |||||
| foreach ($specs as $spec) { | |||||
| $dropdown->addAction( | |||||
| id(new PhabricatorActionView()) | |||||
| ->setName($spec['name']) | |||||
| ->setIcon($spec['icon']) | |||||
| ->setHref($spec['uri'])) | |||||
avivey: Maybe respect `$spec['disabled']` and `'workflow'` here too, just in case? | |||||
| ->setDisabled($head['disabled']) | |||||
| ->setWorkflow($head['workflow']); | |||||
| } | |||||
| } else { | |||||
| $menu_icon = $head['icon']; | |||||
| $menu_name = $head['name']; | |||||
| $workflow = $head['workflow']; | |||||
| $disabled = $head['disabled']; | |||||
| } | |||||
| $action = id(new PHUIListItemView()) | |||||
| ->setName($menu_name) | |||||
| ->setHref($menu_uri) | |||||
| ->setIcon($menu_icon) | |||||
| ->setWorkflow($workflow) | |||||
| ->setDisabled($disabled); | |||||
| if ($dropdown) { | |||||
| $action->setDropdownMenu($dropdown); | |||||
| } | |||||
| $crumbs->addAction($action); | |||||
| } | |||||
| /** | |||||
| * Build a raw description of available "Create New Object" UI options so | |||||
| * other methods can build menus or buttons. | |||||
| */ | |||||
| private function newCreateActionSpecifications(array $parameters) { | |||||
| $viewer = $this->getViewer(); | |||||
| $can_create = $this->hasCreateCapability(); | $can_create = $this->hasCreateCapability(); | ||||
| if ($can_create) { | if ($can_create) { | ||||
| $configs = $this->loadUsableConfigurationsForCreate(); | $configs = $this->loadUsableConfigurationsForCreate(); | ||||
| } else { | } else { | ||||
| $configs = array(); | $configs = array(); | ||||
| } | } | ||||
| $dropdown = null; | |||||
| $disabled = false; | $disabled = false; | ||||
| $workflow = false; | $workflow = false; | ||||
| $menu_icon = 'fa-plus-square'; | $menu_icon = 'fa-plus-square'; | ||||
| $specs = array(); | |||||
| if (!$configs) { | if (!$configs) { | ||||
| if ($viewer->isLoggedIn()) { | if ($viewer->isLoggedIn()) { | ||||
| $disabled = true; | $disabled = true; | ||||
| } else { | } else { | ||||
| // If the viewer isn't logged in, assume they'll get hit with a login | // If the viewer isn't logged in, assume they'll get hit with a login | ||||
| // dialog and are likely able to create objects after they log in. | // dialog and are likely able to create objects after they log in. | ||||
| $disabled = false; | $disabled = false; | ||||
| } | } | ||||
| $workflow = true; | $workflow = true; | ||||
| if ($can_create) { | if ($can_create) { | ||||
| $create_uri = $this->getEditURI(null, 'nodefault/'); | $create_uri = $this->getEditURI(null, 'nodefault/'); | ||||
| } else { | } else { | ||||
| $create_uri = $this->getEditURI(null, 'nocreate/'); | $create_uri = $this->getEditURI(null, 'nocreate/'); | ||||
| } | } | ||||
| } else { | |||||
| $config = head($configs); | |||||
| $form_key = $config->getIdentifier(); | |||||
| $create_uri = $this->getEditURI(null, "form/{$form_key}/"); | |||||
| if ($parameters) { | |||||
| $create_uri = (string)id(new PhutilURI($create_uri)) | |||||
| ->setQueryParams($parameters); | |||||
| } | |||||
| if (count($configs) > 1) { | |||||
| $menu_icon = 'fa-caret-square-o-down'; | |||||
| $dropdown = id(new PhabricatorActionListView()) | |||||
| ->setUser($viewer); | |||||
| $specs[] = array( | |||||
| 'name' => $this->getObjectCreateShortText(), | |||||
| 'uri' => $create_uri, | |||||
| 'icon' => $menu_icon, | |||||
| 'disabled' => $disabled, | |||||
| 'workflow' => $workflow, | |||||
| ); | |||||
| } else { | |||||
| foreach ($configs as $config) { | foreach ($configs as $config) { | ||||
| $form_key = $config->getIdentifier(); | $form_key = $config->getIdentifier(); | ||||
| $config_uri = $this->getEditURI(null, "form/{$form_key}/"); | $config_uri = $this->getEditURI(null, "form/{$form_key}/"); | ||||
| if ($parameters) { | if ($parameters) { | ||||
| $config_uri = (string)id(new PhutilURI($config_uri)) | $config_uri = (string)id(new PhutilURI($config_uri)) | ||||
| ->setQueryParams($parameters); | ->setQueryParams($parameters); | ||||
| } | } | ||||
| $item_icon = 'fa-plus'; | $specs[] = array( | ||||
| 'name' => $config->getDisplayName(), | |||||
| $dropdown->addAction( | 'uri' => $config_uri, | ||||
| id(new PhabricatorActionView()) | 'icon' => 'fa-plus', | ||||
| ->setName($config->getDisplayName()) | 'disabled' => false, | ||||
| ->setIcon($item_icon) | 'workflow' => false, | ||||
| ->setHref($config_uri)); | ); | ||||
| } | |||||
| } | |||||
| } | } | ||||
| $action = id(new PHUIListItemView()) | |||||
| ->setName($this->getObjectCreateShortText()) | |||||
| ->setHref($create_uri) | |||||
| ->setIcon($menu_icon) | |||||
| ->setWorkflow($workflow) | |||||
| ->setDisabled($disabled); | |||||
| if ($dropdown) { | |||||
| $action->setDropdownMenu($dropdown); | |||||
| } | } | ||||
| $crumbs->addAction($action); | return $specs; | ||||
| } | } | ||||
| final public function buildEditEngineCommentView($object) { | final public function buildEditEngineCommentView($object) { | ||||
| $config = $this->loadDefaultEditConfiguration(); | $config = $this->loadDefaultEditConfiguration(); | ||||
| if (!$config) { | if (!$config) { | ||||
| // TODO: This just nukes the entire comment form if you don't have access | // TODO: This just nukes the entire comment form if you don't have access | ||||
| // to any edit forms. We might want to tailor this UX a bit. | // to any edit forms. We might want to tailor this UX a bit. | ||||
| ▲ Show 20 Lines • Show All 789 Lines • Show Last 20 Lines | |||||
Maybe respect $spec['disabled'] and 'workflow' here too, just in case?