Index: openacs-4/packages/xowiki/tcl/form-field-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xowiki/tcl/form-field-procs.tcl,v diff -u -r1.284.2.185 -r1.284.2.186 --- openacs-4/packages/xowiki/tcl/form-field-procs.tcl 4 Jan 2022 17:49:40 -0000 1.284.2.185 +++ openacs-4/packages/xowiki/tcl/form-field-procs.tcl 9 Jan 2022 17:23:26 -0000 1.284.2.186 @@ -114,17 +114,20 @@ Convert from form_constraint syntax to a dict. This is just a partial implementation to be probably extended in the future. it expects that the type is the first element and ignores everything - not in the synteax "*=*", or skips "@*" fields. Don't expect this + not in the syntax "*=*", or skips "@*" fields. Don't expect this to be fully reversible. } { set result "" foreach fc $form_constraints { #ns_log notice "... fc_to_dict works on <$fc>" - if {[regexp {^([^:]+):(.*)$} $fc _ field_name definition]} { + set p [string first : $fc] + if {$p > -1} { + set field_name [string range $fc 0 $p-1] + set short_spec [string range $fc $p+1 end] if {[string match @* $field_name]} continue - dict set result $field_name [spec_to_dict -name $field_name $definition] - dict set result $field_name _definition $definition + dict set result $field_name [spec_to_dict -name $field_name $short_spec] + dict set result $field_name _definition $short_spec } } return $result 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.542.2.130 -r1.542.2.131 --- openacs-4/packages/xowiki/tcl/xowiki-procs.tcl 2 Jan 2022 18:13:12 -0000 1.542.2.130 +++ openacs-4/packages/xowiki/tcl/xowiki-procs.tcl 9 Jan 2022 17:23:26 -0000 1.542.2.131 @@ -2389,11 +2389,16 @@ @return the pretty_link for the current page @see ::xowiki::Package instproc pretty_link } { + if {${:parent_id} eq "0"} { + set msg "you must not call pretty_link on a page with parent_id 0" + ad_log error $msg + error $msg + } ${:package_id} pretty_link -parent_id ${:parent_id} \ -anchor $anchor -query $query -absolute $absolute -siteurl $siteurl \ -lang $lang -download $download -page [self] \ -path_encode $path_encode \ - ${:name} \ + ${:name} } Page instproc detail_link {} { @@ -3176,6 +3181,23 @@ return $content } + Page instproc content_header_append {text} { + # + # This function is to be called on pages that want to prepend + # content prior to the main content. This is especially important + # for HTML forms (e.g. produced by the xowiki::Form renderer), + # where the form-body is not allowed to contain nested forms. + # + append ::__xowiki__content_header $text \n + } + + Page instproc content_header_get {} { + if {[info exists ::__xowiki__content_header]} { + return $::__xowiki__content_header + } + } + + Page instproc form_field_index {form_field_objs} { set marker ::__computed_form_field_names($form_field_objs) if {[info exists $marker]} return @@ -3392,7 +3414,7 @@ if {![nsf::is object $context]} { ::xo::ConnectionContext require \ -package_id $package_id \ - -url [:pretty_link] + -url [::$package_id pretty_link ${:name}] } set creation_user [$context user_id] } @@ -4013,9 +4035,10 @@ # OpenACS 5.10: In case we have a folder instances without the # "description" field set, and we use the new folder.form, and the # update script was not yet executed, folders might appear as - # empty. In htese cases, call child-resosurces manually. + # empty. In these cases, call child-resources manually. # if {$html eq "" && [:is_folder_page]} { + ns_log warning "render_content: [:item_id] {$name} is a folder page without a content (deprecated)" set html [:include child-resources] } @@ -4174,7 +4197,7 @@ set html ""; set mime "" lassign ${:text} html mime set content [:substitute_markup $html] - } elseif {[lindex ${:form} 0] ne ""} { + } elseif {[lindex ${:form} 0] ne ""} { set content [[self class] disable_input_fields [lindex ${:form} 0]] } else { set content "" @@ -4187,7 +4210,39 @@ return [:form_constraints] } - + FormPage instproc create_form_fields_from_names { + {-lookup:switch} + {-set_values:switch} + {-form_constraints} + field_names + } { + # + # Create form-fields from field names. When "-lookup" is + # specified, the code tries to reuseexisting form-field instead of + # creating/recreating it. + # + # Since create_raw_form_field uses destroy_on_cleanup, we do not + # have to care here about destroying the objects. + # + set form_fields {} + foreach field_name $field_names { + if {$lookup && [:form_field_exists $field_name]} { + #:msg "... found form_field for $field_name" + lappend form_fields [:lookup_form_field -name $field_name {}] + } else { + #:msg "create '$spec_name' with spec '$short_spec'" + lappend form_fields [:create_raw_form_field \ + -name $field_name \ + -form_constraints $form_constraints \ + ] + } + } + if {$set_values} { + :load_values_into_form_fields $form_fields + } + return $form_fields + } + Page instproc create_form_fields_from_form_constraints { {-lookup:switch} form_constraints @@ -4214,7 +4269,9 @@ lappend form_fields [:create_raw_form_field \ -name $spec_name \ -slot [:find_slot $spec_name] \ - -spec $short_spec] + -spec $short_spec \ + -form_constraints $form_constraints \ + ] } } return $form_fields @@ -5098,13 +5155,11 @@ # # Produce an HTML rendering from the FormPage. # - #set package_id ${:package_id} :include_header_info -prefix form_view if {[::xo::cc mobile]} { :include_header_info -prefix mobile } - set text [:get_from_template text] if {$text ne ""} { catch {set text [lindex $text 0]} @@ -5165,7 +5220,6 @@ return $HTML } - FormPage instproc get_value {{-field_spec ""} {-cr_field_spec ""} before varname} { # # Read a property (instance attribute) and return 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.368.2.105 -r1.368.2.106 --- openacs-4/packages/xowiki/tcl/xowiki-www-procs.tcl 2 Jan 2022 16:15:02 -0000 1.368.2.105 +++ openacs-4/packages/xowiki/tcl/xowiki-www-procs.tcl 9 Jan 2022 17:23:26 -0000 1.368.2.106 @@ -1912,8 +1912,10 @@ # make use of the same templating machinery below. # if {$content eq ""} { - set content [:render] + set content [:content_header_get][:render] #:msg "--after render" + } else { + set content [:content_header_get]$content } # @@ -2265,6 +2267,7 @@ {-configuration ""} {-omit_field_name_spec:boolean false} {-nls_language ""} + {-form_constraints ""} } { #ns_log notice "... create_raw_form_field name $name spec '$spec'" set save_slot $slot @@ -2323,6 +2326,7 @@ {-configuration ""} {-omit_field_name_spec:boolean false} {-nls_language ""} + {-form_constraints ""} } { # # For workflows, we do not want to get the form constraints of the @@ -2341,7 +2345,7 @@ # Get for the current page (self) the form-constraints and # return the spec for the specifiled name. # - set short_spec [:get_short_spec $name] + set short_spec [:get_short_spec -form_constraints $form_constraints $name] #:log "$name get_short_spec returns <$short_spec>" } @@ -2525,7 +2529,16 @@ } FormPage ad_instproc set_form_data {form_fields} { - Store the instance attributes or default values in the form. + + Store the instance attributes or default values into the form via + set_form_value. This function iterates over the provided + form-fields and checks, if these are known fields in the current + form. These known field names are defined via the method + "field_names" that extracts these names from a form. + + If one wants to load all values from an FormPage into the provided + form-fields, use method "load_values_into_form_fields" instead. + } { ::xo::require_html_procs @@ -2594,8 +2607,8 @@ #:msg "fields $field_names // $form_fields" #foreach f $form_fields { :msg "... $f [$f name]" } # - # We have a form and get all form input from the fields of the - # from into form field objects. + # We have the form data and get all form_parameters into the + # form-field objects. # foreach att $field_names { #:msg "getting att=$att" @@ -2885,6 +2898,7 @@ } FormPage instproc field_names {{-form ""}} { + #ns_log notice "=== field_names form <$form>" # # Ge the field-names mentioned in form (the provided form has # always highest precedence). @@ -2993,7 +3007,13 @@ } - FormPage instproc load_values_into_form_fields {form_fields} { + FormPage ad_instproc load_values_into_form_fields {form_fields} { + + Load either the instance variables or the instance attributes into + the provided form-fields. The function sets the values based on + the default values and the values for the current object. + + } { set is_new [:is_new_entry ${:name}] foreach f $form_fields {