Index: openacs-4/packages/notifications/tcl/notification-display-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/notifications/tcl/notification-display-procs.tcl,v diff -u -r1.12 -r1.13 --- openacs-4/packages/notifications/tcl/notification-display-procs.tcl 20 Jun 2003 15:25:45 -0000 1.12 +++ openacs-4/packages/notifications/tcl/notification-display-procs.tcl 29 Jan 2004 13:04:37 -0000 1.13 @@ -11,87 +11,129 @@ } -namespace eval notification::display { +namespace eval notification::display {} - ad_proc -public request_widget { - {-type:required} - {-object_id:required} - {-pretty_name:required} - {-url:required} - {-user_id ""} - } { - Produce a widget for requesting notifications of a given type. If the notifications package has not been - mounted then return the empty string. - } { - # Check that we're mounted - if { [empty_string_p [apm_package_url_from_key [notification::package_key]]] } { - return {} - } - - if {[empty_string_p $user_id]} { - set user_id [ad_conn user_id] - } +ad_proc -public notification::display::request_widget { + {-type:required} + {-object_id:required} + {-pretty_name:required} + {-url:required} + {-user_id ""} +} { + Produce a widget for requesting notifications of a given type. If the notifications package has not been + mounted then return the empty string. +} { + # Check that we're mounted + if { [empty_string_p [apm_package_url_from_key [notification::package_key]]] } { + return {} + } + + if {[empty_string_p $user_id]} { + set user_id [ad_conn user_id] + } - # Get the type id - set type_id [notification::type::get_type_id -short_name $type] + # Get the type id + set type_id [notification::type::get_type_id -short_name $type] - # Check if subscribed - set request_id [notification::request::get_request_id -type_id $type_id -object_id $object_id -user_id $user_id] - - if {![empty_string_p $request_id]} { - set sub_url [unsubscribe_url -request_id $request_id -url $url] - set pretty_name [ad_quotehtml $pretty_name] - set sub_chunk "[_ notifications.lt_You_have_requested_no]" - } else { - set sub_url [subscribe_url -type $type -object_id $object_id -url $url -user_id $user_id -pretty_name $pretty_name] - set pretty_name [ad_quotehtml $pretty_name] - set sub_chunk "[_ notifications.lt_You_may_a_hrefsub_url]" - } + # Check if subscribed + set request_id [notification::request::get_request_id -type_id $type_id -object_id $object_id -user_id $user_id] + + if {![empty_string_p $request_id]} { + set sub_url [unsubscribe_url -request_id $request_id -url $url] + set pretty_name [ad_quotehtml $pretty_name] + set sub_chunk "[_ notifications.lt_You_have_requested_no]" + } else { + set sub_url [subscribe_url -type $type -object_id $object_id -url $url -user_id $user_id -pretty_name $pretty_name] + set pretty_name [ad_quotehtml $pretty_name] + set sub_chunk "[_ notifications.lt_You_may_a_hrefsub_url]" + } - if { [empty_string_p $sub_url] } { - return "" - } + if { [empty_string_p $sub_url] } { + return "" + } - return $sub_chunk + return $sub_chunk +} + +ad_proc -public notification::display::subscribe_url { + {-type:required} + {-object_id:required} + {-url:required} + {-user_id:required} + {-pretty_name} +} { + Returns the URL that allows one to subscribe to a notification type on a particular object. If the + notifications package has not been mounted return the empty string. +} { + set type_id [notification::type::get_type_id -short_name $type] + + set root_path [apm_package_url_from_key [notification::package_key]] + + if { [empty_string_p $root_path] } { + return "" } - ad_proc -public subscribe_url { - {-type:required} - {-object_id:required} - {-url:required} - {-user_id:required} - {-pretty_name} - } { - Returns the URL that allows one to subscribe to a notification type on a particular object. If the - notifications package has not been mounted return the empty string. - } { - set type_id [notification::type::get_type_id -short_name $type] + set subscribe_url [export_vars -base "${root_path}request-new" { type_id user_id object_id pretty_name {return_url $url} }] - set root_path [apm_package_url_from_key [notification::package_key]] + return $subscribe_url +} - if { [empty_string_p $root_path] } { - return "" - } +ad_proc -public notification::display::unsubscribe_url { + {-request_id:required} + {-url:required} +} { + Returns the URL that allows one to unsubscribe from a particular request. +} { + set root_path [apm_package_url_from_key [notification::package_key]] - set subscribe_url "${root_path}request-new?[export_vars { type_id user_id object_id pretty_name {return_url $url} }]" + if { [empty_string_p $root_path] } { + return "" + } - return $subscribe_url + set unsubscribe_url [export_vars -base "${root_path}request-delete" { request_id { return_url $url } }] + + return $unsubscribe_url +} + +ad_proc -public notification::display::get_urls { + {-type:required} + {-object_id:required} + {-return_url {}} + {-pretty_name} +} { + Get both subscribe_url and unsubscribe_url as . + At most one of them will be set. + + Example:
+ foreach { subscribe_url unsubscribe_url } \ + [notification::display::get_urls \ + -type "my_notif_type" \ + -object_id $object_id \ + -pretty_name $title] {}+ + The above foreach trick will cause subscribe_url and unsubscribe_url + to be set correctly. Don't forget the end pair of curly braces. + + @return a Tcl list with two elements (subscribe_url, unsubscribe_url) +} { + set root_path [apm_package_url_from_key [notification::package_key]] + if { [empty_string_p $root_path] } { + return [list {} {}] } + set type_id [notification::type::get_type_id -short_name $type] - ad_proc -public unsubscribe_url { - {-request_id:required} - {-url:required} - } { - Returns the URL that allows one to unsubscribe from a particular request. - } { - set root_path [apm_package_url_from_key [notification::package_key]] + if { [empty_string_p $return_url] } { + set return_url [ad_return_url] + } - if { [empty_string_p $root_path] } { - return "" - } + # Check if subscribed + set request_id [notification::request::get_request_id -type_id $type_id -object_id $object_id -user_id [ad_conn untrusted_user_id]] - set unsubscribe_url "${root_path}request-delete?request_id=$request_id&return_url=[ns_urlencode $url]" - return $unsubscribe_url + if { [empty_string_p $request_id] } { + return [list [export_vars -base "${root_path}request-new" { type_id object_id pretty_name return_url }] {}] + } else { + return [list {} [export_vars -base "${root_path}request-delete" { request_id return_url }]] } } +