Differential D18457 Diff 44343 src/applications/settings/panel/PhabricatorNotificationsSettingsPanel.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/settings/panel/PhabricatorNotificationsSettingsPanel.php
- This file was moved from src/applications/settings/panel/PhabricatorDesktopNotificationsSettingsPanel.php.
| <?php | <?php | ||||
| final class PhabricatorDesktopNotificationsSettingsPanel | final class PhabricatorNotificationsSettingsPanel | ||||
| extends PhabricatorSettingsPanel { | extends PhabricatorSettingsPanel { | ||||
| public function isEnabled() { | public function isEnabled() { | ||||
| $servers = PhabricatorNotificationServerRef::getEnabledAdminServers(); | $servers = PhabricatorNotificationServerRef::getEnabledAdminServers(); | ||||
| if (!$servers) { | if (!$servers) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| return PhabricatorApplication::isClassInstalled( | return PhabricatorApplication::isClassInstalled( | ||||
| 'PhabricatorNotificationsApplication'); | 'PhabricatorNotificationsApplication'); | ||||
| } | } | ||||
| public function getPanelKey() { | public function getPanelKey() { | ||||
| return 'desktopnotifications'; | return 'notifications'; | ||||
| } | } | ||||
| public function getPanelName() { | public function getPanelName() { | ||||
| return pht('Desktop Notifications'); | return pht('Notifications'); | ||||
| } | } | ||||
| public function getPanelGroupKey() { | public function getPanelGroupKey() { | ||||
| return PhabricatorSettingsApplicationsPanelGroup::PANELGROUPKEY; | return PhabricatorSettingsApplicationsPanelGroup::PANELGROUPKEY; | ||||
| } | } | ||||
| public function processRequest(AphrontRequest $request) { | public function processRequest(AphrontRequest $request) { | ||||
| $viewer = $this->getViewer(); | $viewer = $this->getViewer(); | ||||
| $preferences = $this->getPreferences(); | $preferences = $this->getPreferences(); | ||||
| $notifications_key = PhabricatorDesktopNotificationsSetting::SETTINGKEY; | $notifications_key = PhabricatorNotificationsSetting::SETTINGKEY; | ||||
| $notifications_value = $preferences->getSettingValue($notifications_key); | $notifications_value = $preferences->getSettingValue($notifications_key); | ||||
| if ($request->isFormPost()) { | if ($request->isFormPost()) { | ||||
| $this->writeSetting( | $this->writeSetting( | ||||
| $preferences, | $preferences, | ||||
| $notifications_key, | $notifications_key, | ||||
| $request->getInt($notifications_key)); | $request->getInt($notifications_key)); | ||||
| return id(new AphrontRedirectResponse()) | return id(new AphrontRedirectResponse()) | ||||
| ->setURI($this->getPanelURI('?saved=true')); | ->setURI($this->getPanelURI('?saved=true')); | ||||
| } | } | ||||
| $title = pht('Desktop Notifications'); | $title = pht('Notifications'); | ||||
| $control_id = celerity_generate_unique_node_id(); | $control_id = celerity_generate_unique_node_id(); | ||||
| $status_id = celerity_generate_unique_node_id(); | $status_id = celerity_generate_unique_node_id(); | ||||
| $browser_status_id = celerity_generate_unique_node_id(); | $browser_status_id = celerity_generate_unique_node_id(); | ||||
| $cancel_ask = pht( | $cancel_ask = pht( | ||||
| 'The dialog asking for permission to send desktop notifications was '. | 'The dialog asking for permission to send desktop notifications was '. | ||||
| 'closed without granting permission. Only application notifications '. | 'closed without granting permission. Only application notifications '. | ||||
| 'will be sent.'); | 'will be sent.'); | ||||
| $accept_ask = pht( | $accept_ask = pht( | ||||
| Show All 37 Lines | public function processRequest(AphrontRequest $request) { | ||||
| $message_id = celerity_generate_unique_node_id(); | $message_id = celerity_generate_unique_node_id(); | ||||
| $message_container = phutil_tag( | $message_container = phutil_tag( | ||||
| 'span', | 'span', | ||||
| array( | array( | ||||
| 'id' => $message_id, | 'id' => $message_id, | ||||
| )); | )); | ||||
| $saved_box = null; | |||||
| if ($request->getBool('saved')) { | |||||
| $saved_box = id(new PHUIInfoView()) | |||||
| ->setSeverity(PHUIInfoView::SEVERITY_NOTICE) | |||||
| ->appendChild(pht('Changes saved.')); | |||||
| } | |||||
| $status_box = id(new PHUIInfoView()) | $status_box = id(new PHUIInfoView()) | ||||
| ->setSeverity(PHUIInfoView::SEVERITY_NOTICE) | ->setSeverity(PHUIInfoView::SEVERITY_NOTICE) | ||||
| ->setID($status_id) | ->setID($status_id) | ||||
| ->setIsHidden(true) | ->setIsHidden(true) | ||||
| ->appendChild($message_container); | ->appendChild($message_container); | ||||
| $status_box = id(new PHUIBoxView()) | |||||
| ->addClass('mll mlr') | |||||
| ->appendChild($status_box); | |||||
| $control_config = array( | $control_config = array( | ||||
| 'controlID' => $control_id, | 'controlID' => $control_id, | ||||
| 'statusID' => $status_id, | 'statusID' => $status_id, | ||||
| 'messageID' => $message_id, | 'messageID' => $message_id, | ||||
| 'browserStatusID' => $browser_status_id, | 'browserStatusID' => $browser_status_id, | ||||
| 'defaultMode' => 0, | 'defaultMode' => 0, | ||||
| 'desktopMode' => 1, | 'desktop' => 1, | ||||
| 'desktopOnly' => 2, | |||||
| 'cancelAsk' => $cancel_ask, | 'cancelAsk' => $cancel_ask, | ||||
| 'grantedAsk' => $accept_ask, | 'grantedAsk' => $accept_ask, | ||||
| 'deniedAsk' => $reject_ask, | 'deniedAsk' => $reject_ask, | ||||
| 'defaultStatus' => $default_status, | 'defaultStatus' => $default_status, | ||||
| 'deniedStatus' => $denied_status, | 'deniedStatus' => $denied_status, | ||||
| 'grantedStatus' => $granted_status, | 'grantedStatus' => $granted_status, | ||||
| 'noSupport' => $no_support, | 'noSupport' => $no_support, | ||||
| ); | ); | ||||
| $form = id(new AphrontFormView()) | $form = id(new AphrontFormView()) | ||||
| ->setUser($viewer) | ->setUser($viewer) | ||||
| ->appendChild( | ->appendChild( | ||||
| id(new AphrontFormSelectControl()) | id(new AphrontFormSelectControl()) | ||||
| ->setLabel($title) | ->setLabel($title) | ||||
| ->setControlID($control_id) | ->setControlID($control_id) | ||||
| ->setName($notifications_key) | ->setName($notifications_key) | ||||
| ->setValue($notifications_value) | ->setValue($notifications_value) | ||||
| ->setOptions( | ->setOptions(PhabricatorNotificationsSetting::getOptionsMap()) | ||||
| array( | |||||
| 1 => pht('Send Desktop Notifications Too'), | |||||
| 0 => pht('Send Application Notifications Only'), | |||||
| )) | |||||
| ->setCaption( | ->setCaption( | ||||
| pht( | pht( | ||||
| 'Should Phabricator send desktop notifications? These are sent '. | 'Phabricator can send real-time notifications to your web browser '. | ||||
| 'in addition to the notifications within the Phabricator '. | 'or to your desktop. Select where you\'d want to receive these '. | ||||
| 'application.')) | 'real-time updates.')) | ||||
| ->initBehavior( | ->initBehavior( | ||||
| 'desktop-notifications-control', | 'desktop-notifications-control', | ||||
| $control_config)) | $control_config)) | ||||
| ->appendChild( | ->appendChild( | ||||
| id(new AphrontFormSubmitControl()) | id(new AphrontFormSubmitControl()) | ||||
| ->setValue(pht('Save Preference'))); | ->setValue(pht('Save Preference'))); | ||||
| $test_button = id(new PHUIButtonView()) | $test_button = id(new PHUIButtonView()) | ||||
| ->setTag('a') | ->setTag('a') | ||||
| ->setWorkflow(true) | ->setWorkflow(true) | ||||
| ->setText(pht('Send Test Notification')) | ->setText(pht('Send Test Notification')) | ||||
| ->setHref('/notification/test/') | ->setHref('/notification/test/') | ||||
| ->setIcon('fa-exclamation-triangle'); | ->setIcon('fa-exclamation-triangle'); | ||||
| $form_box = id(new PHUIObjectBoxView()) | $form_box = id(new PHUIObjectBoxView()) | ||||
| ->setHeader( | ->setHeader( | ||||
| id(new PHUIHeaderView()) | id(new PHUIHeaderView()) | ||||
| ->setHeader(pht('Desktop Notifications')) | ->setHeader(pht('Notifications')) | ||||
| ->addActionLink($test_button)) | ->addActionLink($test_button)) | ||||
| ->setForm($form) | |||||
| ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) | ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) | ||||
| ->setInfoView($status_box) | ->appendChild(array( | ||||
| ->setFormSaved($request->getBool('saved')); | $saved_box, | ||||
| $status_box, | |||||
| $form, | |||||
| )); | |||||
| $browser_status_box = id(new PHUIInfoView()) | $browser_status_box = id(new PHUIInfoView()) | ||||
| ->setID($browser_status_id) | ->setID($browser_status_id) | ||||
| ->setSeverity(PHUIInfoView::SEVERITY_NOTICE) | ->setSeverity(PHUIInfoView::SEVERITY_NOTICE) | ||||
| ->setIsHidden(true) | ->setIsHidden(true) | ||||
| ->appendChild($default_status); | ->appendChild($default_status); | ||||
| return array( | return array( | ||||
| $form_box, | $form_box, | ||||
| $browser_status_box, | $browser_status_box, | ||||
| ); | ); | ||||
| } | } | ||||
| } | } | ||||