Hello experts,
this is a knowlidge sharing topic.
All this stuff is solely my ideas nowhere else found on the net. So use it or let it (or give me points ;-))
First I have to describe the problem...
Before Rnext there are different places in design elements to place JavaScript code. The best place to deposit functions is the "JS Header" event on the form. This is not bad, but the big disadvantage is, that if you have some hundred lines of JavaScript code in this place the code is sent again and again to the browser with every browser request. No caching is done. Also if you have same functions on multiple forms you have to update all the forms when somethings is to change in JavaScript code. You can of corse place the code into the data/domino/html directory, but than you loose this fine design distribution and replication feature. You have to care about the JavaScript dataset names on the file system.
So wath would be the solution. I think, some sort of JavaScript libraries in the application databse.nsf.
For R5 this is solved easyly. Create a page. Call it best: "HeaderPage.js"
Mark in the page base property tab the checkbox: Treat page contents as HTML
Place now in this page all the JavaScript code you like to distribute to all forms.
Instead of placing the JavaScript code into forms "JS Header" events place this formula into forms "HTML Head Content" event:
"<SCRIPT LANGUAGE='JavaScript' SRC='/"+@Subset(@DbName;-1
)+"/Header
Page.js' ></SCRIPT>"
That was all. Now you can maintain your JavaScript code in the page and use it in twenty or more forms...
Wath to do in R4.x?
No problems...
Define a form for maintaining JavaScript code. In this form define multiple fields to be able to split your JavaScript code into multiple JavaScript file attachements. When creating a document with this form, than should the text of every field containing javascript code start with this string: </SCRIPT>
If you like to maintain css in the same form, than the field content css should start with this string: </STYLE>
For every field on the form you will get one attachment into the document.
Place into forms Postsave event this code:
Sub Postsave(Source As Notesuidocument)
Dim doc As NotesDocument
Set doc = Source.Document
Forall i In doc.Items
If (i.Type = TEXT) Then
If (Ucase$(Left$(i.text,7)) = "<SCRIPT") Then
Call AttachIncludeFile(doc, i.Name & ".js" , i.Text, "</SCRIPT>")
Elseif (Ucase$(Left$(i.text,6)) = "<STYLE") Then
Call AttachIncludeFile(doc, i.Name & ".css" , i.Text, "</STYLE>")
End If
End If
End Forall
Call doc.Save(True,False)
End Sub
And this additional function:
Sub AttachIncludeFile(doc As NotesDocument, Byval IncludeName As String, Byval IncludeText As String, Byval IncludeEndTag As String)
Dim attName As String
Dim attText As String
Dim txtStart As Integer
Dim txtLen As Integer
Dim fileName As String
Dim fileNum As Integer
Dim rtitem As NotesRichTextItem
Dim object As NotesEmbeddedObject
Set rtitem = doc.GetFirstItem( "Body" )
If Not (rtitem Is Nothing) Then
If ( rtitem.Type = RICHTEXT ) Then
Set object = rtitem.GetEmbeddedObject( IncludeName)
If Not (object Is Nothing) Then
Call object.Remove
End If
End If
Else
Set rtitem = New NotesRichTextItem( doc, "Body" )
End If
txtStart = Instr(IncludeText,">")+1
txtLen = Instr(Ucase$(IncludeText),
IncludeEndTag) - txtStart
If (txtStart > 0) Then
attText = Mid$(IncludeText, txtStart, txtLen)
fileNum = Freefile()
fileName = "C:\temp\" & IncludeName
Open fileName For Output As fileNum
Print #fileNum, attText
Close fileNum
Set object = rtitem.EmbedObject( EMBED_ATTACHMENT, "", fileName, fileName)
Kill fileName
End If
End Sub
The Postasave event and the AttachIncludeFile creates for every field either a js or a css attachment with the contenets of the field.
So you need only a view where you can lookup this document to access the attachments. As experts you know that this view has to be sorted in the first column.
When you have this, you can define in every form where you like to use this JavaScript attachments following formula:
path := "\'/"+@LeftBack(@Subset(@D
bName;-1);
"/")+"/con
fig.nsf/Fi
leLookup/J
avaScriptF
unctions/$
FILE/";
cssPref := "<link rel=stylesheet type=\'text/css\' href="+path;
jsPref := "<SCRIPT LANGUAGE=\'JavaScript\' SRC=" +path;
jsSuff := "\' ></SCRIPT>";
cssPref+"formcss.css\'>"+
jsPref+"navigate.js"+jsSuf
f+
jsPref+"workflow.js"+jsSuf
f+
jsPref+"all.js"+jsSuff
This example is showing how to acces the JavaScript attachments in a config.nsf database with a view FileLookup where the document is sorted as "JavaScriptFunctions"
From there are fetched four attachments to the form. Again, this is done only one time by the browser. Afterwards are the attachments fetched from browsers cache.
So, that is all.
I hope somebody can have any use of this.
Regards,
stamp