1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-25 06:50:55 +01:00
phorge-phorge/webroot/rsrc/js/application/uiexample/notification-example.js
epriestley e00d3b72fe Improve the implementation of Notifications
Summary:
Currently, you can't change a notification that's already shown. There's no reason for this.

(I'm planning to put file upload progress/errors in notifications.)

  - Make `setContent()` and `setDuration()` immediately affect the notification.
  - When there are more than 5 notifications, queue them up instead of dropping them.
  - Allow arbitrarily many classes to be added/removed.
  - Make the examples in the UIExamples tests more rich.

Test Plan:
  - Verified normal notifications continue to function as expected.
  - Played with the UIExamples notifications:
    - Verified the "update every second" notification udpated every second.
    - Verified the permanent alert notification was yellow and requires a click to dismiss.
    - Verified the interactive notification responds correctly to "OK" / "Cancel".
    - Verified the "click every 2 seconds" notification doesn't vanish until not clicked for 2 seconds.

Reviewers: btrahan, vrana

Reviewed By: btrahan

CC: aran

Differential Revision: https://secure.phabricator.com/D3653
2012-10-08 15:22:29 -07:00

67 lines
1.7 KiB
JavaScript

/**
* @requires phabricator-notification
* javelin-stratcom
* javelin-behavior
* javelin-uri
* @provides javelin-behavior-phabricator-notification-example
*/
JX.behavior('phabricator-notification-example', function(config) {
var sequence = 0;
JX.Stratcom.listen(
'click',
'notification-example',
function(e) {
e.kill();
var notification = new JX.Notification();
switch (sequence % 4) {
case 0:
var update = function() {
notification.setContent('It is ' + new Date().toString());
};
update();
setInterval(update, 1000);
break;
case 1:
notification
.setContent('Permanent alert notification (until clicked).')
.setDuration(0)
.alterClassName('jx-notification-alert', true);
break;
case 2:
notification
.setContent('This notification reacts when you click it.');
notification.listen(
'activate',
function() {
if (!confirm("Close notification?")) {
JX.Stratcom.context().kill();
}
});
break;
case 3:
notification
.setDuration(2000)
.setContent('This notification will close after 2 seconds ' +
'unless you keep clicking it!');
notification.listen(
'activate',
function() {
notification.setDuration(2000);
JX.Stratcom.context().kill();
});
break;
}
notification.show();
sequence++;
});
});