ElkArte Community

Elk Development => Theme development => Topic started by: Wizard on October 18, 2015, 01:43:07 am

Title: If ( there is an alert)
Post by: Wizard on October 18, 2015, 01:43:07 am
How do I know if there is an alert to initiate an action ?
Title: Re: If ( there is an alert)
Post by: Wizard on October 18, 2015, 06:44:37 am
I guess I have got a wrong code here

Code: [Select]
/* Growl Notifications Angular */

if (!empty($txt['notify']))
echo '

<growl-notification class="fading">
    You have active notifications
</growl-notification>';
Title: Re: If ( there is an alert)
Post by: Wizard on October 18, 2015, 06:48:56 am
Or, should I have to replace $txt with $context['notification_set'] ?

Title: Re: If ( there is an alert)
Post by: CrimeS on October 18, 2015, 06:51:43 am
Txt only contains strings, so I wouldn't check if it's empty.
Title: Re: If ( there is an alert)
Post by: Wizard on October 18, 2015, 07:01:29 am
What should I check to see whether there is  a notification or not ?
Title: Re: If ( there is an alert)
Post by: CrimeS on October 18, 2015, 07:45:52 am
Do you mean the mentions? This holds the number of mentions (if you compare it > 0, and true, then there is a mention):
Code: [Select]
$context['user']['mentions']
Title: Re: If ( there is an alert)
Post by: Wizard on October 18, 2015, 08:45:10 am
So, I would need to check 2. If there is like , if there is mention. Then I can display notification.
Title: Re: If ( there is an alert)
Post by: emanuele on October 18, 2015, 08:48:47 am
You check is there is a "mention" (i.e. notification, yeah, same name for two things), a mention includes likes, @ mentions, and some other stuff.
Title: Re: If ( there is an alert)
Post by: Wizard on October 18, 2015, 08:51:21 am
Yes. Is it possible that I can have the code to check both ? I am not good in php.

Some other stuff includes what all ? At the moment, I am concentrating on presence of like and @ mention

PS: I mean, compare if > 0 inclusive
Title: Re: If ( there is an alert)
Post by: emanuele on October 18, 2015, 10:46:18 am
Use what CrimeS suggested. It is for both.
Title: Re: If ( there is an alert)
Post by: Wizard on October 19, 2015, 03:58:44 pm
php doubt. Something wrong with this code ?

Code: [Select]
/* Popup alert notification using Growl Notifications */

function growl_based_notification()
{
global $context;

if (!empty($context['user']['mentions']))

// Say they have unread alerts.

 
    $html = '<body ng-app="af_notify" ng-controller="growlCtrl">
   
    <growl-notifications></growl-notifications>
    <growl-notification>
      Psst ! You have unread notifications
    </growl-notification>
  </body>';
    return $html;


}
Title: Re: If ( there is an alert)
Post by: emanuele on October 19, 2015, 04:50:14 pm
Yes and no.

If you mean "is the ElkArte way?" then the answer is: yes there is something wrong.
If you mean "is the code syntactically correct?" Then the answer is: no, nothing wrong.
Title: Re: If ( there is an alert)
Post by: Wizard on October 19, 2015, 04:53:38 pm
Sorry ?
Title: Re: If ( there is an alert)
Post by: Wizard on October 19, 2015, 05:00:13 pm
I asked because I did everything as per this Plunker code but getting no alert despite having an active mention

http://plnkr.co/edit/ZZHW0JKumXfdFgjTjVJz?p=preview
Title: Re: If ( there is an alert)
Post by: emanuele on October 19, 2015, 05:22:43 pm
Another way to say what I wrote it: the snippet of code you posted as is doesn't work in ElkArte, but is valid PHP code.
So, depending on what you are doing it may or may not work.
Guessing from your posts your question is: does that code work in ElkArte?
And then the answer is: no, because "return" is not "echo", and returning the HTML doesn't send it to the template, for that you need "echo", because that's the way ElkArte works.
Then there is the second problem: when $context['user']['mentions'] is 0, $html is not initialized, so ElkArte will throw an error.
Title: Re: If ( there is an alert)
Post by: Wizard on October 19, 2015, 06:34:08 pm
This ?

