Index: openacs-4/contrib/packages/classified-ads/tcl/widget-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/tcl/widget-procs.tcl,v diff -u -r1.2 -r1.3 --- openacs-4/contrib/packages/classified-ads/tcl/widget-procs.tcl 19 Jul 2003 01:48:45 -0000 1.2 +++ openacs-4/contrib/packages/classified-ads/tcl/widget-procs.tcl 24 Jul 2003 01:04:48 -0000 1.3 @@ -9,57 +9,89 @@ } namespace eval classified-ads::widgets { + # + # DEDS: FIXME - check also the datatype in acs_attributes, + # we may be doing it wrong. - - # DEDS: FIXME - we need to accept extra options - # this is true for the format case in the date widgets - # we need support for date widgets - # check also the datatype in acs_attributes, we may be doing it wrong - - - ad_proc -public get_widget_params { {-content_type:required} {-form_id:required} + {-keyword_id ""} } { - returns the widgets for a particular content_type + Returns the widgets for a particular content_type. + If the keyword_id is passed, only widgets belonging to that category + will be returned, otherwise widgets available to all categories are + returned. @param content_type The content type whose widgets we are interested in @param form_id The id of the form where we create the widgets - + @param keyword_id The keyword_id of the category for which we want widgets. } { set package_id [ad_conn package_id] + + if { [empty_string_p $keyword_id] } { + # + # keyword_id was not passed, so we get the keyword_id for this + # package instance. + # + + set keyword_id [classified-ads::categories::package_category_exists_p \ + -package_id $package_id] + } + set widget_list [db_list_of_ns_sets select_widgets {}] foreach one_widget $widget_list { set extra_ops "" - # were html options passed? + # Were html options passed? + set html_options [ns_set get $one_widget html_options] + if {![empty_string_p $html_options]} { append extra_ops " -html $html_options" } - # is there a default value? + # Is there a default value? + set default_value [ns_set get $one_widget default_value] + if {![empty_string_p $default_value]} { append extra_ops " -value $default_value" } - # is there a validate clause? + # Is there a validate clause? set validate_clause [ns_set get $one_widget validate] + if {![empty_string_p $validate_clause]} { append extra_ops " -validate $validate_clause" } - # is it optional? + # Is it optional? + if {[string equal [ns_set get $one_widget optional_p] "t"]} { append extra_ops " -optional" } + # + # RBM: Did the user pass extra form builder options? + # + # This is somewhat dangerous, but the admin must know what + # s/he is doing when entering extra options. It was the only + # way I could think of to allow for different options like + # -format, -help_text, -help, etc. to be added on a + # per-field basis. + # + + set extra_clause [ns_set get $one_widget extra_options] + + if { ![empty_string_p $extra_clause] } { + append extra_ops " $extra_clause" + } + set widget_command "template::element::create $form_id [ns_set get $one_widget attribute_name] \ -label \"[ns_set get $one_widget label]\" \ -datatype \"[ns_set get $one_widget datatype]\" \ @@ -68,46 +100,37 @@ eval $widget_command } - return 0 - } ad_proc -public set_widget_values { {-form_id:required} {-form_values:required} } { + Assigns values to the elements of a form - assigns values to the elements of a form - @param form_id The id of the form that we assign values to @param form_values A list of lists containing the values to assign to. Each sublist must have two elements with the first being the element name and the second the element value. - } { - foreach one_pair $form_values { template::element::set_properties $form_id [lindex $one_pair 0] -value [lindex $one_pair 1] } return 0 - } ad_proc -public date_widget_to_sql { {-date:required} } { + Converts the contents of a date widget into a format understood by sql - converts the contents of a date widget into a format understood by sql - @param date the date value as passed by the widget - } { - set year [template::util::date::get_property year $date] set month [template::util::date::get_property month $date] set day [template::util::date::get_property day $date]