#*******************************************************************************
#
# htmlClasses.itcl
#
# This GENTLE command script defines common functions and [incr Tcl]
# objects used by HTML-generating scripts.
#
#*******************************************************************************
#*******************************************************************************
# HTML Page Class.
#*******************************************************************************
itcl_class Page {
public bodyAttributes {BGCOLOR="#00009C" TEXT="#FFFF00"}
public interval 15
public timedRepeat yes
public title {}
public version "HTTP/1.0"
protected client
protected numFields 0
protected pageTimer {}
protected fieldList ; # Arrays of information indexed by field number.
constructor {theClient config} {
set client $theClient
$client Write "$version 200"
if {$timedRepeat} then {
$client Write "Content-type: multipart/x-mixed-replace;boundary=EndOfUpdate"
$client Write ""
$client Write -- "--EndOfUpdate"
}
global servedBy
set servedBy($client) $this
}
destructor {
if {$timedRepeat} then {
catch {$pageTimer Cancel}
}
catch {
global servedBy
unset servedBy($client)
}
while {$numFields > 0} {
if [catch {$fieldList($numFields) delete} emsg] then {
puts "($this::destructor) Error destroying $fieldList($numFields): $emsg"
}
incr numFields -1
}
}
method Add {field} {
set fieldList([incr numFields]) $field
}
method Generate {{repeat true}} {
set pageTimer {}
catch {
$client Write "Content-type: text/html"
$client Write ""
$client Write ""
$client Write "
$title"
$client Write ""
$client Write "$title
"
$client Write "([tod -format {%D %T}])
"
set i 0
while {[incr i] <= $numFields} {
catch {$fieldList($i) Generate $client}
}
$client Write ""
if {$timedRepeat} then {
$client Write -- "--EndOfUpdate"
Repeat
}
}
}
method Repeat {} {
if {$interval > 0} then {
set pageTimer [timer $interval -expire "$this Generate"]
}
}
}
#*******************************************************************************
# HTML Column Class.
#*******************************************************************************
itcl_class Column {
public rowAttributes {}
public tableAttributes {}
public title {}
protected numFields 0
protected fieldList ; # Array of information indexed by field number.
constructor {config} {
}
destructor {
while {$numFields > 0} {
if [catch {$fieldList($numFields) delete} emsg] then {
puts "($this::destructor) Error destroying $fieldList($numFields): $emsg"
}
incr numFields -1
}
}
method Add {field} {
set fieldList([incr numFields]) $field
}
method Generate {client} {
if {$title != ""} then {
$client Write "$title
"
}
$client Write ""
set i 0
while {[incr i] <= $numFields} {
$client Write ""
catch {$fieldList($i) Generate $client}
$client Write " |
"
}
$client Write "
"
}
}
#*******************************************************************************
# HTML Row Class.
#*******************************************************************************
itcl_class Row {
public rowAttributes "VALIGN=BASELINE"
public tableAttributes {}
public title {}
protected numFields 0
protected fieldList ; # Array of information indexed by field number.
constructor {config} {
}
destructor {
while {$numFields > 0} {
if [catch {$fieldList($numFields) delete} emsg] then {
puts "($this::destructor) Error destroying $fieldList($numFields): $emsg"
}
incr numFields -1
}
}
method Add {field} {
set fieldList([incr numFields]) $field
}
method Generate {client} {
if {$title != ""} then {
$client Write "$title
"
}
$client Write ""
set i 0
while {[incr i] <= $numFields} {
$client Write ""
catch {$fieldList($i) Generate $client}
$client Write " | "
}
$client Write "
"
}
}
#*******************************************************************************
# HTML Section Class.
#*******************************************************************************
itcl_class Section {
public title {}
protected numFields 0
protected label ; # Arrays of information indexed by field number.
protected updateCommand
constructor {config} {
}
method Add {theLabel theUpdateCommand} {
set label([incr numFields]) $theLabel
set updateCommand($numFields) $theUpdateCommand
}
method Generate {client} {
if {$title != ""} then {
$client Write "$title
"
}
$client Write ""
$client Write ""
set i 0
while {[incr i] <= $numFields} {
$client Write "$label($i) "
}
$client Write " | "
$client Write ""
set i 0
while {[incr i] <= $numFields} {
set value [string trimright [eval $updateCommand($i)]]
if {$value == ""} then {
$client Write " "
} elseif {[string index $value 0] == "<"} then {
$client Write "<[string range $value 1 end] "
} else {
$client Write "$value "
}
}
$client Write " |
"
}
}