Code: [Select]
/* Popup alert notification using Growl Notifications */
function growl_notification()
{
global $context;
if (!empty($context['user']['mentions']))
// Say they have unread alerts.
echo '
<body ng-app="af_notify" ng-controller="growlCtrl">
  
    <growl-notifications></growl-notifications>

    <growl-notification>
      Psst ! You have unread notifications
    </growl-notification>

  </body>';
}
Title: Re: If ( there is an alert)
Post by: Wizard on October 19, 2015, 08:32:49 pm
Works fine if I use only echo part. ie, remove if ( context ) in above code

(http://www.elkarte.net/community/index.php?action=dlattach;topic=3029.0;attach=3042;image)
Title: Re: If ( there is an alert)
Post by: CrimeS on October 20, 2015, 03:54:44 am
$context['user']['mentions'] > 0
Title: Re: If ( there is an alert)
Post by: radu81 on October 20, 2015, 04:02:23 am
@Wizard have you seen this addon http://www.elkarte.net/community/index.php?topic=2795.0  ?
Title: Re: If ( there is an alert)
Post by: Wizard on October 20, 2015, 04:03:55 am
Yes. This is mention alerts. It cannot be configured. It will show you an alert window and take your attention to new like or @ mention or whatever it is. Besides, I am using AngularJS

PS : The display is not yet available

Code: [Select]
/* Popup alert notification using Growl Notifications */
function growl_based_notification()
{
global $context;
   
   if (!empty($context['user']['mentions']) > 0)
// Say they have unread alerts.
echo '
  
<body ng-app="af_notify" ng-controller="growlCtrl">
   
 
 
    <growl-notifications>

    <growl-notification>
      Psst ! You have unread notifications
    </growl-notification>

</growl-notifications>
   

  </body>';
}
Title: Re: If ( there is an alert)
Post by: emanuele on October 20, 2015, 08:32:48 am
1st: <body> is a tag with a specific meaning, you should not use it in the middle of a page "at random".
2nd: empty returns true or false, there is no reason to do a !empty($something) > 0

Try with:
Code: [Select]
	global $user_info;
if (!empty($user_info['mentions']))
Title: Re: If ( there is an alert)
Post by: CrimeS on October 20, 2015, 09:01:01 am
Sorry, I didn't see the !empty check :)
Title: Re: If ( there is an alert)
Post by: Wizard on October 20, 2015, 10:25:30 am
Using this, but no Alerts display

Code: [Select]
/* Popup alert notification using Growl Notifications */

function growl_based_notification()
{
global $user_info;
   
if (!empty($user_info['mentions']))
   
// Say they have unread alerts.
      
        echo "<pre>" . print_r($user_info, 1) . "<pre>\n";
echo '
   
 
<html ng-app="af_notify" ng-controller="growlCtrl">
  
 
 
    <growl-notifications>

    <growl-notification>
      Psst ! &nbsp; You have unread notifications
    </growl-notification>

</growl-notifications>
  

  </html>';
}

growl_based_notification();

But when I add

Code: [Select]
 echo "<pre>" . print_r($user_info, 1) . "<pre>\n";

it shows the alert window. But does not vanish even if I logout

(http://www.elkarte.net/community/index.php?action=dlattach;topic=3029.0;attach=3046;image)
Title: Re: If ( there is an alert)
Post by: Wizard on October 20, 2015, 01:21:39 pm
I have added a dismiss button

But still no luck with the condition :(

(http://www.elkarte.net/community/index.php?action=dlattach;topic=3029.0;attach=3048;image)
Title: Re: If ( there is an alert)
Post by: emanuele on October 20, 2015, 02:31:05 pm
Where are you calling that function from?
Title: Re: If ( there is an alert)
Post by: Wizard on October 20, 2015, 02:38:58 pm
I am simply copy pasting this whole code on index.template.php
Title: Re: If ( there is an alert)
Post by: emanuele on October 20, 2015, 05:08:21 pm
You are declaring a function.
If you declare a function you have to call it in order to let it run.
So, where are you calling this function in index.template.php?
Title: Re: If ( there is an alert)
Post by: Wizard on October 20, 2015, 08:43:10 pm
Yes, just after declaring it.
Title: Re: If ( there is an alert)
Post by: Wizard on October 28, 2015, 06:39:04 pm
@emanuele , anything you can do ?
Title: Re: If ( there is an alert)
Post by: emanuele on October 29, 2015, 07:18:59 pm
Then you are running it at the wrong time.
You have to call that function in a particular point of the template, not when the file is "included".
Most likely you have to call that function at the beginning of template_body_above or somewhere like that, but by all means inside a template_* function or through the template layers mechanism.