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.13 2018/12/06 21:24:17 hectorr 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 } { 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 {}} } { Create a richtext_or_file datastructure. } { 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/markdown 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} {"Markdown Text" text/markdown} {"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 } { Validate submitted richtext_or_file by checking that the format is valid, HTML doesn't contain illegal tags, etc. @param value_ref Reference variable to the submitted value @param message_ref Reference variable for returning an error message @return True (1) if the submitted value is valid, false (0) otherwise } { upvar 2 $message_ref message $value_ref richtext_or_file_list lassign $richtext_or_file_list storage_type mime_type text filename tmp_filename content_url if { $text ne "" && [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 { $mime_type in { text/enhanced text/html } } { set check_result [ad_html_security_check $text] if { $check_result ne "" } { set message $check_result return 0 } } return 1 } ad_proc -public template::data::transform::richtext_or_file { element_ref } { Transform submitted data into a valid richtext_or_file data structure (list) @param element_ref Reference variable to the form element @return Submitted data in the richtext_or_datafile list form } { 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 { $text eq "" } { 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 { $file eq "" } { 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 properties are:
}] template::add_event_listener \ -id "$element(id).storage_type_file" \ -script [subst {acs_RichText_Or_File_InputMethodChanged('$element(form_id)', '$element(id)', this);}] } else { append output [subst { }] } if { $storage_type eq "" || $storage_type eq "text" } { append output [subst {} \ [textarea_internal "$element(id).text" attributes $text] \ [subst {
Format: \ [menu "$element(id).mime_type" \ [template::util::richtext_or_file::format_options] \ $mime_type \ attributes]}] } if { $storage_type eq "" } { append output [subst {
}] template::add_event_listener \ -id "$element(id).storage_type_file" \ -script [subst {acs_RichText_Or_File_InputMethodChanged('$element(form_id)', '$element(id)', this);}] } if {$storage_type eq "file"} { append output \ [template::util::richtext_or_file::get_property html_value $element(value)] \ "" } } else { # Display mode if { [info exists element(value)] } { append output [template::util::richtext_or_file::get_property html_value $element(value)] append output "" append output "" append output "" } } return $output } # Local variables: # mode: tcl # tcl-indent-level: 4 # indent-tabs-mode: nil # End:Replace uploaded file: " \ [subst {}] } if { $storage_type eq "" } { append output [subst {}] } if { $storage_type eq "" } { append output "