[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class PhabricatorSettingsPanelHomePreferences 4 extends PhabricatorSettingsPanel { 5 6 public function getPanelKey() { 7 return 'home'; 8 } 9 10 public function getPanelName() { 11 return pht('Home Page'); 12 } 13 14 public function getPanelGroup() { 15 return pht('Application Settings'); 16 } 17 18 public function processRequest(AphrontRequest $request) { 19 $user = $request->getUser(); 20 $preferences = $user->loadPreferences(); 21 22 $apps = id(new PhabricatorApplicationQuery()) 23 ->setViewer($user) 24 ->withInstalled(true) 25 ->withUnlisted(false) 26 ->withLaunchable(true) 27 ->execute(); 28 29 $pinned = $preferences->getPinnedApplications($apps, $user); 30 31 $app_list = array(); 32 foreach ($pinned as $app) { 33 if (isset($apps[$app])) { 34 $app_list[$app] = $apps[$app]; 35 } 36 } 37 38 if ($request->getBool('add')) { 39 $options = array(); 40 foreach ($apps as $app) { 41 $options[get_class($app)] = $app->getName(); 42 } 43 asort($options); 44 45 unset($options['PhabricatorApplicationsApplication']); 46 47 if ($request->isFormPost()) { 48 $pin = $request->getStr('pin'); 49 if (isset($options[$pin]) && !in_array($pin, $pinned)) { 50 $pinned[] = $pin; 51 $preferences->setPreference( 52 PhabricatorUserPreferences::PREFERENCE_APP_PINNED, 53 $pinned); 54 $preferences->save(); 55 56 return id(new AphrontRedirectResponse()) 57 ->setURI($this->getPanelURI()); 58 } 59 } 60 61 $options_control = id(new AphrontFormSelectControl()) 62 ->setName('pin') 63 ->setLabel(pht('Application')) 64 ->setOptions($options) 65 ->setDisabledOptions(array_keys($app_list)); 66 67 $form = id(new AphrontFormView()) 68 ->setUser($user) 69 ->addHiddenInput('add', 'true') 70 ->appendRemarkupInstructions( 71 pht('Choose an application to pin to your home page.')) 72 ->appendChild($options_control); 73 74 $dialog = id(new AphrontDialogView()) 75 ->setUser($user) 76 ->setWidth(AphrontDialogView::WIDTH_FORM) 77 ->setTitle(pht('Pin Application')) 78 ->appendChild($form->buildLayoutView()) 79 ->addSubmitButton(pht('Pin Application')) 80 ->addCancelButton($this->getPanelURI()); 81 82 return id(new AphrontDialogResponse())->setDialog($dialog); 83 } 84 85 $unpin = $request->getStr('unpin'); 86 if ($unpin) { 87 $app = idx($apps, $unpin); 88 if ($app) { 89 if ($request->isFormPost()) { 90 $pinned = array_diff($pinned, array($unpin)); 91 $preferences->setPreference( 92 PhabricatorUserPreferences::PREFERENCE_APP_PINNED, 93 $pinned); 94 $preferences->save(); 95 96 return id(new AphrontRedirectResponse()) 97 ->setURI($this->getPanelURI()); 98 } 99 100 $dialog = id(new AphrontDialogView()) 101 ->setUser($user) 102 ->setTitle(pht('Unpin Application')) 103 ->appendParagraph( 104 pht( 105 'Unpin the %s application from your home page?', 106 phutil_tag('strong', array(), $app->getName()))) 107 ->addSubmitButton(pht('Unpin Application')) 108 ->addCanceLButton($this->getPanelURI()); 109 110 return id(new AphrontDialogResponse())->setDialog($dialog); 111 } 112 } 113 114 $order = $request->getStrList('order'); 115 if ($order && $request->validateCSRF()) { 116 $preferences->setPreference( 117 PhabricatorUserPreferences::PREFERENCE_APP_PINNED, 118 $order); 119 $preferences->save(); 120 121 return id(new AphrontRedirectResponse()) 122 ->setURI($this->getPanelURI()); 123 } 124 125 $list_id = celerity_generate_unique_node_id(); 126 127 $list = id(new PHUIObjectItemListView()) 128 ->setUser($user) 129 ->setID($list_id) 130 ->setStackable(true); 131 132 Javelin::initBehavior( 133 'reorder-applications', 134 array( 135 'listID' => $list_id, 136 'panelURI' => $this->getPanelURI(), 137 )); 138 139 foreach ($app_list as $key => $application) { 140 if ($key == 'PhabricatorApplicationsApplication') { 141 continue; 142 } 143 144 $icon = $application->getIconName(); 145 if (!$icon) { 146 $icon = 'application'; 147 } 148 149 $icon_view = javelin_tag( 150 'span', 151 array( 152 'class' => 'phui-icon-view '. 153 'sprite-apps-large apps-'.$icon.'-dark-large', 154 'aural' => false, 155 ), 156 ''); 157 158 $item = id(new PHUIObjectItemView()) 159 ->setHeader($application->getName()) 160 ->setImageIcon($icon_view) 161 ->addAttribute($application->getShortDescription()) 162 ->setGrippable(true); 163 164 $item->addAction( 165 id(new PHUIListItemView()) 166 ->setIcon('fa-times') 167 ->setHref($this->getPanelURI().'?unpin='.$key) 168 ->setWorkflow(true)); 169 170 $item->addSigil('pinned-application'); 171 $item->setMetadata( 172 array( 173 'applicationClass' => $key, 174 )); 175 176 $list->addItem($item); 177 } 178 179 $header = id(new PHUIHeaderView()) 180 ->setHeader(pht('Pinned Applications')) 181 ->addActionLink( 182 id(new PHUIButtonView()) 183 ->setTag('a') 184 ->setText(pht('Pin Application')) 185 ->setHref($this->getPanelURI().'?add=true') 186 ->setWorkflow(true) 187 ->setIcon( 188 id(new PHUIIconView()) 189 ->setIconFont('fa-thumb-tack'))); 190 191 $box = id(new PHUIObjectBoxView()) 192 ->setHeader($header) 193 ->appendChild($list); 194 195 return $box; 196 } 197 198 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |