Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Dismissible notification boxes
02-21-2018, 12:02 AM,
#11
RE: Dismissible notification boxes
Paul, thanks, yes I have been clearing browser cache.

Ok Tim, great suggestion, I will try using the onload attribute of <body>.

Having looked at your code, I can see <body onload="initial() in header.php.
However, this currently does not exist in weberp code. The <body> tag has no attributes. But strangely, the initial() function does exist in MiscFunctions.js.
Does anyone remember the history on this?

Here is the initial() function from MiscFunctions.js

Code:
function initial() {
    if(document.getElementsByTagName) {
        var as=document.getElementsByTagName("a");
        for(i=0;i<as.length;i++) {
            var a=as[i];
            if(a.getAttribute("href") &&
                a.getAttribute("rel")=="external")
                a.target="_blank";
        }
    }
    var ds=document.getElementsByTagName("input");
    for(i=0;i<ds.length;i++) {
        if(ds[i].className=="date") {
            ds[i].onclick=clickDate;
            ds[i].onchange=changeDate;
        }
        if(ds[i].getAttribute("data-type") == 'no-illegal-chars') ds[i].pattern="(?!^ +$)[^?\'\u0022+.&\\\\><]*";
        if(ds[i].className=="number") ds[i].onkeypress=rTN;
        if(ds[i].className=="integer") ds[i].onkeypress=rTI;
        if(ds[i].className=="number") {
            ds[i].origonchange=ds[i].onchange;
            ds[i].newonchange=rLocaleNumber;
            ds[i].onchange=function() {
                if(this.origonchange)
                    this.origonchange();
                this.newonchange();
            };
        }
    }
    var ds=document.getElementsByTagName("th");
    for(i=0;i<ds.length;i++) {
        if(ds[i].className=="ascending") ds[i].onclick=SortSelect;
    }
}

What is the purpose of the code currently within the initial() function? It appears to relate to external links, date picker, and table sorting.

If I add my alert message javascript code to the above function, and fire it with <body onload="initial()">, will there be any negative effects caused by the other code?

Thanks,

Andy.
https://www.linkedin.com/in/andrewcouling
Reply
02-21-2018, 12:35 AM,
#12
RE: Dismissible notification boxes
Hi Andy, the final line in MiscFunctions.js is:

window.onload=initial;

which runs the initial() function so it should run automatically (a quick test putting in an alert() call in there shows it is running on each page refresh)

Tim
Reply
02-21-2018, 01:08 AM, (This post was last modified: 02-21-2018, 02:23 AM by afcouling.)
#13
RE: Dismissible notification boxes
Hi Tim,

There must ave been an issue with the js originally, because now it works with or without <body onload="initial();">.

So the other code within the initial() functional was being executed by window.onload=initial; - question answered.

I'll have a go with the messages array approach next.

Thank you.

Andy.
https://www.linkedin.com/in/andrewcouling
Reply
02-21-2018, 02:24 AM, (This post was last modified: 02-22-2018, 12:55 AM by afcouling.)
#14
RE: Dismissible notification boxes
(02-20-2018, 02:24 AM)falkoner Wrote: Hi Andy, what I do is to change the prnMsg() function to store all the messages in an array, so the function looks like:

function prnMsg($Msg, $Type = 'info', $Prefix = '') {
global $Messages;
$Messages[] = array(
$Msg,
$Type,
$Prefix
);

}

Then at the place in the code I want them printed (top of footer.php in my case) I then just cycle through the array $Messages printing them out.

Tim

Hi Tim,

In your code, is the getMsg() function in MiscFunctions.php now redundant? It appears you have moved it (with some modification) to where you print the messages in footer.php.

Andy.
https://www.linkedin.com/in/andrewcouling
Reply
02-22-2018, 12:56 AM,
#15
RE: Dismissible notification boxes
I've got the message array working at the top of footer.php, but it doesn't work when I print it at the bottom of header.php, just after the opening <div id="BodyWrapDiv"> tag.
I'd prefer to have the messages at the top of the page above the page title.
Could the cause of this be related to the scope of global variable $Messages?

MiscFunctions.php

