Index: openacs-4/packages/xowiki/tcl/xowiki-form-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xowiki/tcl/xowiki-form-procs.tcl,v diff -u -r1.61 -r1.62 --- openacs-4/packages/xowiki/tcl/xowiki-form-procs.tcl 21 Jun 2007 11:32:17 -0000 1.61 +++ openacs-4/packages/xowiki/tcl/xowiki-form-procs.tcl 22 Jun 2007 13:32:02 -0000 1.62 @@ -762,7 +762,10 @@ # these could support not only asWidgetSpec, but as well asHTML # todo: every formfield type should have its own class - Class FormField -parameter {{required false} {type text} {label} {name} {spell false} {size 80} spec} + Class FormField -parameter { + {required false} {type text} {label} {name} {spell false} {size 80} + {value ""} spec + } FormField instproc init {} { my instvar type options spec widget_type if {![my exists label]} {my label [string totitle [my name]]} @@ -774,9 +777,10 @@ text {set type text} date {set type date} boolean {set type boolean} + numeric {set type text; #for the time being} month {set type month} - label=* {my label [lindex [split $e =] 1]} - size=* {my size [lindex [split $e =] 1]} + label=* {my label [lindex [split $s =] 1]} + size=* {my size [lindex [split $s =] 1]} default {error "unknown spec for entry [my name]: '$s'"} } } @@ -815,6 +819,30 @@ } return $spec } + FormField instproc render_form_widget {} { + # todo: for all types + set atts [list type text] + foreach att {size name value} { + if {[my exists $att]} {lappend atts $att [my set $att]} + } + + ::html::div -class form-widget {::html::input $atts {}} + } + FormField instproc render_item {} { + ::html::div -class form-item-wrapper { + ::html::div -class form-label { + ::html::label -for [my name] { + ::html::t [my label] + } + if {[my required]} { + ::html::div -class form-required-mark { + ::html::t " (#acs-templating.required#)" + } + } + } + my render_form_widget + } + } FormField instproc renderValue {v} { if {[my exists options]} { foreach o [my set options] { 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.116 -r1.117 --- openacs-4/packages/xowiki/tcl/xowiki-procs.tcl 21 Jun 2007 11:32:17 -0000 1.116 +++ openacs-4/packages/xowiki/tcl/xowiki-procs.tcl 22 Jun 2007 13:32:02 -0000 1.117 @@ -7,7 +7,6 @@ } namespace eval ::xowiki { - # # create classes for different kind of pages # @@ -23,8 +22,28 @@ ::Generic::Attribute new -attribute_name creator -datatype text \ -pretty_name "Creator" } \ + -parameter { + page_id + {revision_id 0} + item_id + object_type + parent_id + package_id + name + title + text + {folder_id -100} + {lang en} + {render_adp 1} + {absolute_links 0} + } \ -form ::xowiki::WikiForm + # TODO: the following line is just a start. type, required+label should be just attributes + # of the slot object + ::xowiki::Page::slot::name set spec "text,required,label=#xowiki.name#" + + ::Generic::CrClass create PlainPage -superclass Page \ -pretty_name "XoWiki Plain Page" -pretty_plural "XoWiki Plain Pages" \ -table_name "xowiki_plain_page" -id_column "ppage_id" \ @@ -145,23 +164,7 @@ # Page definitions # - Page parameter { - page_id - {creator ""} - {revision_id 0} - item_id - object_type - parent_id - package_id - name - title - text - {folder_id -100} - {lang en} - {render_adp 1} - {absolute_links 0} - page_order - } + Page set recursion_count 0 Page array set RE { include {([^\\]){{([^<]+?)}}(\s|<|$)?} @@ -1066,6 +1069,7 @@ -parent_id [my parent_id] \ -publish_status "production" \ -page_template [my item_id]] + $f set __title_prefix [my title] $f save_new $package_id returnredirect \ [my query_parameter "return_url" [$package_id pretty_link [$f name]]?m=edit] 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.52 -r1.53 --- openacs-4/packages/xowiki/tcl/xowiki-www-procs.tcl 21 Jun 2007 11:32:17 -0000 1.52 +++ openacs-4/packages/xowiki/tcl/xowiki-www-procs.tcl 22 Jun 2007 13:32:02 -0000 1.53 @@ -296,6 +296,49 @@ return $html } + FormInstance instproc createFormField {{-spec ""} {-configuration ""} -name} { + if {$spec ne ""} { + set f [FormField new -name $name -spec $spec] + } else { + # + # try first to get the information from the form constraints + # + set short_spec [my get_short_spec $name] + if {$short_spec ne ""} { + set f [FormField new -name $name -spec $short_spec] + } else { + + # TODO: this could be made cleaner by using slots, which require xotcl 1.5.*. + # currently, i do not want to force an upgrade to the newer xotcl versions. + set class [my info class] + set __container [::xo::OrderedComposite new -destroy_on_cleanup] + foreach cl [concat $class [$class info heritage]] { + if {[$cl exists cr_attributes]} {$__container contains [$cl cr_attributes]} + } + + # + # try to get the information from the attribute definitions + # + foreach __att [$__container children] { + #ns_log notice "--field compare '$__field' '[$__att attribute_name]'" + if {[$__att attribute_name] eq $name} { + #ns_log notice "--field $name [$__att serialize]" + set f [FormField new \ + -label [$__att pretty_name] -type [$__att datatype] \ + -spec [lindex $__wspec 1]] + break + } + } + } + } + if {![info exists f]} { + error "could not find definitions for field $name" + } + $f destroy_on_cleanup + $f configure $configuration + return $f + } + FormInstance instproc edit {} { my instvar page_template doc root package_id @@ -319,37 +362,26 @@ } $fcn if {$anon_instances eq "f"} { - $root insertBeforeFromScript { - ::html::div -class form-item-wrapper { - ::html::div -class form-label { - ::html::label -for __name { - ::html::t "#xowiki.name#" - } - } - ::html::div -class form-widget { - ::html::input -type text -name __name -value [my set name] - } - } - ::html::div -class form-item-wrapper { - ::html::div -class form-label { - ::html::label -for __title { - ::html::t "#xowiki.title#: " - } - } - ::html::div -class form-widget { - ::html::input -type text -name __title -value [my set title] - } - } - #::html::hr - } $fcn + set f [my createFormField -name __name -spec "text,required,label=#xowiki.name#" \ + -configuration [list -value [my set name]]] + $root insertBeforeFromScript {$f render_item} $fcn + + set f [my createFormField -name __title -spec "text,required,label=#xowiki.title#" \ + -configuration [list -value [my set title]]] + $root insertBeforeFromScript {$f render_item} $fcn } - $root appendFromList [list input [list type submit] {}] + $root appendFromScript { + ::html::br + ::html::input -type submit + } set form [lindex [$root selectNodes //form] 0] if {$form eq ""} { my msg "no form found in page [$page_template name]" } else { $form setAttribute action [$package_id pretty_link [my name]]?m=save-form-data method POST + set oldCSSClass [expr {[$form hasAttribute class] ? [$form getAttribute class] : ""}] + $form setAttribute class [string trim "$oldCSSClass margin-form"] } my set_form_data set result [$root asHTML] Index: openacs-4/packages/xowiki/www/admin/list.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xowiki/www/admin/list.tcl,v diff -u -r1.13 -r1.14 --- openacs-4/packages/xowiki/www/admin/list.tcl 4 Jun 2007 12:32:26 -0000 1.13 +++ openacs-4/packages/xowiki/www/admin/list.tcl 22 Jun 2007 13:32:02 -0000 1.14 @@ -58,12 +58,12 @@ } ImageField_EditIcon edit -label "" -html {style "padding-right: 2px;"} if {$::individual_permissions} { - ImageField permissions -src /resources/xowiki/permissions.png -width 16 \ + ImageAnchorField permissions -src /resources/xowiki/permissions.png -width 16 \ -height 16 -border 0 -title "Manage Individual Permssions for this Item" \ -alt permsissions -label "" -html {style "padding: 2px;"} } if {$::with_publish_status} { - ImageField publish_status -src "" -width 8 \ + ImageAnchorField publish_status -src "" -width 8 \ -height 8 -border 0 -title "Toggle Publish Status" \ -alt "publish status" -label [_ xowiki.publish_status] -html {style "padding: 2px;"} }