Hi web2py,
I am a fairly experienced coder, but am new to web-programming and web2py.
Ihave read the documentation, bought the book, and done quite a few of the
examples which have run OK. I am coding on Windows7 OS - using
Firefox browser.
I am trying to modularise my current demo web2py web-app, so that when i click
on a webGrid (a 'view' link) on the right-hand-side of page, my column on the
left-hand-side of the page updates to show the details of the selected
patient/scan row. Before trying this, I have got it to work so the whole page
updates when I click on that link, but to progress this further, I want only
the left-hand column to update. I am trying to adapt the example from the book
(Chapter 2 - Designing Modular Applications) and the example from the
'Components' section of the online docs
(
http://web2py.com/books/default/chapter/29/12).
Currently, the initial index page loads OK, with the left hand column showing
the default (scanId=1) record. It's the click on 'view' which doesn't work. I
am trying 2 options and they both give me a blank 'none' page, when I click
on the 'view' link. I can't figure out the mistake I am making and have been
working on it for over a day now. The code is below.
As you can see, I think its because I am still unclear on how the load and
'response.ajax = 'web2py_component(' calls work.
Hope you can help.
angle
******************************
******* DEFAULT.PY ********
******************************
def index():
import webgrid
from gluon.tools import Crud
crud = Crud(icc_db)
grid=webgrid.WebGrid(crud)
grid.datasource = icc_db(
icc_db.scan.id>0)
grid.pagesize = 20
grid.action_links = ['view']
grid.action_headers = ['view']
grid.enabled_rows = ['header','pager','footer']
grid.crud_function = 'view'
#if request.controller == 'default' and request.function == 'index':
# if request.args:
# crud.settings[request.args(0)+'_next'] = URL('index')
return dict(grid=grid())
def view():
vars1={'scanId':(request.args[2])}
##### THIS IS WHERE I AM TRYING VARIOUS OPTIONS - RETURN 'NONE' page ####
LOAD('default','post.load',ajax=True,target='patient',vars={'scanId':(
request.args[2] or 1)})
#response.ajax = \
'web2py_component("%s","patient",ajax=True,vars=vars1)' % URL
('patient')
#response.ajax =
'web2py_component("post.load",ajax=True,target="patient",vars={"scanId":(
request.args[2] or 1)})' % URL ('patient')
def post(): #This works OK...
patientId = (icc_db(
icc_db.scan.id ==
request.vars.scanId).select(icc_db.scan.patient_fk)[0].patient_fk or -1)
...
return dict(patientScanRecs = patientScanRecs,
scanImageRecs = scanImageRecs)
...
************************************************************************
* Views/Layout.html (webGrid + the left column) *
************************************************************************
<div id="displayBox_centre">
{{=grid}}
</div>
<div id="displayBox_left">
{{ if request.args: }}
{{ =LOAD('default','post.load',ajax=True,target='patient',vars=
{'scanId':(request.args[2] or 1)}) }}
{{ else: }}
{{
=LOAD('default','post.load',ajax=True,target='patient',
vars={'scanId':1}) }}
{{pass}}
</div>
************************************
****** Views/default/post.load ******
************************************
<H2> Patient ID: {{=patientScanRecs[0].
patient.id}} </H2>
<H2> Diagnostic Group: {{=patientScanRecs[0].patient.DiagnosticGroup}}</H2>
<H2> Source:{{=patientScanRecs[0].patient.Source}} </H2>
<div class="scanList">
{{for patient_scan in patientScanRecs:}}
<div class="scan">
<H2>Age at Scan {{=patient_scan.scan.ageAtScan}}</H2>
<H2>Date of Scan {{=patient_scan.scan.dateOfscan}} </H2>
<div class="scanImageList">
{{for scan_image in scanImageRecs:}}
...
{{pass}}
</div>
</div>
</div>
{{pass}}
</div>