Index: openacs-4/packages/acs-templating/tcl/richtext-or-file-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-templating/tcl/richtext-or-file-procs.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/acs-templating/tcl/richtext-or-file-procs.tcl 29 Jan 2004 15:46:35 -0000 1.1 @@ -0,0 +1,308 @@ +ad_library { + Rich text input widget and datatype for OpenACS templating system. + + @author Lars Pind (lars@pinds.com) + @creation-date 2003-01-27 + @cvs-id $Id: richtext-or-file-procs.tcl,v 1.1 2004/01/29 15:46:35 lars Exp $ +} + +namespace eval template {} +namespace eval template::data {} +namespace eval template::data::transform {} +namespace eval template::data::validate {} +namespace eval template::util {} +namespace eval template::util::richtext_or_file {} +namespace eval template::widget {} + +ad_proc -public template::util::richtext_or_file { command args } { + Dispatch procedure for the richtext_or_file object +} { + eval template::util::richtext_or_file::$command $args +} + +ad_proc -public template::util::richtext_or_file::create { + {storage_type {}} + {mime_type {}} + {text {}} + {filename {}} + {tmp_filename {}} + {content_url {}} +} { + return [list $storage_type $mime_type $text $filename $tmp_filename $content_url] +} + +ad_proc -public template::util::richtext_or_file::acquire { type { value "" } } { + Create a new richtext_or_file value with some predefined value + Basically, create and set the richtext_or_file value +} { + set richtext_or_file_list [template::util::richtext_or_file::create] + return [template::util::richtext_or_file::set_property $type $richtext_or_file_list $value] +} + +ad_proc -public template::util::richtext_or_file::formats {} { + Returns a list of valid richtext_or_file formats +} { + return { text/enhanced text/plain text/html text/fixed-width } +} + +ad_proc -public template::util::richtext_or_file::format_options {} { + Returns a formatting option list +} { + return { + {"Enhanced Text" text/enhanced} + {"Plain Text" text/plain} + {"Fixed-width Text" text/fixed-width} + {"HTML" text/html} + } +} + +ad_proc -public template::data::validate::richtext_or_file { value_ref message_ref } { + + upvar 2 $message_ref message $value_ref richtext_or_file_list + + set storage_type [lindex $richtext_or_file_list 0] + set mime_type [lindex $richtext_or_file_list 1] + set text [lindex $richtext_or_file_list 2] + set filename [lindex $richtext_or_file_list 3] + set tmp_filename [lindex $richtext_or_file_list 4] + set content_url [lindex $richtext_or_file_list 5] + + if { ![empty_string_p $text] && [lsearch -exact [template::util::richtext_or_file::formats] $mime_type] == -1 } { + set message "Invalid text format, '$mime_type'." + return 0 + } + + # enhanced text and HTML needs to be security checked + if { [lsearch { text/enhanced text/html } $mime_type] == -1 } { + set check_result [ad_html_security_check $text] + if { ![empty_string_p $check_result] } { + set message $check_result + return 0 + } + } + + return 1 +} + +ad_proc -public template::data::transform::richtext_or_file { element_ref } { + + upvar $element_ref element + set element_id $element(id) + + # We need to return the empty list in order for form builder to think of it + # as a non-value in case of a required element. + + set storage_type [ns_queryget $element_id.storage_type] + switch $storage_type { + text { + set text [ns_queryget $element_id.text] + if { [empty_string_p $text] } { + return [list] + } + set mime_type [ns_queryget $element_id.mime_type] + + return [list [list "text" $mime_type $text {} {} {}]] + } + file { + set file [template::util::file_transform $element_id.file] + if { [empty_string_p $file] } { + return [list] + } + set filename [template::util::file::get_property filename $file] + set tmp_filename [template::util::file::get_property tmp_filename $file] + set mime_type [template::util::file::get_property mime_type $file] + + return [list [list "file" $mime_type {} $filename $tmp_filename {}]] + } + default { + return [list] + } + } +} + +ad_proc -public template::util::richtext_or_file::set_property { what richtext_or_file_list value } { + Set a property of the richtext_or_file datatype. Valid proerties are: + +
" + } else { + append output "" + } + + if { [empty_string_p $storage_type] || [string equal $storage_type "text"] } { + append output {} + + append output [textarea_internal "$element(id).text" attributes $text] + append output "" + append output "" + append output "" + append output "
Format: [menu "$element(id).mime_type" [template::util::richtext_or_file::format_options] $mime_type attributes]" + } + + if { [empty_string_p $storage_type] } { + append output "
" + } + + if { [string equal $storage_type "file"] } { + append output [template::util::richtext_or_file::get_property html_value $element(value)] + append output "" + } + } else { + # Display mode + if { [info exists element(value)] } { + + # TODO + + append output [template::util::richtext_or_file::get_property html_value $element(value)] + append output "" + append output "" + } + } + + return $output +}Replace uploaded file: " + append output "" + } + if { [empty_string_p $storage_type] } { + append output "" + } + + + if { [empty_string_p $storage_type] } { + append output "