In order to include scripting in a very dynamic component I'm appending a js
file to the response files of every template that uses the component, such
as:

{{response.files.append(URL(request.application,'static/base_components','view_oppty.js'))}}
{{extend 'layout.html'}}

However, this has the problem of decoupling the scripting from the
component. Although, I find the advantage of leaving the js in its own file
which is convenient for editing and maintenance.
My reading of the web2py Book chapter 13 suggests that the answer would be
to minify the js code and include it in the controller, such as:

def oppty_contacts():
   define var to be used on the template
   ...

response.headers['web2py-component-command']="$('#show_assoc_contact').click(function(event){...);"
   form=...
   return dict(..., form=form)

However I can't get this is to work.

My doubts are:
I wonder if there is a way to couple a scripting file with the component (so
I can enjoy the advantage of having the js in its own file)?
What am I doing wrong in the alternative solution of including the js code
via response.headers?

Miguel

Reply via email to