May I share a helper function borrowed from RoR, that renders a button
which is inline by default (meaning you can put it anywhere on web
page just like a link, no line feed will happen) but you can set any
style. Put it somewhere to models directory. Call it from your
template code as e.g.
{{=BUTTON_TO(T('Change Avatar'), URL
(request.application,'default','user/change_password'))}}

If users find this useful I can port more helpers from RoR, and
Massimo could tell us where it is best to put them - maybe in modules?

# similar to Rails button_to
def BUTTON_TO(name, uri, confirm=None, style="display:inline;margin:
0px;", target=None):
    if target:
        c = confirm and ("return confirm(\"%s\");" % confirm) or ''
        f = FORM(INPUT(_type="submit",_value=name),
                _style=style,
                _onclick="javascript:" + c + target + ".location='" +
uri +"';return false;")
    else:
        f = FORM(INPUT(_type="submit",_value=name),
                _style=style, _action=uri,
                _onclick=confirm and ("javascript:return confirm(\"%s
\")" % confirm) or None)
    return f

# similar to Rails button_to but calls javascript prompt
#prompt parameter must be a tuple of text and suggested value
#uri must have GET params part because what user entered into prompt
dialog is passed to server thru uri
#e.g. uri='www.com?x=' or uri='www.com?x=100&y='
def PROMPT_TO(name, uri, prompt=('Enter value', '0'),
style="display:inline;margin:0px;", target=None):
    c = prompt and ("promptValue=prompt(\"%s\", \"%s\")" % prompt) or
''
    if target:
        f = FORM(INPUT(_type="submit",_value=name),
                _style=style,
                _onclick="javascript:%s;
%s.location='%s'+promptValue;return false;" % (c, target, uri))
    else:
        f = FORM(INPUT(_type="submit",_value=name),
                _style=style,
                _onclick="javascript:
%s;document.location='%s'+promptValue;return promptValue==null;" % (c,
uri))
    return f

def SCRIPT(scrpt):
    return XML("<script type=\"text/javascript\"><!--\n" + scrpt +
"\n//--></script>")

On Oct 21, 8:56 pm, waTR <r...@devshell.org> wrote:
> I simply use javascript for a button. In my <select type=button> code,
> I put a on-click="javascript to open link to {{=URL()}}"
>
> On Oct 20, 9:59 pm, mdipierro <mdipie...@cs.depaul.edu> wrote:
>
>
>
> > 3) URL builds the url to the action /app/controller/function,
> > request.application is the name of the current application so that the
> > link does not break if it is renamed
>
> > 2) it is a flag that should be set to True if the menu item should be
> > selected. The default layout does not use this flag but some layouts
> > may give a different class (color/style/background) to a selected menu
> > item.
>
> > On Oct 20, 11:31 pm, Checho <sergioriver...@gmail.com> wrote:
>
> > > Thanks for your answer Massimo!
>
> > > Can you explain me in this statement which are the parameters???
>
> > > "[T('Change Avatar'), False,URL(request.application,'default','user/
> > > change_password')]"
>
> > > 1. I supose de 1st parameter is the name of the option in the menú.
> > > 2. What does it mean having False instead of True???
> > > 3. In URL, where is redirected the user after clicking there which is
> > > the meaning of "request.application"?
>
> > > Thanks...again
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To post to this group, send email to web2py@googlegroups.com
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to