Code:
function prnMsg($Msg, $Type = 'info', $Prefix = '') {
    global $Messages;
    $Messages[] = array(
        $Msg,
        $Type,
        $Prefix
    );
} //prnMsg

header.php

Code:
                '<div id="BodyWrapDiv">';
                
    if (isset($Messages) and count($Messages) > 0) {
        echo '<br />';
        foreach ($Messages as $Message) {
            $Prefix = '';
            switch ($Message[1]) {
                case 'error':
                    $Class = 'error';
                    $Prefix = $Prefix ? $Prefix : _('ERROR') . ' ' . _('Report');
                    if (isset($_SESSION['LogSeverity']) and $_SESSION['LogSeverity'] > 3) {
                        fwrite($LogFile, date('Y-m-d h-m-s') . ',' . $Type . ',' . $_SESSION['UserID'] . ',' . trim($Msg, ',') . "\n");
                    }
                    echo '<div class="Alert ' . $Class . ' noPrint">
                    <span class="AlertCloseButton">&times;</span>
                    <b>' . $Prefix . '</b> : ' . $Message[0] . '</div>';
                    break;
                case 'warn':
                    
                    $Class = 'warn';
                    $Prefix = $Prefix ? $Prefix : _('WARNING') . ' ' . _('Report');
                    if (isset($_SESSION['LogSeverity']) and $_SESSION['LogSeverity'] > 3) {
                        fwrite($LogFile, date('Y-m-d h-m-s') . ',' . $Type . ',' . $_SESSION['UserID'] . ',' . trim($Msg, ',') . "\n");
                    }
                    echo '<br /><div class="Alert ' . $Class . ' noPrint">
                    <span class="AlertCloseButton">&times;</span>
                    <b>' . $Prefix . '</b> : ' . $Message[0] . '</div>';
                    break;
                case 'success':
                    $Class = 'success';
                    $Prefix = $Prefix ? $Prefix : _('SUCCESS') . ' ' . _('Report');
                    if (isset($_SESSION['LogSeverity']) and $_SESSION['LogSeverity'] > 3) {
                        fwrite($LogFile, date('Y-m-d h-m-s') . ',' . $Type . ',' . $_SESSION['UserID'] . ',' . trim($Msg, ',') . "\n");
                    }
                    echo '<div class="Alert ' . $Class . ' noPrint">
                    <span class="AlertCloseButton">&times;</span>
                    <b>' . $Prefix . '</b> : ' . $Message[0] . '</div>';
                    break;
                case 'info':
                default:
                    $Prefix = $Prefix ? $Prefix : _('INFORMATION') . ' ' . _('Message');
                    $Class = 'info';
                    if (isset($_SESSION['LogSeverity']) and $_SESSION['LogSeverity'] > 2) {
                        fwrite($LogFile, date('Y-m-d h-m-s') . ',' . $Type . ',' . $_SESSION['UserID'] . ',' . trim($Msg, ',') . "\n");
                    }
                    echo '<div class="Alert ' . $Class . ' noPrint">
                    <span class="AlertCloseButton">&times;</span>
                    <b>' . $Prefix . '</b> : ' . $Message[0] . '</div>';
            }
        }
    }    
?>

Andy.
https://www.linkedin.com/in/andrewcouling
Reply
02-22-2018, 01:12 AM,
#16
RE: Dismissible notification boxes
I suspect it is because the messages haven't been created by the point you are running it. It needs careful planning so that all the prnMsg() calls happen before the call to header.php (which should be possible). I think this is probably why I went for the footer.

It is maybe best done using javascript, but a bit messy.

Tim
Reply
02-22-2018, 01:47 AM, (This post was last modified: 02-22-2018, 01:49 AM by afcouling.)
#17
RE: Dismissible notification boxes
Could I stick the code below in a function inside header.php, and then execute the function from footer.php (after the messages have been created)?

