[eGroupWare-svn] r55945 - in /trunk/egroupware/api/js/jsapi: egw.js egw_notification.js

[email protected] Fri, 29 Apr 2016 14:25:07 -0000
Newsgroups gmane.comp.web.egroupware.cvs
Message-ID <[email protected]>
Author: hnategh
Date: Fri Apr 29 16:25:07 2016
New Revision: 55945

URL: http://svn.stylite.de/viewvc/egroupware?rev=55945&view=rev
Log:
Implement Web Notification API into egw_notification

Added:
    trunk/egroupware/api/js/jsapi/egw_notification.js
Modified:
    trunk/egroupware/api/js/jsapi/egw.js

Modified: trunk/egroupware/api/js/jsapi/egw.js
URL: http://svn.stylite.de/viewvc/egroupware/trunk/egroupware/api/js/jsapi/egw.js?rev=55945&r1=55944&r2=55945&view=diff
==============================================================================
--- trunk/egroupware/api/js/jsapi/egw.js (original)
+++ trunk/egroupware/api/js/jsapi/egw.js Fri Apr 29 16:25:07 2016
@@ -32,6 +32,7 @@
 	egw_tail;
 	egw_inheritance;
 	egw_message;
+	egw_notification;
 	app_base;
 */
 

Added: trunk/egroupware/api/js/jsapi/egw_notification.js
URL: http://svn.stylite.de/viewvc/egroupware/trunk/egroupware/api/js/jsapi/egw_notification.js?rev=55945&view=auto
==============================================================================
--- trunk/egroupware/api/js/jsapi/egw_notification.js (added)
+++ trunk/egroupware/api/js/jsapi/egw_notification.js Fri Apr 29 16:25:07 2016
@@ -1,0 +1,81 @@
+/**
+ * EGroupware clientside API object
+ *
+ * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
+ * @package etemplate
+ * @subpackage api
+ * @link http://www.egroupware.org
+ * @author Hadi Nategh <hn-AT-stylite.de>
+ * @version $Id: $
+ */
+
+/*egw:uses
+	egw_core;
+*/
+
+/**
+ * Methods to display browser notification
+ *
+ * @augments Class
+ * @param {string} _app application name object is instanciated for
+ * @param {object} _wnd window object is instanciated for
+ */
+egw.extend('notification', egw.MODULE_WND_LOCAL, function(_app, _wnd)
+{
+	"use strict";
+
+	// Notification permission, the default value is 'default' which is equivalent to 'denied'
+	var permission = Notification.permission || 'default';
+
+	if (Notification && Notification.requestPermission) Notification.requestPermission (function(_permission){
+		permission = _permission;
+	});
+
+	return {
+
+		/**
+		 *
+		 * @param {string} _title a string to be shown as notification message
+		 * @param {object} _options an object of Notification possible options:
+		 *		options = {
+		 *			dir:  // direction of notification to be shown rtl, ltr or auto
+		 *			lang: // a valid BCP 47 language tag
+		 *			body: // DOM body
+		 *			icon: // parse icon URL, default icon is app icon
+		 *			tag: // a string value used for tagging an instance of notification, default is app name
+		 *			onclick: // Callback function dispatches on click on notification message
+		 *			onshow: // Callback function dispatches when notification is shown
+		 *			onclose: // Callback function dispateches on notification close
+		 *			onerror: // Callback function dispatches on error, default is a egw.debug log
+		 *		}
+		 */
+		notification: function (_title, _options)
+		{
+			// All options including callbacks
+			var options = _options || {};
+
+			// Options used for creating Notification instane
+			var inst_options = {
+				tag: options.tag || egw.app_name(),
+				dir: options.dir || 'ltr',
+				lang: options.lang || egw.preference('lang', 'common'),
+				body: options.body || '',
+				icon: options.icon || egw.image('navbar', egw.app_name())
+			};
+
+			// Create an  instance of Notification object
+			var notification = new Notification(_title, inst_options);
+
+			// Callback function dispatches on click on notification message
+			notification.onclick = options.onclick || '';
+			// Callback function dispatches when notification is shown
+			notification.onshow = options.onshow || '';
+			// Callback function dispateches on notification close
+			notification.onclose = options.onclose || '';
+			// Callback function dispatches on error
+			notification.onerror = options.onerror || function (e) {egw.debug('Notification failed because of ' + e);};
+			
+		}
+
+	};
+});


------------------------------------------------------------------------------
Find and fix application performance issues faster with Applications Manager
Applications Manager provides deep performance insights into multiple tiers of
your business applications. It resolves application problems quickly and
reduces your MTTR. Get your free trial!
https://ad.doubleclick.net/ddm/clk/302982198;130105516;z