I don't have an answer, just a comment on the style...
This is what you should not do - you're mixing the model, view, and
controller into an inconceivable mess.
On Tuesday, April 7, 2015 at 7:11:58 AM UTC-7, sasogeek wrote:
>
> default.py
>
> @auth.requires_login()
> def load_home():
> loader = """$('#right-side').html("<i style='font-size:24px;'
> class='fa fa-spinner fa-spin'></i>")"""
> websocket_send('http://127.0.0.1:8888', loader, 'mykey', 'home%s' %
> auth.user.id)
> remove_class1 = "$('#bk').removeClass('active')" #books
> remove_class2 = "$('#ls').removeClass('active')" #lecture slides
> remove_class3 = "$('#pq').removeClass('active')" #past questions
> remove_class4 = "$('#cs').removeClass('active')" #courses
> remove_class5 = "$('#bl').removeClass('active')" #blogs
> remove_class6 = "$('#nt').removeClass('active')" #notes
> remove_class7 = "$('#fr').removeClass('active')" #friends
> add_class = "$('#hm').addClass('active')" #home
> websocket_send('http://127.0.0.1:8888', remove_class1, 'mykey',
> 'home%s' % auth.user.id)
> websocket_send('http://127.0.0.1:8888', remove_class2, 'mykey',
> 'home%s' % auth.user.id)
> websocket_send('http://127.0.0.1:8888', remove_class3, 'mykey',
> 'home%s' % auth.user.id)
> websocket_send('http://127.0.0.1:8888', remove_class4, 'mykey',
> 'home%s' % auth.user.id)
> websocket_send('http://127.0.0.1:8888', remove_class5, 'mykey',
> 'home%s' % auth.user.id)
> websocket_send('http://127.0.0.1:8888', remove_class6, 'mykey',
> 'home%s' % auth.user.id)
> websocket_send('http://127.0.0.1:8888', remove_class7, 'mykey',
> 'home%s' % auth.user.id)
> websocket_send('http://127.0.0.1:8888', add_class, 'mykey', 'home%s'
> % auth.user.id)
>
> message = """<section class='content'><br/><div class='row'><div
> class='col-md-4'><div class='grid box-profile bg-red'><div
> class='grid-body'><img src='%s' class='img-circle' alt='User
> Profile'><h3>%s</h3><span>Lorem ipsum dolor sit amet consectetur
> adipisicing elit sed do eiusmod</span></div><div class='footer clearfix
> bg-red'><div class='col-xs-4'><div class='grid-body full'><h3><i class='fa
> fa-facebook-square'></i> 823k</h3></div></div><div class='col-xs-4'><div
> class='grid-body full'><h3><i class='fa fa-twitter'></i>
> 402k</h3></div></div><div class='col-xs-4'><div class='grid-body
> full'><h3><i class='fa fa-linkedin-square'></i>
> 97k</h3></div></div></div></div></div> <div class='col-md-8
> pull-right'><div class='grid'><div class='grid-header'><img
> style='height:30px;' src='%s' class='img-polaroid pull-left' alt='User
> Profile'><span class='grid-title'>Status</span></div><div class='grid-body'
> id='sf'></div></div></div></div></section>""" % (URL('download',
> args=[auth.user.profile_picture]) if auth.user.profile_picture else
> "../static/nb/html/assets/img/logo.png", auth.user.full_name,
> URL('download', args=[auth.user.profile_picture]) if
> auth.user.profile_picture else "../static/nb/html/assets/img/logo.png")
>
> message = message.strip().replace("'", '"')
> message = message.strip().replace("\n", "")
> message = message.strip().replace("\r", "")
> message = message.strip().replace("\t", "")
> message =
> "$('#right-side').html($('%s').fadeIn('slow').slideDown('slow'))" % message
> websocket_send('http://127.0.0.1:8888', message, 'mykey', 'home%s' %
> auth.user.id)
>
> form = LOAD(c='default', f='statusform', ajax=True, content=XML('<i
> style="font-size:24px;" class="fa fa-cog fa-spin"></i>'))
> form = "$('#sf').html($('%s').fadeIn('slow').slideDown('slow'))" % form
> websocket_send('http://127.0.0.1:8888', form, 'mykey', 'home%s' %
> auth.user.id)
>
> def statusform():
> status = crud.create(db.statuses)
> msg = status.element('textarea', _name="status")
> msg['_class'] = "form-control"
> msg['_style'] = "height: 40px; width:45vw; margin-bottom:5px;"
> user_id = status.element('input', _name='user_id')
> user_id['_type'] = 'hidden'
> user_id['_value'] = auth.user.id
> submit = status.element('input', _type="submit")
> submit['_class'] = "btn btn-primary pull-right"
> submit['_value'] = "Post"
> if status.process().accepted:
> userPic=db(db.auth_user.id
> ==request.post_vars.user_id).select().first().profile_picture
> now = prettydate(datetime.datetime.now())
> message1 = """<div class="col-md-8 pull-right"
> style="width:51.9vw;"><div class="grid"><div class="grid-header"><img
> style="height:30px; width: 30px;" src="%s" class="img-polaroid pull-left"
> alt="User Profile"><span class="grid-title">%s</span><div class="pull-right
> grid-tools"><a data-widget="collapse"
> title="Collapse">%s</a></div></div><div
> class="grid-body">%s</div></div></div>""" % (URL('download',
> args=[userPic]) if userPic else "../static/nb/html/assets/img/logo.png", db(
> db.auth_user.id == request.post_vars.user_id).select().first().full_name,
> now, request.post_vars.status)
>
> message1 = message1.strip().replace("\n", "<br/>")
> message1 = message1.strip().replace("\r", "")
> script1 =
> """$('#statuses1').prepend($('%s').fadeIn('slow').slideDown('slow'))""" %
> message1
> script2 = "$('#statuses1').show('slow')"
>
> message2 = """<div class="col-md-8 pull-right"
> style="width:95vw;"><div class="grid"><div class="grid-header"><img
> style="height:30px; width: 30px;" src="%s" class="img-polaroid pull-left"
> alt="User Profile"><span class="grid-title">%s</span><div class="pull-right
> grid-tools"><a data-widget="collapse"
> title="Collapse">%s</a></div></div><div
> class="grid-body">%s</div></div></div>""" % (URL('download',
> args=[userPic]) if userPic else "../static/nb/html/assets/img/logo.png", db(
> db.auth_user.id == request.post_vars.user_id).select().first().full_name,
> now, request.post_vars.status)
>
> message2 = message2.strip().replace("\n", "<br/>")
> message2 = message2.strip().replace("\r", "")
> script3 =
> """$('#statuses2').prepend($('%s').fadeIn('slow').slideDown('slow'))""" %
> message2
> script4 = "$('#statuses2').show('slow')"
>
> websocket_send('http://127.0.0.1:8888', script1, 'mykey',
> 'mygroup')
> websocket_send('http://127.0.0.1:8888', script2, 'mykey',
> 'mygroup')
> websocket_send('http://127.0.0.1:8888', script3, 'mykey',
> 'mygroup')
> websocket_send('http://127.0.0.1:8888', script4, 'mykey',
> 'mygroup')
> return status
>
>
>
> home.html
> <ul class="sidebar-menu">
> <li class="active" id="hm" onclick="ajax('load_home', [], 'mmmm');">
> <a href="#">
> <i class="fa fa-home"></i><span>Home</span>
> </a>
> </li>
> ...
> </ul>
>
> ...
> <aside class="right-side" id="right-side">
> </aside>
>
> <script>
> $(document).ready(function(){
> var data;
>
> $.web2py.web2py_websocket('ws://127.0.0.1:8888/realtime/home{{=auth.user.id}}',function(e){data=eval('('+e.data+')')});
> });
> </script>
>
>
> I'm using ajax to call the function *load_home* and load_home is supposed
> to return a form using LOAD with ajax=True. The normal home function in the
> controller returns form using LOAD with ajax=True and that works just fine.
> But now I'm also using websocket_messaging.py to load parts of the page for
> navigation without whole page reloads, chats, etc. I'm trying to use the
> same mechanism to reload the home page when the "Home" link is clicked, so
> that I have the form working just as though the home page was being loaded
> afresh.... if that makes sense....
>
> The problem here is that when I use ajax=False in the load_home function
> form = LOAD(c='default', f='statusform', ajax=False, content=XML('<i
> style="font-size:24px;" class="fa fa-cog fa-spin"></i>'))
>
> The form appears just fine (but even that when someone submits the form,
> it doesn't save the details in the db), but when ajax=True
> form = LOAD(c='default', f='statusform', ajax=True, content=XML('<i
> style="font-size:24px;" class="fa fa-cog fa-spin"></i>'))
>
> The cog icon keeps spinning.
>
> How can I accomplish what I'm aiming at...
>
>
>
>
--
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 [email protected].
For more options, visit https://groups.google.com/d/optout.