3 final class PhabricatorNotificationsSettingsPanel
4 extends PhabricatorSettingsPanel
{
6 public function isEnabled() {
7 $servers = PhabricatorNotificationServerRef
::getEnabledAdminServers();
12 return PhabricatorApplication
::isClassInstalled(
13 'PhabricatorNotificationsApplication');
16 public function getPanelKey() {
17 return 'notifications';
20 public function getPanelName() {
21 return pht('Notifications');
24 public function getPanelMenuIcon() {
28 public function getPanelGroupKey() {
29 return PhabricatorSettingsApplicationsPanelGroup
::PANELGROUPKEY
;
32 public function processRequest(AphrontRequest
$request) {
33 $viewer = $this->getViewer();
34 $preferences = $this->getPreferences();
36 $notifications_key = PhabricatorNotificationsSetting
::SETTINGKEY
;
37 $notifications_value = $preferences->getSettingValue($notifications_key);
39 if ($request->isFormPost()) {
44 $request->getInt($notifications_key));
46 return id(new AphrontRedirectResponse())
47 ->setURI($this->getPanelURI('?saved=true'));
50 $title = pht('Notifications');
51 $control_id = celerity_generate_unique_node_id();
52 $status_id = celerity_generate_unique_node_id();
53 $browser_status_id = celerity_generate_unique_node_id();
55 'The dialog asking for permission to send desktop notifications was '.
56 'closed without granting permission. Only application notifications '.
59 'Click "Save Preference" to persist these changes.');
61 'Permission for desktop notifications was denied. Only application '.
62 'notifications will be sent.');
64 'This web browser does not support desktop notifications. Only '.
65 'application notifications will be sent for this browser regardless of '.
67 $default_status = phutil_tag(
71 pht('This browser has not yet granted permission to send desktop '.
72 'notifications for this Phabricator instance.'),
78 'sigil' => 'desktop-notifications-permission-button',
81 pht('Grant Permission')),
83 $granted_status = phutil_tag(
86 pht('This browser has been granted permission to send desktop '.
87 'notifications for this Phabricator instance.'));
88 $denied_status = phutil_tag(
91 pht('This browser has denied permission to send desktop notifications '.
92 'for this Phabricator instance. Consult your browser settings / '.
93 'documentation to figure out how to clear this setting, do so, '.
94 'and then re-visit this page to grant permission.'));
96 $message_id = celerity_generate_unique_node_id();
98 $message_container = phutil_tag(
105 if ($request->getBool('saved')) {
106 $saved_box = id(new PHUIInfoView())
107 ->setSeverity(PHUIInfoView
::SEVERITY_NOTICE
)
108 ->appendChild(pht('Changes saved.'));
111 $status_box = id(new PHUIInfoView())
112 ->setSeverity(PHUIInfoView
::SEVERITY_NOTICE
)
115 ->appendChild($message_container);
117 $status_box = id(new PHUIBoxView())
118 ->addClass('mll mlr')
119 ->appendChild($status_box);
121 $control_config = array(
122 'controlID' => $control_id,
123 'statusID' => $status_id,
124 'messageID' => $message_id,
125 'browserStatusID' => $browser_status_id,
129 'cancelAsk' => $cancel_ask,
130 'grantedAsk' => $accept_ask,
131 'deniedAsk' => $reject_ask,
132 'defaultStatus' => $default_status,
133 'deniedStatus' => $denied_status,
134 'grantedStatus' => $granted_status,
135 'noSupport' => $no_support,
138 $form = id(new AphrontFormView())
141 id(new AphrontFormSelectControl())
143 ->setControlID($control_id)
144 ->setName($notifications_key)
145 ->setValue($notifications_value)
146 ->setOptions(PhabricatorNotificationsSetting
::getOptionsMap())
149 'Phabricator can send real-time notifications to your web browser '.
150 'or to your desktop. Select where you want to receive these '.
151 'real-time updates.'))
153 'desktop-notifications-control',
156 id(new AphrontFormSubmitControl())
157 ->setValue(pht('Save Preference')));
159 $button = id(new PHUIButtonView())
161 ->setIcon('fa-send-o')
163 ->setText(pht('Send Test Notification'))
164 ->setHref('/notification/test/')
165 ->setColor(PHUIButtonView
::GREY
);
167 $form_content = array($saved_box, $status_box, $form);
168 $form_box = $this->newBox(
169 pht('Notifications'), $form_content, array($button));
171 $browser_status_box = id(new PHUIInfoView())
172 ->setID($browser_status_id)
173 ->setSeverity(PHUIInfoView
::SEVERITY_NOTICE
)
175 ->appendChild($default_status);