Current File : /home/escuelai/public_html/it/js/notifications_ajax.min.js
/**
 * ---------------------------------------------------------------------
 *
 * GLPI - Gestionnaire Libre de Parc Informatique
 *
 * http://glpi-project.org
 *
 * @copyright 2015-2022 Teclib' and contributors.
 * @copyright 2003-2014 by the INDEPNET Development Team.
 * @licence   https://www.gnu.org/licenses/gpl-3.0.html
 *
 * ---------------------------------------------------------------------
 *
 * LICENSE
 *
 * This file is part of GLPI.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 *
 * ---------------------------------------------------------------------
 */
(function(i,t){function o(n){var e=this;var s=t("<div></div>");var a=t("<div></div>");this.options=t.extend({},o.default,n);this.showNotification=function(o,n,a,r){s.queue((function(){var s=this;setTimeout((function(){t(s).dequeue()}),100);var c=new Notification(n,{body:a,icon:e.options.icon});if(typeof r!="undefined"&&r!=null){c.url_item=CFG_GLPI.url_base+"/"+r;c.onclick=function(t){t.preventDefault();i.open(this.url_item,"_blank")}}t.ajax({url:CFG_GLPI.root_doc+"/ajax/notifications_ajax.php",method:"GET",data:{delete:o}})}))};this.playAudio=function(o){if(!o||!("Audio"in i)){return false}var n=new Audio;t(n).append(t("<source />",{src:CFG_GLPI.root_doc+"/sound/"+o+".mp3",type:"audio/mpeg"}));t(n).append(t("<source />",{src:CFG_GLPI.root_doc+"/sound/"+o+".ogg",type:"audio/ogg"}));a.queue((function(){var i=this;n.onended=function(){t(i).dequeue()};n.play()}))};this.checkNewNotifications=function(){if(!e.isSupported()){return false}var i=t.getJSON(CFG_GLPI.root_doc+"/ajax/notifications_ajax.php");i.done((function(i){if(i){for(var t=0;t<i.length;t++){var o=i[t];e.showNotification(o.id,o.title,o.body,o.url)}if(e.options.sound){e.playAudio(e.options.sound)}}}))};this.checkConcurrence=function(){var i="glpi_ajaxnotification_lastcheck_"+this.options.user_id;var t=localStorage.getItem(i);if(!t){t=0}var o=(new Date).getTime();if(t<=o-this.options.interval+50){localStorage.setItem(i,o);this.checkNewNotifications()}};this.startMonitoring=function(){this.checkConcurrence();setInterval(this.checkConcurrence.bind(this),this.options.interval)};this.checkPermission=function(){if(Notification.permission==="granted"){this.startMonitoring()}else if(Notification.permission!=="denied"){Notification.requestPermission((function(i){if(i==="granted"){this.startMonitoring()}}))}};this.start=function(){if(!this.isSupported()){return false}this.checkPermission()};this.isSupported=function(){return"Notification"in i&&"localStorage"in i}}o.default={interval:1e4,sound:false,icon:false,user_id:0};i.GLPINotificationsAjax=o})(window,jQuery);