Mercurial > libervia-web
view browser_side/notification.py @ 392:f539f6f8ee9c
browser_side: standardize the dialogs size and buttons display:
- do not set a default width/height for the XMLUI dialogs
- do not display an extra "Close" button when XMLUI form is showed
- the buttons order is OK/Save on the left, Cancel/Close on the right
- horizontally center the dialog buttons
author | souliane <souliane@mailoo.org> |
---|---|
date | Mon, 03 Mar 2014 16:24:00 +0100 |
parents | 835a8ae799e7 |
children | f9130176bc8d |
line wrap: on
line source
from __pyjamas__ import JS class Notification(object): """ If the browser supports it, the user allowed it to and the tab is in the background, send desktop notifications on messages. Requires both Web Notifications and Page Visibility API. """ def __init__(self): JS(""" this.enabled = false; if (!('hidden' in document)) document.hidden = false; if (!('Notification' in window)) return; if (Notification.permission === 'granted') this.enabled = true; else if (Notification.permission === 'default') { Notification.requestPermission(function(permission){ if (permission !== 'granted') return; this.enabled = true; }); } """) def notify(self, title, body, icon='/media/icons/apps/48/sat.png'): JS(""" if (this.enabled && document.hidden) { notification = Notification(title, {body: body, icon: icon}); // Probably won’t work, but it doesn’t hurt to try. notification.addEventListener('click', function() { window.focus(); }); } """)