Index: openacs-4/contrib/packages/portal/tcl/element-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/portal/tcl/element-procs.tcl,v diff -u -r1.19 -r1.20 --- openacs-4/contrib/packages/portal/tcl/element-procs.tcl 20 Jun 2004 00:39:05 -0000 1.19 +++ openacs-4/contrib/packages/portal/tcl/element-procs.tcl 26 Jun 2004 00:36:00 -0000 1.20 @@ -34,7 +34,8 @@ {-state full} {-datasource_name:required} {-name ""} - {-args ""} + {-element_args ""} + {-initialize:boolean} } { Create a new portal element of type datasource_name on the given portal. @@ -44,10 +45,14 @@ @param region The page region to placer the element on. @param datasource_name The portal datasource name @param name The name of the element - @param args Optional args to set in array get format + @param element_args Optional args to set in array get format + @param initialize If set, call the portal's default initializer @return The element_id of the new portlet + Note of the day: use of a parameter named "args" breaks ad_proc in very hard + to debug ways ... + } { set page_id [portal::page::get_id -portal_id $portal_id -page_name $page_name] @@ -65,6 +70,9 @@ set element_id [db_nextval portal_seq] +ns_log Notice "Huh? portal_id: $portal_id portal [db_list_of_lists foo {select * from portals where portal_id = :portal_id}]" +ns_log Notice "Huh? page_id: $page_id elements [db_list_of_lists foo {select * from portal_elements where page_id = :page_id}]" + db_transaction { if {[db_0or1row select_template_element_id {}]} { db_dml insert_element_with_template {} @@ -75,16 +83,18 @@ } } - for {key value} $args { + foreach {key value} $element_args { portal::element::parameter::new \ -element_id $element_id \ -key $key \ -value $value } - portal::element::initialize \ - -datasource_name $datasource_name \ - -element_id $element_id + if { $initialize_p } { + portal::element::initialize \ + -datasource_name $datasource_name \ + -element_id $element_id + } return $element_id @@ -410,7 +420,6 @@ ad_proc -private get_render_data { {-element_id:required} - {-decorate_p 1} {-edit_p 0} } { Return all the good stuff a render template needs to render an element. @@ -423,19 +432,6 @@ array set element [get -element_id $element_id] - if { $decorate_p } { - array set theme [portal::theme::get \ - -theme_id [portal::get_theme_id \ - -portal_id [portal::page::get_portal_id -page_id $element(page_id)] \ - ] \ - ] - set element(filename) "$theme(filename)" - set element(resource_dir) "$theme(resource_dir)" - } else { - set element(filename) /packages/portal/lib/undecorated-element - set element(resource_dir) "" - } - if {!$edit_p || ![::parameter::get -parameter ShowShadeButton]} { set element(shadeable_p) f } @@ -670,4 +666,19 @@ } { } + ad_proc -public get_element_id { + -page_id:required + -datasource_name:required + } { + + Return the element_id of the datasource on the given page if there is exactly one + such portlet on the page, an error otherwise. + + @param page_id The page_id + @param datasource_name The name of the datasource used to create the portlet + @return The element_id if there's exactly one portlet of this type on the page, error + otherwise + } { + return [db_string element_id {}] + } }