Code:
                if (isset($Messages) and count($Messages) > 0) {
        echo '<br />';
        foreach ($Messages as $Message) {
            $Prefix = '';
            switch ($Message[1]) {
                case 'error':
                    $Class = 'error';
                    $Prefix = $Prefix ? $Prefix : _('ERROR') . ' ' . _('Report');
                    if (isset($_SESSION['LogSeverity']) and $_SESSION['LogSeverity'] > 3) {
                        fwrite($LogFile, date('Y-m-d h-m-s') . ',' . $Type . ',' . $_SESSION['UserID'] . ',' . trim($Msg, ',') . "\n");
                    }
                    echo '<div class="Alert ' . $Class . ' noPrint">
                    <span class="AlertCloseButton">&times;</span>
                    <b>' . $Prefix . '</b> : ' . $Message[0] . '</div>';
                    break;
                case 'warn':
                    
                    $Class = 'warn';
                    $Prefix = $Prefix ? $Prefix : _('WARNING') . ' ' . _('Report');
                    if (isset($_SESSION['LogSeverity']) and $_SESSION['LogSeverity'] > 3) {
                        fwrite($LogFile, date('Y-m-d h-m-s') . ',' . $Type . ',' . $_SESSION['UserID'] . ',' . trim($Msg, ',') . "\n");
                    }
                    echo '<br /><div class="Alert ' . $Class . ' noPrint">
                    <span class="AlertCloseButton">&times;</span>
                    <b>' . $Prefix . '</b> : ' . $Message[0] . '</div>';
                    break;
                case 'success':
                    $Class = 'success';
                    $Prefix = $Prefix ? $Prefix : _('SUCCESS') . ' ' . _('Report');
                    if (isset($_SESSION['LogSeverity']) and $_SESSION['LogSeverity'] > 3) {
                        fwrite($LogFile, date('Y-m-d h-m-s') . ',' . $Type . ',' . $_SESSION['UserID'] . ',' . trim($Msg, ',') . "\n");
                    }
                    echo '<div class="Alert ' . $Class . ' noPrint">
                    <span class="AlertCloseButton">&times;</span>
                    <b>' . $Prefix . '</b> : ' . $Message[0] . '</div>';
                    break;
                case 'info':
                default:
                    $Prefix = $Prefix ? $Prefix : _('INFORMATION') . ' ' . _('Message');
                    $Class = 'info';
                    if (isset($_SESSION['LogSeverity']) and $_SESSION['LogSeverity'] > 2) {
                        fwrite($LogFile, date('Y-m-d h-m-s') . ',' . $Type . ',' . $_SESSION['UserID'] . ',' . trim($Msg, ',') . "\n");
                    }
                    echo '<div class="Alert ' . $Class . ' noPrint">
                    <span class="AlertCloseButton">&times;</span>
                    <b>' . $Prefix . '</b> : ' . $Message[0] . '</div>';
            }
        }
    }

Thanks,

Andy.
https://www.linkedin.com/in/andrewcouling
Reply
02-22-2018, 03:34 AM, (This post was last modified: 02-22-2018, 04:17 AM by afcouling.)
#18
RE: Dismissible notification boxes
Nope, that doesn't work.
What about sticking the code in footer.php (as you have done), and use css to position the messages towards the top of the page, perhaps top right, relative to BodyDiv ???

It appears that to make all prnMsg() calls occur before include('includes/header.php'); would require a lot of reconfiguration of existing scripts.

I might just commit the javascript and css mods for now, and leave the message array for another time (I need to crack on with pc receipt uploads).

Andy.




https://www.linkedin.com/in/andrewcouling
Reply
03-07-2018, 06:53 AM,
#19
RE: Dismissible notification boxes
I have this working now, but with a small compromise.

I've fired the messages array from the footer, as per Tims code, and used css to position the messages towards the top of the page.
I stuck the messages in a container div, with absolute positioning, and then gave relative positioning to BodyWrapDiv.

The messages are displayed just beneath the header. However, as elements with absolute positioning are removed from page flow, the messages overlap the BodyWrapDiv content.
With one single line message, the page title is obscured.
Although, with the dismissable functionality, messages can be cleared from view with ease.

Screenshots attached.
Opinions welcomed.

Andy.

   
   
https://www.linkedin.com/in/andrewcouling
Reply
03-07-2018, 07:02 AM,
#20
RE: Dismissible notification boxes
Good stuff Andy. How about instead of running the length of the screen the messages are put in rectangles on the right third of the screen?

Tim
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)