Display the number of notifications on page title.

This commit is contained in:
Pierre HUBERT 2018-11-24 16:01:45 +01:00
parent d49b04e6fb
commit 46bb22b17b
15 changed files with 89 additions and 11 deletions

View File

@ -228,6 +228,22 @@ var ComunicWeb = {
getAndShowJSONtemplate: function(targetElem, templateURI, additionalData, afterParsingJSONtemplate, cleanContainer){}, getAndShowJSONtemplate: function(targetElem, templateURI, additionalData, afterParsingJSONtemplate, cleanContainer){},
}, },
/**
* Page title management
*/
pageTitle: {
/**
* Set a new title to the page
*/
setTitle: function(title){},
/**
* Set new number of notifications
*/
setNotificationsNumber: function(number){}
},
/** /**
* Functions to check data input in forms * Functions to check data input in forms
*/ */

View File

@ -196,7 +196,7 @@ ComunicWeb.common.page = {
} }
//Change page title //Change page title
document.title = pageInfos.pageTitle; ComunicWeb.common.pageTitle.setTitle(pageInfos.pageTitle);
//Change page URL, if required //Change page URL, if required
if(additionnalData.no_url_update ? !additionnalData.no_url_update : true) if(additionnalData.no_url_update ? !additionnalData.no_url_update : true)

View File

@ -0,0 +1,53 @@
/**
* Page title management
*
* @author Pierre HUBERT
*/
ComunicWeb.common.pageTitle = {
/**
* Current page title
*/
_curr_title: "Comunic",
/**
* Current number of notifications
*/
_curr_notifications_number: 0,
/**
* Set a new title to the page
*
* @param {string} title The new title for the page
*/
setTitle: function(title){
this._curr_title = title;
this.__refresh();
},
/**
* Set new number of notifications
*
* @param {number} number The new number of notifications
*/
setNotificationsNumber: function(number){
this._curr_notifications_number = number;
this.__refresh();
},
/**
* Refresh document title
*/
__refresh: function(){
let title = "";
if(this._curr_notifications_number > 0)
title += "(" + this._curr_notifications_number + ") ";
title += this._curr_title;
document.title = title;
}
}

View File

@ -22,8 +22,11 @@ ComunicWeb.components.notifications.service = {
var interval = setInterval(function(){ var interval = setInterval(function(){
//Auto-remove interval if the target has been removed //Auto-remove interval if the target has been removed
if(!target.isConnected) if(!target.isConnected){
ComunicWeb.common.pageTitle.setNotificationsNumber(0);
return clearInterval(interval); return clearInterval(interval);
}
//Get the number of notifications from the API //Get the number of notifications from the API
ComunicWeb.components.notifications.interface.getAllUnread(function(response){ ComunicWeb.components.notifications.interface.getAllUnread(function(response){
@ -55,6 +58,8 @@ ComunicWeb.components.notifications.service = {
} }
//Update page title too
ComunicWeb.common.pageTitle.setNotificationsNumber(response.notifications + response.conversations);
}); });
}, 2000); }, 2000);

View File

@ -14,7 +14,7 @@ ComunicWeb.pages.groups.pages.create = {
open: function(target){ open: function(target){
//Update page title //Update page title
document.title = "Create a group"; ComunicWeb.common.pageTitle.setTitle("Create a group");
//Create page container //Create page container
var pageContainer = createElem2({ var pageContainer = createElem2({

View File

@ -62,7 +62,7 @@ ComunicWeb.pages.groups.pages.forbidden = {
display: function(id, result, target){ display: function(id, result, target){
//Update page title //Update page title
document.title = result.name; ComunicWeb.common.pageTitle.setTitle(result.name);
//Create a box to contain information about registration //Create a box to contain information about registration
var box = createElem2({ var box = createElem2({

View File

@ -49,7 +49,7 @@ ComunicWeb.pages.groups.pages.group = {
display: function(id, info, target){ display: function(id, info, target){
//Update page title //Update page title
document.title = info.name; ComunicWeb.common.pageTitle.setTitle(info.name);
//Create page row //Create page row
var pageRow = createElem2({ var pageRow = createElem2({

View File

@ -61,7 +61,7 @@ ComunicWeb.pages.groups.pages.members = {
*/ */
applyGroupInfo: function(id, info, target){ applyGroupInfo: function(id, info, target){
document.title = info.name + " - Members"; ComunicWeb.common.pageTitle.setTitle(info.name + " - Members");
//Append the title of the group //Append the title of the group
createElem2({ createElem2({

View File

@ -92,7 +92,7 @@ ComunicWeb.pages.groups.pages.settings = {
*/ */
display: function(id, settings, target){ display: function(id, settings, target){
document.title = settings.name + " - Settings"; ComunicWeb.common.pageTitle.setTitle(settings.name + " - Settings");
//Create form container //Create form container
var formContainer = createElem2({ var formContainer = createElem2({

View File

@ -14,7 +14,7 @@ ComunicWeb.pages.home.landingPage = {
ComunicWeb.debug.logMessage("Open home landing page."); ComunicWeb.debug.logMessage("Open home landing page.");
//Change page title //Change page title
document.title = "Comunic, a transparent social network"; ComunicWeb.common.pageTitle.setTitle("Comunic, a transparent social network");
//Prepare additional data //Prepare additional data
var additionalData = { var additionalData = {

View File

@ -20,6 +20,9 @@ ComunicWeb.pages.logout = {
//Perform logout //Perform logout
ComunicWeb.user.userLogin.logoutUser(); ComunicWeb.user.userLogin.logoutUser();
//Reset notifications number
ComunicWeb.common.pageTitle.setNotificationsNumber(0);
//Clean all caches //Clean all caches
ComunicWeb.common.system.reset(true, "home"); ComunicWeb.common.system.reset(true, "home");

View File

@ -52,7 +52,7 @@ ComunicWeb.pages.settings.main = {
var section = ComunicWeb.pages.settings.sectionsList[section]; var section = ComunicWeb.pages.settings.sectionsList[section];
//Update document title //Update document title
document.title += " - " + section.title; ComunicWeb.common.pageTitle.setTitle("Settings - " + section.title);
//Call handler //Call handler
eval(section.handler + "(args, rightArea);"); eval(section.handler + "(args, rightArea);");

View File

@ -72,7 +72,7 @@ ComunicWeb.pages.userPage.accessForbidden = {
showBasicInfos: function(userInfos, target){ showBasicInfos: function(userInfos, target){
//Update page title //Update page title
document.title = userInfos.firstName + " " + userInfos.lastName; ComunicWeb.common.pageTitle.setTitle(userInfos.firstName + " " + userInfos.lastName);
//Create box root //Create box root
var boxRoot = createElem2({ var boxRoot = createElem2({

View File

@ -121,7 +121,7 @@ ComunicWeb.pages.userPage.main = {
displayUserPage: function(infos, params, target){ displayUserPage: function(infos, params, target){
//Update page title //Update page title
document.title = infos.firstName + " " + infos.lastName; ComunicWeb.common.pageTitle.setTitle(infos.firstName + " " + infos.lastName);
//Create the section class content //Create the section class content
var sectionContent = createElem2({ var sectionContent = createElem2({

View File

@ -288,6 +288,7 @@ class Dev {
"js/common/jsFiles.js", "js/common/jsFiles.js",
"js/common/debug.js", "js/common/debug.js",
"js/common/page.js", "js/common/page.js",
"js/common/pageTitle.js",
"js/common/notifications.js", "js/common/notifications.js",
"js/common/formChecker.js", "js/common/formChecker.js",
"js/common/date.js", "js/common/date.js",