[web2py] Re: AJAX component reload problem using .html vs .load

2014-02-28 Thread Dan M
I abridged the code to make it easier to diagnose.  Yes, at the beginning 
of the controller a0=request.args(0).  Sorry, the click handler is 
vestigial, as AJAX reload obviates the need for it.  TIP_APP as well is 
just old and haven't cleaned that up.  Thank you for pointing these out!

Your response helped me figure it out!  Thank you!  The problem was the 
callback:

callback=URL('user', 'stat_del', str(row.id))

For row=127. this calls "/user/stat_del/127.load" so the callback should be 
written URL('user', 'stat_del',  args=[str(row.id)]))  !!!  That 
correctly calls  "/user/stat_del.load/127" 

So simple.  I apologize.  I had just worked through the recipe to get image 
uploads working in LOADed components and I thought I might have had an AJAX 
problem.

Thank you Anthony!



On Monday, February 24, 2014 7:42:59 AM UTC-5, Anthony wrote:
>
> Is the below your exact code? I ask because in stats_del, you refer to a 
> variable a0 that has not been defined (presumably it is request.args(0)). 
> Also, your click handler refers to a ".del-div" class, but I don't see any 
> elements with that class.
>
> Anyway, by default, if an incoming URL has no extension, .html is assumed, 
> so:
>
> {{=LOAD('user','stats', args=[user.id], target='stats-ajax', ajax=True,content
> ='')}}
>
> will look for a /views/user/stats.html view. If you instead want to use a 
> stats.load view, you have to explicitly specify the .load extension:
>
> {{=LOAD('user','stats.load', args=[user.id], target='stats-ajax', ajax=
> True, content='')}}
>
> Finally, this:
>
> URL(TIP_APP+'/user', 'stat_del', str(row.id))
>
> is the wrong way to call the URL function. It happens to work in your case 
> by accident (the first argument is interpreted as the app, the second as 
> the controller, and the third as the function, when in fact the first is 
> really the app+controller, the second the function, and the third is an 
> arg). Instead, it should be:
>
> URL(TIP_APP, 'user', 'stat_del', args=str(row.id))
>
> or more simply:
>
> URL('user', 'stat_del', args=str(row.id))
>
> Note, you can leave out the app name, as it will get included 
> automatically.
>
> Anthony
>
> On Sunday, February 23, 2014 11:15:32 PM UTC-5, Dan M wrote:
>>
>> In the following code, when pressing the "X" link, the row and DIV are 
>> deleted and the component is refreshed in the controller function 
>> stat_del().  This only works when the loaded component is named ".html" 
>> rather than ".load"  So this code works but the ".load" naming does not 
>> work.  
>>
>>
>> ***
>> *** CONTROLLER: user.py ***
>> ***
>> def stats():
>> user = session.r_cur_user
>> tipuser = session.r_tip_user
>> query = (Stat.crea_id==user.id)
>> rows = db(query).select(orderby=~Stat.time_stamp)
>> return locals()
>>
>> def stat_del():
>> db(Stat.id==a0).delete()
>> response.js = "jQuery('#stats-ajax').get(0).reload();"
>> return locals()
>>
>> *
>> *** LOADED:  stats.html ***
>> *
>> {{for row in rows:}}
>> 
>> {{=A('X', _class="tip-del", 
>> _style="margin-top: 2px;", callback=URL(TIP_APP+'/user', 'stat_del', str(
>> row.id)))}}
>> 
>> 
>> {{="Status goes here"}}
>> {{="Time 
>> stamp goes here"}}
>> 
>> {{pass}}
>> 
>> $('.del-div').on('click', function(){
>> $(this).parent().parent().remove();
>> });
>> 
>>
>> 
>> *** MAIN VIEW:  home.html ***
>> 
>> {{left_sidebar_enabled,right_sidebar_enabled=True,True}}
>> {{extend 'layout.html'}}
>> {{block profile}}
>> {{=LOAD('user','profile',user.id,ajax=True, content='')}}
>> {{end}}
>> {{block follows}}
>> {{=LOAD('user','friends',user.id,ajax=True, content='')}}
>> {{end}}
>> {{block center}}
>> 
>>   
>> Status
>> Received
>> Given
>>   
>>   
>> {{if user.creator:}}
>> {{block stats}}
>> > style="width:100%;height:70%;overflow-y:auto; overflow-x:hidden;">
>> {{if mypage:}}
>> {{=LOAD('user','stat', args=[user.id], target='stat-ajax', 
>> ajax=True, content='')}}
>> {{pass}}
>> {{=LOAD('user','stats', args=[user.id], target='stats-ajax', 
>> ajax=True, content='')}}
>> 
>> {{end}}
>> {{pass}}
>>   
>> 
>> {{end}}
>>
>>

-- 
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


[web2py] AJAX component reload problem using .html vs .load

2014-02-23 Thread Dan M
In the following code, when pressing the "X" link, the row and DIV are 
deleted and the component is refreshed in the controller function 
stat_del().  This only works when the loaded component is named ".html" 
rather than ".load"  So this code works but the ".load" naming does not 
work.  


***
*** CONTROLLER: user.py ***
***
def stats():
user = session.r_cur_user
tipuser = session.r_tip_user
query = (Stat.crea_id==user.id)
rows = db(query).select(orderby=~Stat.time_stamp)
return locals()

def stat_del():
db(Stat.id==a0).delete()
response.js = "jQuery('#stats-ajax').get(0).reload();"
return locals()

*
*** LOADED:  stats.html ***
*
{{for row in rows:}}

{{=A('X', _class="tip-del", 
_style="margin-top: 2px;", callback=URL(TIP_APP+'/user', 'stat_del', 
str(row.id)))}}


{{="Status goes here"}}
{{="Time 
stamp goes here"}}

{{pass}}

$('.del-div').on('click', function(){
$(this).parent().parent().remove();
});



*** MAIN VIEW:  home.html ***

{{left_sidebar_enabled,right_sidebar_enabled=True,True}}
{{extend 'layout.html'}}
{{block profile}}
{{=LOAD('user','profile',user.id,ajax=True, content='')}}
{{end}}
{{block follows}}
{{=LOAD('user','friends',user.id,ajax=True, content='')}}
{{end}}
{{block center}}

  
Status
Received
Given
  
  
{{if user.creator:}}
{{block stats}}

{{if mypage:}}
{{=LOAD('user','stat', args=[user.id], target='stat-ajax', 
ajax=True, content='')}}
{{pass}}
{{=LOAD('user','stats', args=[user.id], target='stats-ajax', 
ajax=True, content='')}}

{{end}}
{{pass}}
  

{{end}}

-- 
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.