Thanks for your comments. I'll answer each one below, along with the answer
to Andrew's question in a seperate message.
+ Full code, and results of view page source (for successful opening page)
are attached.
On Friday, June 1, 2012 8:01:02 PM UTC+1, Anthony wrote:
>
> On Friday, June 1, 2012 2:03:23 PM UTC-4, angle wrote:
>>
>> Thanks for your response, I've answered your points below:
>>
>>>
>>>
>> #response.ajax = \
>>>> 'web2py_component("%s","patient",ajax=True,vars=vars1)' % URL
>>>> ('patient')
>>>
>>> I think this should be response.js rather than response.ajax.
>>>
>>
>> This code is copied from the example 'Designing Modular Applications' on
>> page 94 of the web2py book.
>>
>
> Unfortunately, I think there are a number of errors in that example, one
> of which is that it should be response.js, not response.ajax.
>
OK thanks, I'll keep it as response.js.
>
>> In that example it is called when a forms 'onaccept' event is
>> triggered. In my code it is called in my 'viewPatient' function that is
>> called by setting the webGrid's crud_function... (grid.crud_function =
>> 'viewPatient'). I thought that these were similar calls, so that
>> response.ajax should work in the same way. Are they not the same? ???
>>
>
> In the book example, response.ajax (which should be response.js) is set in
> the edit_items() function, which is always called as an Ajax component. You
> are setting it in your view() function, but I can't see where that function
> is actually called, so I don't know if it is being called as an Ajax
> component or as a regular web page.
>
[[NB: To avoid confusion, in the code (included below) I've updated this
function name to be viewPatient().]]
This viewPatient() function is set as the webGrid.crud_function property,
within my index() function of default.py....
(grid.crud_function = 'viewPatient'). I believe the answer to your question
is that it is called as a regular webpage,
as webGrid is not an ajax component.
>
>
>> Also, response.js is only used if the action that sets it is being called
>>> as a web2py component -- is that the case here?
>>>
>>
>> I believe so, but I am not 100% sure. It appears that the response.ajax
>> is being set via a call to 'web2py_component(...)' . Is that correct?
>>
>
> No, you are setting response.ajax to "web2py_component(...)" -- that's not
> what I'm talking about. The question is whether the function in which
> response.js is being set is itself being accessed by a call to
> web2py_component() on the client side. It is being set in your view()
> function, so the question is how is the view() function being called?
>
See last answer above. Sorry about the confusion.
>
> Finally, web2py_component() does not take an ajax or vars argument. If you
>>> want vars included in the URL, then pass it to the URL function.
>>>
>>
>> The URL is pointing to a div element - (as in the example from the book).
>>
>
> I think there is an error in the book -- it mistakenly builds a URL that
> refers to a div id rather than the name of the controller function. Is that
> what you're talking about?
>
Yes. Since reading your comments, and looking at the page-source for the
(successful) initial index page upload, I've updated this to:
response.js = \
'web2py_component("/ICC_Data_Management/default/post.load?scanId=4","patient");'
\
% URL('/ICC_Data_Management/default/post.load?scanId=4')
... and this returns the error: '<type 'exceptions.SyntaxError'> not
enough information to build the url'
>
>
>
+ to answer the question from Andrew, in a seperate message:
---'Also, I don't see a div with an Id = patient. That's your target. Is
it in the code but not in your post?'
>From the example in the book, it appears (to me) to imply that the
'{{=LOAD('default', 'list_items', ajax=True, target='showItems')}}' call in
the html, automatically creates a div id='showItems'. This was further
evidenced by my own application, where I do not explicitly create a div tag
with id=patient, but when I view pagesource for my opening page (which
works OK) and has the call
{{
=LOAD('default','post.load',ajax=True,target='patient',vars={'scanId':1})
}}, the resulting page source does include a '<div
id="patient">loading...</div>' element.
#########################################################################
########################### - 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 = 10
grid.action_links = ['view']
grid.action_headers = ['view']
grid.enabled_rows = ['header','pager','footer']
grid.crud_function = 'viewPatient'
return dict(grid=grid())
def viewPatient():
scanId=request.args[2] #ignoring this whilst debugging, and hard-coding
scanId=4 below...
response.js = \
'web2py_component("/ICC_Data_Management/default/post.load?scanId=4","patient");'
\
% URL('/ICC_Data_Management/default/post.load?scanId=4')
def post():
patientId = (icc_db(icc_db.scan.id == request.vars.scanId).select \
(icc_db.scan.patient_fk)[0].patient_fk or -1)
patientScanRecs = icc_db(icc_db.patient.id==icc_db.scan.patient_fk) \
(icc_db.scan.patient_fk == patientId).select()
scanImageRecs = icc_db(icc_db.patient.id==icc_db.scan.patient_fk) \
(icc_db.scan_image.scan_fk == icc_db.scan.id) \
(icc_db.scan_image.image_fk == icc_db.image.id) \
(icc_db.scan.patient_fk == patientId).select(icc_db.scan.id, \
icc_db.image.title, icc_db.image.id)
return dict(patientScanRecs = patientScanRecs, scanImageRecs =
scanImageRecs)
def show():
image = icc_db(icc_db.image.id==request.args(0)).select().first()
return dict(image=image)
def download():
return response.download(request, icc_db)
#########################################################################
########################## - layout.html - ##############################
#########################################################################
<html>
<head>
<title> {{=response.title or request.application}} </title>
<!-- include stylesheets -->
{{
response.files.append(URL('static','css/columns_3_DisplayBoxes.css'))
}}
{{include 'web2py_ajax.html'}}
</head>
<body>
<div id="masthead">
<H1> {{=response.title or request.application}} Project</H1>
<div id="navigation_box_brain">
<div id="imgLeft">
<img src="{{=URL('static','images/sagittal.JPG')}}" alt="sagittal"/>
<div class="highlight">
<div class="highlight_topLeft"></div>
<div class="highlight_topMid"></div>
<div class="highlight_topRight"></div>
<div class="highlight_midLeft"></div>
<div class="highlight_midMid"></div>
<div class="highlight_midRight"></div>
<div class="highlight_bottomLeft"></div>
<div class="highlight_bottomMid"></div>
<div class="highlight_bottomRight"></div>
</div>
</div>
<div id="imgCentre">
<img src="{{=URL('static','images/axial.jpg')}}" alt="axial"/>
<div class="highlight">
<div class="highlight_topLeft"></div>
<div class="highlight_topMid"></div>
<div class="highlight_topRight"></div>
<div class="highlight_midLeft"></div>
<div class="highlight_midMid"></div>
<div class="highlight_midRight"></div>
<div class="highlight_bottomLeft"></div>
<div class="highlight_bottomMid"></div>
<div class="highlight_bottomRight"></div>
</div>
</div>
<div id="imgRight">
<img src="{{=URL('static','images/coronal.jpg')}}" alt="coronal"/>
<div class="highlight">
<div class="highlight_topLeft"></div>
<div class="highlight_topMid"></div>
<div class="highlight_topRight"></div>
<div class="highlight_midLeft"></div>
<div class="highlight_midMid"></div>
<div class="highlight_midRight"></div>
<div class="highlight_bottomLeft"></div>
<div class="highlight_bottomMid"></div>
<div class="highlight_bottomRight"></div>
</div>
</div>
</div>
</div>
</div>
<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>
<div id="footer">
<H3>Footer</H3>
</div>
</body>
</html>
#########################################################################
########################### - 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:}}
<div class="scanImage">
{{=LI(A(scan_image.image.title, _href=URL("show",
extension='html', args=scan_image.image.id)))}}
</div>
{{pass}}
</div>
</div>
</div>
{{pass}}
</div>
#########################################################################
###### This is what I get when I view Page Source #######################
###### for the successful opening page #######################
#########################################################################
<html>
<head>
<title> Icc Data Management </title>
<!-- include stylesheets -->
<script type="text/javascript"><!--
// These variables are used by the web2py_ajax_init function in
web2py_ajax.js (which is loaded below).
var w2p_ajax_confirm_message = "Are you sure you want to delete this
object?";
var w2p_ajax_date_format = "%Y-%m-%d";
var w2p_ajax_datetime_format = "%Y-%m-%d %H:%M:%S";
//--></script>
<meta name="keywords" content="web2py, python, framework" /><meta
name="copyright" content="Copyright 2011" /><meta name="description" content="a
cool new app" /><meta name="generator" content="Web2py Web Framework" /><meta
name="author" content="Your Name <[email protected]>" /><script
src="/ICC_Data_Management/static/js/jquery.js"
type="text/javascript"></script><link
href="/ICC_Data_Management/static/css/calendar.css" rel="stylesheet"
type="text/css" /><script src="/ICC_Data_Management/static/js/calendar.js"
type="text/javascript"></script><script
src="/ICC_Data_Management/static/js/web2py.js"
type="text/javascript"></script><link
href="/ICC_Data_Management/static/css/columns_3_DisplayBoxes.css"
rel="stylesheet" type="text/css" />
</head>
<body>
<div id="masthead">
<H1> Icc Data Management Project</H1>
<div id="navigation_box_brain">
... unrelated HTML code
</div>
</div>
</div>
<div id="displayBox_centre">
<form action="" class="index-webgrid" enctype="multipart/form-data"
method="post" name="index-webgrid-form"><table id="index">
...
[[[[ I've omitted most of the webGrid html, but in the next line, I've
left in a call to 'viewPatient()' ]]]]
<td class="index-webgrid view_link"><a
href="/ICC_Data_Management/default/viewPatient/read/scan/1">view</a>
...
</table></form>
</div>
<div id="displayBox_left">
<script type="text/javascript"><!--
web2py_component('/ICC_Data_Management/default/post.load?scanId=1','patient');
//--></script><div id="patient">loading...</div>
</div>
<div id="footer">
<H3>Footer</H3>
</div>
</body>
</html>