Forum OpenACS Q&A: Help on (1) Use of template::form in notes module (2) IFRAME cached by browser

Hello.

This is the first time I've posted a question on the forum, so please inform me if I lacked any details in my question.

Context:

I am trying to add a new function that lets a non-technical user do simple text formating on a form on a html page. A user can press buttons to bold/italic/underline text in a form.

I have got its interface working and am trying to incorporate it into the notes module. Within the file /web/eric4/packages/notes/www/add- edit.tcl I've replaced the 2 "-widget" calls (ie template::element ...) by:

template::element create new_note title

   -widget editor  
-datatype text
-label "Title"
-html { height 100 width 180 src /web/eric4/packages/notes/www/title.html }

-value $title

template::element create new_note body

    -widget editor  
-datatype text
-label "Body"
-html { height 160 width 350 src /web/eric4/packages/notes/www/body.html }
-value $body

"-widget editor" refers to a new block of code I've added to file: /web/eric4/packages/acs-templating/tcl/widget-procs.tcl . The code is "ad_proc -public template::widget::editor ... " in file: widget- procs.tcl or widget- procs.tcl

For the moment, it only works for Internet Explorer 4.0 or above, and I've left room for future development for Netscape.

Question 1:

For module notes now to update content after the submit button is pressed, it would have to recognise that it's now talking to an iframe (iframe's innerhtml) rather than, say, a textarea. However, I have trouble understanding the form templates which add-edit.tcl in notes/www use:

if [template::form is_valid new_note] {

  set user_id [ad_conn user_id] 
set peeraddr [ad_conn peeraddr]

if [info exists note_id] {

    db_dml note_update { 
      update notes 
set title = :title,
body = :body
where note_id = :note_id
}
} else {
db_exec_plsql new_note {
declare
        id integer; 
begin
        id := note.new( 
owner_id => :user_id,
title => :title,
body => :body,
creation_user => :user_id,
creation_ip => :peeraddr,
context_id => :package_id
);
end;
}
}

ad_returnredirect "."
}

And more specifically the meaning of ':' before 'title', 'body' etc. If I can assign the content of the iframe's innerhtml and assign it to the sql string, I think I am there.

Question 2

Altough I keep updating the file the iframe is sourcing from (ie. src=body.html), because the filename does not change, the browser kept displaying the cached body.html content inside the iframe. I've already used the tag: (meta http-equiv="Refresh" content="5") but without success. Any ideas?

Thanks for your help in advance. And I would really appreciate any opinion on whether or not I am on the right track. :)

Eric

I can answer the easiest part. :)

the ':' tells the db driver that this refers to a bind variable that's going to be sent separately, instead of interpolating the value into the string before handing it to the DB.  This allows the DB to cache its query plan for all instances of this query.  (Note the PG driver emulates bind variables by doing string interpolation "behind the scenes" so you don't actually get this benefit.)  With the ACS DB api, bind variables are grabbed from variables in the script with the same name.  For instance,

set bar "a value"

db_dml foo_dml "update foo set i = :bar"

I should mention that Eric's project is related to the thread: word prcessing in forms.
In that thread most people found a lot of value for the users, but found hard to maintain and did not like the fact that it would work only for IE (for a while)...
I am not sure if this is the right approach but would definetely add value. Since it is designed as an API that can be used from other packages it makes it more interesting.
Thanks for your help Jonathan :)

Do you have any idea where the variables title, body etc is set? (before :title is called?) in the notes module? I have examined the file add-edit.tcl in the notes module, and I can not understand how the code:

template::element create new_note body

    -widget textarea  
-datatype text
-label "Body"
-html { rows 10 cols 40 wrap soft }
-value $body

actually sets the variable 'body'.

From my understanding, '-widget textarea' defined in widget- procs.tcl only displays the textarea and its content (from database). How does the file notes/www/add-edit.tcl get the new content in the body textarea inputed by the user?

thanks :)

Eric

what sets the variables body and title is ad_page_contract.  This tells it to expect those variables from the get or post request.  In this case it looks like they are coming from www/index.adp.