Message from discussion
Is it possible to define a function to be called when a MenuItem is selected?
Received: by 10.101.3.11 with SMTP id f11mr12782794ani.26.1337737217669;
Tue, 22 May 2012 18:40:17 -0700 (PDT)
X-BeenThere: liftweb@googlegroups.com
Received: by 10.100.234.34 with SMTP id g34ls66241anh.3.gmail; Tue, 22 May
2012 18:40:10 -0700 (PDT)
Received: by 10.101.136.25 with SMTP id o25mr4124451ann.8.1337737210755;
Tue, 22 May 2012 18:40:10 -0700 (PDT)
Received: by 10.101.136.25 with SMTP id o25mr4124450ann.8.1337737210733;
Tue, 22 May 2012 18:40:10 -0700 (PDT)
Return-Path: <j...@spiralarm.com>
Received: from mail-yw0-f43.google.com (mail-yw0-f43.google.com [209.85.213.43])
by gmr-mx.google.com with ESMTPS id w40si8352459anp.3.2012.05.22.18.40.10
(version=TLSv1/SSLv3 cipher=OTHER);
Tue, 22 May 2012 18:40:10 -0700 (PDT)
Received-SPF: neutral (google.com: 209.85.213.43 is neither permitted nor denied by best guess record for domain of j...@spiralarm.com) client-ip=209.85.213.43;
Authentication-Results: gmr-mx.google.com; spf=neutral (google.com: 209.85.213.43 is neither permitted nor denied by best guess record for domain of j...@spiralarm.com) smtp.mail=j...@spiralarm.com
Received: by yhkk6 with SMTP id k6so7103280yhk.2
for <liftweb@googlegroups.com>; Tue, 22 May 2012 18:40:10 -0700 (PDT)
d=google.com; s=20120113;
h=mime-version:in-reply-to:references:date:message-id:subject:from:to
:content-type:x-gm-message-state;
bh=bpDpCqhDJFXID+EtWfGLG3KeoacJQRyZ83v/Tk/1foQ=;
b=Ve7OgAH858gGEmtzXO1QxOQu3HwzNx/KXtjJI/iFld82AveHCwgQBZQ2QK+B3FoPs/
vSbi/KzIXRfISHxfgonFQksBC1MiZZJPhTZqMVUuE2C+gx0jDdDHiX/7FKLaITe9Vk8Q
RNPJ1yT3HHy/5gT7Buy3s+PoNjOnzP3SBM2QTfYiu5nm7FhAgLnYR9pqvGO/DLjjm9n9
H7YkauwNYtRJZds0w1sqn4t/xxItgkok7lcKzOlIzRoASTftH9bfzRY7UD+ak/yl7CPU
qEuGcSFKY3ScDbS/JS+A8L85tmf1AKc4ZTHvZJd0PtZtt5FBKmzFg4opoFd+j0XfGnoe
8l7A==
MIME-Version: 1.0
Received: by 10.50.89.166 with SMTP id bp6mr11373617igb.69.1337737210259; Tue,
22 May 2012 18:40:10 -0700 (PDT)
Received: by 10.42.18.133 with HTTP; Tue, 22 May 2012 18:40:10 -0700 (PDT)
In-Reply-To: <CABXnLXRva=N3_RW=xugxDoGvWhMe2Vu2RoT70c9wA-pcqgr...@mail.gmail.com>
References: <28793886.1645.1337065221023.JavaMail.geo-discussion-forums@pbcoz4>
<CABXnLXTE=jq4C5Pq2Pp85wqO7F7+8102dawjfhDdx6XHK9J...@mail.gmail.com>
<20199294.175.1337120328968.JavaMail.geo-discussion-forums@pbcqf6>
<CABXnLXRva=N3_RW=xugxDoGvWhMe2Vu2RoT70c9wA-pcqgr...@mail.gmail.com>
Date: Wed, 23 May 2012 11:40:10 +1000
Message-ID: <CAFUZPrWrXkmCUSHuLsJL__rkmVwQCfbQgznnV_2aHA6ohd=...@mail.gmail.com>
Subject: Re: [Lift] Is it possible to define a function to be called when a
MenuItem is selected?
From: Jonathan Ferguson <j...@spiralarm.com>
To: liftweb@googlegroups.com
Content-Type: multipart/alternative; boundary=e89a8f3ba7a138696604c0aa3732
X-Gm-Message-State: ALoCoQnJ906MJyTWhnxnsoLaGaoO98Z3WP2mRLFlAAGLICiq8HB8+9u/SQsnbGWlOFXfu3ttV/Gk
--e89a8f3ba7a138696604c0aa3732
Content-Type: text/plain; charset=UTF-8
Hi David,
Sorry for the delay, I got caught up with another project.
I think this could be a viable solution. Do you know where there is
anything documentation on type safe Loc and LocParam other than the scala
docs?
I'll have a look at the scala doc and see if I can get an example working.
Thank you
Jono
On 16 May 2012 08:39, David Whittaker <d...@iradix.com> wrote:
> Jono,
>
> Could you not accomplish that through a type safe Loc that calculates a
> value? Maybe this doesn't fit your particular use case but I'm thinking
> that a Loc[State] where the the State is calculated via a CalcValue
> LocParam would make the State available to the snippets when the Loc is
> matched. You can then define your snippets as:
>
> class MySnippet(val state: State) extends DispatchSnippet {
> ..... some transforms that use your state .....
> }
>
> On Tue, May 15, 2012 at 6:18 PM, Jonathan Ferguson <j...@spiralarm.com>wrote:
>
>> Hi David,
>>
>> The code needs to run when the menu item is clicked. So the new state is
>> available to the snippets when the page is being built.
>>
>> Jono
>>
>>
>> On Wednesday, 16 May 2012 01:42:58 UTC+10, David Whittaker wrote:
>>>
>>> Hi Jono,
>>>
>>> What type of state are we talking about? Does your code need to run
>>> when the menu item is clicked, or can it be invoked when the page the menu
>>> item points to is displayed?
>>>
>>> On Tue, May 15, 2012 at 3:00 AM, Jonathan Ferguson <j...@spiralarm.com>wrote:
>>>
>>>> Hello all,
>>>> I have a custom Loc in which I override **supplimentalKidMenuItems
>>>> to build a sub menu based on a database table. Ideally when a MenuItem
>>>> from the sub menu is clicked a function would be run allowing me to change
>>>> state. Currently I'm stuck and am thinking about using a RestHelper to
>>>> trigger the state change, which seems ugly.
>>>>
>>>> override def supplimentalKidMenuItems = CurrentUser.is match{
>>>>
>>>> case Full(u) =>
>>>>
>>>> val ts = u.things
>>>>
>>>> ts.size match {
>>>>
>>>> case 1 => Nil
>>>>
>>>> case otherwise =>
>>>>
>>>> val x = for { t <- ts} yield {MenuItem(Text(t.name.is),
>>>> Text("switch/%s".format(t.id))**, Nil, false, false,Nil)}
>>>>
>>>> x.toList ::: super.**supplimentalKidMenuItems
>>>>
>>>> }
>>>>
>>>> case otherwise => Nil
>>>>
>>>> }
>>>> Any pointers would be appreciated.
>>>>
>>>>
>>>> Thank you
>>>> Jono
>>>>
>>>> --
>>>> Lift, the simply functional web framework: http://liftweb.net
>>>> Code: http://github.com/lift
>>>> Discussion: http://groups.google.com/**group/liftweb<http://groups.google.com/group/liftweb>
>>>> Stuck? Help us help you: https://www.assembla.com/wiki/**
>>>> show/liftweb/Posting_example_**code<https://www.assembla.com/wiki/show/liftweb/Posting_example_code>
>>>>
>>>
>>> --
>> Lift, the simply functional web framework: http://liftweb.net
>> Code: http://github.com/lift
>> Discussion: http://groups.google.com/group/liftweb
>> Stuck? Help us help you:
>> https://www.assembla.com/wiki/show/liftweb/Posting_example_code
>>
>
> --
> Lift, the simply functional web framework: http://liftweb.net
> Code: http://github.com/lift
> Discussion: http://groups.google.com/group/liftweb
> Stuck? Help us help you:
> https://www.assembla.com/wiki/show/liftweb/Posting_example_code
>
--e89a8f3ba7a138696604c0aa3732
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
Hi David,=C2=A0<div><br></div><div>Sorry for the delay, I got caught up wit=
h another project.=C2=A0</div><div><br></div><div>I think this could be a v=
iable solution. Do you know where there is anything documentation on type s=
afe Loc and LocParam other than the scala docs?</div>
<div><br></div><div>I'll have a look at the scala doc and see if I can =
get an example working.=C2=A0</div><div><br></div><div>Thank you=C2=A0</div=
><div><br></div><div>Jono<br><br><div class=3D"gmail_quote">On 16 May 2012 =
08:39, David Whittaker <span dir=3D"ltr"><<a href=3D"mailto:dave@iradix.=
com" target=3D"_blank">d...@iradix.com</a>></span> wrote:<br>
<blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p=
x #ccc solid;padding-left:1ex">Jono,<div><br></div><div>Could you not accom=
plish that through a type safe Loc that calculates a value? =C2=A0Maybe thi=
s doesn't fit your particular use case but I'm thinking that a Loc[=
State] where the the State is calculated via a CalcValue LocParam would mak=
e the State available to the snippets when the Loc is matched. =C2=A0You ca=
n then define your snippets as:</div>
<div><br></div><div>class MySnippet(val state: State) extends DispatchSnipp=
et {</div><div>..... some transforms that use your state .....</div><div cl=
ass=3D"HOEnZb"><div class=3D"h5"><div>}</div><div><br><div class=3D"gmail_q=
uote">
On Tue, May 15, 2012 at 6:18 PM, Jonathan Ferguson <span dir=3D"ltr"><<a=
href=3D"mailto:j...@spiralarm.com" target=3D"_blank">j...@spiralarm.com</a=
>></span> wrote:<br>
<blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p=
x #ccc solid;padding-left:1ex">Hi David,=C2=A0<div>=C2=A0=C2=A0</div><div>T=
he code needs to run when the menu item is clicked. So the new state is ava=
ilable to the snippets when the page is being built.=C2=A0</div>
<div><br></div><div>Jono<div><div><br><br>On Wednesday, 16 May 2012 01:42:5=
8 UTC+10, David Whittaker wrote:<blockquote class=3D"gmail_quote" style=3D=
"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi Jono,<div><br></div><div>What type of state are we talking about? =C2=A0=
Does your code need to run when the menu item is clicked, or can it be invo=
ked when the page the menu item points to is displayed?<br><div><br><div cl=
ass=3D"gmail_quote">
On Tue, May 15, 2012 at 3:00 AM, Jonathan Ferguson <span dir=3D"ltr"><<a=
href=3D"mailto:j...@spiralarm.com" target=3D"_blank">j...@spiralarm.com</a=
>></span> wrote:<br><blockquote class=3D"gmail_quote" style=3D"margin:0 =
0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hello all,=C2=A0<div>=C2=A0 =C2=A0I have a custom Loc in which I override=
=C2=A0<u></u>supplimentalKidMenuItems to build a sub menu based on a databa=
se table. =C2=A0Ideally when a MenuItem from the sub menu is clicked a func=
tion would be run allowing me to change state. =C2=A0Currently I'm stuc=
k and am thinking about using a RestHelper to trigger the state change, whi=
ch seems ugly.</div>
<div><br></div><div>
<p>=C2=A0 =C2=A0<span>override</span> <span>def</span> supplimentalKidMenuI=
tems =3D=C2=A0 CurrentUser.is <span>match</span>{</p>
<p>=C2=A0 =C2=A0 =C2=A0 <span>case</span> Full(<span>u</span>) =3D></p>
<p>=C2=A0 =C2=A0 =C2=A0 =C2=A0 <span>val</span> <span>ts</span> =3D <span>u=
</span>.things</p>
<p>=C2=A0 =C2=A0 =C2=A0 =C2=A0=C2=A0<span>ts</span>.size <span>match</span>=
{<br></p>
<p>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 <span>case</span> 1 =3D> Nil =C2=
=A0</p>
<p>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 <span>case</span> <span>otherwise</sp=
an> =3D></p>
<p>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 <span>val</span> <span>x</span=
> =3D <span>for</span> { <span>t</span> <- <span>ts</span>}=C2=A0 <span>=
yield</span> {MenuItem(Text(<span>t</span>.<span>name</span>.is), Text(<spa=
n>"switch/%s"</span>.format(<span>t</span>.id))<u></u>, Nil, <spa=
n>false</span>, <span>false</span>,Nil)}</p>
<p>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 <span>x</span>.toList ::: <spa=
n>super</span>.<u></u>supplimentalKidMenuItems=C2=A0</p>
<p>=C2=A0 =C2=A0 =C2=A0 =C2=A0 }</p>
<p>=C2=A0 =C2=A0 =C2=A0 <span>case</span> <span>otherwise</span> =3D>=C2=
=A0Nil</p>
<p>=C2=A0 =C2=A0 =C2=A0 }</p></div><div>Any pointers would be appreciated.<=
/div><div><br></div><div><br></div><div>Thank you=C2=A0</div><div>Jono</div=
><span><font color=3D"#888888">
<p></p>
-- <br>
Lift, the simply functional web framework: <a href=3D"http://liftweb.net" t=
arget=3D"_blank">http://liftweb.net</a><br>
Code: <a href=3D"http://github.com/lift" target=3D"_blank">http://github.co=
m/lift</a><br>
Discussion: <a href=3D"http://groups.google.com/group/liftweb" target=3D"_b=
lank">http://groups.google.com/<u></u>group/liftweb</a><br>
Stuck? Help us help you: <a href=3D"https://www.assembla.com/wiki/show/lift=
web/Posting_example_code" target=3D"_blank">https://www.assembla.com/wiki/<=
u></u>show/liftweb/Posting_example_<u></u>code</a><br>
</font></span></blockquote></div><br></div></div>
</blockquote></div></div></div><div><div>
<p></p>
-- <br>
Lift, the simply functional web framework: <a href=3D"http://liftweb.net" t=
arget=3D"_blank">http://liftweb.net</a><br>
Code: <a href=3D"http://github.com/lift" target=3D"_blank">http://github.co=
m/lift</a><br>
Discussion: <a href=3D"http://groups.google.com/group/liftweb" target=3D"_b=
lank">http://groups.google.com/group/liftweb</a><br>
Stuck? Help us help you: <a href=3D"https://www.assembla.com/wiki/show/lift=
web/Posting_example_code" target=3D"_blank">https://www.assembla.com/wiki/s=
how/liftweb/Posting_example_code</a><br>
</div></div></blockquote></div><br></div>
<p></p>
-- <br>
Lift, the simply functional web framework: <a href=3D"http://liftweb.net" t=
arget=3D"_blank">http://liftweb.net</a><br>
Code: <a href=3D"http://github.com/lift" target=3D"_blank">http://github.co=
m/lift</a><br>
Discussion: <a href=3D"http://groups.google.com/group/liftweb" target=3D"_b=
lank">http://groups.google.com/group/liftweb</a><br>
Stuck? Help us help you: <a href=3D"https://www.assembla.com/wiki/show/lift=
web/Posting_example_code" target=3D"_blank">https://www.assembla.com/wiki/s=
how/liftweb/Posting_example_code</a><br>
</div></div></blockquote></div><br></div>
--e89a8f3ba7a138696604c0aa3732--