// where our WebSockets logic will go later var socket, host; var notification_count = 0; var notification_array=new Array(); var ajaxnotifications_url = "index.php?module=Schedulers&action=EcmNotificationAjax&to_pdf=1"; var audiotypes = { "mp3" : "audio/mpeg", "mp4" : "audio/mp4", "ogg" : "audio/ogg", "wav" : "audio/wav" } function ss_soundbits(sound) { var audio_element = document.createElement('audio') if (audio_element.canPlayType) { for (var i = 0; i < arguments.length; i++) { var source_element = document.createElement('source') source_element.setAttribute('src', arguments[i]) if (arguments[i].match(/\.(\w+)$/i)) source_element.setAttribute('type', audiotypes[RegExp.$1]) audio_element.appendChild(source_element) } audio_element.load() audio_element.playclip = function() { audio_element.pause() audio_element.currentTime = 0 audio_element.play() } return audio_element } } var clicksound = ss_soundbits( 'include/ECM/EcmNotifications/sounds/bell_ring.ogg', "include/ECM/EcmNotifications/sounds/bell_ring.mp3") host = "wss://system.saas-systems.pl:444"; function connect() { try { socket = new WebSocket(host); addMessage("Socket State: " + socket.readyState); socket.onopen = function() { addMessage("Socket Status: " + socket.readyState + " (open)"); } socket.onclose = function() { socket.close(); } socket.onmessage = function(msg) { DrawMessage(msg.data); } } catch (exception) { addMessage("Error: " + exception); } } function addMessage(msg) { $("#chat-log").append("

" + msg + "

"); } function DrawNotificationDiv(){ var html=''; var toggle="if($('#notification_list').css('display')=='none'){$('#notification_list').show();}else{$('#notification_list').hide();}"; if(notification_array.length>1){ html='Masz '+notification_array.length+' nowe przypomnienia!'; } if(notification_array.length==0){ html='

Brak nowych przypomnień.

'; } if(notification_array.length==1) { html='Masz 1 nowe przypomnienie!'; } var div_header=''; $("#notification-Div").html(html+div_header); } function makeid() { var text = ""; var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; for( var i=0; i < 5; i++ ) text += possible.charAt(Math.floor(Math.random() * possible.length)); return text; } function leaveSelect(id){ var html=''; return html; } function dialogContent(obj,id){ if(obj.date_start === null){ obj.date_start='brak'; } var toggle="if($('#leave_"+obj.id+"').css('display')=='none'){$('#leave_"+obj.id+"').show();}else{$('#leave_"+obj.id+"').hide();}"; var html=''; html+=''; html+='
Temat:'+obj.name+'
Data rozpoczęcia:'+obj.date_start.substr(0,16)+'
Opis:'+obj.description+'
'; html+='
'; html+=''; return html; } function saveNotification(id,index){ var params = { job : 'changeNotificationDate', id : id, flag : $('#leaveSel_'+id+' :selected').val(), }; $.ajax({ type : "POST", url : ajaxnotifications_url, dataType : "json", success : function(data) { if (data != '-1') $( "#dialog_"+id ).dialog( "close" ); notification_array.splice(index, 1); send(id); DrawNotificationDiv(); }, data : params }); } function showLeavedNotifications(data){ for( var i=0; i < data.length; i++ ){ createDialog(data[i]); } } function getLeaveadNotifications(){ var params = { job : 'getLeaveadNotifications', user_id : $('#current_user_id').val(), }; $.ajax({ type : "POST", url : ajaxnotifications_url, dataType : "json", success : function(data) { if (data != '-1'){ notification_array=data; DrawNotificationDiv(); } }, data : params }); } function createDialog(obj){ var id=obj; var obj=notification_array[obj]; var div_id=makeid(); $( "#notification-Dialog" ).html('
'); $( "#dialog_"+obj.id).html(dialogContent(obj,id)); $( "#dialog_"+obj.id).dialog({ title: "Nowe przypomnienie o: "+obj.name.substr(0,15)+'...', open: function() { // open event handler $(this) // the element being dialogged .parent() // get the dialog widget element .find(".ui-dialog-titlebar-close") // find the close button for this dialog .hide(); // hide it }, modal: true, buttons: { 'Przyjąłem': function() { $( this ).dialog( "close" ); }, }, beforeClose: function( event, ui ) { var params = { job : 'updateNotificationStatus', id : obj.id, flag : '2', }; $.ajax({ type : "POST", url : ajaxnotifications_url, dataType : "json", success : function(data) { if (data != '-1') console.log(data); notification_array.splice(id, 1); send(obj.id); DrawNotificationDiv(); }, data : params }); } }); } function srt(desc) { return function(a,b){ return desc ? ~~(a < b) : ~~(a > b); }; } function checkExist(id){ for(i=0;i