Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot create different options for the different classes of gritter. #13

Closed
rvwong opened this issue Jan 24, 2012 · 5 comments
Closed

Comments

@rvwong
Copy link

rvwong commented Jan 24, 2012

According to the documentation, if I did this...

gflash :success => {:sticky => true, :time => 2000}
gflash :warning => {:sticky => false, :time => 7000}
gflash :success =>  "User activation notice sent", :warning => "email address was unreachable"

The success gritter should behave differently than the warning gritter, i.e. one you can optionally dismiss, and the other you have to wait for the time out for it to fade. If I execute this, both of my messages, the success and the warning fade out after 7 secs. I don't think this is right is it??

@RobinBrouwer
Copy link
Owner

You should do it like this:

gflash :success => { :value => "User activation notice sent", :sticky => true, :time => 2000 }
gflash :warning => { :value => "email address was unreachable", :sticky => false, :time => 7000 }

If that doesn't work: could you tell me what Ruby and Rails version you're using?

@rvwong
Copy link
Author

rvwong commented Jan 24, 2012

Hello Robin,
Thanks for the suggestion, I would not have guessed that from the documentation. It is working better, the 'warning' notification is fading out after 7 secs. However the other 'success' notification remains even though there was a :time of 2sec specified. Also on the warning notification, because :sticky is set to 'false' I believe its not supposed to have a close box, which it does when I hover over the notice box. I'm using rails 3.0.9 and ruby 1.8.7 on a Windows platform.

@RobinBrouwer
Copy link
Owner

There is a part in the documentation that shows you need to use the :value key to set a value per gritter notification. I don't really know how I can explain it more clearly. If you have a suggestion: feel free to add a pull request or add it as a comment.

The success notification isn't fading, because 'sticky' is set to true. When sticky is true, the gritter message won't disappear by itself. The user has to click on the close-box to make it go away. That's why the close-box appears on mouse-over. So sticky isn't for making the notice permanent. The user can still make it go away. ;)

@rvwong
Copy link
Author

rvwong commented Jan 24, 2012

Thanks again for clearing this up for me Robin. I double checked with the original gritter demo website, and in fact I didn't realize that the notification window ALWAYS has a close box if you hover over it. Therefore if I want the desired behaviour of popping up a notification box for a longer time, ( so the user won't miss it ) but provide an option for more diligent users to dismiss the notification box earlier, all I have to do is create a notification with
sticky => :false, time => 15000
And that would serve both needs.

As far as the documentation goes I think the corrected version of my attempt that you gave me I think illustrates what one has to do quite clearly. Perhaps you can substitute that for your easy example:

So instead of this...

def create
  gflash :success => "The product has been created successfully!"
end

replace it with this...

def create
    gflash :success => { :value => "User activation notice sent", :sticky => true  }
end

def edit
    ... 
    gflash :warning => { :value => "email address was unreachable", :sticky => false, :time => 7000 }
end

I left out the time feature in the first line since the :sticky option over rides the fade out timer. What confused me was later in your documentation you showed the example:

gflash :success => { :value => true, :time => 2000, :class_name => "my_class", :sticky => true }

So I saw the attribute :value being used to set a 'true' value, so it didn't occur to me that you can use it to supply the text for your notification.

Thanks again for all your help and time

@rvwong rvwong closed this as completed Jan 24, 2012
@RobinBrouwer
Copy link
Owner

Thanks for your feedback. I changed the README a bit to explain it in more detail:

....

You can change the default time, sticky and class_name options for each gritter message.
This is done inside the Controller and works like this:

gflash :success => { :time => 2000, :class_name => "my_class", :sticky => true }
gflash :success => { :value => true, :time => 2000, :class_name => "my_class", :sticky => true }
gflash :error => { :value => "Custom error", :time => 3000, :class_name => "my_error_class", :sticky => false }

When you don't pass a :value it uses the locale. Same goes for when you pass true to :value. When you give :value a String, that String will be used to display the message. Here's another example:

def create
  @user = User.new(params[:user])
  if @user.save
    gflash :success => { :value => "Account has been created!", :time => 5000 },
           :notice => { :value => "You have received an e-mail notification.", :sticky => true }
    redirect_to :root
  else
    gflash :error => { :value => "Something went wrong.", :time => 4000 },
           :warning => { :value => "Some fields weren't filled in correctly.", :time => 7000 }
    render :new
  end
end

....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants