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(
72 'Your browser has not yet granted this server permission to send '.
73 'desktop notifications.'),
79 'sigil' => 'desktop-notifications-permission-button',
82 pht('Grant Permission')),
84 $granted_status = phutil_tag(
87 pht('Your browser has granted this server permission to send desktop '.
89 $denied_status = phutil_tag(
92 pht('This browser has denied permission to send desktop notifications '.
93 'to this server. Consult your browser settings / '.
94 'documentation to figure out how to clear this setting, do so, '.
95 'and then re-visit this page to grant permission.'));
97 $message_id = celerity_generate_unique_node_id();
99 $message_container = phutil_tag(
106 if ($request->getBool('saved')) {
107 $saved_box = id(new PHUIInfoView())
108 ->setSeverity(PHUIInfoView
::SEVERITY_NOTICE
)
109 ->appendChild(pht('Changes saved.'));
112 $status_box = id(new PHUIInfoView())
113 ->setSeverity(PHUIInfoView
::SEVERITY_NOTICE
)
116 ->appendChild($message_container);
118 $status_box = id(new PHUIBoxView())
119 ->addClass('mll mlr')
120 ->appendChild($status_box);
122 $control_config = array(
123 'controlID' => $control_id,
124 'statusID' => $status_id,
125 'messageID' => $message_id,
126 'browserStatusID' => $browser_status_id,
130 'cancelAsk' => $cancel_ask,
131 'grantedAsk' => $accept_ask,
132 'deniedAsk' => $reject_ask,
133 'defaultStatus' => $default_status,
134 'deniedStatus' => $denied_status,
135 'grantedStatus' => $granted_status,
136 'noSupport' => $no_support,
139 $form = id(new AphrontFormView())
142 id(new AphrontFormSelectControl())
144 ->setControlID($control_id)
145 ->setName($notifications_key)
146 ->setValue($notifications_value)
147 ->setOptions(PhabricatorNotificationsSetting
::getOptionsMap())
150 'This server can send real-time notifications to your web browser '.
151 'or to your desktop. Select where you want to receive these '.
152 'real-time updates.'))
154 'desktop-notifications-control',
157 id(new AphrontFormSubmitControl())
158 ->setValue(pht('Save Preference')));
160 $button = id(new PHUIButtonView())
162 ->setIcon('fa-send-o')
164 ->setText(pht('Send Test Notification'))
165 ->setHref('/notification/test/')
166 ->setColor(PHUIButtonView
::GREY
);
168 $form_content = array($saved_box, $status_box, $form);
169 $form_box = $this->newBox(
170 pht('Notifications'), $form_content, array($button));
172 $browser_status_box = id(new PHUIInfoView())
173 ->setID($browser_status_id)
174 ->setSeverity(PHUIInfoView
::SEVERITY_NOTICE
)
176 ->appendChild($default_status);