Index: openacs-4/packages/acs-object-management/acs-object-management.info =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-object-management/acs-object-management.info,v diff -u -r1.5 -r1.6 --- openacs-4/packages/acs-object-management/acs-object-management.info 22 Feb 2011 17:37:03 -0000 1.5 +++ openacs-4/packages/acs-object-management/acs-object-management.info 9 May 2011 02:03:46 -0000 1.6 @@ -21,6 +21,7 @@ + Index: openacs-4/packages/acs-object-management/catalog/acs-object-management.en_US.ISO-8859-1.xml =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-object-management/catalog/acs-object-management.en_US.ISO-8859-1.xml,v diff -u -r1.5 -r1.6 --- openacs-4/packages/acs-object-management/catalog/acs-object-management.en_US.ISO-8859-1.xml 22 Dec 2009 19:59:15 -0000 1.5 +++ openacs-4/packages/acs-object-management/catalog/acs-object-management.en_US.ISO-8859-1.xml 9 May 2011 02:03:46 -0000 1.6 @@ -34,7 +34,7 @@ Delete delete Delete checked attributes - Dynamic Types + Dynamic Edit Form Name edit widget Edit widget parameters @@ -60,6 +60,8 @@ node 'element' must have either a 'name' attribute or an 'attribute' attribute. Object Type Object View + Object view is based on a content type + Object view is not based on a content type Parameter Parameter "%param%" Source Index: openacs-4/packages/acs-object-management/lib/forms/generic.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-object-management/lib/forms/generic.tcl,v diff -u -r1.2 -r1.3 --- openacs-4/packages/acs-object-management/lib/forms/generic.tcl 6 Mar 2011 18:43:20 -0000 1.2 +++ openacs-4/packages/acs-object-management/lib/forms/generic.tcl 9 May 2011 02:03:46 -0000 1.3 @@ -11,9 +11,14 @@ " ad_form -name $object_view -export {return_url} \ - -form [form::form_part -object_view $object_view] \ + -form [object::form::form_part -object_view $object_view] \ -select_query_name select_values \ -on_request { + if { [content::type::is_content_type -object_type \ + [object_view::get_element -object_view $object_view -element object_type] } { + ad_return_complaint 1 [_ object_view_content_type] + ad_script_abort + } if { [info exists ${object_view}_id] } { permission::require_permission \ -party_id [ad_conn user_id] \ @@ -26,9 +31,9 @@ -privilege create } } -new_data { - object::new_from_form -object_view $object_view + object::form::new -object_view $object_view } -edit_data { - object::update_from_form -object_view $object_view + object::form::update -object_view $object_view } -after_submit { if { [info exists return_url] } { ad_returnredirect $return_url Index: openacs-4/packages/acs-object-management/tcl/apm-callback-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-object-management/tcl/apm-callback-procs.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/acs-object-management/tcl/apm-callback-procs.tcl 9 May 2011 02:03:46 -0000 1.1 @@ -0,0 +1,84 @@ + +ad_library { + APM callback procedures. + + @creation-date 2011-03-27 + @author Don Baccus (dhogaza@pacifier.com) + @cvs-id $Id: apm-callback-procs.tcl,v 1.1 2011/05/09 02:03:46 donb Exp $ +} + +namespace eval acs_object_management::apm {} + +ad_proc -public acs_object_management::apm::after_install {} { + After install callback. Create acs_object_management views. +} { + + source [acs_package_root_dir acs-object-management]/tcl/cache-init.tcl + + object_view::new -object_view object -pretty_name Object -object_type acs_object + + db_1row q {select attribute_id + from acs_attributes + where object_type = 'acs_object' + and attribute_name = 'title'} + object_view::attribute::copy -to_object_view object -attribute_id $attribute_id + object_view::attribute::widget::register \ + -object_view object \ + -attribute_id $attribute_id \ + -widget text \ + -required_p t \ + -help_text "" + + object_view::new -object_view item -pretty_name Item -object_type content_item + + db_1row q {select attribute_id + from acs_attributes + where object_type = 'content_item' + and attribute_name = 'name'} + object_view::attribute::copy -to_object_view item -attribute_id $attribute_id + object_view::attribute::widget::register \ + -object_view item \ + -attribute_id $attribute_id \ + -widget text \ + -required_p t \ + -help_text "" + + object_view::new -object_view revision -pretty_name Revision -object_type content_revision + + db_1row q {select attribute_id + from acs_attributes + where object_type = 'content_revision' + and attribute_name = 'title'} + object_view::attribute::copy -to_object_view revision -attribute_id $attribute_id + object_view::attribute::widget::register \ + -object_view revision \ + -attribute_id $attribute_id \ + -widget text \ + -required_p t \ + -help_text "" + + db_1row q {select attribute_id + from acs_attributes + where object_type = 'content_revision' + and attribute_name = 'description'} + object_view::attribute::copy -to_object_view revision -attribute_id $attribute_id + object_view::attribute::widget::register \ + -object_view revision \ + -attribute_id $attribute_id \ + -widget text \ + -required_p f \ + -help_text "" + + db_1row q {select attribute_id + from acs_attributes + where object_type = 'content_revision' + and attribute_name = 'content'} + object_view::attribute::copy -to_object_view revision -attribute_id $attribute_id + object_view::attribute::widget::register \ + -object_view revision \ + -attribute_id $attribute_id \ + -widget richtext \ + -required_p t \ + -help_text "" + +} Index: openacs-4/packages/acs-object-management/tcl/form-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-object-management/tcl/form-procs.tcl,v diff -u -r1.7 -r1.8 --- openacs-4/packages/acs-object-management/tcl/form-procs.tcl 22 Mar 2011 16:31:51 -0000 1.7 +++ openacs-4/packages/acs-object-management/tcl/form-procs.tcl 9 May 2011 02:03:46 -0000 1.8 @@ -10,28 +10,6 @@ namespace eval form {} -ad_proc form::form_part { - -object_view:required - {-extend:boolean "f"} -} { - - Returns an ad_form snippet meant to be embedded in the "-form" part of the call. - - @param object_view The object view whose form we should render. - @param extend Extend an existing form. - -} { - set form_part [list] - if {!$extend_p} { - lappend form_part [list ${object_view}_id:key(acs_object_id_seq)] - } - lappend form_part [list object_view:text(hidden) [list value $object_view]] - foreach attribute_id [object_view::get_attribute_ids -object_view $object_view] { - lappend form_part [form::element -object_view $object_view -attribute_id $attribute_id] - } - return $form_part -} - ad_proc form::get_attributes { -object_view:required -array:required Index: openacs-4/packages/acs-object-management/tcl/object-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-object-management/tcl/object-procs.tcl,v diff -u -r1.8 -r1.9 --- openacs-4/packages/acs-object-management/tcl/object-procs.tcl 28 Feb 2011 01:26:31 -0000 1.8 +++ openacs-4/packages/acs-object-management/tcl/object-procs.tcl 9 May 2011 02:03:46 -0000 1.9 @@ -10,6 +10,7 @@ } namespace eval object {} +namespace eval object::form {} ad_proc -private object::split_attributes { -object_type:required @@ -54,6 +55,8 @@ ad_proc -private object::new_inner { -object_type:required -object_id:required + {-parent_id ""} + {-item_id ""} -attributes:required } { @@ -62,14 +65,21 @@ supertypes as it goes. object::new wraps the outer call in a transaction to guarantee that object creation is atomic. + The content repository hacks are in here because adding the missing attributes + might well screw up the insert view that's created by the package, and I don't + care to go screwing around with that part of core at this point in time. + @param object_type The type we're creating. @param object_id The id of the object we're creating. If empty, a new object_id will be created. + @param parent_id content_item hack due to the CR not defining parent_id as an + attribute @param attributes The attribute values for the new object in array get format. @return The object_id of the new object. } { +ns_log Notice "Huh? object_type: $object_type attributes: $attributes" array set attributes_array $attributes object_type::get -object_type $object_type -array object_type_info @@ -81,30 +91,26 @@ -type_attributes_array our_attributes \ -supertype_attributes_array supertype_attributes - # If this conditional looks weird to you, it's because the supertype of acs_object is - # acs_object, not null (boo, hiss, aD!) - - if { $object_type_info(supertype) ne $object_type } { + if { $object_type_info(supertype) ne "" } { set object_id \ [object::new_inner \ -object_type $object_type_info(supertype) \ -object_id $object_id \ + -parent_id $parent_id \ + -item_id $item_id \ -attributes [array get supertype_attributes]] } else { if { $object_id eq "" } { set object_id [db_nextval acs_object_id_seq] } - if { [llength [array names supertype_attributes]] > 0 } { - # Internal error check - if we're creating an acs_object, it has no supertype - # therefore should have no supertype_attributes. - ns_log Error "supertype_attributes should be empty, value: [array get supertype_attributes]" - return -code error "Internal error - supertype_attributes should be empty" - } } if { $object_type_info(table_name) ne "" } { set our_attributes($id_column) $object_id + if { $parent_id ne "" && $object_type eq "content_item" } { + set our_attributes(parent_id) $parent_id + } foreach name [array names our_attributes] { lappend name_list $name set __$name $our_attributes($name) @@ -175,42 +181,6 @@ return $object_id } -ad_proc object::new_from_form { - -object_view:required - -object_id - -form -} { -} { - - if { ![info exists form] } { - set form $object_view - } - - if { ![info exists object_id] } { - set object_id [template::element::get_value $form \ - [template::element::get_value $form __key]] - } - - form::get_attributes \ - -object_view $object_view \ - -array attributes - - set object_type [object_view::get_element \ - -object_view $object_view \ - -element object_type] - - set attributes(creation_user) "[ad_conn user_id]" - set attributes(creation_ip) "[ad_conn peeraddr]" - set attributes(object_type) "$object_type" - db_transaction { - object::new_inner \ - -object_type $object_type \ - -object_id $object_id \ - -attributes [array get attributes] - } - return $object_id -} - ad_proc object::delete { -object_id:required } { @@ -294,18 +264,11 @@ # If this conditional looks weird to you, it's because the supertype of acs_object is # acs_object, not null (boo, hiss, aD!) - if { $object_type_info(supertype) ne $object_type } { + if { $object_type_info(supertype) ne "" } { object::update_inner \ -object_type $object_type_info(supertype) \ -object_id $object_id \ -attributes [array get supertype_attributes] - } else { - if { [llength [array names supertype_attributes]] > 0 } { - # Internal error check - if we're creating an acs_object, it has no supertype - # therefore should have no supertype_attributes. - ns_log Error "supertype_attributes should be empty, value: [array get supertype_attributes]" - return -code error "Internal error - supertype_attributes should be empty" - } } if { $object_type_info(table_name) ne "" } { @@ -362,8 +325,29 @@ } } -ad_proc object::update_from_form { +ad_proc object::form::form_part { -object_view:required + {-extend:boolean "f"} +} { + + Returns an ad_form snippet meant to be embedded in the "-form" part of the call. + + @param object_view The object view whose form we should render. + @param extend Extend an existing form. + +} { + set form_part [list] + if {!$extend_p} { + lappend form_part [list ${object_view}_id:key(acs_object_id_seq)] + } + lappend form_part [list object_view:text(hidden) [list value $object_view]] + foreach attribute_id [object_view::get_attribute_ids -object_view $object_view] { + lappend form_part [form::element -object_view $object_view -attribute_id $attribute_id] + } + return $form_part +} +ad_proc object::form::new { + -object_view:required -object_id -form } { @@ -380,6 +364,42 @@ form::get_attributes \ -object_view $object_view \ + -array attributes + + set object_type [object_view::get_element \ + -object_view $object_view \ + -element object_type] + + set attributes(creation_user) "[ad_conn user_id]" + set attributes(creation_ip) "[ad_conn peeraddr]" + set attributes(object_type) "$object_type" + db_transaction { + object::new_inner \ + -object_type $object_type \ + -object_id $object_id \ + -attributes [array get attributes] + } + return $object_id +} + +ad_proc object::form::update { + -object_view:required + -object_id + -form +} { +} { + + if { ![info exists form] } { + set form $object_view + } + + if { ![info exists object_id] } { + set object_id [template::element::get_value $form \ + [template::element::get_value $form __key]] + } + + form::get_attributes \ + -object_view $object_view \ -form $form \ -array attributes Index: openacs-4/packages/acs-object-management/tcl/test/object-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-object-management/tcl/test/object-procs.tcl,v diff -u -r1.4 -r1.5 --- openacs-4/packages/acs-object-management/tcl/test/object-procs.tcl 13 Mar 2011 22:56:22 -0000 1.4 +++ openacs-4/packages/acs-object-management/tcl/test/object-procs.tcl 9 May 2011 02:03:46 -0000 1.5 @@ -95,7 +95,7 @@ aa_false "Form created" \ [catch { - set form_part [form::form_part -object_view $view_name] + set form_part [object::form::form_part -object_view $view_name] aa_log $form_part ad_form -name $view_name \ -form $form_part @@ -107,7 +107,7 @@ aa_log $error aa_false "Object created from form" \ - [catch {set object_id [object::new_from_form \ + [catch {set object_id [object::form::new \ -object_view $view_name \ -object_id [db_nextval acs_object_id_seq] \ -form $view_name]} error] Index: openacs-4/packages/acs-object-management/www/admin/form-preview.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-object-management/www/admin/form-preview.tcl,v diff -u -r1.1 -r1.2 --- openacs-4/packages/acs-object-management/www/admin/form-preview.tcl 27 Nov 2009 00:38:50 -0000 1.1 +++ openacs-4/packages/acs-object-management/www/admin/form-preview.tcl 9 May 2011 02:03:46 -0000 1.2 @@ -9,7 +9,7 @@ } ad_form -name object_view \ - -form [form::form_part -object_view $object_view] \ + -form [object::form::form_part -object_view $object_view] \ -after_submit { ad_returnredirect [export_vars -base form {object_view}] ad_script_abort Index: openacs-4/packages/acs-object-management/www/admin/index.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-object-management/www/admin/index.tcl,v diff -u -r1.4 -r1.5 --- openacs-4/packages/acs-object-management/www/admin/index.tcl 27 Nov 2009 00:38:50 -0000 1.4 +++ openacs-4/packages/acs-object-management/www/admin/index.tcl 9 May 2011 02:03:46 -0000 1.5 @@ -10,7 +10,7 @@ {orderby "pretty_name,asc"} } -set page_title "[_ acs-object-management.dynamic_types]" +set page_title "[_ acs-object-management.types]" set context [list $page_title] list::create \ @@ -19,7 +19,7 @@ -multirow object_types \ -key object_type \ -actions [list "[_ acs-object-management.add_type]" [export_vars -base object-type-add] "[_ acs-object-management.add_type]"] \ - -row_pretty_plural "[_ acs-object-management.dynamic_types]" \ + -row_pretty_plural "[_ acs-object-management.types]" \ -elements { pretty_name { label "[_ acs-object-management.pretty_name]" @@ -30,12 +30,18 @@ label "[_ acs-object-management.object_type]" orderby "object_type" } + dynamic_p { + label "[_ acs-object-management.dynamic]" + orderby "dynamic_p" + } action { label "[_ acs-object-management.Action]" display_template " - - [_ acs-object-management.delete] - " + + + [_ acs-object-management.delete] + + " } } Index: openacs-4/packages/acs-object-management/www/admin/index.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-object-management/www/admin/index.xql,v diff -u -r1.2 -r1.3 --- openacs-4/packages/acs-object-management/www/admin/index.xql 27 Nov 2009 00:38:50 -0000 1.2 +++ openacs-4/packages/acs-object-management/www/admin/index.xql 9 May 2011 02:03:46 -0000 1.3 @@ -5,9 +5,8 @@ - select object_type, pretty_name + select object_type, pretty_name, dynamic_p from acs_object_types - where dynamic_p = 't' $orderby_clause Index: openacs-4/packages/acs-object-management/www/admin/object-type.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-object-management/www/admin/object-type.tcl,v diff -u -r1.1 -r1.2 --- openacs-4/packages/acs-object-management/www/admin/object-type.tcl 27 Nov 2009 00:38:50 -0000 1.1 +++ openacs-4/packages/acs-object-management/www/admin/object-type.tcl 9 May 2011 02:03:46 -0000 1.2 @@ -14,36 +14,50 @@ set context [list [list . "Object Types"] $page_title] set return_url [ad_conn url]?[ad_conn query] +set actions "" +if { $type_info(dynamic_p) } { + set actions [list "[_ acs-object-management.add_attribute]" [export_vars -base attribute {object_type}] "[_ acs-object-management.add_attribute]"] +} + list::create \ -name attributes \ -caption [_ acs-object-management.attributes] \ -multirow attributes \ -key attribute_id \ -pass_properties { object_type - } -actions [list "[_ acs-object-management.add_attribute]" [export_vars -base attribute {object_type}] "[_ acs-object-management.add_attribute]"] \ + } -actions $actions \ -elements { pretty_name { label "[_ acs-object-management.attribute]" - link_url_eval $attribute_url + display_template " + + + + @attributes.pretty_name@ + + + " } datatype { label "[_ acs-object-management.datatype]" } action { label "[_ acs-object-management.Action]" display_template " + [_ acs-object-management.delete] - " + + " } } -filters { object_type {} } db_multirow -cache_pool acs_metadata -cache_key t::${object_type}::get_attributes \ -extend { attribute_url delete_url} attributes get_attributes {} { - set attribute_url [export_vars -base attribute {attribute_id object_type}] + set attribute_url [expr {$type_info(dynamic_p) ? [export_vars -base attribute {attribute_id object_type}] : "" }] set delete_url [export_vars -base attribute-delete {object_type attribute_name}] }