Custom Response.flash

236 views
Skip to first unread message

LoveWeb2py

unread,
Jan 6, 2017, 10:43:00 AM1/6/17
to web2py-users
Hello,

I have created my own response.flash

Here is the code:

def notification(message, mtype):
    a = "<script>\n"
    a += "$(\"notify\").ready(function() {\n"
    a += "toastr.options.timeOut = 2000; // 1.5s\n"
    a += "toastr.{mtype}('{message}');\n".format(mtype=mtype, message=message)
    a += "$('#linkButton').click(function() {\n"
    a += "toastr.success('Click Button');\n"
    a += "});\n"
    a += "});\n"
    a += "</script>"
    a = XML(a)
    return a



The problem is when I call it using auth.messages.logged_in = notification('Signed In', 'success') I get two pop ups of the message.

I suspect this has something to do with the way .flash is defined in web2py.js because when I comment out
        main_hook: function () {
        /*var flash = $('.w2p_flash');*/
        /*flash.hide();*/
        /*if (flash.html()) web2py.flash(flash.html());*/
        web2py.ajax_init(document);
        web2py.event_handlers();
        web2py.a_handlers();
        web2py.form_handlers();
    }
};

It works fine! Is this a bug or is something wrong with the way I'm creating a custom response.flash

Richard Vézina

unread,
Jan 6, 2017, 10:45:36 AM1/6/17
to web2py-users
Why doing that? You can't just style differently the actual web2py flash popup in the web2py.css file to achieve what you want? I mean flash message is flash message...

Richard

--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups "web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

LoveWeb2py

unread,
Jan 6, 2017, 11:05:14 AM1/6/17
to web2py-users
Hi Richard,

I'm trying to use this: https://github.com/CodeSeven/toastr

and it's working okay right now, but I feel like there has to be a better way.

If I just use response.flash = 'message' and change the css I'd have to change the javascript as well (I think) and I also wouldn't be able to specify if the type: "info", "success", "warning", etc...
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+un...@googlegroups.com.

António Ramos

unread,
Jan 6, 2017, 12:20:21 PM1/6/17
to web...@googlegroups.com
to catch all users attention i use


To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscribe@googlegroups.com.

Anthony

unread,
Jan 6, 2017, 3:26:11 PM1/6/17
to web2py-users
The problem is when I call it using auth.messages.logged_in = notification('Signed In', 'success') I get two pop ups of the message.

I suspect this has something to do with the way .flash is defined in web2py.js because when I comment out
        main_hook: function () {
        /*var flash = $('.w2p_flash');*/
        /*flash.hide();*/
        /*if (flash.html()) web2py.flash(flash.html());*/
        web2py.ajax_init(document);
        web2py.event_handlers();
        web2py.a_handlers();
        web2py.form_handlers();
    }
};

It works fine! Is this a bug or is something wrong with the way I'm creating a custom response.flash

Are you saying you are seeing the standard web2py flash in addition to your own? If so, that means you probably left the flash message in layout.html -- just remove it (it is a div with class .w2p_flash, as implied by the above code).

Anthony
Reply all
Reply to author
Forward
0 new messages