Index: openacs-4/packages/imsld/tcl/imsld-runtime-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/imsld/tcl/imsld-runtime-procs.tcl,v diff -u -r1.3 -r1.4 --- openacs-4/packages/imsld/tcl/imsld-runtime-procs.tcl 29 Jun 2006 09:27:57 -0000 1.3 +++ openacs-4/packages/imsld/tcl/imsld-runtime-procs.tcl 4 Jul 2006 18:06:02 -0000 1.4 @@ -30,6 +30,8 @@ {-identifier ""} {-property_id ""} } { + Sets a property to the given value. If some restriction is violated returns 0 and an explanation. +} { # context info db_1row context_info { select ic.item_id as component_item_id, @@ -62,8 +64,79 @@ where property_id = :property_id } } + + # validate against restrictions + set enumeration_list [list] + db_foreach restriction { + select restriction_type, + value as restriction_value + from imsld_restrictions + where property_id = :property_id + } { + switch $restriction_type { + length { + if { [length $value] <> $restriction_value } { + return [list 0 "<#_ The length must be %restriction_value% #>"] + } + } + minLength { + if { [length $value] < $restriction_value } { + return [list 0 "<#_ The length must be greather than %restriction_value% #>"] + } + } + maxLength { + if { [length $value] > $restriction_value } { + return [list 0 "<#_ The length must be lower than %restriction_value% #>"] + } + } + enumeration { + lappend enumeration_list $restriction_value + } + maxInclusive { + if { $value > $restriction_value } { + return [list 0 "<#_ The value must be lower than %restriction_value% (inclusive #>"] + } + } + minInclusive { + if {$value < $restriction_value } { + return [list 0 "<#_ The value must be greather than %restriction_value% (inclusive) #>"] + } + } + maxExclusive { + if { $value >= $restriction_value } { + return [list 0 "<#_ The value must be lower than %restriction_value% #>"] + } + } + minExclusive { + if { $value <= $restriction_value } { + return [list 0 "<#_ The value must be greather than %restriction_value% #>"] + } + } + totalDigits { + if { [expr int($value)] <> $restriction_value } { + return [list 0 "<#_ The integer part can't have more than %restriction_value% digits #>"] + } + } + fractionDigits { + if { [expr [string length "$value"] - [string last "." "$value"] - 1] > $restriction_value } { + return [list 0 "<#_ The decimal digits can't be more than %restriction_value% #>"] + } + } + pattern { + if { ![regexp "$restriction_value" $value] } { + return [list 0 "<#_ The value (%value%) doesn't match with the expression %restriction_value% #>"] + } + } + } + } + + if { [llength $enumeration_list] && [lsearch -exact $enumeration_list $value] == -1 } { + return [list 0 "<#_ The value %value% is not alowed #>"] + } + # instance info + set role_instance_id "" if { ![string eq $role_id ""] } { # find the role instance which the user belongs to set role_instance_id [imsld::roles::get_user_role_instance -run_id $run_id -role_id $role_id -user_id $user_id] Index: openacs-4/packages/imsld/www/imsld-content-serve.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/imsld/www/imsld-content-serve.tcl,v diff -u -r1.2 -r1.3 --- openacs-4/packages/imsld/www/imsld-content-serve.tcl 21 Jun 2006 12:33:34 -0000 1.2 +++ openacs-4/packages/imsld/www/imsld-content-serve.tcl 4 Jul 2006 18:06:03 -0000 1.3 @@ -56,7 +56,8 @@ # 2. replace the view-property-group tags with the properties titles(optional) and value of all the referenced properties # 3. replace the set-property tags with input fields depending on the property type # 4. replace the set-groperty-group tags with one input field per each referenced property in the group -# 5. if there was at least one set-property* tag, add a submit button +# 5. if there was at least one set-property* tag, add a submit button (FIX ME: currently for each set-property* a new form is added) +# 6. for each class, check the visibility value in the database # 1. view-property nodes set view_property_nodes [$dom_root selectNodes {//*[local-name()='view-property']}] @@ -249,7 +250,7 @@ # get the restrictions and translate them to HTML # currently, in HTML we can only deal with the restriction types: length, - # length, maxlength, enumeration and totaldigits. + # maxlength, enumeration and totaldigits. # the rest are checked after submission set restriction_nodes [list] set input_text_node "" @@ -263,7 +264,6 @@ switch $restriction_type { length - maxlength - - maxinclusive - totaldigits { if { [string eq "" $input_text_node] } { set input_text_node [$dom_doc createElement "input"] @@ -286,25 +286,6 @@ $option_node appendChild [$dom_doc createTextNode "$restriction_value"] $select_node appendChild $option_node } - maxexclusive { - if { [string eq "" $input_text_node] } { - set input_text_node [$dom_doc createElement "input"] - $input_text_node setAttribute type "text" - $input_text_node setAttribute name "instances_ids.$instance_id" - } - $input_text_node setAttribute maxlength [expr $restriction_value - 1] - $input_text_node setAttribute value "$value" - } - minlength { - } - mininclusive { - } - minexclusive { - } - pattern { - } - whitespace { - } } } if_no_rows { # no restrictions @@ -422,7 +403,7 @@ set identifier [lindex $properties_in_group 5] # get the restrictions and translate them to HTML # currently, in HTML we can only deal with the restriction types: length, - # length, maxlength, enumeration and totaldigits. + # maxlength, enumeration and totaldigits. # the rest are checked after submission set input_text_node "" set select_node "" @@ -435,7 +416,6 @@ switch $restriction_type { length - maxlength - - maxinclusive - totaldigits { if { [string eq "" $input_text_node] } { set input_text_node [$dom_doc createElement "input"] @@ -458,25 +438,6 @@ $option_node appendChild [$dom_doc createTextNode "$restriction_value"] $select_node appendChild $option_node } - maxexclusive { - if { [string eq "" $input_text_node] } { - set input_text_node [$dom_doc createElement "input"] - $input_text_node setAttribute type "text" - $input_text_node setAttribute name "instances_ids.$instance_id" - } - $input_text_node setAttribute maxlength [expr $restriction_value - 1] - $input_text_node setAttribute value "$value" - } - minlength { - } - mininclusive { - } - minexclusive { - } - pattern { - } - whitespace { - } } } if_no_rows { # no restrictions @@ -520,4 +481,33 @@ $form_node removeAttribute xmlns } +# 6. class nodes +set class_nodes [$dom_root selectNodes {//*[@class]}] +foreach class_node $class_nodes { + # get requested info + set class_name_list [split [string tolower [$class_node getAttribute class]] " "] + + foreach class_name $class_name_list { + # get class info + if { [db_0or1row class_info { + select is_visible_p, + title, + with_control_p + from imsld_attribute_instances + where run_id = :run_id + and identifier = :class_name + and type = 'class' + }] } { + if { [string eq $is_visible_p "f"] } { + set style_value [$class_node getAttribute "style" ""] + if { ![string eq style_value ""] } { + $class_node setAttribute "style" "display:none;" + } else { + $class_node setAttribute "style" "${style_value}; display:none;" + } + } + } + } +} + ns_return 200 application/xml "[$dom_root asXML]" \ No newline at end of file Index: openacs-4/packages/imsld/www/properties-value-set.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/imsld/www/properties-value-set.tcl,v diff -u -r1.1 -r1.2 --- openacs-4/packages/imsld/www/properties-value-set.tcl 20 Jun 2006 19:20:38 -0000 1.1 +++ openacs-4/packages/imsld/www/properties-value-set.tcl 4 Jul 2006 18:06:03 -0000 1.2 @@ -1,6 +1,7 @@ # packages/imsld/www/properties-value-set.tcl ad_page_contract { + Sets the property value through a function call } { instances_ids:array,notnull return_url @@ -16,7 +17,13 @@ if { [info exists instances_ids($instance_id)] } { # avoiding hacks set value $instances_ids($instance_id) - imsld::runtime::property::instance_value_set -instance_id $instance_id -value $value + db_1row instance_info_id { + select property_id, + run_id + from imsld_property_instances + where instance_id = :instance_id + } + imsld::runtime::property::property_value_set -run_id $run_id -user_id [ad_conn user_id] -value $value -property_id $property_id } }