Index: openacs-4/contrib/packages/classified-ads/sql/postgresql/attributes-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/sql/postgresql/attributes-create.sql,v diff -u -r1.4 -r1.5 --- openacs-4/contrib/packages/classified-ads/sql/postgresql/attributes-create.sql 30 Jul 2003 04:56:41 -0000 1.4 +++ openacs-4/contrib/packages/classified-ads/sql/postgresql/attributes-create.sql 31 Jul 2003 09:31:00 -0000 1.5 @@ -103,6 +103,8 @@ returns integer as' begin + insert into ca_attribute_widgets (widget) values (''currency''); + insert into ca_attribute_widgets (widget) values (''richtext''); insert into ca_attribute_widgets (widget) values (''checkbox''); insert into ca_attribute_widgets (widget) values (''date''); insert into ca_attribute_widgets (widget) values (''hidden''); Index: openacs-4/contrib/packages/classified-ads/tcl/categories-procs-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/tcl/categories-procs-postgresql.xql,v diff -u -r1.3 -r1.4 --- openacs-4/contrib/packages/classified-ads/tcl/categories-procs-postgresql.xql 30 Jul 2003 04:56:41 -0000 1.3 +++ openacs-4/contrib/packages/classified-ads/tcl/categories-procs-postgresql.xql 31 Jul 2003 09:31:00 -0000 1.4 @@ -110,7 +110,7 @@ subtree.keyword_id from cr_keywords parent, cr_keywords subtree where parent.keyword_id = :keyword_id - and parent.tree_sortkey between subtree.tree_sortkey and tree_right(subtree.tree_sortkey) + and subtree.tree_sortkey between parent.tree_sortkey and tree_right(parent.tree_sortkey) ) keywords WHERE att.attribute_id = ca.attribute_id @@ -120,6 +120,29 @@ + + + + SELECT + attribute_name, datatype + FROM + acs_attributes att, + ca_attributes ca, + ( + select + subtree.keyword_id + from cr_keywords parent, cr_keywords subtree + where parent.keyword_id = :keyword_id + and subtree.tree_sortkey between parent.tree_sortkey and tree_right(parent.tree_sortkey) + ) keywords + WHERE + att.attribute_id = ca.attribute_id + AND + ca.keyword_id = keywords.keyword_id + + + + @@ -131,7 +154,7 @@ where parent.keyword_id = :keyword_id and - parent.tree_sortkey between subtree.tree_sortkey and tree_right(subtree.tree_sortkey) + subtree.tree_sortkey between parent.tree_sortkey and tree_right(parent.tree_sortkey) Index: openacs-4/contrib/packages/classified-ads/tcl/categories-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/tcl/categories-procs.tcl,v diff -u -r1.5 -r1.6 --- openacs-4/contrib/packages/classified-ads/tcl/categories-procs.tcl 31 Jul 2003 01:24:31 -0000 1.5 +++ openacs-4/contrib/packages/classified-ads/tcl/categories-procs.tcl 31 Jul 2003 09:31:00 -0000 1.6 @@ -220,6 +220,24 @@ return [db_list get_fields {}] } +ad_proc -public classified-ads::categories::get_custom_fields_and_datatypes { + {-keyword_id:required} +} { + Returns a list (of lists) of column names and their datatypes of custom + fields available for this category. Either the field was assigned + directly to this category or to one of its parents. + + @author Roberto Mello + @creation-date 2003-07-29 +} { + # + # RBM: FIXME: Hmmm, this API needs refactoring. I added this function + # to "make up" for another, old one. + # + + return [db_list get_fields {}] +} + ad_proc -public classified-ads::categories::generate_trail { {-keyword_id:required} {-append_element} Index: openacs-4/contrib/packages/classified-ads/tcl/classified-ads-procs-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/tcl/classified-ads-procs-postgresql.xql,v diff -u -r1.5 -r1.6 --- openacs-4/contrib/packages/classified-ads/tcl/classified-ads-procs-postgresql.xql 31 Jul 2003 01:24:31 -0000 1.5 +++ openacs-4/contrib/packages/classified-ads/tcl/classified-ads-procs-postgresql.xql 31 Jul 2003 09:31:00 -0000 1.6 @@ -276,10 +276,14 @@ aa.sort_order, coalesce(aa.table_name, at.table_name) as table_name, coalesce(aa.column_name, aa.attribute_name) as column_name, + cawv.widget, cawv.label, cawv.html_options, + cawv.extra_options, cawv.select_options, + cawv.validate, cawv.optional_p, cawv.enabled_p, keywords.heading AS category_heading FROM acs_attributes aa, ca_attributes ca, + ca_attribute_widget_values cawv, acs_object_types at, ( select @@ -292,12 +296,16 @@ WHERE aa.attribute_id = ca.attribute_id AND + ca.attribute_id = cawv.attribute_id + AND ca.keyword_id = keywords.keyword_id AND aa.object_type = :content_type AND at.object_type = :content_type - $storage_stub + $storage_stub + ORDER BY + aa.sort_order asc Index: openacs-4/contrib/packages/classified-ads/tcl/classified-ads-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/tcl/classified-ads-procs.tcl,v diff -u -r1.12 -r1.13 --- openacs-4/contrib/packages/classified-ads/tcl/classified-ads-procs.tcl 31 Jul 2003 01:33:13 -0000 1.12 +++ openacs-4/contrib/packages/classified-ads/tcl/classified-ads-procs.tcl 31 Jul 2003 09:31:00 -0000 1.13 @@ -124,7 +124,7 @@ set html_options "" set extra_options "" set select_options "" - set validate "" + set validate "{ price { [expr \$value < 0] } { \"Price has to be positive.\" }}" set optional_p "f" set enabled_p "t" } @@ -567,25 +567,24 @@ ad_proc -public classified-ads::get_attributes { {-content_type "ca_ad"} - {-package_id} + {-keyword_id} {-storage "all"} } { Returns a list of ns_sets of the attributes for one content type @param content_type This is the content type whose attributes we get - @param package_id Only the attributes belonging to this package are retrieved. - Defaults to current package. + @param keyword_id Only the attributes belonging to this category are retrieved. + Defaults to current package's main category. @param storage Only the attributes who belong to this storage type are retrieved. Can be "type_specific", "generic", or "all". } { - if {![exists_and_not_null package_id]} { + if {![exists_and_not_null keyword_id]} { set package_id [ad_conn package_id] + set keyword_id [util_memoize "classified-ads::categories::get_package_keyword_id -package_id $package_id"] } - set keyword_id [classified-ads::categories::get_package_keyword_id -package_id $package_id] - if {![string equal $storage "all"]} { set storage_stub "and storage = '$storage'" } else { @@ -595,14 +594,21 @@ return [db_list_of_ns_sets select_attributes {}] } -ad_proc -public classified-ads::get_attribute_names { +ad_proc -public -deprecated classified-ads::get_attribute_names { {-item_id} {-storage "all"} } { - Returns a list of lists of the attribute names for one item + Returns a list of lists of the attribute names for one item. @param package_id The item id whose attribute names we get } { + # + # RBM: I don't understand why we need to support more than one + # content_type and all the associated complications. + # This proc was only used in one place, and I didn't see + # a reason to not deprecate it until I figure out why. + # + if {![exists_and_not_null package_id]} { set package_id [ad_conn package_id] } @@ -624,13 +630,17 @@ {-storage "all"} {-revision_id} } { + Returns a list of lists of the attribute values for one item. - Returns a list of lists of the attribute values for one item - @param item_id The ID of the object whose values we retrieve @param storage Only the attribute values who belong to this storage type are retrieved. Can be "type_specific", "generic", or "all". } { + # + # RBM: FIXME: This looks too messy. Find out reason for all this + # and try to simplify. + # + set values_list [list] set cr_subclass_p [is_subclass -content_type [get_content_type \ @@ -643,7 +653,10 @@ if {[string match $storage "type_specific"] || [string match $storage "all"]} { set table_name [get_table_name -content_type [get_content_type -item_id $item_id]] - set names_value_list [get_attribute_names -item_id $item_id -storage type_specific] + # set names_value_list [get_attribute_names -item_id $item_id -storage type_specific] + set keyword_id [classified-ads::ads::get_category_id -ad_id $item_id] + set names_value_list \ + [classified-ads::categories::get_custom_fields_and_datatypes -keyword_id $keyword_id] set names_list [list] foreach one_name_value $names_value_list { 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.7 -r1.8 --- openacs-4/contrib/packages/classified-ads/tcl/widget-procs.tcl 30 Jul 2003 04:56:41 -0000 1.7 +++ openacs-4/contrib/packages/classified-ads/tcl/widget-procs.tcl 31 Jul 2003 09:31:00 -0000 1.8 @@ -41,10 +41,14 @@ -package_id $package_id] } - set widget_list [db_list_of_ns_sets select_widgets {}] + set widget_list [classified-ads::get_attributes -keyword_id $keyword_id] foreach one_widget $widget_list { set extra_ops "" + 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]\" \ + -widget \"[ns_set get $one_widget widget]\"" # Were html options passed? @@ -76,6 +80,14 @@ append extra_ops " -optional" } + # If it has select options + + set options_clause [ns_set get $one_widget select_options] + + if {![empty_string_p $options_clause]} { + append extra_ops " -options " + append extra_ops $options_clause + } # # RBM: Did the user pass extra form builder options? # @@ -92,11 +104,8 @@ 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]\" \ - -options \"[ns_set get $one_widget select_options]\" \ - -widget \"[ns_set get $one_widget widget]\" $extra_ops" + append widget_command $extra_ops + ns_log notice $widget_command eval $widget_command } 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.2 -r1.3 --- openacs-4/contrib/packages/classified-ads/tcl/widget-procs.xql 24 Jul 2003 01:04:48 -0000 1.2 +++ openacs-4/contrib/packages/classified-ads/tcl/widget-procs.xql 31 Jul 2003 09:31:00 -0000 1.3 @@ -1,29 +1,6 @@ - - - - - select cawv.*, - aa.default_value, - aa.attribute_name, - aa.datatype - from acs_attributes aa, - ca_attribute_widget_values cawv, - ca_attributes ca - where aa.attribute_id = cawv.attribute_id and - ca.attribute_id = aa.attribute_id and - aa.object_type = :content_type and - cawv.enabled_p = 't' and - (ca.sitewide_p = 't' or - 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.6 -r1.7 --- openacs-4/contrib/packages/classified-ads/www/admin/ad-new.tcl 30 Jul 2003 04:56:41 -0000 1.6 +++ openacs-4/contrib/packages/classified-ads/www/admin/ad-new.tcl 31 Jul 2003 09:31:01 -0000 1.7 @@ -47,6 +47,23 @@ {html {cols 60 rows 3 wrap soft}} } {data:text(textarea),optional {label "Content"} {html {cols 60 rows 10 wrap soft}} } +} -on_request { + # Get extra custom widgets, if any + + classified-ads::widgets::get_widget_params \ + -content_type "ca_ad" \ + -form_id ad \ + -keyword_id $keyword_id + + # + # If this is not a submission, get the values we have stored for + # custom fields. + # + + 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 + } -new_data { set ad_id [classified-ads::ads::new \ -item_id_element ad_id \ @@ -59,13 +76,7 @@ ad_script_abort } -# Get extra custom widgets, if any -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/field-addedit.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/classified-ads/www/admin/field-addedit.tcl,v diff -u -r1.4 -r1.5 --- openacs-4/contrib/packages/classified-ads/www/admin/field-addedit.tcl 30 Jul 2003 04:56:41 -0000 1.4 +++ openacs-4/contrib/packages/classified-ads/www/admin/field-addedit.tcl 31 Jul 2003 09:31:01 -0000 1.5 @@ -18,7 +18,7 @@ {keyword_id:integer 0} {html_options:nohtml ""} {select_options:nohtml ""} - {validate:nohtml ""} + {validate ""} {extra_help_p:boolean t} {extra_help_text ""} {extra_format ""}