--- /tmp/dsg/dolibarr/htdocs/core/js/github_lib_head.js.php +++ /tmp/dsg/dolibarr/htdocs/core/js/client_lib_head.js.php @@ -183,18 +183,17 @@ } // Called after selection of a date to save details into detailed fields -function dpChangeDay(dateFieldID, format) +function dpChangeDay(dateFieldID,format) { //showDP.datefieldID=dateFieldID; - console.log("Call dpChangeDay, we save date into detailed fields from format = "+format); + console.log("Call dpChangeDay, we save date into detailed fields."); var thefield=getObjectFromID(dateFieldID); var thefieldday=getObjectFromID(dateFieldID+"day"); var thefieldmonth=getObjectFromID(dateFieldID+"month"); var thefieldyear=getObjectFromID(dateFieldID+"year"); - var date=getDateFromFormat(thefield.value, format); - //console.log(date); + var date=getDateFromFormat(thefield.value,format); if (date) { thefieldday.value=date.getDate(); @@ -517,27 +516,23 @@ /* - * Used by button to set on/off. - * Call url then make complementary action (like show/hide, enable/disable or set another option). + * Used by button to set on/off * - * @param string url Url (warning: as any url called in ajax mode, the url called here must not renew the token) + * @param string url Url * @param string code Code - * @param string intput Array of complementary actions to do if success + * @param string intput Input * @param int entity Entity * @param int strict Strict * @param int forcereload Force reload * @param int userid User id - * @param string token Token - */ -function setConstant(url, code, input, entity, strict, forcereload, userid, token) { - var saved_url = url; /* avoid undefined url */ - $.post( url, { + */ +function setConstant(url, code, input, entity, strict, forcereload, userid) { + $.get( url, { action: "set", name: code, - entity: entity, - token: token + entity: entity }, - function() { /* handler for success of post */ + function() { console.log("url request success forcereload="+forcereload); $("#set_" + code).hide(); $("#del_" + code).show(); @@ -575,12 +570,11 @@ $.each(data, function(key, value) { $("#set_" + key).hide(); $("#del_" + key).show(); - $.post( saved_url, { + $.get( url, { action: "set", name: key, value: value, - entity: entity, - token: token + entity: entity }); }); } @@ -588,29 +582,25 @@ if (forcereload) { location.reload(); } - }).fail(function(error) { location.reload(); }); /* When it fails, we always force reload to have setEventErrorMEssage in session visible */ + }); } /* * Used by button to set on/off - * Call url then make complementary action (like show/hide, enable/disable or set another option). * - * @param string url Url (warning: as any url called in ajax mode, the url called here must not renew the token) + * @param string url Url * @param string code Code - * @param string intput Array of complementary actions to do if success + * @param string intput Input * @param int entity Entity * @param int strict Strict * @param int forcereload Force reload * @param int userid User id - * @param string token Token - */ -function delConstant(url, code, input, entity, strict, forcereload, userid, token) { - var saved_url = url; /* avoid undefined url */ - $.post( url, { + */ +function delConstant(url, code, input, entity, strict, forcereload, userid) { + $.get( url, { action: "del", name: code, - entity: entity, - token: token + entity: entity }, function() { console.log("url request success forcereload="+forcereload); @@ -647,11 +637,10 @@ $.each(data, function(key, value) { $("#del_" + value).hide(); $("#set_" + value).show(); - $.post( saved_url, { + $.get( url, { action: "del", name: value, - entity: entity, - token: token + entity: entity }); }); } @@ -659,26 +648,24 @@ if (forcereload) { location.reload(); } - }).fail(function(error) { location.reload(); }); /* When it fails, we always force reload to have setEventErrorMEssage in session visible */ -} - -/* - * Call the setConstant or delConstant but with a confirmation before. - * Used by button to set on/off. + }); +} + +/* + * Used by button to set on/off * * @param string action Action * @param string url Url * @param string code Code - * @param string intput Array of complementary actions to do if success + * @param string intput Input * @param string box Box * @param int entity Entity * @param int yesButton yesButton * @param int noButton noButton * @param int strict Strict * @param int userid User id - * @param string token Token - */ -function confirmConstantAction(action, url, code, input, box, entity, yesButton, noButton, strict, userid, token) { + */ +function confirmConstantAction(action, url, code, input, box, entity, yesButton, noButton, strict, userid) { var boxConfirm = box; $("#confirm_" + code) .attr("title", boxConfirm.title) @@ -694,9 +681,9 @@ text : yesButton, click : function() { if (action == "set") { - setConstant(url, code, input, entity, strict, 0, userid, token); + setConstant(url, code, input, entity, strict, 0, userid); } else if (action == "del") { - delConstant(url, code, input, entity, strict, 0, userid, token); + delConstant(url, code, input, entity, strict, 0, userid); } // Close dialog $(this).dialog("close"); @@ -1111,7 +1098,7 @@ global->MAIN_DISABLE_JQUERY_JNOTIFY) && !defined('DISABLE_JQUERY_JNOTIFY')) { - ?> + ?> // Defined properties for JNotify $(document).ready(function() { if (typeof $.jnotify == 'function') @@ -1136,15 +1123,4 @@ }); -// Force to hide menus when page is inside an iFrame -$(document).ready(function() { - if (window.location !== window.parent.location ) { - console.log("Page is detected to be into an iframe, we hide by CSS the menus"); - // The page is in an iframe - jQuery(".side-nav-vert, .side-nav, .websitebar").hide(); - jQuery(".id-container").css('width', '100%'); - - } -}); - // End of lib_head.js.php --- /tmp/dsg/dolibarr/htdocs/core/js/github_lib_notification.js.php +++ /tmp/dsg/dolibarr/htdocs/core/js/client_lib_notification.js.php @@ -30,130 +30,100 @@ require_once '../../main.inc.php'; if (!($_SERVER['HTTP_REFERER'] === $dolibarr_main_url_root.'/' || $_SERVER['HTTP_REFERER'] === $dolibarr_main_url_root.'/index.php' - || preg_match('/getmenu_div\.php/', $_SERVER['HTTP_REFERER']))) + || preg_match('/getmenu_div\.php/', $_SERVER['HTTP_REFERER']))) { - global $langs, $conf; + global $langs, $conf; - top_httphead('text/javascript; charset=UTF-8'); + top_httphead('text/javascript; charset=UTF-8'); - print 'var login = \''.$_SESSION['dol_login'].'\';'."\n"; + print 'var login = \''.$_SESSION['dol_login'].'\';'."\n"; print 'var nowtime = Date.now();'; - print 'var time_auto_update = '.$conf->global->MAIN_BROWSER_NOTIFICATION_FREQUENCY.';'."\n"; // Always defined - print 'var time_js_next_test;'."\n"; - ?> + print 'var time_auto_update = '.$conf->global->MAIN_BROWSER_NOTIFICATION_FREQUENCY.';'."\n"; // Always defined + print 'var time_js_next_test = (nowtime + time_auto_update);'."\n"; + ?> /* Check if permission ok */ if (Notification.permission !== "granted") { - console.log("Ask Notification.permission"); Notification.requestPermission() } /* Launch timer */ // We set a delay before launching first test so next check will arrive after the time_auto_update compared to previous one. - //var time_first_execution = (time_auto_update + (time_js_next_test - nowtime)) * 1000; //need milliseconds - var time_first_execution = global->MAIN_BROWSER_NOTIFICATION_CHECK_FIRST_EXECUTION) ? 0 : $conf->global->MAIN_BROWSER_NOTIFICATION_CHECK_FIRST_EXECUTION); ?>; + var time_first_execution = (time_auto_update - (nowtime - time_js_next_test)) * 1000; //need milliseconds if (login != '') { - setTimeout(first_execution, time_first_execution * 1000); - time_js_next_test = nowtime + time_first_execution; - console.log("Launch browser notif check: setTimeout is set to launch 'first_execution' function after a wait of time_first_execution="+time_first_execution+". nowtime (time php page generation) = "+nowtime+" time_js_next_check = "+time_js_next_test); + console.log("Launch browser notif check: setTimeout is set to launch 'first_execution' function after a wait of time_first_execution="+time_first_execution+". nowtime (time php page generation) = "+nowtime+" time_js_next_test = "+time_js_next_test+" time_auto_update="+time_auto_update); + setTimeout(first_execution, time_first_execution); } //first run auto check function first_execution() { - console.log("Call first_execution then set repeat time to time_auto_update = MAIN_BROWSER_NOTIFICATION_FREQUENCY = "+time_auto_update); - check_events(); //one check before setting the new time for other checks - setInterval(check_events, time_auto_update * 1000); // Set new time to run next check events + console.log("Call first_execution time_auto_update (MAIN_BROWSER_NOTIFICATION_FREQUENCY) = "+time_auto_update); + check_events(); //one check before launching timer to launch other checks + setInterval(check_events, time_auto_update * 1000); //program time to run next check events } function check_events() { if (Notification.permission === "granted") { - time_js_next_test += time_auto_update; - console.log("Call ajax to check_events with time_js_next_test = "+time_js_next_test); - + console.log("Call check_events time_js_next_test = date we are looking for event after ="+time_js_next_test); $.ajax("", { type: "post", // Usually post or get async: true, - data: { time_js_next_test: time_js_next_test, forcechecknow: 1, token: 'notrequired' }, - dataType: "json", + data: {time: time_js_next_test}, success: function (result) { - //console.log(result); - var arrayofpastreminders = Object.values(result.pastreminders); - if (arrayofpastreminders && arrayofpastreminders.length > 0) { - console.log("Retrieved "+arrayofpastreminders.length+" reminders to do."); + var arr = JSON.parse(result); + if (arr.length > 0) { var audio = null; global->AGENDA_REMINDER_BROWSER_SOUND)) { print 'audio = new Audio(\''.DOL_URL_ROOT.'/theme/common/sound/notification_agenda.wav\');'; } ?> - var listofreminderids = ''; - var noti = [] - $.each(arrayofpastreminders, function (index, value) { - console.log(value); - var url = "notdefined"; - var title = "Not defined"; - var body = value.label; - if (value.type == 'agenda' && value.location != null && value.location != '') { - body += '\n' + value.location; + $.each(arr, function (index, value) { + var url="notdefined"; + var title="Not defined"; + var body = value['tipo'] + ': ' + value['titulo']; + if (value['type'] == 'agenda' && value['location'] != null && value['location'] != '') { + body += '\n' + value['location']; } - if (value.type == 'agenda' && (value.event_date_start_formated != null || value.event_date_start_formated['event_date_start'] != '')) { - body += '\n' + value.event_date_start_formated; - } - - if (value.type == 'agenda') + if (value['type'] == 'agenda') { - url = '' + value.id_agenda; - title = 'trans('EventReminder')) ?>'; + url = '' + value['id']; + title = 'trans('Agenda') ?>'; } var extra = { icon: '', - //image: '', body: body, - tag: value.id_agenda, - requireInteraction: true + tag: value['id'] }; // We release the notify - console.log("Send notification on browser"); - noti[index] = new Notification(title, extra); + var noti = new Notification(title, extra); if (index==0 && audio) { audio.play(); } - - if (noti[index]) { - noti[index].onclick = function (event) { - console.log("A click on notification on browser has been done"); - event.preventDefault(); // prevent the browser from focusing the Notification's tab - window.focus(); - window.open(url, '_blank'); - noti[index].close(); - }; - - listofreminderids = (listofreminderids == '' ? '' : listofreminderids + ',') + value.id_reminder - } + noti.onclick = function (event) { + console.log("An event to notify on browser was received"); + event.preventDefault(); // prevent the browser from focusing the Notification's tab + window.focus(); + window.open(url, '_blank'); + noti.close(); + }; }); - - // Update status of all notifications we sent on browser (listofreminderids) - console.log("Flag notification as done for listofreminderids="+listofreminderids); - $.ajax(""+listofreminderids, { - type: "post", // Usually post or get - async: true, - data: { time_js_next_test: time_js_next_test, token: 'notrequired' } - }); - } else { - console.log("No reminder to do found, next search at "+time_js_next_test); } } }); } else { - console.log("Cancel check_events. Useless because javascript Notification.permission is "+Notification.permission+" (blocked manualy or web site is not https)."); + console.log("Cancel check_events. Useless because Notification.permission is "+Notification.permission); } + + time_js_next_test += time_auto_update; + console.log('Updated time_js_next_test. New value is '+time_js_next_test); } return nbofextradays="+Math.floor(hours / 24)+" hours="+dt.getHours()); - return Math.floor(hours / 24); + return 0; } -/* Update total. days = column nb starting from 0 */ +/* Update total. days = column nb staring from 0 */ function updateTotal(days,mode) { console.log('updateTotal days='+days+' mode='+mode); @@ -125,15 +124,12 @@ if (document.getElementById('numberOfFirstLine')) { startline = parseInt(document.getElementById('numberOfFirstLine').value); } - var nbextradays = 0; for (var i=-1; i < nbline; i++) { - /* get value into timespent cell */ - var id='timespent['+i+']['+days+']'; - var taskTime = new Date(0); - var element = document.getElementById(id); - if (element) + var taskTime= new Date(0); + var element=document.getElementById(id); + if(element) { /* alert(element.value);*/ if (element.value) @@ -146,16 +142,11 @@ } if (result >= 0) { - nbextradays = nbextradays + Math.floor((total.getHours()+taskTime.getHours() + result*24) / 24); - //console.log("i="+i+" result="+result); - total.setHours(total.getHours()+taskTime.getHours()); + total.setHours(total.getHours()+taskTime.getHours()); total.setMinutes(total.getMinutes()+taskTime.getMinutes()); - //console.log("i="+i+" nbextradays cumul="+nbextradays+" h="+total.getHours()+" "+taskTime.getHours()); - } - } - - /* get value into timeadded cell */ - + } + } + var id='timeadded['+i+']['+days+']'; var taskTime= new Date(0); var element=document.getElementById(id); @@ -172,11 +163,8 @@ } if (result >= 0) { - nbextradays = nbextradays + Math.floor((total.getHours()+taskTime.getHours() + result*24) / 24); - //console.log("i="+i+" result="+result); total.setHours(total.getHours()+taskTime.getHours()); total.setMinutes(total.getMinutes()+taskTime.getMinutes()); - //console.log("i="+i+" nbextradays cumul="+nbextradays+" h="+total.getHours()+" "+taskTime.getHours()); } } } @@ -235,15 +223,10 @@ stringdays = '0'+stringdays; } - /* Output total in top of column */ - if (total.getHours() || total.getMinutes()) jQuery('.totalDay'+stringdays).addClass("bold"); else jQuery('.totalDay'+stringdays).removeClass("bold"); - var texttoshow = pad(nbextradays * 24 + total.getHours())+':'+pad(total.getMinutes()); - jQuery('.totalDay'+stringdays).text(texttoshow); - - /* Output total of all total */ - + jQuery('.totalDay'+stringdays).text(pad(total.getHours())+':'+pad(total.getMinutes())); + var totalhour = 0; var totalmin = 0; for (var i=0; i<7; i++)