Index: openacs-4/contrib/packages/classified-ads/tcl/ads-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/tcl/ads-procs.tcl,v diff -u -r1.5 -r1.6 --- openacs-4/contrib/packages/classified-ads/tcl/ads-procs.tcl 23 Jul 2003 21:08:19 -0000 1.5 +++ openacs-4/contrib/packages/classified-ads/tcl/ads-procs.tcl 24 Jul 2003 01:04:48 -0000 1.6 @@ -90,16 +90,25 @@ } { upvar $array row - # Get extra widgets that we need to display - # + # + # Get some necessary information + # + set package_id [ad_conn package_id] set content_type "ca_ad" - set widget_list [db_list_of_ns_sets select_widgets {}] if {[empty_string_p $revision_id]} { set revision_id [classified-ads::get_latest_revision -item_id $ad_id] } + set keyword_id [classified-ads::ads::get_category_id -ad_id $ad_id] + + # + # Get extra widgets that we need to display + # + + set widget_list [db_list_of_ns_sets select_widgets {}] + # object_id, object_type, context_id, security_inherit_p, creation_user, # creation_date, creation_ip, last_modified, modifying_user, modifying_ip, # tree_sortkey, revision_id, title, item_id, description, publish_date, @@ -109,6 +118,7 @@ set row(pretty_publish_date) [util_AnsiDatetoPrettyDate $row(publish_date)] set row(data) [classified-ads::get_content -revision_id $revision_id] + set row(keyword_id) $keyword_id return 0 } @@ -174,7 +184,11 @@ @author Roberto Mello } { - return [db_0or1row get_category_id {}] + if { [db_0or1row get_category_id {}] } { + return $keyword_id + } else { + return 0 + } } ad_proc -public classified-ads::ads::generate_trail { 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] Index: openacs-4/contrib/packages/classified-ads/tcl/widget-procs.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/tcl/widget-procs.xql,v diff -u -r1.1 -r1.2 --- openacs-4/contrib/packages/classified-ads/tcl/widget-procs.xql 16 Jul 2003 04:52:32 -0000 1.1 +++ openacs-4/contrib/packages/classified-ads/tcl/widget-procs.xql 24 Jul 2003 01:04:48 -0000 1.2 @@ -17,7 +17,7 @@ aa.object_type = :content_type and cawv.enabled_p = 't' and (ca.sitewide_p = 't' or - ca.package_id = :package_id) + cawv.keyword_id = :keyword_id) order by aa.sort_order asc Index: openacs-4/contrib/packages/classified-ads/www/admin/ad-new.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/www/admin/ad-new.tcl,v diff -u -r1.4 -r1.5 --- openacs-4/contrib/packages/classified-ads/www/admin/ad-new.tcl 19 Jul 2003 01:48:45 -0000 1.4 +++ openacs-4/contrib/packages/classified-ads/www/admin/ad-new.tcl 24 Jul 2003 01:04:48 -0000 1.5 @@ -60,8 +60,12 @@ } # Get extra custom widgets, if any -classified-ads::widgets::get_widget_params -content_type "ca_ad" -form_id ad +classified-ads::widgets::get_widget_params \ + -content_type "ca_ad" \ + -form_id ad \ + -keyword_id $keyword_id + set context [list [list "ads" "Ads"] $title] ad_return_template Index: openacs-4/contrib/packages/classified-ads/www/admin/ad-one.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/www/admin/ad-one.tcl,v diff -u -r1.2 -r1.3 --- openacs-4/contrib/packages/classified-ads/www/admin/ad-one.tcl 23 Jul 2003 21:08:19 -0000 1.2 +++ openacs-4/contrib/packages/classified-ads/www/admin/ad-one.tcl 24 Jul 2003 01:04:48 -0000 1.3 @@ -41,14 +41,18 @@ {html {cols 60 rows 10 wrap soft}} } } -on_request { + classified-ads::ads::get -ad_id $ad_id -revision_id $revision_id -array adinfo + # Get extra custom widgets, if any - classified-ads::widgets::get_widget_params -content_type "ca_ad" -form_id ad + classified-ads::widgets::get_widget_params \ + -content_type "ca_ad" \ + -form_id ad \ + -keyword_id $adinfo(keyword_id) set form_values [classified-ads::get_attribute_values -item_id $ad_id -item_id_element ad_id] classified-ads::widgets::set_widget_values -form_id ad -form_values $form_values - classified-ads::ads::get -ad_id $ad_id -revision_id $revision_id -array adinfo element set_properties ad ad_id -value $ad_id element set_properties ad title -value $adinfo(title)