| |
489 |
489 |
} |
| |
490 |
490 |
hidden - |
| |
491 |
491 |
text { $field setAttribute value $value} |
| |
492 |
492 |
default {my msg "can't handle $type so far $att=$value"} |
| |
493 |
493 |
} |
| |
494 |
494 |
} |
| |
495 |
495 |
} |
| |
496 |
496 |
} |
| |
497 |
497 |
|
| |
498 |
498 |
|
| |
499 |
499 |
namespace eval ::xowiki { |
| |
500 |
500 |
|
| |
501 |
501 |
FormPage ad_instproc set_form_data {form_fields} { |
| |
502 |
502 |
Store the instance attributes or default values in the form. |
| |
503 |
503 |
} { |
| |
504 |
504 |
#my msg "set_form_value instance attributes = [my instance_attributes]" |
| |
505 |
505 |
array set __ia [my instance_attributes] |
| |
506 |
506 |
foreach f $form_fields { |
| |
507 |
507 |
set att [$f name] |
| |
508 |
508 |
# just handle fields of the form entry |
| |
509 |
|
if {![my exists field_in_form($att)]} continue |
| |
|
509 |
if {![my exists __field_in_form($att)]} continue |
| |
510 |
510 |
#my msg "set form_value to form-field $att __ia($att)" |
| |
511 |
511 |
if {[info exists __ia($att)]} { |
| |
512 |
512 |
#my msg "my set_form_value from ia $att $__ia($att)" |
| |
513 |
513 |
my set_form_value $att $__ia($att) |
| |
514 |
514 |
} else { |
| |
515 |
515 |
# we have no instance attributes, use the default value from the form field |
| |
516 |
516 |
#my msg "no instance attribute, set form_value $att '[$f value]'" |
| |
517 |
517 |
my set_form_value $att [$f value] |
| |
518 |
518 |
} |
| |
519 |
519 |
} |
| |
520 |
520 |
} |
| |
521 |
521 |
} |
| |
522 |
522 |
|
| |
523 |
523 |
|
| |
524 |
524 |
namespace eval ::xowiki { |
| |
525 |
525 |
|
| |
526 |
526 |
Page ad_instproc get_form_data {-field_names form_fields} { |
| |
527 |
527 |
Get the values from the form and store it as |
| |
528 |
528 |
instance attributes. |
| |
529 |
529 |
} { |
|
| |
708 |
709 |
FormPage instproc create_form_field {{-cr_field_spec ""} {-field_spec ""} field_name} { |
| |
709 |
710 |
if {$cr_field_spec eq ""} {set cr_field_spec [my get_short_spec @cr_fields]} |
| |
710 |
711 |
if {$field_spec eq ""} {set field_spec [my get_short_spec @fields]} |
| |
711 |
712 |
return [next -cr_field_spec $cr_field_spec -field_spec $field_spec $field_name] |
| |
712 |
713 |
} |
| |
713 |
714 |
FormPage instproc create_form_fields {field_names} { |
| |
714 |
715 |
set form_fields [my create_category_fields] |
| |
715 |
716 |
foreach att $field_names { |
| |
716 |
717 |
if {[string match "__*" $att]} continue |
| |
717 |
718 |
lappend form_fields [my create_form_field \ |
| |
718 |
719 |
-cr_field_spec [my get_short_spec @cr_fields] \ |
| |
719 |
720 |
-field_spec [my get_short_spec @fields] $att] |
| |
720 |
721 |
} |
| |
721 |
722 |
return $form_fields |
| |
722 |
723 |
} |
| |
723 |
724 |
|
| |
724 |
725 |
FormPage instproc field_names {} { |
| |
725 |
726 |
my instvar package_id |
| |
726 |
727 |
foreach {form_vars needed_attributes} [my form_attributes] break |
| |
727 |
728 |
#my msg "form_vars=$form_vars needed_attributes=$needed_attributes" |
| |
728 |
|
my array unset field_in_form |
| |
729 |
|
if {$form_vars} {foreach v $needed_attributes {my set field_in_form($v) 1}} |
| |
|
729 |
my array unset __field_in_form |
| |
|
730 |
if {$form_vars} {foreach v $needed_attributes {my set __field_in_form($v) 1}} |
| |
730 |
731 |
|
| |
731 |
732 |
# |
| |
732 |
733 |
# Remove the fields already included in auto_fields form the needed_attributes. |
| |
733 |
734 |
# The final list field_names determines the order of the fields in the form. |
| |
734 |
735 |
# |
| |
735 |
736 |
set auto_fields [list _name _page_order _creator _title _text _description _nls_language] |
| |
736 |
737 |
set reduced_attributes $needed_attributes |
| |
737 |
738 |
|
| |
738 |
739 |
foreach f $auto_fields { |
| |
739 |
740 |
set p [lsearch $reduced_attributes $f] |
| |
740 |
741 |
if {$p > -1} { |
| |
741 |
742 |
#if {$form_vars} { |
| |
742 |
743 |
#set auto_field_in_form($f) 1 |
| |
743 |
744 |
#} |
| |
744 |
745 |
set reduced_attributes [lreplace $reduced_attributes $p $p] |
| |
745 |
746 |
} |
| |
746 |
747 |
} |
| |
747 |
748 |
#my msg reduced_attributes=$reduced_attributes |
| |
748 |
|
#my msg fields_from_form=[array names field_in_form] |
| |
|
749 |
#my msg fields_from_form=[my array names __field_in_form] |
| |
749 |
750 |
|
| |
750 |
751 |
set field_names [list _name] |
| |
751 |
752 |
if {[$package_id show_page_order]} { lappend field_names _page_order } |
| |
752 |
753 |
lappend field_names _title _creator |
| |
753 |
754 |
foreach fn $reduced_attributes { lappend field_names $fn } |
| |
754 |
755 |
foreach fn [list _text _description _nls_language] { lappend field_names $fn } |
| |
755 |
756 |
#my msg field_names=$field_names |
| |
756 |
757 |
return $field_names |
| |
757 |
758 |
} |
| |
758 |
759 |
|
| |
759 |
760 |
Page instproc field_names {} { |
| |
760 |
761 |
array set dont_modify [list item_id 1 revision_id 1 object_id 1 object_title 1 page_id 1 name 1] |
| |
761 |
762 |
set field_names [list] |
| |
762 |
763 |
foreach field_name [[my info class] array names db_slot] { |
| |
763 |
764 |
if {[info exists dont_modify($field_name)]} continue |
| |
764 |
765 |
lappend field_names _$field_name |
| |
765 |
766 |
} |
| |
766 |
767 |
#my msg field_names=$field_names |
| |
767 |
768 |
return $field_names |
| |
768 |
769 |
} |
|
| |
876 |
877 |
} |
| |
877 |
878 |
|
| |
878 |
879 |
set field_names [my field_names] |
| |
879 |
880 |
set form_fields [my create_form_fields $field_names] |
| |
880 |
881 |
|
| |
881 |
882 |
# check name field: |
| |
882 |
883 |
# - if it is not required, hide it, |
| |
883 |
884 |
# - if it is required but hidden, show it anyway |
| |
884 |
885 |
# (might happen, when e.g. set via @cr_fields ... hidden) |
| |
885 |
886 |
set name_field [my lookup_form_field -name _name $form_fields] |
| |
886 |
887 |
if {$anon_instances} { |
| |
887 |
888 |
$name_field config_from_spec hidden |
| |
888 |
889 |
} else { |
| |
889 |
890 |
if {[$name_field istype ::xowiki::FormField::hidden]} { |
| |
890 |
891 |
$name_field config_from_spec text,required |
| |
891 |
892 |
$name_field type text |
| |
892 |
893 |
} |
| |
893 |
894 |
} |
| |
894 |
895 |
|
| |
895 |
896 |
# include _text only, if explicitely needed (in form or template) |
| |
896 |
|
if {![my exists field_in_form(_text)]} { |
| |
|
897 |
if {![my exists __field_in_form(_text)]} { |
| |
897 |
898 |
#my msg "setting text hidden" |
| |
898 |
899 |
set f [my lookup_form_field -name _text $form_fields] |
| |
899 |
900 |
$f config_from_spec hidden |
| |
900 |
901 |
} |
| |
901 |
902 |
#my show_fields $form_fields |
| |
902 |
903 |
|
| |
903 |
904 |
if {[my form_parameter __form_action ""] eq "save-form-data"} { |
| |
904 |
905 |
#my msg "we have to validate" |
| |
905 |
906 |
# |
| |
906 |
907 |
# we have to valiate and save the form data |
| |
907 |
908 |
# |
| |
908 |
909 |
foreach {validation_errors category_ids} [my get_form_data $form_fields] break |
| |
909 |
910 |
if {$validation_errors != 0} { |
| |
910 |
911 |
#my msg "$validation_errors errors in $form_fields" |
| |
911 |
912 |
#foreach f $form_fields { my msg "$f: [$f name] '[$f set value]' err: [$f error_msg] " } |
| |
912 |
913 |
# reset the name in error cases to the original one |
| |
913 |
914 |
my set name [my form_parameter __object_name] |
| |
914 |
915 |
} else { |
| |
915 |
916 |
# |
| |
916 |
917 |
# we have no validation erros, so we can save the content |
|
| |
999 |
1000 |
# magic chars finally with the fields resulting from tdom. |
| |
1000 |
1001 |
|
| |
1001 |
1002 |
set form [string map [list @ \x003] $form] |
| |
1002 |
1003 |
#my msg form=$form |
| |
1003 |
1004 |
|
| |
1004 |
1005 |
dom parse -simple -html $form doc |
| |
1005 |
1006 |
$doc documentElement root |
| |
1006 |
1007 |
|
| |
1007 |
1008 |
::require_html_procs |
| |
1008 |
1009 |
$root firstChild fcn |
| |
1009 |
1010 |
# |
| |
1010 |
1011 |
# prepend some fields above the HTML contents of the form |
| |
1011 |
1012 |
# |
| |
1012 |
1013 |
$root insertBeforeFromScript { |
| |
1013 |
1014 |
::html::input -type hidden -name __object_name -value [my name] |
| |
1014 |
1015 |
::html::input -type hidden -name __form_action -value save-form-data |
| |
1015 |
1016 |
|
| |
1016 |
1017 |
# insert automatic form fields on top |
| |
1017 |
1018 |
foreach att $field_names { |
| |
1018 |
1019 |
#if {$formgiven && ![string match _* $att]} continue |
| |
1019 |
|
if {[my exists field_in_form($att)]} continue |
| |
|
1020 |
if {[my exists __field_in_form($att)]} continue |
| |
1020 |
1021 |
set f [my lookup_form_field -name $att $form_fields] |
| |
1021 |
1022 |
#my msg "insert auto_field $att" |
| |
1022 |
1023 |
$f render_item |
| |
1023 |
1024 |
} |
| |
1024 |
1025 |
} $fcn |
| |
1025 |
1026 |
# |
| |
1026 |
1027 |
# append some fields after the HTML contents of the form |
| |
1027 |
1028 |
# |
| |
1028 |
1029 |
set submit_button_class "" |
| |
1029 |
1030 |
$root appendFromScript { |
| |
1030 |
1031 |
# append category fields |
| |
1031 |
1032 |
foreach f $form_fields { |
| |
1032 |
1033 |
if {[string match "__category_*" [$f name]]} { |
| |
1033 |
1034 |
$f render_item |
| |
1034 |
1035 |
} elseif {[$f istype "::xowiki::FormField::richtext::wym"]} { |
| |
1035 |
1036 |
set submit_button_class "wymupdate" |
| |
1036 |
1037 |
} elseif {[$f istype "::xowiki::CompoundField"]} { |
| |
1037 |
1038 |
foreach c [$f components] { |
| |
1038 |
1039 |
if {[$c istype "::xowiki::FormField::richtext::wym"]} { |
| |
1039 |
1040 |
set submit_button_class "wymupdate"; break |