Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / settings / panel / PhabricatorNotificationsSettingsPanel.php
blobd0165dc3f125cc1337dfa6c11b29a2c4016abf58
1 <?php
3 final class PhabricatorNotificationsSettingsPanel
4 extends PhabricatorSettingsPanel {
6 public function isEnabled() {
7 $servers = PhabricatorNotificationServerRef::getEnabledAdminServers();
8 if (!$servers) {
9 return false;
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() {
25 return 'fa-bell-o';
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()) {
41 $this->writeSetting(
42 $preferences,
43 $notifications_key,
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();
54 $cancel_ask = pht(
55 'The dialog asking for permission to send desktop notifications was '.
56 'closed without granting permission. Only application notifications '.
57 'will be sent.');
58 $accept_ask = pht(
59 'Click "Save Preference" to persist these changes.');
60 $reject_ask = pht(
61 'Permission for desktop notifications was denied. Only application '.
62 'notifications will be sent.');
63 $no_support = pht(
64 'This web browser does not support desktop notifications. Only '.
65 'application notifications will be sent for this browser regardless of '.
66 'this preference.');
67 $default_status = phutil_tag(
68 'span',
69 array(),
70 array(
71 pht('This browser has not yet granted permission to send desktop '.
72 'notifications for this Phabricator instance.'),
73 phutil_tag('br'),
74 phutil_tag('br'),
75 javelin_tag(
76 'button',
77 array(
78 'sigil' => 'desktop-notifications-permission-button',
79 'class' => 'green',
81 pht('Grant Permission')),
82 ));
83 $granted_status = phutil_tag(
84 'span',
85 array(),
86 pht('This browser has been granted permission to send desktop '.
87 'notifications for this Phabricator instance.'));
88 $denied_status = phutil_tag(
89 'span',
90 array(),
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(
99 'span',
100 array(
101 'id' => $message_id,
104 $saved_box = null;
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)
113 ->setID($status_id)
114 ->setIsHidden(true)
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,
126 'defaultMode' => 0,
127 'desktop' => 1,
128 'desktopOnly' => 2,
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())
139 ->setUser($viewer)
140 ->appendChild(
141 id(new AphrontFormSelectControl())
142 ->setLabel($title)
143 ->setControlID($control_id)
144 ->setName($notifications_key)
145 ->setValue($notifications_value)
146 ->setOptions(PhabricatorNotificationsSetting::getOptionsMap())
147 ->setCaption(
148 pht(
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.'))
152 ->initBehavior(
153 'desktop-notifications-control',
154 $control_config))
155 ->appendChild(
156 id(new AphrontFormSubmitControl())
157 ->setValue(pht('Save Preference')));
159 $button = id(new PHUIButtonView())
160 ->setTag('a')
161 ->setIcon('fa-send-o')
162 ->setWorkflow(true)
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)
174 ->setIsHidden(true)
175 ->appendChild($default_status);
177 return array(
178 $form_box,
179 $browser_status_box,