TransWikia.com

Show persistent status bar + form to update easily

SharePoint Asked on January 26, 2021

I want to keep informed the end-users of my SharePoint site of any issue or relevant informations. Naturally, I would like to do so by filling HTML elements (input and select tags). Hence displaying a status bar message to the top of the page.

I have the following JS code written into a Code Webpart on my SP home page :

ExecuteOrDelayUntilScriptLoaded(addStatusMethod, "sp.js");

var statusID;

$('#idStatusText').change(function() {
    // when the value of the dropdown list changes
    // update the input field
    $('#idPreStatusText').val($(this).val());
});

//fonction qui permet d'afficher un statut
function addStatusMethod()
{
    var title = document.getElementById("idStatusTitle").value;
    var text = document.getElementById("idStatusText").value;
    var color = document.getElementById("idMsgType").options[document.getElementById("idMsgType").options.selectedIndex].value;
    statusID = SP.UI.Status.addStatus(title, text, true);
    SP.UI.Status.setStatusPriColor(statusID, color);
}
// fonction qui permet de suppriemr le statut ajouté
function removeInfoMethod()
{
    SP.UI.Status.removeStatus(statusID);
}
// fonction qui permet de supprimer tout les statuts
function removeAllInfosMethod()
{
    SP.UI.Status.removeAllStatus(true);
}

And the corresponding HTML source in the same Code Webpart :

<div>
    <h3>Formulaire de mise à jour du statut</h3><br>
    <label for="idMsgType">Type du message à afficher</label>
    <select name="msgType" id="idMsgType">
        <option value="red">Problème critique</option>
        <option value="yellow">Avertissement</option>
        <option value="blue">Information</option>
        <option value="green">Problème résolu</option>
    </select>
<br>
    <label for="idStatusText">Titre du message</label>
    <input name="statusTitle" id="idStatusTitle" placeholder="Tapez votre titre ici ..."/>
<br>
    <label for="idStatusText">Saisissez ici la phrase à afficher dans la barre de statut</label>
    <input name="statusText" id="idStatusText" placeholder="Tapez votre phrase personnalisée ici ..."/>
<br>
    <select name="preStatusText" id="idPreStatusText">
        <option>Vous pouvez séléctionnez un modèle de phrase puis le modifier ...</option>
        <option>Le serveur de fichiers connaît actuellement des difficultés, merci de votre patience</option>
        <option>Le service de messagerie est actuellement hors-ligne, merci de votre compréhension</option>
        <option>Une erreur est survenue sur</option>
        <option>Imprimantes</option>
        <option>Opération de maintenance sur</option>
        <option>Erreur sur le service général</option>
        <option>Serveur d'application</option>
        <option>Le problème est résolu</option>
    </select>
<br>
    <label for="idTimeoutDisplayed">Temps d'affichage du statut </label>
    <input name="timeoutDisplayed" id="idTimeoutDisplayed" placeholder=""/>
<br>
    <input type="button" name="go" value="Valider" onClick="addStatusMethod();" />
    <input type="button" name="delete" value="Effacer le dernier statut" onClick="removeInfoMethod();" />
    <input type="button" name="delete" value="Effacer tous les status" onClick="removeAllInfosMethod();" />
</div>

The fact is when I fill the title, the text and I chose a message type, the correct status bar is showed.
My page after click on Submit button

But other clients only see the default red void status bar (because it call the addStatusMethod() with void var and default red value).

Default page loading

So I would like to know if, to your knowledge it’s possible to apply my status bar, in a persistent way with the correct content for all client ?

One Answer

Ok, I found a way to do what I need : - Display a status bar for all SharePoint users - Keep it until we decide to remove it

I hosted a .jso file on a Shared Documents application, I put the Read rights on it, and I created a jQuery function on the homepage, that is executed every time you refresh the page.

It's retrieving the content of my .jso file on the JSON format and then call the associated

SP.UI.Status.addStatus(title, text, true);
SP.UI.Status.setStatusPriColor(statusID, color);

Then when I modify this file with the possible values that I defined, I can display the status bar with the right infos :)

Ask me in comment if you want some details, I will also post some stuff in my blog about that so you should find it on Google in few weeks.

Answered by Alex on January 26, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP