Index: openacs-4/packages/xowiki/tcl/includelet-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xowiki/tcl/includelet-procs.tcl,v diff -u -r1.52 -r1.53 --- openacs-4/packages/xowiki/tcl/includelet-procs.tcl 12 Sep 2008 12:10:42 -0000 1.52 +++ openacs-4/packages/xowiki/tcl/includelet-procs.tcl 12 Sep 2008 17:28:42 -0000 1.53 @@ -149,6 +149,24 @@ return $prefix$suffix } + ::xowiki::Includelet proc publish_status_clause {{-base_table ci} value} { + if {$value eq "all"} { + # legacy + set publish_status_clause "" + } else { + array set valid_state [list production 1 ready 1 life 1 expired 1] + set clauses [list] + foreach state [split $value |] { + if {![info exists valid_state($state)]} { + error "no such state: '$state'; valid states are: production, ready, life, expired" + } + lappend clauses "$base_table.publish_status='$state'" + } + set publish_status_clause " and ([join $clauses { or }])" + } + return $publish_status_clause + } + ::xowiki::Includelet proc locale_clause { -revisions -items @@ -208,6 +226,8 @@ return [list $cnames $extra_where_clause] } + + ::xowiki::Includelet instproc resolve_page_name {page_name} { return [[my set __including_page] resolve_included_page_name $page_name] } @@ -2634,7 +2654,11 @@ {method list} } form-menu-button-answers instproc render {} { - set count [[my form] count_usages] + set (publish_status) ready + array set "" [::xowiki::PageInstance get_list_from_form_constraints \ + -name @table_properties \ + -form_constraints [[my form] get_form_constraints -trylocal true]] + set count [[my form] count_usages -publish_status $(publish_status)] my label_suffix " ($count)" next } @@ -2723,6 +2747,22 @@ set form_constraints [$form_item get_form_constraints -trylocal true] #my msg fc=[$form_item get_form_constraints] + # load table properties; order_by won't work due to comma, but solve that later (TODO) + set table_properties [::xowiki::PageInstance get_list_from_form_constraints \ + -name @table_properties \ + -form_constraints $form_constraints] + foreach {attr value} $table_properties { + switch $attr { + orderby - publish_status - category_id - unless - + where - with_categories - csv - voting_form - + voting_form_form - voting_form_anon_instances { + set $attr $value + #my msg " set $attr $value" + } + default {error "unknown table property '$attr' provided"} + } + } + if {![info exists field_names]} { set fn [::xowiki::PageInstance get_short_spec_from_form_constraints \ -name @table \ Index: openacs-4/packages/xowiki/tcl/xowiki-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xowiki/tcl/xowiki-procs.tcl,v diff -u -r1.276 -r1.277 --- openacs-4/packages/xowiki/tcl/xowiki-procs.tcl 12 Sep 2008 14:32:02 -0000 1.276 +++ openacs-4/packages/xowiki/tcl/xowiki-procs.tcl 12 Sep 2008 17:28:42 -0000 1.277 @@ -1456,12 +1456,12 @@ PageTemplate parameter { {render_adp 0} } - PageTemplate instproc count_usages {{-all false}} { - return [::xowiki::PageTemplate count_usages -item_id [my item_id] -all $all] + PageTemplate instproc count_usages {{-publish_status ready}} { + return [::xowiki::PageTemplate count_usages -item_id [my item_id] -publish_status $publish_status] } - PageTemplate proc count_usages {-item_id:required {-all:boolean false}} { - set publish_status_clause [expr {$all ? "" : " and i.publish_status <> 'production' "}] + PageTemplate proc count_usages {-item_id:required {-publish_status ready}} { + set publish_status_clause [::xowiki::Includelet publish_status_clause -base_table i $publish_status] set count [db_string [my qn count_usages] \ "select count(page_instance_id) from xowiki_page_instance, cr_items i \ where page_template = $item_id \ @@ -1474,6 +1474,21 @@ # PageInstance methods # + PageInstance proc get_list_from_form_constraints {-name -form_constraints} { + set spec [::xowiki::PageInstance get_short_spec_from_form_constraints \ + -name $name \ + -form_constraints $form_constraints] + set result [list] + foreach spec [split $spec ,] { + if {[regexp {^([^=]+)=(.*)$} $spec _ attr value]} { + lappend result $attr $value + } else { + my log "can't parse $spec in attribute and value; ignoring" + } + } + return $result + } + PageInstance proc get_short_spec_from_form_constraints {-name -form_constraints} { # For the time being we cache the form_constraints per request as a global # variable, which is reclaimed at the end of the connection. @@ -1659,10 +1674,10 @@ } next } - PageInstance instproc count_usages {{-all false}} { - # TODO: if we continue this approach, this method should go into Page - return [::xowiki::PageTemplate count_usages -item_id [my item_id] -all $all] - } + # PageInstance instproc count_usages {{-all false}} { + # # TODO: if we continue this approach, this method should go into Page + # return [::xowiki::PageTemplate count_usages -item_id [my item_id] -all $all] + # } # # Methods of ::xowiki::Object @@ -1726,9 +1741,23 @@ dom parse -simple -html $form doc $doc documentElement root my dom_disable_input_fields -with_submit $with_submit $root + set form [lindex [$root selectNodes //form] 0] + Form add_dom_attribute_value $form class "margin-form" return [$root asHTML] } + Form proc add_dom_attribute_value {dom_node attr value} { + if {[$dom_node hasAttribute $attr]} { + set old_value [$dom_node getAttribute $attr] + if {[lsearch -exact $old_value $value] == -1} { + append value " " $old_value + } else { + set value $old_value + } + } + $dom_node setAttribute $attr $value + } + Form instproc get_content {} { my instvar text form ::xowiki::Form requireFormCSS @@ -1766,7 +1795,7 @@ set form_fields [list] foreach name_and_spec $form_constraints { regexp {^([^:]+):(.*)$} $name_and_spec _ spec_name short_spec - if {$spec_name eq "@table" || $spec_name eq "@categories"} continue + if {[string match "@table*" $spec_name] || $spec_name eq "@categories"} continue #my msg "checking spec '$short_spec' for form field '$spec_name'" lappend form_fields [my create_raw_form_field \ @@ -1849,21 +1878,7 @@ # # Build WHERE clause # - if {$publish_status eq "all"} { - # legacy - set publish_status_clause "" - } else { - array set valid_state [list production 1 ready 1 life 1 expired 1] - set clauses [list] - foreach state [split $publish_status |] { - if {![info exists valid_state($state)]} { - error "no such state: '$state'; valid states are: production, ready, life, expired" - } - lappend clauses "ci.publish_status='$state'" - } - set publish_status_clause " and ([join $clauses { or }])" - } - + set publish_status_clause [::xowiki::Includelet publish_status_clause -base_table ci $publish_status] set filter_clause "" array set wc $h_where set use_hstore [expr {[::xo::db::has_hstore] && @@ -2047,14 +2062,22 @@ if {$form_vars} {foreach v $field_names {my set __field_in_form($v) 1}} set form_fields [my create_form_fields $field_names] my load_values_into_form_fields $form_fields + + # deactivate form-fields and do some final sanity checks + foreach f $form_fields {$f set_disabled 1} + my form_fields_sanity_check $form_fields + set form [my regsub_eval \ [template::adp_variable_regexp] $form \ {my form_field_as_html -mode display "\\\1" "\2" $form_fields}] + # we parse the form just for the margin-form.... maybe regsub? dom parse -simple -html $form doc $doc documentElement root - my set_form_data $form_fields - return [Form disable_input_fields [$root asHTML]] + set form_node [lindex [$root selectNodes //form] 0] + Form add_dom_attribute_value $form_node class "margin-form" + #my set_form_data $form_fields + return [$root asHTML] } } Index: openacs-4/packages/xowiki/tcl/xowiki-www-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xowiki/tcl/xowiki-www-procs.tcl,v diff -u -r1.167 -r1.168 --- openacs-4/packages/xowiki/tcl/xowiki-www-procs.tcl 11 Sep 2008 13:47:14 -0000 1.167 +++ openacs-4/packages/xowiki/tcl/xowiki-www-procs.tcl 12 Sep 2008 17:28:42 -0000 1.168 @@ -821,7 +821,7 @@ set f [my create_raw_form_field -name $name -slot [my find_slot $name]] } - #my msg "$found $name mode=$mode type=[$f set type] value=[$f value]" + #my msg "$found $name mode=$mode type=[$f set type] value=[$f value] disa=[$f exists disabled]" if {$mode eq "edit" || [$f display_field]} { set html [$f asHTML] } else { @@ -1019,6 +1019,21 @@ } } + FormPage instproc form_fields_sanity_check {form_fields} { + foreach f $form_fields { + if {[$f exists disabled]} { + # don't mark disabled fields as required + if {[$f required]} { + $f required false + } + #don't show the help-text, if you cannot input + if {[$f help_text] ne ""} { + $f help_text "" + } + } + } + } + FormPage instproc edit { {-validation_errors ""} {-disable_input_fields 0} @@ -1176,20 +1191,9 @@ } } } - + # some final sanity checks - foreach f $form_fields { - if {[$f exists disabled]} { - # don't mark disabled fields as required - if {[$f required]} { - $f required false - } - #don't show the help-text, if you cannot input - if {[$f help_text] ne ""} { - $f help_text "" - } - } - } + my form_fields_sanity_check $form_fields # The following command would be correct, but does not work due to a bug in # tdom. @@ -1263,10 +1267,7 @@ } set url [export_vars -base [$package_id pretty_link [my name]] {{m "edit"} return_url}] $form setAttribute action $url method POST - set oldCSSClass [expr {[$form hasAttribute class] ? [$form getAttribute class] : ""}] - if {[lsearch -exact $oldCSSClass margin-form] == -1} { - $form setAttribute class [string trim "$oldCSSClass margin-form"] - } + Form add_dom_attribute_value $form class "margin-form" } my set_form_data $form_fields if {$disable_input_fields} {