|
| 1 | +<?php |
| 2 | + |
| 3 | +final class PhabricatorProjectEditIconController |
| 4 | + extends PhabricatorProjectController { |
| 5 | + |
| 6 | + private $id; |
| 7 | + |
| 8 | + public function willProcessRequest(array $data) { |
| 9 | + $this->id = $data['id']; |
| 10 | + } |
| 11 | + |
| 12 | + public function processRequest() { |
| 13 | + $request = $this->getRequest(); |
| 14 | + $viewer = $request->getUser(); |
| 15 | + |
| 16 | + $project = id(new PhabricatorProjectQuery()) |
| 17 | + ->setViewer($viewer) |
| 18 | + ->withIDs(array($this->id)) |
| 19 | + ->requireCapabilities( |
| 20 | + array( |
| 21 | + PhabricatorPolicyCapability::CAN_VIEW, |
| 22 | + PhabricatorPolicyCapability::CAN_EDIT, |
| 23 | + )) |
| 24 | + ->executeOne(); |
| 25 | + if (!$project) { |
| 26 | + return new Aphront404Response(); |
| 27 | + } |
| 28 | + |
| 29 | + $view_uri = '/tag/'.$project->getPrimarySlug().'/'; |
| 30 | + $edit_uri = $this->getApplicationURI('edit/'.$project->getID().'/'); |
| 31 | + |
| 32 | + if ($request->isFormPost()) { |
| 33 | + $v_icon = $request->getStr('icon'); |
| 34 | + $type_icon = PhabricatorProjectTransaction::TYPE_ICON; |
| 35 | + $xactions = array(id(new PhabricatorProjectTransaction()) |
| 36 | + ->setTransactionType($type_icon) |
| 37 | + ->setNewValue($v_icon)); |
| 38 | + |
| 39 | + $editor = id(new PhabricatorProjectTransactionEditor()) |
| 40 | + ->setActor($viewer) |
| 41 | + ->setContentSourceFromRequest($request) |
| 42 | + ->setContinueOnMissingFields(true) |
| 43 | + ->setContinueOnNoEffect(true); |
| 44 | + |
| 45 | + $editor->applyTransactions($project, $xactions); |
| 46 | + |
| 47 | + return id(new AphrontReloadResponse())->setURI($edit_uri); |
| 48 | + } |
| 49 | + |
| 50 | + require_celerity_resource('project-icon-css'); |
| 51 | + Javelin::initBehavior('phabricator-tooltips'); |
| 52 | + |
| 53 | + $project_icons = PhabricatorProjectIcon::getIconMap(); |
| 54 | + $ii = 0; |
| 55 | + $buttons = array(); |
| 56 | + foreach ($project_icons as $icon => $label) { |
| 57 | + $view = id(new PHUIIconView()) |
| 58 | + ->setIconFont($icon.' bluegrey'); |
| 59 | + |
| 60 | + $aural = javelin_tag( |
| 61 | + 'span', |
| 62 | + array( |
| 63 | + 'aural' => true, |
| 64 | + ), |
| 65 | + pht('Choose "%s" Icon', $label)); |
| 66 | + |
| 67 | + if ($icon == $project->getIcon()) { |
| 68 | + $class_extra = ' selected'; |
| 69 | + $tip = $label . pht(' - selected'); |
| 70 | + } else { |
| 71 | + $class_extra = null; |
| 72 | + $tip = $label; |
| 73 | + } |
| 74 | + |
| 75 | + $buttons[] = javelin_tag( |
| 76 | + 'button', |
| 77 | + array( |
| 78 | + 'class' => 'icon-button'.$class_extra, |
| 79 | + 'name' => 'icon', |
| 80 | + 'value' => $icon, |
| 81 | + 'type' => 'submit', |
| 82 | + 'sigil' => 'has-tooltip', |
| 83 | + 'meta' => array( |
| 84 | + 'tip' => $tip, |
| 85 | + ) |
| 86 | + ), |
| 87 | + array( |
| 88 | + $aural, |
| 89 | + $view, |
| 90 | + )); |
| 91 | + if ((++$ii % 4) == 0) { |
| 92 | + $buttons[] = phutil_tag('br'); |
| 93 | + } |
| 94 | + } |
| 95 | + |
| 96 | + $buttons = phutil_tag( |
| 97 | + 'div', |
| 98 | + array( |
| 99 | + 'class' => 'icon-grid', |
| 100 | + ), |
| 101 | + $buttons); |
| 102 | + |
| 103 | + $dialog = id(new AphrontDialogView()) |
| 104 | + ->setUser($viewer) |
| 105 | + ->setTitle(pht('Choose Project Icon')) |
| 106 | + ->appendChild($buttons) |
| 107 | + ->addCancelButton($edit_uri); |
| 108 | + |
| 109 | + return id(new AphrontDialogResponse())->setDialog($dialog); |
| 110 | + } |
| 111 | +} |
0 commit comments