Looks like the javascript part is not working, obviously. Instead, why
not to change the helper instance programatically (from A to P and P
to A) if the user is logged in or not? Even it is possible to change
the helper class according to the condition in the helper
initialization:
if something:
A(..., _class=myclass)
else:
P(..., _class=myotherclass)
That way you wouldn't have to put conditional script sentences for
each case.
in the script
$("a.myclass")....
$("p.myotherclass")....
On Feb 15, 7:43 am, Annet <[email protected]> wrote:
> I have a view in which I want links to be enabled/disabled depending
> on the user being logged in and his account settings.
>
> {{if not auth.is_logged_in():}}
> <script type="text/javascript">
> $(document).ready(function(){
> $('#root a').click(function(e) {e.preventDefault();});
> $('#hub a').click(function(e) {e.preventDefault();});
> $('#vcardsite a').click(function(e) {e.preventDefault();});
> $('#calendar a').click(function(e) {e.preventDefault();});
> });
> </script>
>
> <style type="text/css">
> .admin {opacity: 0.5; filter:Alpha(opacity=50);}
> </style>
>
> {{else:}}
> <script type="text/javascript">
> $(document).ready(function(){
> $('#root a').click(function(e) {e.preventDefault();});
> $('#hub a').click(function(e) {e.preventDefault();});
> $('#vcardsite a').click(function(e) {e.preventDefault();});
> $('#calendar a').click(function(e) {e.preventDefault();});
> });
> {{if rows:}}
> {{for row in rows:}}
> {{i=row.accountID}}
> {{if i==1:}}
> $('#root a').unbind('click',function(e));
> {{elif i==2:}}
> $('#hub a').unbind('click',function(e));
> {{elif i==3:}}
> $('#vcardsite a').unbind('click',function(e));
> {{elif i==4:}}
> $('#calendar a').unbind('click',function(e));
> {{pass}}
> {{pass}}
> {{pass}}
> </script>
>
> <style type="text/css">
> #root, #hub, #vcardsite, #calendar {opacity: 0.5;
> filter:Alpha(opacity=50);}
> {{if rows:}}
> {{for row in rows:}}
> {{i=row.accountID}}
> {{if i==1:}}
> #root {opacity: 1.0; filter:Alpha(opacity=100);}
> {{elif i==2:}}
> #hub {opacity: 1.0; filter:Alpha(opacity=100);}
> {{elif i==3:}}
> #vcardsite {opacity: 1.0; filter:Alpha(opacity=100);}
> {{elif i==4:}}
> #calendar {opacity: 1.0; filter:Alpha(opacity=100);}
> {{pass}}
> {{pass}}
> {{pass}}
> </style>
>
> {{pass}}
>
> The css part works, the {{if not auth.is_logged_in():}} javascript
> part works, however, the {{else:}}
> <script type="text/javascript"> {{if rows:}} ... {{pass}} </script>
> {{pass}} part doesn't work. This:
>
> {{if rows:}}
> {{for row in rows:}}
> {{i=row.accountID}}
> {{if i==1:}}
> $('#root a').unbind('click',function(e));
> {{elif i==2:}}
> $('#hub a').unbind('click',function(e));
> {{elif i==3:}}
> $('#vcardsite a').unbind('click',function(e));
> {{elif i==4:}}
> $('#calendar a').unbind('click',function(e));
> {{pass}}
> {{pass}}
> {{pass}}
>
> ... gives all the links their default behaviour back. If accountID=2
> not only the #hub link becomes clickable the # root, #vcardsite and
> #calendar links become clickable as well. How do I code the desired
> behaviour correctly?
>
> Kind regards,
>
> Annet.